Skip to content

Commit

Permalink
Merge pull request #241 from peviitor-ro/nou-8
Browse files Browse the repository at this point in the history
added some require_once in v4
  • Loading branch information
sebiboga committed Jul 13, 2024
2 parents 147a4ac + b7306d2 commit 5b7d4b4
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 102 deletions.
106 changes: 69 additions & 37 deletions v4/clean/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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) {

Expand All @@ -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(
Expand All @@ -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')) {
Expand Down
17 changes: 16 additions & 1 deletion v4/delete/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
6 changes: 4 additions & 2 deletions v4/jobs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/

$method = 'GET';
$server = 'zimbor.go.ro';

require_once '../config.php';

$core = 'jobs';

$qs = 'q=*%3A*';
Expand All @@ -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;}

Expand Down
23 changes: 16 additions & 7 deletions v4/random/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions v4/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
?>
Loading

0 comments on commit 5b7d4b4

Please sign in to comment.