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 {
function deleteCrontabValuesEngine() {
$aValuesPycronNewFile = Array();
if (is_file($this->sCrontabFile)) {
$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;
}
if (is_file($sCronFile)) {
$aPycronValues = file($sCronFile);
$bWrite = true;
foreach ($aPycronValues as $sPycronValue) {
$sPycronValue = str_replace("\n", "", $sPycronValue);
......@@ -64,7 +70,7 @@ class ServerClass {
}
}
// On écrit dans le fichier texte
$sFichierCrontab = fopen($this->sCrontabFile, "w");
$sFichierCrontab = fopen($sCronFile, "w");
// Le fichier texte est vidé
ftruncate($sFichierCrontab, 0);
$aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile);
......@@ -74,10 +80,20 @@ class ServerClass {
}
// 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() {
$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();
$bWrite = true;
foreach ($aPycronValues as $sPycronValue) {
......@@ -95,7 +111,7 @@ class ServerClass {
}
}
// On écrit dans le fichier texte
$sFichierCrontab = fopen($this->sCrontabFile, "w");
$sFichierCrontab = fopen($sCronFile, "w");
// Le fichier texte est vidé
ftruncate($sFichierCrontab, 0);
$aValuesPycronNewFile = str_replace("\n", "", $aValuesPycronNewFile);
......@@ -105,6 +121,10 @@ class ServerClass {
}
// 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 = "") {
......@@ -116,7 +136,14 @@ class ServerClass {
}
$aParams['iIdServer'] = array('value' => $this->iId, 'type' => 'number');
$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");
while ($oGTF = $this->oBd->objetSuivant($oPDOresult)) {
if ($oGTF->enabled == true) {
......@@ -133,17 +160,21 @@ class ServerClass {
}
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);
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());
$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");
while ($oPeriod = $this->oBd->objetSuivant($oPDOresult)) {
if ($oPeriod->enabled == true) {
......@@ -160,10 +191,8 @@ class ServerClass {
}
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);
exec("crontab -u www-data " . $sCronFile);
exec("rm " . $sCronFile);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment