From 6f35e199702448d80171181cc01a857cbca872d9 Mon Sep 17 00:00:00 2001 From: Anthony Borghi <anthony.borghi@veremes.com> Date: Mon, 3 Dec 2018 11:18:28 +0100 Subject: [PATCH] Squashed 'src/module_gtf/' changes from 73d00dca..d7bf5b35 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit d7bf5b35 merge file fd04f40f pull subtree af461eb9 Modification de la manière de modifier le crontab sur Linux pour éviter de donner des droits particulier f5030f47 add subtree d2cf5d0d add subtree c56f5a1d Squashed 'src/closure/' content from commit 622066d 65247182 add subtree 82408f30 Squashed 'src/vitis/' content from commit 355b5f8 83cce5ca Reset sources 7fb843da set dependency.xml 1d571171 Merge branch 'master' into next_version bbab977f Change __DIR__ by dirname($_SERVER['SCRIPT_FILENAME']) b1438204 update app template c5717edc Update readme 2d488f46 add subtree 10346dce Squashed 'src/module_gtf/' content from commit 9c28fdd 9c2ebb7c add subtree 98fcb48d Squashed 'src/closure/' content from commit 622066d a7f230ce add subtree be874a23 Squashed 'src/vitis/' content from commit 01d199c 6c1b3e3c Reset sources a195a4d9 Init from SVN 4ad29c4b add subtree 1ac46cd9 Squashed 'src/closure/' content from commit 622066d 635a2f96 add subtree 7593c383 Squashed 'src/vitis/' content from commit 01d199c b487cd6f Update from SVN 266e19a6 Initial commit 4d8d920c Update from SVN fb0113e7 Update from SVN git-subtree-dir: src/module_gtf git-subtree-split: d7bf5b354feb1386bb8bbae04ca261b31940f132 --- web_service/ws/ServerClass.class.inc | 419 ++++++++++++++------------- 1 file changed, 224 insertions(+), 195 deletions(-) diff --git a/web_service/ws/ServerClass.class.inc b/web_service/ws/ServerClass.class.inc index 8eb898ae..ccae65b8 100755 --- a/web_service/ws/ServerClass.class.inc +++ b/web_service/ws/ServerClass.class.inc @@ -1,196 +1,225 @@ -<?php - -require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/dbUtil.inc'; -require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/logUtil.inc'; - -class ServerClass { - - //Chemin du fichier crontab - var $sCrontabFile; - //Id du server - var $iId; - //Nom du server - var $sServerName; - //Ancien nom du server - var $sOldServerName; - //Répertoire racine - var $sGtfHome; - //Répertoire Engines - var $EnginesHome; - //Objet de labase de données - var $oBd; - - function __construct($iId, $oBd, $sGtfHome, $sOldServerName = "", $aProperties = array()) { - $this->iId = $iId; - $this->oBd = $oBd; - $this->sOldServerName = $sOldServerName; - $this->sGtfHome = $sGtfHome; - $this->aProperties = $aProperties; - $this->setValues($iId); - } - - function setValues($iId) { - if ($iId != "") { - $sSql = 'SELECT scheduler_network_home, hostname, engines_home FROM ' . $this->aProperties['schema_gtf'] . '.server where server_id=[iIdServer]'; - $aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number'); - $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); - $oServer = $this->oBd->objetSuivant($oPDOresult); - $this->sCrontabFile = $oServer->scheduler_network_home; - $this->sServerName = $oServer->hostname; - $this->EnginesHome = $oServer->engines_home; - if ($this->sOldServerName == "") { - $this->sOldServerName = $this->sServerName; - } - } - } - - function deleteCrontabValuesEngine() { - $aValuesPycronNewFile = Array(); - if (is_file($this->sCrontabFile)) { - $aPycronValues = file($this->sCrontabFile); - $bWrite = true; - foreach ($aPycronValues as $sPycronValue) { - $sPycronValue = str_replace("\n", "", $sPycronValue); - $sPycronValue = str_replace("\r", "", $sPycronValue); - if ($sPycronValue == "#<gtf_engines " . gethostname() . " " . $this->sGtfHome . ">") { - - $bWrite = false; - } else if ($sPycronValue == "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">") { - $bWrite = true; - } - if ($bWrite == true && $sPycronValue != "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">") { - $aValuesPycronNewFile[] = $sPycronValue; - } - } - } - // On écrit dans le fichier texte - $sFichierCrontab = fopen($this->sCrontabFile, "w"); - // Le fichier texte est vidé - ftruncate($sFichierCrontab, 0); - $aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile); - $aValuesPycronNewFile = str_replace("\r", "", $aValuesPycronNewFile); - foreach ($aValuesPycronNewFile as $sPycronValues2) { - fputs($sFichierCrontab, $sPycronValues2 . "\n"); - } - // Enfin fermer le fichier - fclose($sFichierCrontab); - } - - function deleteCrontabValuesSubscription() { - $aPycronValues = file($this->sCrontabFile); - $aValuesPycronNewFile = Array(); - $bWrite = true; - foreach ($aPycronValues as $sPycronValue) { - $sPycronValue = str_replace("\n", "", $sPycronValue); - $sPycronValue = str_replace("\r", "", $sPycronValue); - - if ($sPycronValue == "#<gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">") { - - $bWrite = false; - } else if ($sPycronValue == "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">") { - $bWrite = true; - } - if ($bWrite == true && $sPycronValue != "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">") { - $aValuesPycronNewFile[] = $sPycronValue; - } - } - // On écrit dans le fichier texte - $sFichierCrontab = fopen($this->sCrontabFile, "w"); - // Le fichier texte est vidé - ftruncate($sFichierCrontab, 0); - $aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile); - $aValuesPycronNewFile = str_replace("\r", "", $aValuesPycronNewFile); - foreach ($aValuesPycronNewFile as $sPycronValues2) { - fputs($sFichierCrontab, $sPycronValues2 . "\n"); - } - // Enfin fermer le fichier - fclose($sFichierCrontab); - } - - function AddCrontabValuesEngines($sNotInList = "") { - if ($sNotInList == "") { - $sSql = 'SELECT gtf_engine_id, period, enabled FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE server_id=[iIdServer]'; - } else { - $sSql = 'SELECT gtf_engine_id, period, enabled FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE server_id=[iIdServer] AND gtf_engine_id not in ([sNotInList])'; - $aParams['sNotInList'] = array('value' => str_replace(',', '|', $sNotInList), 'type' => 'group'); - } - $aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number'); - $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); - $sFichierCrontab = fopen($this->sCrontabFile, "a"); - fputs($sFichierCrontab, "#<gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); - while ($oGTF = $this->oBd->objetSuivant($oPDOresult)) { - if ($oGTF->enabled == true) { - $sActif = ""; - } else { - $sActif = "#"; - } - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $sLigne = $sActif . "*/" . $oGTF->period . " * * * * \"" . $this->EnginesHome . "/engine.exe\" " . $oGTF->gtf_engine_id; - } else { - $sLigne = $sActif . "*/" . $oGTF->period . " * * * * cd \"" . $this->EnginesHome . "\" && \"" . $this->EnginesHome . "/engine\" " . $oGTF->gtf_engine_id; - } - fputs($sFichierCrontab, $sLigne . "\n"); - } - fputs($sFichierCrontab, "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $sCronTmp = '/tmp/' . uniqid('cron_'); - exec("crontab -u www-data -l > " . $sCronTmp); - exec("crontab -u www-data " . $sCronTmp); - exec("rm " . $sCronTmp); - } - } - - function AddCrontabValuesSubscription() { - $sSql = 'SELECT period_id, cron_expression, enabled FROM ' . $this->aProperties['schema_gtf'] . '.period'; - $oPDOresult = $this->oBd->executeWithParams($sSql, array()); - $sFichierCrontab = fopen($this->sCrontabFile, "a"); - fputs($sFichierCrontab, "#<gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); - while ($oPeriod = $this->oBd->objetSuivant($oPDOresult)) { - if ($oPeriod->enabled == true) { - $sActif = ""; - } else { - $sActif = "#"; - } - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $sLigne = $sActif . $oPeriod->cron_expression . " \"" . $this->EnginesHome . "/php/php.exe\" \"" . $this->EnginesHome . "/subscription.php\" " . $oPeriod->period_id; - } else { - $sLigne = $sActif . $oPeriod->cron_expression . " (\"" . $this->EnginesHome . "/php/bin/php\" \"" . $this->EnginesHome . "/subscription.php\" " . $oPeriod->period_id . ")"; - } - fputs($sFichierCrontab, $sLigne . "\n"); - } - fputs($sFichierCrontab, "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $sCronTmp = '/tmp/' . uniqid('cron_'); - exec("crontab -u www-data -l > " . $sCronTmp); - exec("crontab -u www-data " . $sCronTmp); - exec("rm " . $sCronTmp); - } - } - - function AddPropertiesFME($sNotInList = "") { - $sFichierProperties = fopen($this->sGtfHome . "/rest/conf/gtf/properties_post_engines.inc", "w"); - fputs($sFichierProperties, "<?php" . "\n"); - $sLigne = '$properties["engines_list"] = \''; - $aParams = array(); - if ($sNotInList == "") { - $sSql = 'SELECT gtf_engine_id FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE enabled = true ORDER BY gtf_engine_id'; - } else { - $sSql = 'SELECT gtf_engine_id FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE gtf_engine_id not in (' . $sNotInList . ") AND enabled = true ORDER BY gtf_engine_id"; - $aParams['sNotInList'] = array('value' => str_replace(',', '|', $sNotInList), 'type' => 'group'); - } - $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); - while ($oFme = $this->oBd->objetSuivant($oPDOresult)) { - if ($sLigne == '$properties["engines_list"] = \'') { - $sLigne .= $oFme->gtf_engine_id; - } else { - $sLigne .= "," . $oFme->gtf_engine_id; - } - } - $sLigne .= "';"; - fputs($sFichierProperties, $sLigne . "\n"); - fputs($sFichierProperties, "?>" . "\n"); - } - -} - +<?php + +require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/dbUtil.inc'; +require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/class/vmlib/logUtil.inc'; + +class ServerClass { + + //Chemin du fichier crontab + var $sCrontabFile; + //Id du server + var $iId; + //Nom du server + var $sServerName; + //Ancien nom du server + var $sOldServerName; + //Répertoire racine + var $sGtfHome; + //Répertoire Engines + var $EnginesHome; + //Objet de labase de données + var $oBd; + + function __construct($iId, $oBd, $sGtfHome, $sOldServerName = "", $aProperties = array()) { + $this->iId = $iId; + $this->oBd = $oBd; + $this->sOldServerName = $sOldServerName; + $this->sGtfHome = $sGtfHome; + $this->aProperties = $aProperties; + $this->setValues($iId); + } + + function setValues($iId) { + if ($iId != "") { + $sSql = 'SELECT scheduler_network_home, hostname, engines_home FROM ' . $this->aProperties['schema_gtf'] . '.server where server_id=[iIdServer]'; + $aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number'); + $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); + $oServer = $this->oBd->objetSuivant($oPDOresult); + $this->sCrontabFile = $oServer->scheduler_network_home; + $this->sServerName = $oServer->hostname; + $this->EnginesHome = $oServer->engines_home; + if ($this->sOldServerName == "") { + $this->sOldServerName = $this->sServerName; + } + } + } + + function deleteCrontabValuesEngine() { + $aValuesPycronNewFile = Array(); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $sCronFile = '/tmp/' . uniqid('cron_'); + exec("crontab -u www-data -l > " . $sCronFile); + } else { + $sCronFile = $this->sCrontabFile; + } + if (is_file($sCronFile)) { + $aPycronValues = file($sCronFile); + $bWrite = true; + foreach ($aPycronValues as $sPycronValue) { + $sPycronValue = str_replace("\n", "", $sPycronValue); + $sPycronValue = str_replace("\r", "", $sPycronValue); + if ($sPycronValue == "#<gtf_engines " . gethostname() . " " . $this->sGtfHome . ">") { + + $bWrite = false; + } else if ($sPycronValue == "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">") { + $bWrite = true; + } + if ($bWrite == true && $sPycronValue != "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">") { + $aValuesPycronNewFile[] = $sPycronValue; + } + } + } + // On écrit dans le fichier texte + $sFichierCrontab = fopen($sCronFile, "w"); + // Le fichier texte est vidé + ftruncate($sFichierCrontab, 0); + $aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile); + $aValuesPycronNewFile = str_replace("\r", "", $aValuesPycronNewFile); + foreach ($aValuesPycronNewFile as $sPycronValues2) { + fputs($sFichierCrontab, $sPycronValues2 . "\n"); + } + // Enfin fermer le fichier + fclose($sFichierCrontab); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + exec("crontab -u www-data " . $sCronFile); + exec("rm " . $sCronFile); + } + } + + function deleteCrontabValuesSubscription() { + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $sCronFile = '/tmp/' . uniqid('cron_'); + exec("crontab -u www-data -l > " . $sCronFile); + } else { + $sCronFile = $this->sCrontabFile; + } + $aPycronValues = file($sCronFile); + $aValuesPycronNewFile = Array(); + $bWrite = true; + foreach ($aPycronValues as $sPycronValue) { + $sPycronValue = str_replace("\n", "", $sPycronValue); + $sPycronValue = str_replace("\r", "", $sPycronValue); + + if ($sPycronValue == "#<gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">") { + + $bWrite = false; + } else if ($sPycronValue == "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">") { + $bWrite = true; + } + if ($bWrite == true && $sPycronValue != "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">") { + $aValuesPycronNewFile[] = $sPycronValue; + } + } + // On écrit dans le fichier texte + $sFichierCrontab = fopen($sCronFile, "w"); + // Le fichier texte est vidé + ftruncate($sFichierCrontab, 0); + $aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile); + $aValuesPycronNewFile = str_replace("\r", "", $aValuesPycronNewFile); + foreach ($aValuesPycronNewFile as $sPycronValues2) { + fputs($sFichierCrontab, $sPycronValues2 . "\n"); + } + // Enfin fermer le fichier + fclose($sFichierCrontab); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + exec("crontab -u www-data " . $sCronFile); + exec("rm " . $sCronFile); + } + } + + function AddCrontabValuesEngines($sNotInList = "") { + if ($sNotInList == "") { + $sSql = 'SELECT gtf_engine_id, period, enabled FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE server_id=[iIdServer]'; + } else { + $sSql = 'SELECT gtf_engine_id, period, enabled FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE server_id=[iIdServer] AND gtf_engine_id not in ([sNotInList])'; + $aParams['sNotInList'] = array('value' => str_replace(',', '|', $sNotInList), 'type' => 'group'); + } + $aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number'); + $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $sCronFile = '/tmp/' . uniqid('cron_'); + exec("crontab -u www-data -l > " . $sCronFile); + } else { + $sCronFile = $this->sCrontabFile; + } + $sFichierCrontab = fopen($sCronFile, "a"); + + fputs($sFichierCrontab, "#<gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); + while ($oGTF = $this->oBd->objetSuivant($oPDOresult)) { + if ($oGTF->enabled == true) { + $sActif = ""; + } else { + $sActif = "#"; + } + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $sLigne = $sActif . "*/" . $oGTF->period . " * * * * \"" . $this->EnginesHome . "/engine.exe\" " . $oGTF->gtf_engine_id; + } else { + $sLigne = $sActif . "*/" . $oGTF->period . " * * * * cd \"" . $this->EnginesHome . "\" && \"" . $this->EnginesHome . "/engine\" " . $oGTF->gtf_engine_id; + } + fputs($sFichierCrontab, $sLigne . "\n"); + } + fputs($sFichierCrontab, "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + exec("crontab -u www-data " . $sCronFile); + exec("rm " . $sCronFile); + } + } + + function AddCrontabValuesSubscription() { + $sSql = 'SELECT period_id, cron_expression, enabled FROM ' . $this->aProperties['schema_gtf'] . '.period'; + $oPDOresult = $this->oBd->executeWithParams($sSql, array()); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $sCronFile = '/tmp/' . uniqid('cron_'); + exec("crontab -u www-data -l > " . $sCronFile); + } else { + $sCronFile = $this->sCrontabFile; + } + $sFichierCrontab = fopen($sCronFile, "a"); + fputs($sFichierCrontab, "#<gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); + while ($oPeriod = $this->oBd->objetSuivant($oPDOresult)) { + if ($oPeriod->enabled == true) { + $sActif = ""; + } else { + $sActif = "#"; + } + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $sLigne = $sActif . $oPeriod->cron_expression . " \"" . $this->EnginesHome . "/php/php.exe\" \"" . $this->EnginesHome . "/subscription.php\" " . $oPeriod->period_id; + } else { + $sLigne = $sActif . $oPeriod->cron_expression . " (\"" . $this->EnginesHome . "/php/bin/php\" \"" . $this->EnginesHome . "/subscription.php\" " . $oPeriod->period_id . ")"; + } + fputs($sFichierCrontab, $sLigne . "\n"); + } + fputs($sFichierCrontab, "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + exec("crontab -u www-data " . $sCronFile); + exec("rm " . $sCronFile); + } + } + + function AddPropertiesFME($sNotInList = "") { + $sFichierProperties = fopen($this->sGtfHome . "/rest/conf/gtf/properties_post_engines.inc", "w"); + fputs($sFichierProperties, "<?php" . "\n"); + $sLigne = '$properties["engines_list"] = \''; + $aParams = array(); + if ($sNotInList == "") { + $sSql = 'SELECT gtf_engine_id FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE enabled = true ORDER BY gtf_engine_id'; + } else { + $sSql = 'SELECT gtf_engine_id FROM ' . $this->aProperties['schema_gtf'] . '.gtf_engine WHERE gtf_engine_id not in (' . $sNotInList . ") AND enabled = true ORDER BY gtf_engine_id"; + $aParams['sNotInList'] = array('value' => str_replace(',', '|', $sNotInList), 'type' => 'group'); + } + $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); + while ($oFme = $this->oBd->objetSuivant($oPDOresult)) { + if ($sLigne == '$properties["engines_list"] = \'') { + $sLigne .= $oFme->gtf_engine_id; + } else { + $sLigne .= "," . $oFme->gtf_engine_id; + } + } + $sLigne .= "';"; + fputs($sFichierProperties, $sLigne . "\n"); + fputs($sFichierProperties, "?>" . "\n"); + } + +} + ?> \ No newline at end of file -- GitLab