From 8b2fedf630c9b8438f7c17356ca526f1e4e53c5c Mon Sep 17 00:00:00 2001 From: dmd2222 Date: Fri, 4 Dec 2020 18:21:17 +0100 Subject: [PATCH] I did it https://github.com/dmd2222 on 04.12.2020 at 18:21:17,72 --- api/external_ping_api/0.1/README | 8 ++- api/external_ping_api/0.1/data/1.txt | 1 + api/external_ping_api/0.1/data/2.txt | 1 + api/external_ping_api/0.1/data/test1.txt | 1 - api/external_ping_api/0.1/index.php | 79 ++++++++++++++++++++++++ api/external_ping_api/0.1/keyit.php | 5 +- 6 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 api/external_ping_api/0.1/data/1.txt create mode 100644 api/external_ping_api/0.1/data/2.txt delete mode 100644 api/external_ping_api/0.1/data/test1.txt diff --git a/api/external_ping_api/0.1/README b/api/external_ping_api/0.1/README index 2678e8c8..95243774 100644 --- a/api/external_ping_api/0.1/README +++ b/api/external_ping_api/0.1/README @@ -28,5 +28,11 @@ Search string/pattern = "Last update" +There is additional: -Best regards M.S. \ No newline at end of file +You can also use the i=getall&iv=1 GET call, +it returns the status of all monitored index_values (or tokens). + + +Best regards +https://github.com/dmd2222 diff --git a/api/external_ping_api/0.1/data/1.txt b/api/external_ping_api/0.1/data/1.txt new file mode 100644 index 00000000..301f987e --- /dev/null +++ b/api/external_ping_api/0.1/data/1.txt @@ -0,0 +1 @@ +1607102400 \ No newline at end of file diff --git a/api/external_ping_api/0.1/data/2.txt b/api/external_ping_api/0.1/data/2.txt new file mode 100644 index 00000000..77d2e638 --- /dev/null +++ b/api/external_ping_api/0.1/data/2.txt @@ -0,0 +1 @@ +1607102327 \ No newline at end of file diff --git a/api/external_ping_api/0.1/data/test1.txt b/api/external_ping_api/0.1/data/test1.txt deleted file mode 100644 index 33d92310..00000000 --- a/api/external_ping_api/0.1/data/test1.txt +++ /dev/null @@ -1 +0,0 @@ -1607042212 \ No newline at end of file diff --git a/api/external_ping_api/0.1/index.php b/api/external_ping_api/0.1/index.php index 50573f3c..75e77068 100644 --- a/api/external_ping_api/0.1/index.php +++ b/api/external_ping_api/0.1/index.php @@ -71,6 +71,13 @@ switch ($index) { throw new Exception('run_get function failed.'); } break; + case "getall": + //GET_ALL + if (run_get_all($old_time_definition)==true){}else{ + //Error + throw new Exception('run_get function failed.'); + } + break; case "set": //SET if (run_set($index_value)==true){}else{ @@ -155,6 +162,78 @@ function run_get($index_value, $old_time_definition){ } + +function run_get_all($old_time_definition){ + + //make HTML comment + echo ""; + + + //Prepare result_text + $result_text=""; + + // generate file path for every file in folder + foreach(glob('data/*.txt') as $file) { + + + + //Open File + $information_file = read_from_file($file); + + //Get now timestamp + $date = new DateTime(); + $timestamp_now = $date->getTimestamp(); + + //calculate time diff + $time_diff = $timestamp_now - $information_file ; + + + // Check if older than + if ($information_file + ($old_time_definition) < $timestamp_now){ + + + + //Last updtae is older than x time + $result_text= $result_text . $file . " Older than " . $old_time_definition . "sec. Timediff: " . $time_diff . " sec." . "
" ; + + + } + + + + +//Secure file +secure_file($file); + + + + } + + + //Check if every index_value / token is up to date + if($result_text ==""){ + //all up to date + // Last update is NOT older than x time + echo "Last update done. All index_values or tokens are up to date."; + + }else{ + //nor all are up to date + echo $result_text; + } + + + + + +//giveback ok +return true; + + +} + + + + function run_set($index_value){ //make HTML comment echo ""; diff --git a/api/external_ping_api/0.1/keyit.php b/api/external_ping_api/0.1/keyit.php index 8e4a0feb..68e8b2f4 100644 --- a/api/external_ping_api/0.1/keyit.php +++ b/api/external_ping_api/0.1/keyit.php @@ -29,7 +29,7 @@ include_once("config.php"); if (file_exists($filename)) { - $key = $_GET[$key_name]; + $key = check_and_give_me_get_input($key_name); //open file and read it $myfile = fopen($filename, "r") or die("keyit.php: 1 Unable to open file!"); @@ -188,4 +188,7 @@ function sendmailtorecipients($contacts_array,$subject,$message,$output=false){ return ((empty($_SERVER['HTTPS'])) ? 'http' : 'https') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } + + + ?> \ No newline at end of file