Compare commits

...

2 commits

Author SHA1 Message Date
Daniel Gröber a8bbdf907a Mandate POST method for ping.php 2022-03-27 18:20:16 +02:00
Daniel Gröber cf570fdeea Move apikeys to config file 2022-03-27 18:20:16 +02:00
4 changed files with 67 additions and 41 deletions

View file

@ -0,0 +1,10 @@
<?php
// api-keys
$config = array(
'ping' => array('key1'),
'ping-get' => array('key2'),
'update' => array('key3'),
);
?>

View file

@ -1,6 +1,10 @@
<?php <?php
require_once('config.inc.php');
$apikeys = $config['ping-get'];
header('Content-type: text/plain'); header('Content-type: text/plain');
if(isset($_GET['apikey']) && ($_GET['apikey']=='apikey1' || $_GET['apikey']=='apikey2')){ if(isset($_GET['apikey']) && in_array($_GET['apikey'], $apikeys, true)) {
$str=file_get_contents('pinged.txt'); $str=file_get_contents('pinged.txt');
echo $str; echo $str;
file_put_contents ( 'pinged.txt' , 'false' ); file_put_contents ( 'pinged.txt' , 'false' );
@ -10,4 +14,3 @@
echo $str; echo $str;
} }
?> ?>

View file

@ -1,12 +1,17 @@
<?php <?php
require_once('config.inc.php');
$apikeys = $config['ping'];
header('Content-type: text/plain'); header('Content-type: text/plain');
if(isset($_GET['apikey']) && ($_GET['apikey']=='apikey1' || $_GET['apikey']=='apikey2')){ if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_GET['apikey']) && in_array($_GET['apikey'], $apikeys, true))
{
file_put_contents ( 'pinged.txt' , 'true' ); file_put_contents ( 'pinged.txt' , 'true' );
echo true; echo $str;
} else { } else {
$str=file_get_contents('pinged.txt'); $str=file_get_contents('pinged.txt');
echo "API Key Missing!\n"; echo "API Key Missing (must be POST method)!\n";
echo $str; echo $str;
} }
?> ?>

View file

@ -1,14 +1,22 @@
<?php <?php
require_once('config.inc.php');
$apikeys = $config['update'];
header('Content-type: text/plain'); header('Content-type: text/plain');
if(isset($_GET['apikey']) && ($_GET['apikey']=='apikey1' || $_GET['apikey']=='apikey2')){ if( isset($_GET['apikey']) && in_array($_GET['apikey'], $apikeys, true) ) {
if(isset($_GET['open']) && $_GET['open']=='true') if(isset($_GET['open']) && $_GET['open']=='true')
{ {
file_put_contents ( 'status.txt' , 'true,'.time() ); file_put_contents ( 'status.txt' , 'true,'.time() );
exec("./open.sh");
echo "true"; echo "true";
}else if(isset($_GET['open']) && $_GET['open'] =='false') } else if(isset($_GET['open']) && $_GET['open'] =='false') {
{
file_put_contents ( 'status.txt' , 'false,'.time() ); file_put_contents ( 'status.txt' , 'false,'.time() );
exec("./close.sh");
echo "false"; echo "false";
}else{
echo "you are too stupid to use the api!\n";
} }
} else { } else {
$str=file_get_contents('status.txt'); $str=file_get_contents('status.txt');
@ -18,5 +26,5 @@
echo "API Key Missing!\n"; echo "API Key Missing!\n";
echo $open; echo $open;
} }
?>
?>