alpha_full/admin/styles/upCompass.php
2026-04-06 22:58:51 +02:00

131 lines
6.0 KiB
PHP
Executable File

<?php
$nomFicAppelant = basename(__FILE__);
// on est sur le front
$arreterCompass=2;
if (isset($_POST['arreterCompass'])) {$arreterCompass=$_POST['arreterCompass'];}
if (!isset($affCompass)) $affCompass='AfficherMessages';
// -----------------------------------------------------
// Traitement
// -----------------------------------------------------
// code a garder : lance une console mais en mode console (argh:!) donc client ?!
// exec("php -r \"exec('konsole');\"");
switch ($arreterCompass) {
case 0:
$admMsg .= 'Arrêter ... ';
// Le traitement est fait plus loin
break;
case 1:
$admMsg .= 'Démarrer ... ';
$filename=$includePathPublication. "/_makeCss/startAutoCompass.log";
$stdout = shell_exec('/bin/sh ../Publication/_makeCss/startAutoCompass.sh 2>&1 | tee -a ' .$filename. ' 2>/dev/null >/dev/null &');
echo "<pre>$stdout</pre>";
// $arreterCompass=2;
break;
case 2:
$admMsg .= 'Demande de statut ... ';
// echo "<pre>$stdout</pre>";
break;
}
$filename=$includePathPublication. "/_makeCss/statutCompass.log";
// shell_exec("echo statut > " .$filename);
shell_exec("ps -ef | grep compass > " .$filename);
// -----------------------------------------------------
// Menu & form ( affCompass = lancement au démarrage )
// -----------------------------------------------------
if ($affCompass!='pasAfficherMessages') {
echo '<div style="margin:auto; width:100%; text-align:center;margin:auto; border:1px solid lightgrey; text-align:center;padding:20px; font-size:1.2rem;" >';
echo '<input type="hidden" action="upCompass.php" name="arreterCompass" id="arreterCompass" value="' .$arreterCompass. '" >';
echo '<span style="margin:auto;display:flex;justify-content: space-around;width:50%;" >';
echo '<span style="display:flex;flex-direction:column;" onClick="document.getElementById(\'arreterCompass\').value=0;document.menuSiteForm.submit();" >';
echo '<span class="boutonsWebmaster" style="width:100%;padding:15px;line-height:5px;">Arrêter</span>';
// echo '<span><a href="' .$includePathPublication. '"/_makeCss/stopCompass.log">stopCompass.log</a></span>';
echo '</span>';
echo '<span style="display:flex;flex-direction:column;" style="width:100%;padding:8px;" onClick="document.getElementById(\'arreterCompass\').value=1;document.menuSiteForm.submit();" >';
echo '<span class="boutonsWebmaster" style="width:100%;padding:15px;line-height:5px;">Démarrer</span>';
// echo '<span> <a href="' .$includePathPublication. '"/_makeCss/startCompass.log">startAutoCompass.log</a></span>';
echo '</span>';
echo '<span style="display:flex;flex-direction:column;" onClick="document.getElementById(\'arreterCompass\').value=2;document.menuSiteForm.submit();" >';
echo '<span class="boutonsWebmaster" style="width:100%;padding:15px;line-height:5px;">Statut</span>';
// echo '<span> <a href="' .$includePathPublication. '"/_makeCss/statutCompass.html">statutCompass.log</a></span>';
echo '</span>';
echo '</span>';
}
// -----------------------------------------------------
// En fait, dans tous les cas on lance
// ------------------------------------------------
$filename=$includePathPublication. "/_makeCss/statutCompass.log";
if ($handle = fopen($filename, "r")) {
echo '<div style="width:100%; text-align:left; margin:auto; border:0px solid grey; padding:20px; font-size:1.3rem;" >';
if (filesize($filename) >0) {
$indexBuffer = fread($handle, filesize($filename));
fclose($handle);
$filename2="../Publication/_makeCss/stopCompass.log";
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['lecture du fichier' => $filename], '');}
$trouve=false;
// Read in entire file
$lines = file($filename);
$nbLignes=0;
foreach ($lines as $line) {
// if ($arreterCompass==0) {
// $test=false;
// $test=strpos($line,'php');
// if ($test!==false) {
// $line=str_replace ( 'wwwrun ','',$line);
// $line=str_replace ( 'root','',$line);
// $line=trim($line);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['line' => $line], '');}
// $psID=substr($line,0,5);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['id process (php)' => $psID], '');}
// $trouve=true;
// if ($arreterCompass==0) {
// shell_exec("kill -9 " .$psID. " >> " .$filename2);
// // shell_exec("sudo kill -9 " .$psID. " >> " .$filename2);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['= kill -9' => $psID, ' >>' => $filename2)], '');}
// }
// // exec ('php -r "exec (\'sudo kill -9 ' .$psID. ' >> ' .$filename2. ';\')"');
// // echo ' php -r "exec (\'sudo kill -9 ' .$psID. ' >> ' .$filename2. ';\')"';
// }
$test=false;
$test=strpos($line,'watch');
if ($test!==false) {
$line=str_replace ( 'wwwrun ','',$line);
$line=str_replace ( 'root','',$line);
$line=trim($line);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['line' => $line], '');}
$psID=substr($line,0,5);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['id process (watch)' => $psID], '');}
$trouve=true;
if ($arreterCompass==0) {
shell_exec("/bin/kill -9 " .$psID. " >> " .$filename2);
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['= kill -9' => $psID, ' >' => ''], '');}
}
}
// }
// echo 'ligne=' .$lines;
// echo '<br>test' .$test;
// $line=str_replace ( '/datas/07Prod/wwwRoot/','/',$line);
// echo '<br>&#160;arreterCompass => ' .$arreterCompass;
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['&#160;' => $line], '');}
} //for
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['psID' => $psID], '');}
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['&#160;Le moteur compass est inactif' => ''], '');}
} //file size
echo '<div>';
} //handle
?>