add cpu power mode
This commit is contained in:
@@ -1423,3 +1423,95 @@ if ($type == "detect_envea_device") {
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
____ ____ _ _ ____ __ __ _
|
||||
/ ___| _ \| | | | | _ \ _____ _____ _ _| \/ | __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_
|
||||
| | | |_) | | | | | |_) / _ \ \ /\ / / _ \ '__| |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __|
|
||||
| |___| __/| |_| | | __/ (_) \ V V / __/ | | | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_
|
||||
\____|_| \___/ |_| \___/ \_/\_/ \___|_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__|
|
||||
|___/
|
||||
*/
|
||||
|
||||
// Get current CPU power mode
|
||||
if ($type == "get_cpu_power_mode") {
|
||||
try {
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/power/set_cpu_mode.py get 2>&1';
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Try to parse JSON output
|
||||
$result = json_decode($output, true);
|
||||
|
||||
if ($result && isset($result['success']) && $result['success']) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'mode' => $result['config_mode'] ?? 'unknown',
|
||||
'cpu_state' => $result['cpu_state'] ?? null
|
||||
], JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Failed to get CPU power mode',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Script execution failed: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Set CPU power mode
|
||||
if ($type == "set_cpu_power_mode") {
|
||||
$mode = $_GET['mode'] ?? null;
|
||||
|
||||
if (empty($mode)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'No mode specified'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate mode (whitelist)
|
||||
$allowedModes = ['normal', 'powersave'];
|
||||
|
||||
if (!in_array($mode, $allowedModes)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Invalid mode. Allowed: normal, powersave'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Execute the CPU power mode script
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/power/set_cpu_mode.py ' . escapeshellarg($mode) . ' 2>&1';
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Try to parse JSON output
|
||||
$result = json_decode($output, true);
|
||||
|
||||
if ($result && isset($result['success']) && $result['success']) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'mode' => $mode,
|
||||
'message' => "CPU power mode set to: $mode",
|
||||
'description' => $result['description'] ?? ''
|
||||
], JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => $result['error'] ?? 'Failed to set CPU power mode',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Script execution failed: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user