diff options
author | Simon Rettberg | 2014-11-18 19:48:44 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-11-18 19:48:44 +0100 |
commit | 463d695c4f7ba87ba99f0ffc548ad6f994ff49d0 (patch) | |
tree | 49f7f26bf4368f0947a59d34e4f441ad8d20261c /inc | |
parent | Create slxlog URL dynamically depending on current script's directory (diff) | |
download | slx-admin-463d695c4f7ba87ba99f0ffc548ad6f994ff49d0.tar.gz slx-admin-463d695c4f7ba87ba99f0ffc548ad6f994ff49d0.tar.xz slx-admin-463d695c4f7ba87ba99f0ffc548ad6f994ff49d0.zip |
Added proxy server settings
Diffstat (limited to 'inc')
-rw-r--r-- | inc/fileutil.inc.php | 66 | ||||
-rw-r--r-- | inc/trigger.inc.php | 49 | ||||
-rw-r--r-- | inc/util.inc.php | 19 |
3 files changed, 116 insertions, 18 deletions
diff --git a/inc/fileutil.inc.php b/inc/fileutil.inc.php new file mode 100644 index 00000000..f35f987e --- /dev/null +++ b/inc/fileutil.inc.php @@ -0,0 +1,66 @@ +<?php + +class FileUtil +{ + + /** + * Return contents of given file as string, but only read up to maxBytes bytes. + * + * @param string $file file to read + * @param int $maxBytes maximum length to read + * @return boolean|string data, false on error + */ + public static function readFile($file, $maxBytes = 1000) + { + $fh = @fopen($file, 'rb'); + if ($fh === false) + return false; + $data = fread($fh, $maxBytes); + fclose($fh); + return $data; + } + + /** + * Read a file of key=value lines to assoc array. + * + * @param string $file Filename + * @return boolean|array assoc array, false on error + */ + public static function fileToArray($file) + { + $data = self::readFile($file, 2000); + if ($data === false) + return false; + $data = explode("\n", str_replace("\r", "\n", $data)); + $ret = array(); + foreach ($data as $line) { + if (preg_match('/^(\w+)\s*=\s*(.*?)\s*$/', $line, $out)) { + $ret[$out[1]] = $out[2]; + } + } + return $ret; + } + + /** + * Write given associative array to file as key=value pairs. + * + * @param string $file Filename + * @param array $array Associative array to write + * @return boolean success of operation + */ + public static function arrayToFile($file, $array) + { + $fh = fopen($file, 'wb'); + if ($fh === false) + return false; + foreach ($array as $key => $value) { + if (false === fwrite($fh, $key . ' = ' . preg_replace('/[\x00-\x1F]/s', '', (string)$value) . "\n")) { + fclose($fh); + return false; + } + } + fclose($fh); + return true; + } + +}
\ No newline at end of file diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php index 73ad6ce8..ce56c815 100644 --- a/inc/trigger.inc.php +++ b/inc/trigger.inc.php @@ -177,4 +177,53 @@ class Trigger } } + private static function triggerDaemons($action, $parent, &$taskids) + { + $task = Taskmanager::submit('SyncdaemonLauncher', array( + 'operation' => $action, + 'parentTask' => $parent, + 'failOnParentFail' => false + )); + if (isset($task['id'])) { + $taskids['syncid'] = $task['id']; + $parent = $task['id']; + } + $task = Taskmanager::submit('DozmodLauncher', array( + 'operation' => $action, + 'parentTask' => $parent, + 'failOnParentFail' => false + )); + if (isset($task['id'])) { + $taskids['dmsdid'] = $task['id']; + $parent = $task['id']; + } + return $parent; + } + + public static function stopDaemons($parent, &$taskids) + { + $parent = self::triggerDaemons('stop', $parent, $taskids); + $task = Taskmanager::submit('LdadpLauncher', array( + 'ids' => array(), + 'parentTask' => $parent, + 'failOnParentFail' => false + )); + if (isset($task['id'])) { + $taskids['ldadpid'] = $task['id']; + $parent = $task['id']; + } + return $parent; + } + + public static function startDaemons($parent, &$taskids) + { + $parent = self::triggerDaemons('start', $parent, $taskids); + $taskid = self::ldadp($parent); + if ($taskid !== false) { + $taskids['ldadpid'] = $taskid; + $parent = $taskid; + } + return $parent; + } + } diff --git a/inc/util.inc.php b/inc/util.inc.php index 109c0c5d..6e97e0bd 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -30,7 +30,7 @@ class Util public static function redirect($location = false) { if ($location === false) { - $location = preg_replace('/(&|\?)message\[\]\=[^&]*(&|$)/', '\1', $_SERVER['REQUEST_URI']); + $location = preg_replace('/(&|\?)message\[\]\=[^&]*/', '\1', $_SERVER['REQUEST_URI']); } Session::save(); $messages = Message::toRequest(); @@ -187,22 +187,5 @@ class Util return true; } - - /** - * Return contents of given file as string, but only read up to maxBytes bytes. - * - * @param string $file file to read - * @param int $maxBytes maximum length to read - * @return boolean success or failure - */ - public static function readFile($file, $maxBytes = 1000) - { - $fh = @fopen($file, 'rb'); - if ($fh === false) - return false; - $data = fread($fh, $maxBytes); - fclose($fh); - return $data; - } } |