aboutsummaryrefslogtreecommitdiff
path: root/utils/upload.php
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-10-26 00:05:46 +0800
committerKunoiSayami <[email protected]>2022-10-26 00:05:46 +0800
commit685c74c4fa212b132c55be1c91e5b366a3593b83 (patch)
tree25a9aa9024f517ce51107c89e60267fea56f105e /utils/upload.php
parent596fc2317eae72d006e4c528ac3f14c4d9d712e8 (diff)
refactor: Move script out from ng folder
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'utils/upload.php')
-rw-r--r--utils/upload.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/utils/upload.php b/utils/upload.php
new file mode 100644
index 0000000..da848eb
--- /dev/null
+++ b/utils/upload.php
@@ -0,0 +1,35 @@
+<?PHP
+ if (isset($_POST) && isset($_POST['token']) &&
+ $_POST['token'] === 'be688838ca8686e5c90689bf2ab585cef1137c999b48c70b92f67a5c34dc15697b5d11c982ed6d71be1e1e7f7b4e0733884aa97c3f7a339a8ed03577cf74be09';
+ ) {
+ if (!isset($_POST['arch'])) {
+ http_response_code(400);
+ echo "400 Bad Request: Should specify arch field while post files";
+ die();
+ }
+ if (!empty($_FILES['file'])) {
+
+ $path = "/var/www/repo/". $_POST['arch'] . "/";
+ $path = $path . basename($_FILES['file']['name']);
+
+ if (move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
+ echo "The file " . basename( $_FILES['file']['name']) . " has been uploaded";
+ } else {
+ echo "There was an error uploading the file, please try again!";
+ }
+ } else if (isset($_POST['action'])) {
+ if ($_POST['action'] === 'UPLOADED') {
+ $sock = stream_socket_client('unix:///run/update-repo-notify.sock', $errno, $errst);
+ fwrite($sock, "ARCH=". $_POST['arch'] ."\r\n");
+ fclose($sock);
+ echo "200 OK STARTED";
+ } else if ($_POST['action'] === 'REQUIRE_CLEAN') {
+ shell_exec("/usr/bin/rm -rf /var/www/repo/". $_POST['arch'] . "*");
+ shell_exec("/usr/bin/mkdir /var/www/repo/". $_POST['arch']);
+ echo "200 OK CLEANED";
+ }
+ }
+ } else {
+ http_response_code(403);
+ }
+?>