Files
assetmgt/cronjob.php
2024-11-27 09:42:49 +01:00

122 lines
4.0 KiB
PHP

<?php
define('secure_34563$52', true);
include_once './assets/functions.php';
include_once './settings/settings.php';
include_once './settings/config.php';
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// check for security_code if not exit +++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (isset($_GET['code']) && $_GET['code'] != '') {
$test = $_GET['code'] / cronjob_number;
if ($test !== 1){
//EXIT IF CODE DOES NOT EQUAL 1
http_response_code(404);
exit;
} }
else {
//EXIT IF NOT CODE IS SEND
http_response_code(404);
exit;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// CODE IS CORRECT +++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//CONNECT TO DB
$pdo = dbConnect($dbname);
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SEND FIRMWARE COMMUNICATION TO END-USER ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$sql = 'SELECT rowID, email FROM communication WHERE type_1 = 1 AND send_indicator = 1 LIMIT 0,15';
$stmt = $pdo->prepare($sql);
$stmt->execute();
$communications = $stmt->fetchAll(PDO::FETCH_ASSOC);
//ITERATE OVER RESULTS
foreach ($communications as $communication){
$to = $communication['email'];
include './assets/mail/email_template_firmware.php';
send_mail($to,$subject,$message,'','');
//UPDATE COMMUNICATION RECORD
$sql = 'UPDATE communication SET send_indicator = 0, send = ? WHERE rowID = ?';
$stmt = $pdo->prepare($sql);
$stmt->execute([$date,$communication['rowID']]);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// END FIRMWARE COMMUNICATION TO END-USER ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// getUserkey ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$token ='';
$data = json_encode(array("username" => interface_user, "password" => interface_pw), JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v1/authorization', $payload);
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = '400';}
if ($responses === 'NOK' || $responses === '400'){
//Not allowed
http_response_code(403);
exit;
}
else {
// Store data in session
$token = $responses->userkey;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Contracts ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
//close contracts past due
closeContract();
//block contract where usage limit is reached
//blockContracts($token);
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Machine learning ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$total_measurement = traintotalMeasurement();
$total_results = statisticalAnalyses($total_measurement);
//update Productversions
storeMeasurementProduct($total_results, $token);
//update Equipment data
storeMeasurementEquipment('');
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// GeoUpdate ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
geolocationUpdate($token);
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Debuglog ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
if (debug){
$time_elapsed = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
$message = $date.';cronjob;'.$time_elapsed.';interface';
debuglog($message);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// EXIT ++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
http_response_code(200);
exit;