45 private function load()
48 if ($this->
user != NULL) {
49 $cmd.=
' -u ' . escapeshellarg($this->
user);
51 $cmd.=
' 2> /dev/null';
53 $ph = popen(
$cmd,
'r');
55 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error popen");
61 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error stream_get_contents");
70 private function save()
72 include_once (
'WHAT/Lib.System.php');
76 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error creating temporary file");
80 $ret = file_put_contents($tmp, $this->crontab);
82 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error writing content to file '" . $tmp .
"'");
87 if ($this->
user != NULL) {
88 $cmd.=
' -u ' . escapeshellarg($this->
user);
90 $cmd.=
' ' . escapeshellarg($tmp);
91 $cmd.=
' > /dev/null 2>&1';
95 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab '" . $tmp .
"'");
104 include_once (
'WHAT/Lib.Prefix.php');
108 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading content from file '" .
$file .
"'");
114 $activeCrontab = $this->load();
115 if ($activeCrontab === FALSE) {
116 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
120 if (preg_match(
'/^#\s+BEGIN:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':' . preg_quote(
$file,
'/') .
'.*?#\s+END:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':' . preg_quote(
$file,
'/') .
'$/ms', $activeCrontab) === 1) {
121 print
"Removing existing crontab\n";
122 $tmpCrontab = preg_replace(
'/^#\s+BEGIN:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':' . preg_quote(
$file,
'/') .
'.*?#\s+END:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':' . preg_quote(
$file,
'/') .
'$/ms',
'', $activeCrontab);
123 if ($tmpCrontab === NULL) {
124 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error removing existing registered crontab");
127 $activeCrontab = $tmpCrontab;
131 $this->crontab = $activeCrontab;
133 $ret = $this->save();
134 if (
$ret === FALSE) {
135 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab");
144 include_once (
'WHAT/Lib.Prefix.php');
146 $activeCrontab = $this->load();
147 if ($activeCrontab === FALSE) {
148 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
152 $tmpCrontab = preg_replace(
'/^#\s+BEGIN:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':' . preg_quote(
$file,
'/') .
'.*?#\s+END:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':' . preg_quote(
$file,
'/') .
'$/ms',
'', $activeCrontab);
153 if ($tmpCrontab === NULL) {
154 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error unregistering crontab '" .
DEFAULT_PUBDIR .
":" .
$file .
"' from active crontab");
158 $this->crontab = $tmpCrontab;
160 $ret = $this->save();
161 if (
$ret === FALSE) {
162 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error saving crontab");
172 if ($crontabs === FALSE) {
173 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error retrieving active crontabs");
178 print
"Active crontabs\n";
179 print
"---------------\n";
182 print
"Crontab: " . $crontab[
'file'] .
"\n";
183 print
"--8<--\n" . $crontab[
'content'] .
"\n-->8--\n\n";
191 include_once (
'WHAT/Lib.Prefix.php');
193 $activeCrontab = $this->load();
194 if ($activeCrontab === FALSE) {
195 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error reading active crontab");
199 $ret = preg_match_all(
'/^#\s+BEGIN:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':(.*?)\n(.*?)\n#\s+END:FREEDOM_CRONTAB:' . preg_quote(
DEFAULT_PUBDIR,
'/') .
':\1/ms', $activeCrontab, $matches, PREG_SET_ORDER);
200 if (
$ret === FALSE) {
201 error_log(__CLASS__ .
"::" . __FUNCTION__ .
" Error in preg_match_all");
206 foreach ($matches as $match) {
207 array_push($crontabs, array(
209 'content' => $match[2]