„vm_control.php“ hinzufügen
This commit is contained in:
parent
566bc9c5eb
commit
1cb99aa4ef
1 changed files with 69 additions and 0 deletions
69
vm_control.php
Normal file
69
vm_control.php
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
// Filename: /volume3/web/updateserver.php
|
||||||
|
// Aufruf-URL: https://example.com/vm_control.php?vmname= &state=[on|off] &key=
|
||||||
|
|
||||||
|
// vmname= Name der VM wie im VMM angegeben (wahrscheinlich sind hier einige Sonderzeichen ungünstig)
|
||||||
|
// state= gewünschter Zustand der VM: on / off
|
||||||
|
// key= ein kleiner Schutz, damit nicht jeder, der die Steuerung übernehmen kann
|
||||||
|
|
||||||
|
// zu überprüfenden Key hier anpassen:
|
||||||
|
$defined_key = "0815";
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// Auswertung der Argumente:
|
||||||
|
// -----------------------------------------------
|
||||||
|
// leeren Parameter 'vmname' unterbinden:
|
||||||
|
if(!isset($_GET['vmname'])){
|
||||||
|
exit("EXIT - keine VM angegeben!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// Statusdatei inistialisieren:
|
||||||
|
touch ('vm_state.php');
|
||||||
|
|
||||||
|
$fp = fopen ('vm_state.php', 'r+');
|
||||||
|
// Konnte die Datei nicht öffnen!:
|
||||||
|
if (!is_resource ($fp)) {
|
||||||
|
http_response_code(503);
|
||||||
|
die ();
|
||||||
|
}
|
||||||
|
// Sperren der Datei fehlgeschlagen!:
|
||||||
|
if (!flock ($fp, LOCK_EX)) {
|
||||||
|
http_response_code(503);
|
||||||
|
die ();
|
||||||
|
}
|
||||||
|
include("vm_state.php");
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// letzten Zugriff dokumentieren:
|
||||||
|
$vm_state["letzter Zugriff:"] = "VM: ".$_GET['vmname']." / Status: ".$_GET['state']." / Key: ".$_GET['key']." / Zeitpunkt: ".date("Y-m-d_H-i-s", time());
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// check Key:
|
||||||
|
if(strcmp($_GET['key'], "$defined_key")) {
|
||||||
|
exit("Zugriff verweigert");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// schreibe Status in Array:
|
||||||
|
$vm_state[$_GET['vmname']] = $_GET['state'];
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// Daten speichern:
|
||||||
|
fseek ($fp, 0, SEEK_SET);
|
||||||
|
ftruncate ($fp, 0);
|
||||||
|
$input = "<?php\n";
|
||||||
|
$input .= "\$vm_state = ".var_export($vm_state, true).";\n";
|
||||||
|
$input .= "?>";
|
||||||
|
fwrite($fp, $input);
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// Datei freigeben
|
||||||
|
flock ($fp, LOCK_UN);
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
// -----------------------------------------------
|
||||||
|
// Rückgabe:
|
||||||
|
exit("Status notiert ...");
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in a new issue