From cf570fdeead27b5c68529dc4e2110c0a3eb1a4ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sun, 27 Mar 2022 18:19:55 +0200 Subject: [PATCH] Move apikeys to config file --- server/config.inc.php.example | 10 ++++++++ server/ping-get.php | 25 ++++++++++-------- server/update.php | 48 ++++++++++++++++++++--------------- 3 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 server/config.inc.php.example diff --git a/server/config.inc.php.example b/server/config.inc.php.example new file mode 100644 index 0000000..d55735f --- /dev/null +++ b/server/config.inc.php.example @@ -0,0 +1,10 @@ + array('key1'), + 'ping-get' => array('key2'), + 'update' => array('key3'), +); + +?> diff --git a/server/ping-get.php b/server/ping-get.php index 4199aff..5985715 100644 --- a/server/ping-get.php +++ b/server/ping-get.php @@ -1,13 +1,16 @@ +require_once('config.inc.php'); +$apikeys = $config['ping-get']; + +header('Content-type: text/plain'); +if(isset($_GET['apikey']) && in_array($_GET['apikey'], $apikeys, true)) { + $str=file_get_contents('pinged.txt'); + echo $str; + file_put_contents ( 'pinged.txt' , 'false' ); +} else { + $str=file_get_contents('pinged.txt'); + echo "API Key Missing!\n"; + echo $str; +} +?> diff --git a/server/update.php b/server/update.php index 02aa585..8494869 100755 --- a/server/update.php +++ b/server/update.php @@ -1,22 +1,30 @@ +require_once('config.inc.php'); + +$apikeys = $config['update']; + +header('Content-type: text/plain'); +if( isset($_GET['apikey']) && in_array($_GET['apikey'], $apikeys, true) ) { + if(isset($_GET['open']) && $_GET['open']=='true') + { + file_put_contents ( 'status.txt' , 'true,'.time() ); + exec("./open.sh"); + echo "true"; + } else if(isset($_GET['open']) && $_GET['open'] =='false') { + file_put_contents ( 'status.txt' , 'false,'.time() ); + exec("./close.sh"); + echo "false"; + }else{ + echo "you are too stupid to use the api!\n"; + } +} else { + $str=file_get_contents('status.txt'); + $arr=explode(',',$str); + $open=$arr[0]; + $date=$arr[1]; //lastchange: upadate via file see explode/implode + echo "API Key Missing!\n"; + echo $open; +} + +?>