aboutsummaryrefslogtreecommitdiff
path: root/utils/ng/upload.php
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-10-25 22:12:18 +0800
committerKunoiSayami <[email protected]>2022-10-25 22:12:18 +0800
commit125ebfac956440f3a26e160a02d0c54c402a7bca (patch)
treeeae012a8cfb277f7f7649d2a9dc6705bb43130e1 /utils/ng/upload.php
parentdf89a33152cf430fdc6fca0a70f47e60a5ea1ef7 (diff)
feat(script): Add upload rated scripts
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'utils/ng/upload.php')
-rw-r--r--utils/ng/upload.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/utils/ng/upload.php b/utils/ng/upload.php
new file mode 100644
index 0000000..fc60a61
--- /dev/null
+++ b/utils/ng/upload.php
@@ -0,0 +1,38 @@
+<?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";
+ $sock = stream_socket_client('unix:///run/update-repo-notify.sock', $errno, $errst);
+ fwrite($sock, $['file']['name']."\r\n");
+ fclose($sock);
+ } 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, "EOF\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);
+ }
+?>