Skip to content
Snippets Groups Projects
Commit e352595f authored by Sébastien Legrand's avatar Sébastien Legrand
Browse files

Modification de la manière de modifier le crontab sur Linux pour éviter de...

Modification de la manière de modifier le crontab sur Linux pour éviter de donner des droits particulier
parent 1ea2910b
No related branches found
No related tags found
No related merge requests found
...@@ -46,8 +46,14 @@ class ServerClass { ...@@ -46,8 +46,14 @@ class ServerClass {
function deleteCrontabValuesEngine() { function deleteCrontabValuesEngine() {
$aValuesPycronNewFile = Array(); $aValuesPycronNewFile = Array();
if (is_file($this->sCrontabFile)) { if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$aPycronValues = file($this->sCrontabFile); $sCronFile = '/tmp/' . uniqid('cron_');
exec("crontab -u www-data -l > " . $sCronFile);
} else {
$sCronFile = $this->sCrontabFile;
}
if (is_file($sCronFile)) {
$aPycronValues = file($sCronFile);
$bWrite = true; $bWrite = true;
foreach ($aPycronValues as $sPycronValue) { foreach ($aPycronValues as $sPycronValue) {
$sPycronValue = str_replace("\n", "", $sPycronValue); $sPycronValue = str_replace("\n", "", $sPycronValue);
...@@ -64,7 +70,7 @@ class ServerClass { ...@@ -64,7 +70,7 @@ class ServerClass {
} }
} }
// On écrit dans le fichier texte // On écrit dans le fichier texte
$sFichierCrontab = fopen($this->sCrontabFile, "w"); $sFichierCrontab = fopen($sCronFile, "w");
// Le fichier texte est vidé // Le fichier texte est vidé
ftruncate($sFichierCrontab, 0); ftruncate($sFichierCrontab, 0);
$aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile); $aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile);
...@@ -74,10 +80,20 @@ class ServerClass { ...@@ -74,10 +80,20 @@ class ServerClass {
} }
// Enfin fermer le fichier // Enfin fermer le fichier
fclose($sFichierCrontab); fclose($sFichierCrontab);
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
exec("crontab -u www-data " . $sCronFile);
exec("rm " . $sCronFile);
}
} }
function deleteCrontabValuesSubscription() { function deleteCrontabValuesSubscription() {
$aPycronValues = file($this->sCrontabFile); 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(); $aValuesPycronNewFile = Array();
$bWrite = true; $bWrite = true;
foreach ($aPycronValues as $sPycronValue) { foreach ($aPycronValues as $sPycronValue) {
...@@ -95,7 +111,7 @@ class ServerClass { ...@@ -95,7 +111,7 @@ class ServerClass {
} }
} }
// On écrit dans le fichier texte // On écrit dans le fichier texte
$sFichierCrontab = fopen($this->sCrontabFile, "w"); $sFichierCrontab = fopen($sCronFile, "w");
// Le fichier texte est vidé // Le fichier texte est vidé
ftruncate($sFichierCrontab, 0); ftruncate($sFichierCrontab, 0);
$aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile); $aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile);
...@@ -105,6 +121,10 @@ class ServerClass { ...@@ -105,6 +121,10 @@ class ServerClass {
} }
// Enfin fermer le fichier // Enfin fermer le fichier
fclose($sFichierCrontab); fclose($sFichierCrontab);
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
exec("crontab -u www-data " . $sCronFile);
exec("rm " . $sCronFile);
}
} }
function AddCrontabValuesEngines($sNotInList = "") { function AddCrontabValuesEngines($sNotInList = "") {
...@@ -116,7 +136,14 @@ class ServerClass { ...@@ -116,7 +136,14 @@ class ServerClass {
} }
$aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number'); $aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number');
$oPDOresult = $this->oBd->executeWithParams($sSql, $aParams); $oPDOresult = $this->oBd->executeWithParams($sSql, $aParams);
$sFichierCrontab = fopen($this->sCrontabFile, "a"); 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"); fputs($sFichierCrontab, "#<gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n");
while ($oGTF = $this->oBd->objetSuivant($oPDOresult)) { while ($oGTF = $this->oBd->objetSuivant($oPDOresult)) {
if ($oGTF->enabled == true) { if ($oGTF->enabled == true) {
...@@ -133,17 +160,21 @@ class ServerClass { ...@@ -133,17 +160,21 @@ class ServerClass {
} }
fputs($sFichierCrontab, "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); fputs($sFichierCrontab, "#</gtf_engines " . gethostname() . " " . $this->sGtfHome . ">" . "\n");
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$sCronTmp = '/tmp/' . uniqid('cron_'); exec("crontab -u www-data " . $sCronFile);
exec("crontab -u www-data -l > " . $sCronTmp); exec("rm " . $sCronFile);
exec("crontab -u www-data " . $sCronTmp);
exec("rm " . $sCronTmp);
} }
} }
function AddCrontabValuesSubscription() { function AddCrontabValuesSubscription() {
$sSql = 'SELECT period_id, cron_expression, enabled FROM ' . $this->aProperties['schema_gtf'] . '.period'; $sSql = 'SELECT period_id, cron_expression, enabled FROM ' . $this->aProperties['schema_gtf'] . '.period';
$oPDOresult = $this->oBd->executeWithParams($sSql, array()); $oPDOresult = $this->oBd->executeWithParams($sSql, array());
$sFichierCrontab = fopen($this->sCrontabFile, "a"); 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"); fputs($sFichierCrontab, "#<gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n");
while ($oPeriod = $this->oBd->objetSuivant($oPDOresult)) { while ($oPeriod = $this->oBd->objetSuivant($oPDOresult)) {
if ($oPeriod->enabled == true) { if ($oPeriod->enabled == true) {
...@@ -160,10 +191,8 @@ class ServerClass { ...@@ -160,10 +191,8 @@ class ServerClass {
} }
fputs($sFichierCrontab, "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n"); fputs($sFichierCrontab, "#</gtf_subscription " . gethostname() . " " . $this->sGtfHome . ">" . "\n");
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$sCronTmp = '/tmp/' . uniqid('cron_'); exec("crontab -u www-data " . $sCronFile);
exec("crontab -u www-data -l > " . $sCronTmp); exec("rm " . $sCronFile);
exec("crontab -u www-data " . $sCronTmp);
exec("rm " . $sCronTmp);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment