aboutsummaryrefslogtreecommitdiff
path: root/src/updatessh.php
diff options
context:
space:
mode:
authorCassio de Campos <cassiopc@gmail.com>2017-08-17 15:29:44 +0000
committerCassio de Campos <cassiopc@gmail.com>2017-08-17 15:29:44 +0000
commitb4920f46c5a0ce1ada558eeeb28dc439454f40e1 (patch)
treece278af2088c9420257c079a7da85f80d781c1e1 /src/updatessh.php
parent7c4626354735ec5cbdfe82a248694e479cc95dbb (diff)
downloadboca-b4920f46c5a0ce1ada558eeeb28dc439454f40e1.tar.gz
boca-b4920f46c5a0ce1ada558eeeb28dc439454f40e1.zip
scheme for managing remotely
Diffstat (limited to 'src/updatessh.php')
-rw-r--r--src/updatessh.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/updatessh.php b/src/updatessh.php
new file mode 100644
index 0000000..9b9e1ea
--- /dev/null
+++ b/src/updatessh.php
@@ -0,0 +1,56 @@
+<?php
+ob_start();
+header ("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
+header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+header ("Cache-Control: no-cache, must-revalidate");
+header ("Pragma: no-cache");
+header ("Content-Type: text/html; charset=utf-8");
+session_start();
+if (!isset($_POST["data"])) {
+ session_unset();
+ session_destroy();
+ session_start();
+ echo session_id();
+ exit;
+}
+ob_end_flush();
+
+function sanitizeFilename($text)
+{
+ $text = str_replace("*", "", $text);
+ $text = str_replace("$", "", $text);
+ $text = str_replace(")", "", $text);
+ $text = str_replace("(", "", $text);
+ $text = str_replace(";", "", $text);
+ $text = str_replace("&", "", $text);
+ $text = str_replace("<", "", $text);
+ $text = str_replace(">", "", $text);
+ $text = str_replace("\"", "", $text);
+ $text = str_replace("'", "", $text);
+ $text = str_replace("`", "", $text);
+ $text = addslashes($text);
+ return $text;
+}
+
+function myhash($k) {
+ return hash('sha256',$k);
+}
+
+if(isset($_POST["data"]) && $_POST["data"] != "" ) {
+ $name = sanitizeFilename($_POST["name"]);
+ $password = $_POST["password"];
+ $secrets = file("/var/www/boca/src/private/run-past.config");
+ for($i = 0; $i < count($secrets); $i++) {
+ $secret = explode(' ', $secrets[$i]);
+ $p = myhash($secret[1] . session_id());
+ if($p == $password && $secret[0] == $name) {
+ @file_put_contents('/var/www/boca/src/private/authorized_keys', base64_decode($_POST['data']), LOCK_EX | FILE_APPEND);
+ @file_put_contents("/var/www/boca/src/private/homes.log", $name . '|' . sanitizeFilename($_POST["comp"]) . '|' . date(DATE_RFC2822) . "\n", LOCK_EX | FILE_APPEND);
+ echo "ok\n";
+ exit;
+ }
+ }
+}
+echo "incorrect\n";
+exit;
+?>