From b7306d2505db47fe90a5c3dac4b4fdcf9f7fbfc7 Mon Sep 17 00:00:00 2001 From: ale23yfm Date: Fri, 12 Jul 2024 23:01:31 +0300 Subject: [PATCH] added some require_once in v4 --- v4/clean/index.php | 106 ++++++++++++++++++++++------------- v4/delete/index.php | 17 +++++- v4/jobs/index.php | 6 +- v4/random/index.php | 23 +++++--- v4/search/index.php | 9 ++- v4/update/index.php | 131 ++++++++++++++++++++++++++------------------ 6 files changed, 190 insertions(+), 102 deletions(-) diff --git a/v4/clean/index.php b/v4/clean/index.php index 706f5bf..d987a6b 100644 --- a/v4/clean/index.php +++ b/v4/clean/index.php @@ -2,13 +2,22 @@ header("Access-Control-Allow-Origin: *"); - function validate_api_key($key) { +function validate_api_key($key) { $method = 'GET'; - $server = 'http://zimbor.go.ro/solr/'; + + require_once '../config.php'; + $core = 'auth'; $command ='/select'; - $qs = '?q.op=OR&q=apikey%3A"'.$key.'"&rows=0'; - $url = $server.$core.$command.$qs; + + $qs = '?'; + $qs = $qs . 'q.op=OR'; + $qs = $qs . '&'; + $qs = $qs . 'q=apikey%3A"'; + $qs = $qs . $key; + $qs = $qs . '"&rows=0'; + + $url = 'http://' . $server . '/solr/' . $core . $command . $qs; $options = array( 'http' => array( @@ -17,25 +26,38 @@ function validate_api_key($key) { 'content' => $data ) ); + $context = stream_context_create($options); $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } + $json = json_decode($result); + $y = $json->response->numFound; - $y = $json->response->numFound; if ($y==1) {$x = true;} if ($y==0) {$x = false;} - return $x; - } + + return $x; +} - function get_user_from_api_key($key) { +function get_user_from_api_key($key) { $method = 'GET'; - $server = 'http://zimbor.go.ro/solr/'; + + require_once '../config.php'; + $core = 'auth'; $command ='/select'; - $qs = '?q.op=OR&q=apikey%3A"'.$key.'"&rows=1'; - $url = $server.$core.$command.$qs; + + $qs = '?'; + $qs = $qs . 'q.op=OR'; + $qs = $qs . '&'; + $qs = $qs . 'q=apikey%3A"'; + $qs = $qs . $key; + $qs = $qs . '"&rows=1'; + + $url = 'http://' . $server . '/solr/' . $core . $command . $qs; $options = array( 'http' => array( @@ -44,32 +66,35 @@ function get_user_from_api_key($key) { 'content' => $data ) ); + $context = stream_context_create($options); $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } + $json = json_decode($result); + $y = $json->response->numFound; - $y = $json->response->numFound; if ($y==1) {$x = $json->response->docs[0]->id;} if ($y==0) {$x = false;} - return $x; - } + + return $x; +} - function get_company($token) { - $x=$company = $_POST['company']; +function get_company($token) { + $x=$company = $_POST['company']; return $x; - } +} - function company_exist($company) { +function company_exist($company) { $url = 'https://api.peviitor.ro/v0/search/?indent=true&q.op=OR&q=company%3A%22'.$company.'%22&rows=0&useParams='; $string = file_get_contents($url); $json = json_decode($string, true); if ($json['response']['numFound']==0) {return "new";} if ($json['response']['numFound']!=0) {return "existing";} - - } +} function discord_webhook($msg) { @@ -86,29 +111,35 @@ function discord_webhook($msg) { 'content' => $data ) ); + $context = stream_context_create($options); $result = file_get_contents($url, false, $context); - if ($result === FALSE) { /* Handle error */ } - - } + if ($result === FALSE) { /* Handle error */ } +} +function clean($xcompany,$key) { + $method = 'POST'; - function clean($xcompany,$key) { + require_once '../config.php'; - - $method = 'POST'; - $server = 'http://zimbor.go.ro/solr/'; $core = 'jobs'; $command ='/update'; - $qs = '?_=1617366504771&commitWithin=100&overwrite=true&wt=json'; + + $qs = '?'; + $qs = $qs . '_=1617366504771'; + $qs = $qs . '&'; + $qs = $qs . 'commitWithin=100'; + $qs = $qs . '&'; + $qs = $qs . 'overwrite=true'; + $qs = $qs . '&'; + $qs = $qs . 'wt=json'; $data = "{'delete': {'query': 'company:"; - $data.=$xcompany; + $data.=$xcompany; $data.="'}}"; //echo $data; - $options = array( 'http' => array( @@ -117,22 +148,23 @@ function clean($xcompany,$key) { 'content' => $data ) ); + $msg=''; + if (company_exist($xcompany)=="new") {$msg.="!!! COMPLETELY NEW !!!";} + $msg .= $xcompany.' user: '.get_user_from_api_key($key); discord_webhook($msg); $context = stream_context_create($options); - - $url = $server.$core.$command.$qs; + $url = 'http://' . $server . '/solr/' . $core . $command . $qs; + $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } - - - } +} - - // endpoint starts here +// endpoint starts here foreach (getallheaders() as $name => $value) { if (($name=='apikey')) { diff --git a/v4/delete/index.php b/v4/delete/index.php index 9fde4bd..3c073cc 100644 --- a/v4/delete/index.php +++ b/v4/delete/index.php @@ -17,7 +17,22 @@ } // Solr endpoint URL -$solrEndpoint = 'http://zimbor.go.ro/solr/jobs/update?_=1617366504771&commitWithin=100&overwrite=true&wt=json'; + +require_once '../config.php'; + +$core = 'jobs'; +$command = '/update'; + +$qs = '?'; +$qs = $qs . '_=1617366504771'; +$qs = $qs . '&'; +$qs = $qs . 'commitWithin=100'; +$qs = $qs . '&'; +$qs = $qs . 'overwrite=true'; +$qs = $qs . '&'; +$qs = $qs . 'wt=json'; + +$solrEndpoint = 'http://' . $server . '/solr/' . $core . $command . $qs; // Create an array to store the delete operations $deleteOperations = []; diff --git a/v4/jobs/index.php b/v4/jobs/index.php index 2a24cfd..1815ddb 100644 --- a/v4/jobs/index.php +++ b/v4/jobs/index.php @@ -17,7 +17,9 @@ */ $method = 'GET'; -$server = 'zimbor.go.ro'; + +require_once '../config.php'; + $core = 'jobs'; $qs = 'q=*%3A*'; @@ -26,7 +28,7 @@ $qs = $qs . '&'; $qs = $qs . 'omitHeader=true'; -$url = 'http://' . $server . '/solr/' . '/select?' . $qs; +$url = 'http://' . $server . '/solr/' . $core . '/select?' . $qs; if (isset($_GET["start"])) {$start=$_GET["start"];$qs.="&start=".$start;} diff --git a/v4/random/index.php b/v4/random/index.php index 8b36e68..2850681 100644 --- a/v4/random/index.php +++ b/v4/random/index.php @@ -11,27 +11,36 @@ * ) */ -$server = 'zimbor.go.ro'; -$core = 'jobs'; //production +require_once '../config.php'; + +$core = 'jobs'; + $qs = '?'; -$qs = $qs . 'q=' . urlencode('*:*'); +$qs = $qs . 'q='; +$qs = $qs . urlencode('*:*'); $qs = $qs . '&'; $qs = $qs . 'rows=0'; -$url = 'http://' .$server .'/solr/' . $core . '/select' . $qs; + +$url = 'http://' . $server . '/solr/' . $core . '/select' . $qs; + $string = file_get_contents($url); $json = json_decode($string, true); $max = $json['response']['numFound']; $start = rand(0, $max-1); -$qs = '?q=' . urlencode('*:*'); //query string + +$qs = '?'; +$qs = $qs . 'q='; +$qs = $qs . urlencode('*:*'); $qs = $qs . '&'; $qs = $qs . 'rows=1'; $qs = $qs . '&'; -$qs = $qs . 'start=' . $start; +$qs = $qs . 'start='; +$qs = $qs . $start; $qs = $qs . '&'; $qs = $qs . 'omitHeader=true'; -$url = 'http://' .$server .'/solr/' . $core . '/select' . $qs; +$url = 'http://' . $server . '/solr/' . $core . '/select' . $qs; $json = file_get_contents($url); echo $json; diff --git a/v4/search/index.php b/v4/search/index.php index f687cc1..2c30378 100644 --- a/v4/search/index.php +++ b/v4/search/index.php @@ -13,9 +13,12 @@ $q .= "&start=".$start; } -$server = 'zimbor.go.ro'; -$core = 'jobs'; //production -$url = 'http://' .$server .'/solr/' . $core . '/select/?' . $q; +require_once '../config.php'; + +$core = 'jobs'; + +$url = 'http://' . $server . '/solr/' . $core . '/select/?' . $q; + $json = file_get_contents($url); echo $json; ?> \ No newline at end of file diff --git a/v4/update/index.php b/v4/update/index.php index 7605ce1..19bab02 100644 --- a/v4/update/index.php +++ b/v4/update/index.php @@ -2,15 +2,21 @@ header("Access-Control-Allow-Origin: *"); - function validate_api_key($key) { +function validate_api_key($key) { $method = 'GET'; - - $server = 'http://zimbor.go.ro/solr/'; + + require_once '../config.php'; + $core = 'auth'; $command ='/select'; - $qs = '?q.op=OR&q=apikey%3A"'.$key.'"&rows=0'; + + $qs = '?'; + $qs = $qs . 'q.op=OR'; + $qs = $qs . '&'; + $qs = $qs . 'q=apikey%3A"'; + $qs = $qs . $key; + $qs = $qs . '"&rows=0'; - $options = array( 'http' => array( 'header' => "Content-type: application/json\r\n", @@ -18,28 +24,40 @@ function validate_api_key($key) { 'content' => $data ) ); + $context = stream_context_create($options); - $url = $server.$core.$command.$qs; + + $url = 'http://' . $server . '/solr/' . $core . $command . $qs; + $result = file_get_contents($url, false, $context); if ($result === FALSE) { /* Handle error */ } $json = json_decode($result); - - $y = $json->response->numFound; + $y = $json->response->numFound; + if ($y==1) {$x = true;} if ($y==0) {$x = false;} - return $x; - } + + return $x; +} - function get_user_from_api_key($key) { +function get_user_from_api_key($key) { $method = 'GET'; - - $server = 'http://zimbor.go.ro/solr/'; + + require_once '../config.php'; + $core = 'auth'; $command ='/select'; - $qs = '?q.op=OR&q=apikey%3A"'.$key.'"&rows=1'; - $url = $server.$core.$command.$qs; + + $qs = '?'; + $qs = $qs . 'q.op=OR'; + $qs = $qs . '&'; + $qs = $qs . 'q=apikey%3A"'; + $qs = $qs . $key; + $qs = $qs . '"&rows=1'; + + $url = 'http://' . $server . '/solr/' . $core . $command . $qs; $options = array( 'http' => array( @@ -48,20 +66,24 @@ function get_user_from_api_key($key) { 'content' => $data ) ); + $context = stream_context_create($options); $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } - $json = json_decode($result); - $y = $json->response->numFound; + $json = json_decode($result); + $y = $json->response->numFound; + if ($y==1) {$x = $json->response->docs[0]->id;} if ($y==0) {$x = false;} - return $x; - } + + return $x; +} - function get_company($token) { - $x=$company = $_POST['company']; - return $x; +function get_company($token) { + $x = $company = $_POST['company']; + return $x; } @@ -80,42 +102,46 @@ function discord_webhook($msg) { ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } - - } + +} - function update($key) { - + +function update($key) { + $method = 'POST'; + require_once '../config.php'; - $method = 'POST'; - $server = 'http://zimbor.go.ro/solr/'; $core = 'jobs'; $command ='/update'; - $qs = '?_=1617366504771&commitWithin=1000&overwrite=true&wt=json'; - - + + $qs = '?'; + $qs = $qs . '_=1617366504771'; + $qs = $qs . '&'; + $qs = $qs . 'commitWithin=1000'; + $qs = $qs . '&'; + $qs = $qs . 'overwrite=true'; + $qs = $qs . '&'; + $qs = $qs . 'wt=json'; $data = file_get_contents('php://input'); $json = json_decode($data); foreach ($json as $item) { - - $item->job_title = html_entity_decode($item->job_title); - $item->country = str_replace("Romania","România",$item->country); + $item->job_title = html_entity_decode($item->job_title); + $item->country = str_replace("Romania","România",$item->country); $item->city = str_replace("Cluj Napoca","Cluj-Napoca",$item->city); $item->city = str_replace("Bucharest","București",$item->city); $item->city = str_replace("Bucuresti","București",$item->city); - $item->id = md5($item->job_link).""; - $company = $item->company; + $item->id = md5($item->job_link).""; + $company = $item->company; } $data = json_encode($json); - - $options = array( 'http' => array( 'header' => "Content-type: application/json\r\n", @@ -123,29 +149,30 @@ function update($key) { 'content' => $data ) ); + $msg = $company.' user: '.get_user_from_api_key($key); discord_webhook($msg); $context = stream_context_create($options); - - $url = $server.$core.$command.$qs; - $result = file_get_contents($url, false, $context); + $url = 'http://' . $server . '/solr/' . $core . $command . $qs; + + $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } - var_dump($result); - } +} - // endpoint starts here +// endpoint starts here - foreach (getallheaders() as $name => $value) { - if (($name=='apikey')) { - if (validate_api_key($value)==true) - { +foreach (getallheaders() as $name => $value) { + if (($name=='apikey')) { + if (validate_api_key($value)==true) + { - update($value); - } else {echo "apikey error";} - } - } + update($value); + } else {echo "apikey error";} + } +} ?> \ No newline at end of file