summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/fileutil.inc.php66
-rw-r--r--inc/trigger.inc.php49
-rw-r--r--inc/util.inc.php19
-rw-r--r--index.php8
-rw-r--r--lang/de/templates/internetaccess/_page.json14
-rw-r--r--lang/de/templates/internetaccess/restart.json5
-rw-r--r--lang/de/templates/main-menu.json1
-rw-r--r--lang/en/templates/internetaccess/_page.json14
-rw-r--r--lang/en/templates/internetaccess/restart.json5
-rw-r--r--lang/en/templates/main-menu.json1
-rw-r--r--modules/internetaccess.inc.php51
-rw-r--r--templates/internetaccess/_page.html38
-rw-r--r--templates/internetaccess/restart.html22
-rw-r--r--templates/main-menu.html1
14 files changed, 276 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;
- }
}
diff --git a/index.php b/index.php
index f9d9e9fc..969a3d47 100644
--- a/index.php
+++ b/index.php
@@ -2,6 +2,14 @@
require_once 'config.php';
+if (CONFIG_SQL_PASS === '%MYSQL_OPENSLX_PASS%') {
+ Header('Content-Type: text/plain; charset=utf-8');
+ die("The server has not been configured yet. Please log in to the server via console/SSH and follow the instructions."
+ . "\n\n"
+ . "Der Server wurde noch nicht konfiguriert. Bitte loggen Sie sich auf der Konsole oder per SSH auf dem Server ein"
+ . " und folgen Sie den Instruktionen.");
+}
+
require_once('inc/user.inc.php');
/**
diff --git a/lang/de/templates/internetaccess/_page.json b/lang/de/templates/internetaccess/_page.json
new file mode 100644
index 00000000..61e324a8
--- /dev/null
+++ b/lang/de/templates/internetaccess/_page.json
@@ -0,0 +1,14 @@
+{
+ "lang_automatic": "Automatisch",
+ "lang_description": "Hier k\u00f6nnen Sie konfigurieren, wie der Satellitenserver auf das Internet zugreifen soll. Dies wird in erster Linie f\u00fcr das Aktualisieren des Systems sowie das Synchronisieren von Virtuellen Maschinen mit dem Zentralserver verwendet. Gegenw\u00e4rtig wird neben Direktzugriff noch SOCKS4\/5 unterst\u00fctzt.",
+ "lang_internetAccess": "Internetzugriff",
+ "lang_manual": "Manuelle Angabe",
+ "lang_manualProxyConfig": "Wenn Sie einen SOCKS-Proxy manuell konfigurieren m\u00f6chten, geben Sie bitte hier die Verbindungsdaten an.",
+ "lang_no": "Keiner",
+ "lang_proxyAddress": "Adresse",
+ "lang_proxyPassword": "Passwort",
+ "lang_proxyPort": "Port",
+ "lang_proxyType": "Proxy Typ",
+ "lang_proxyUsername": "Benutzername",
+ "lang_save": "Speichern"
+} \ No newline at end of file
diff --git a/lang/de/templates/internetaccess/restart.json b/lang/de/templates/internetaccess/restart.json
new file mode 100644
index 00000000..899a1d28
--- /dev/null
+++ b/lang/de/templates/internetaccess/restart.json
@@ -0,0 +1,5 @@
+{
+ "lang_restartFailed": "Neustart eines oder mehrerer Dienste fehlgeschlagen!",
+ "lang_restarting": "Neustart",
+ "lang_serviceRestart": "Neustarten der Dienste"
+} \ No newline at end of file
diff --git a/lang/de/templates/main-menu.json b/lang/de/templates/main-menu.json
index 564865a8..36ecf597 100644
--- a/lang/de/templates/main-menu.json
+++ b/lang/de/templates/main-menu.json
@@ -6,6 +6,7 @@
"lang_configurationBasic": "Grundkonfiguration",
"lang_configurationVariables": "KonfigurationsVariablen",
"lang_eventLog": "Server Log",
+ "lang_internetAccess": "Internetzugriff",
"lang_language": "Sprachen",
"lang_localization": "Lokalisierung",
"lang_login": "Anmelden",
diff --git a/lang/en/templates/internetaccess/_page.json b/lang/en/templates/internetaccess/_page.json
new file mode 100644
index 00000000..c02ca4f5
--- /dev/null
+++ b/lang/en/templates/internetaccess/_page.json
@@ -0,0 +1,14 @@
+{
+ "lang_automatic": "Auto",
+ "lang_description": "Here you can configure how the satellite server has to access the internet.",
+ "lang_internetAccess": "Internet access",
+ "lang_manual": "Manual",
+ "lang_manualProxyConfig": "If you want to configure a proxy server manually, please supply the credentials here.",
+ "lang_no": "None",
+ "lang_proxyAddress": "Address",
+ "lang_proxyPassword": "Password",
+ "lang_proxyPort": "Port",
+ "lang_proxyType": "Proxy type",
+ "lang_proxyUsername": "User",
+ "lang_save": "Save"
+} \ No newline at end of file
diff --git a/lang/en/templates/internetaccess/restart.json b/lang/en/templates/internetaccess/restart.json
new file mode 100644
index 00000000..badad460
--- /dev/null
+++ b/lang/en/templates/internetaccess/restart.json
@@ -0,0 +1,5 @@
+{
+ "lang_restartFailed": "Restarting one or more services failed!",
+ "lang_restarting": "Restarting",
+ "lang_serviceRestart": "Restart of services"
+} \ No newline at end of file
diff --git a/lang/en/templates/main-menu.json b/lang/en/templates/main-menu.json
index 16fe70d4..50ffabb5 100644
--- a/lang/en/templates/main-menu.json
+++ b/lang/en/templates/main-menu.json
@@ -6,6 +6,7 @@
"lang_configurationBasic": "Basic Configuration",
"lang_configurationVariables": "Configuration Variables",
"lang_eventLog": "Server Log",
+ "lang_internetAccess": "Internet access",
"lang_language": "Language",
"lang_localization": "Localization",
"lang_login": "Login",
diff --git a/modules/internetaccess.inc.php b/modules/internetaccess.inc.php
new file mode 100644
index 00000000..a292926c
--- /dev/null
+++ b/modules/internetaccess.inc.php
@@ -0,0 +1,51 @@
+<?php
+
+class Page_InternetAccess extends Page
+{
+
+ protected function doPreprocess()
+ {
+ User::load();
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('no-permission');
+ Util::redirect('?do=Main');
+ }
+ if (isset($_POST['PROXY_CONF'])) {
+ $data = array();
+ foreach (array('PROXY_CONF', 'PROXY_ADDR', 'PROXY_PORT', 'PROXY_USERNAME', 'PROXY_PASSWORD') as $key) {
+ $data[$key] = Request::post($key, '');
+ }
+ if (!FileUtil::arrayToFile(CONFIG_PROXY_CONF, $data)) {
+ Message::addError('error-write', CONFIG_PROXY_CONF);
+ Util::redirect();
+ } else {
+ Message::addSuccess('settings-updated');
+ Taskmanager::release(Taskmanager::submit('ReloadProxy'));
+ $taskids = array();
+ Trigger::stopDaemons(NULL, &$taskids);
+ $taskids = array();
+ Trigger::startDaemons(NULL, &$taskids);
+ Session::set('ia-restart', $taskids);
+ Util::redirect('?do=InternetAccess&show=update');
+ }
+ }
+ }
+
+ protected function doRender()
+ {
+ if (Request::any('show') === 'update') {
+ $taskids = Session::get('ia-restart');
+ if (is_array($taskids)) {
+ Render::addTemplate('internetaccess/restart', $taskids);
+ } else {
+ Message::addError('invalid-action', 'Restart');
+ }
+ }
+ $data = FileUtil::fileToArray(CONFIG_PROXY_CONF);
+ if (!isset($data['PROXY_CONF']))
+ $data['PROXY_CONF'] = 'AUTO';
+ $data['selected_' . $data['PROXY_CONF']] = 'selected';
+ Render::addTemplate('internetaccess/_page', $data);
+ }
+
+}
diff --git a/templates/internetaccess/_page.html b/templates/internetaccess/_page.html
new file mode 100644
index 00000000..c5b6efe9
--- /dev/null
+++ b/templates/internetaccess/_page.html
@@ -0,0 +1,38 @@
+<h1>{{lang_internetAccess}}</h1>
+
+<form action="?do=InternetAccess" method="post">
+ <input type="hidden" name="token" value="{{token}}">
+ <div class="panel panel-default">
+ <div class="panel-heading">{{lang_internetAccess}}</div>
+ <div class="panel-body">
+ <p>{{lang_description}}</p>
+ <div class="input-group">
+ <span class="input-group-addon slx-ga">{{lang_proxyType}}</span>
+ <select name="PROXY_CONF" class="form-control">
+ <option value="AUTO" {{selected_AUTO}}>{{lang_automatic}} (dns-wpad)</option>
+ <option value="NO" {{selected_NO}}>{{lang_no}}</option>
+ <option value="YES" {{selected_YES}}>{{lang_manual}}</option>
+ </select>
+ </div>
+ <br>
+ <p>{{lang_manualProxyConfig}}</p>
+ <div class="input-group">
+ <span class="input-group-addon slx-ga">{{lang_proxyAddress}} *</span>
+ <input name="PROXY_ADDR" value="{{PROXY_ADDR}}" type="text" class="form-control">
+ </div>
+ <div class="input-group">
+ <span class="input-group-addon slx-ga">{{lang_proxyPort}} *</span>
+ <input name="PROXY_PORT" value="{{PROXY_PORT}}" type="text" class="form-control">
+ </div>
+ <div class="input-group">
+ <span class="input-group-addon slx-ga">{{lang_proxyUsername}}</span>
+ <input name="PROXY_USERNAME" value="{{PROXY_USERNAME}}" type="text" class="form-control">
+ </div>
+ <div class="input-group">
+ <span class="input-group-addon slx-ga">{{lang_proxyPassword}}</span>
+ <input name="PROXY_PASSWORD" value="{{PROXY_PASSWORD}}" type="text" class="form-control">
+ </div>
+ <button class="btn btn-primary" type="submit">{{lang_save}}</button>
+ </div>
+ </div>
+</form>
diff --git a/templates/internetaccess/restart.html b/templates/internetaccess/restart.html
new file mode 100644
index 00000000..effe1feb
--- /dev/null
+++ b/templates/internetaccess/restart.html
@@ -0,0 +1,22 @@
+<div class="panel panel-default">
+ <div class="panel-heading">{{lang_serviceRestart}}</div>
+ <div class="panel-body">
+ <div data-tm-id="{{syncid}}" data-tm-log="messages" data-tm-callback="restartCb">{{lang_restarting}} syncdaemon</div>
+ <div data-tm-id="{{dmsdid}}" data-tm-log="messages" data-tm-callback="restartCb">{{lang_restarting}} dmsd</div>
+ <div data-tm-id="{{ldadpid}}" data-tm-log="messages" data-tm-callback="restartCb">{{lang_restarting}} ldadp</div>
+ <div id="restartfailed" class="alert alert-danger" style="display:none">
+ {{lang_restartFailed}}
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+ function restartCb(task)
+ {
+ if (!task || !task.statusCode)
+ return;
+ if (task.statusCode === 'TASK_ERROR') {
+ $('#restartfailed').show('slow');
+ }
+ }
+</script>
diff --git a/templates/main-menu.html b/templates/main-menu.html
index 7f376a4a..518db2d5 100644
--- a/templates/main-menu.html
+++ b/templates/main-menu.html
@@ -23,6 +23,7 @@
<li class="divider"></li>
<li class="dropdown-header">{{lang_server}}</li>
<li><a href="?do=ServerSetup">{{lang_configurationBasic}}</a></li>
+ <li><a href="?do=InternetAccess">{{lang_internetAccess}}</a></li>
<li><a href="?do=VmStore">{{lang_vmLocation}}</a></li>
<li><a href="?do=Backup">{{lang_backup}}</a></li>
</ul>