summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2011-12-25 17:58:03 +0100
committerAleksander Machniak <alec@alec.pl>2011-12-25 17:58:03 +0100
commit92a5add47382cd41e782f45ef47e46806acdd615 (patch)
tree2a7993dc635df3746a037f78203746d2a3cbf330 /lib
parente8ea8f9522098c104eae131b773c4fd6cb7d329c (diff)
downloadwebadmin-92a5add47382cd41e782f45ef47e46806acdd615.tar.gz
Restructured directory tree and class names (I'm not happy with it still)
Some improvements in the client
Diffstat (limited to 'lib')
-rw-r--r--lib/client/kolab_admin_client_task_main.php39
-rw-r--r--lib/client/kolab_admin_client_task_user.php146
-rw-r--r--lib/functions.php187
-rw-r--r--lib/kolab_admin_api.php30
-rw-r--r--lib/kolab_admin_api_result.php4
-rw-r--r--lib/kolab_admin_client_output.php4
-rw-r--r--lib/kolab_admin_client_task.php113
-rw-r--r--lib/kolab_form.php54
-rw-r--r--lib/kolab_html.php18
-rw-r--r--lib/kolab_utils.php141
-rw-r--r--lib/locale/en_US.php3
11 files changed, 480 insertions, 259 deletions
diff --git a/lib/client/kolab_admin_client_task_main.php b/lib/client/kolab_admin_client_task_main.php
index d15a9ca..bd538cf 100644
--- a/lib/client/kolab_admin_client_task_main.php
+++ b/lib/client/kolab_admin_client_task_main.php
@@ -1,30 +1,27 @@
<?php
- class kolab_admin_client_task_main extends kolab_admin_client_task
- {
- protected $menu = array(
- 'user.default' => 'menu.users',
- 'group.default' => 'menu.groups',
- 'domain.default' => 'menu.domains',
- 'about.default' => 'menu.about',
- );
-
+class kolab_admin_client_task_main extends kolab_admin_client_task
+{
+ protected $menu = array(
+ 'user.default' => 'menu.users',
+ 'group.default' => 'menu.groups',
+ 'about.default' => 'menu.about',
+ );
- public function action_default()
- {
- // assign token
- $this->output->set_env('token', $_SESSION['user']['token']);
- // add watermark content
- $this->output->set_env('watermark', $this->output->get_template('watermark'));
+ public function action_default()
+ {
+ // assign token
+ $this->output->set_env('token', $_SESSION['user']['token']);
- // assign default set of translations
- $this->output->add_translation('loading', 'servererror', 'search');
+ // add watermark content
+ $this->output->set_env('watermark', $this->output->get_template('watermark'));
- $this->output->assign('main_menu', $this->menu());
- $this->output->assign('user', $_SESSION['user']);
- }
+ // assign default set of translations
+ $this->output->add_translation('loading', 'servererror', 'search');
+ $this->output->assign('main_menu', $this->menu());
+ $this->output->assign('user', $_SESSION['user']);
}
-?>
+}
diff --git a/lib/client/kolab_admin_client_task_user.php b/lib/client/kolab_admin_client_task_user.php
index 66c3d99..2550c7d 100644
--- a/lib/client/kolab_admin_client_task_user.php
+++ b/lib/client/kolab_admin_client_task_user.php
@@ -8,6 +8,9 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
'add' => 'user.add',
);
+ /**
+ * Default action.
+ */
public function action_default()
{
$this->output->set_object('content', 'user', true);
@@ -16,6 +19,9 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
$this->action_list();
}
+ /**
+ * Users list action.
+ */
public function action_list()
{
$result = $this->api->post('users.list');
@@ -54,12 +60,38 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
$this->output->set_object('userlist', $table);
}
+ /**
+ * User information (form) action.
+ */
public function action_info()
{
$id = $this->get_input('id', 'POST');
$result = $this->api->get('user.info', array('user' => $id));
$user = $result->get($id);
+ $output = $this->user_form(null, $user);
+
+ $this->output->set_object('taskcontent', $output);
+ }
+
+ /**
+ * Users adding (form) action.
+ */
+ public function action_add()
+ {
+ $output = $this->user_form(null, null);
+
+ $this->output->set_object('taskcontent', $output);
+ }
+
+ private function user_form($attribs, $data = array())
+ {
$form = new kolab_form();
+ $utypes = $this->user_types();
+
+ foreach ($utypes as $idx => $elem) {
+ $utypes[$idx] = array('value' => $elem['key'], 'content' => $elem['name']);
+ }
+
$fields = array(
'personal' => array(
'label' => 'user.personal',
@@ -71,12 +103,6 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
'type' => kolab_form::INPUT_TEXT,
'maxlength' => 50,
),
- 'initials' => array(
- 'label' => 'user.initials',
- 'description' => 'user.initials.desc',
- 'type' => kolab_form::INPUT_TEXT,
- 'maxlength' => 50,
- ),
'sn' => array(
'label' => 'user.surname',
'description' => 'user.surname.desc',
@@ -84,6 +110,12 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
'type' => kolab_form::INPUT_TEXT,
'maxlength' => 50,
),
+ 'initials' => array(
+ 'label' => 'user.initials',
+ 'description' => 'user.initials.desc',
+ 'type' => kolab_form::INPUT_TEXT,
+ 'maxlength' => 50,
+ ),
'title' => array(
'label' => 'user.title',
'description' => 'user.title.desc',
@@ -100,6 +132,41 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
'description' => 'user.email.desc',
'type' => kolab_form::INPUT_TEXT,
'maxlength' => 50,
+ 'required' => true,
+ ),
+ 'uid' => array(
+ 'label' => 'user.uid',
+ 'description' => 'user.uid.desc',
+ 'type' => kolab_form::INPUT_TEXT,
+ 'maxlength' => 50,
+ 'required' => true,
+ ),
+ 'password' => array(
+ 'label' => 'user.password',
+ 'description' => 'user.password.desc',
+ 'type' => kolab_form::INPUT_TEXT,
+ 'maxlength' => 50,
+ 'required' => true,
+ ),
+ 'password2' => array(
+ 'label' => 'user.password-confirm',
+ 'description' => 'user.password-confirm.desc',
+ 'type' => kolab_form::INPUT_TEXT,
+ 'maxlength' => 50,
+ 'required' => true,
+ ),
+ 'kolabhomeserver' => array(
+ 'label' => 'user.homeserver',
+ 'description' => 'user.homeserver.desc',
+ 'type' => kolab_form::INPUT_TEXT,
+ 'maxlength' => 50,
+ 'required' => true,
+ ),
+ 'accttype' => array(
+ 'label' => 'user.type',
+ 'description' => 'user.type.desc',
+ 'type' => kolab_form::INPUT_SELECT,
+ 'options' => $utypes,
),
),
),
@@ -111,12 +178,34 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
'description' => 'user.quota.desc',
'type' => kolab_form::INPUT_TEXT,
'maxlength' => 10,
+ 'suffix' => 'MB',
),
'kolabFreeBusyFuture' => array(
'label' => 'user.fbinterval',
'description' => 'user.fbinterval.desc',
'type' => kolab_form::INPUT_TEXT,
'maxlength' => 5,
+ 'suffix' => 'days',
+ ),
+ 'kolabinvitationpolicy' => array(
+ 'label' => 'user.invitation-policy',
+ 'description' => 'user.invitation-policy.desc',
+ 'type' => kolab_form::INPUT_TEXTAREA,
+ ),
+ 'alias' => array(
+ 'label' => 'user.alias',
+ 'description' => 'user.alias.desc',
+ 'type' => kolab_form::INPUT_TEXTAREA,
+ ),
+ 'kolabdelegate' => array(
+ 'label' => 'user.delegate',
+ 'description' => 'user.delegate.desc',
+ 'type' => kolab_form::INPUT_TEXTAREA,
+ ),
+ 'kolabAllowSMTPRecipient' => array(
+ 'label' => 'user.smtp-recipients',
+ 'description' => 'user.smtp-recipients.desc',
+ 'type' => kolab_form::INPUT_TEXTAREA,
),
),
),
@@ -187,29 +276,56 @@ class kolab_admin_client_task_user extends kolab_admin_client_task
),
);
-
+ // Parse elements and add them to the form object
foreach ($fields as $section_idx => $section) {
$form->add_section($section_idx, kolab_html::escape($this->translate($section['label'])));
foreach ($section['fields'] as $idx => $field) {
$field['section'] = $section_idx;
- $field['value'] = kolab_html::escape($user[$idx]);
$field['label'] = kolab_html::escape($this->translate($field['label']));
- $field['description'] = kolab_html::escape($this->translate($field['description']));
+
+ if (isset($data[$idx])) {
+ $field['value'] = kolab_html::escape($data[$idx]);
+ }
+
+ if (!empty($field['suffix'])) {
+ $field['suffix'] = kolab_html::escape($this->translate($field['suffix']));
+ }
+
+ if (!empty($field['options'])) {
+ foreach ($field['options'] as $opt_idx => $option) {
+ if (is_array($option)) {
+ $field['options'][$opt_idx]['content'] = kolab_html::escape($this->translate($option['content']));
+ }
+ else {
+ $field['options'][$opt_idx] = kolab_html::escape($this->translate($option));
+ }
+ }
+ }
+
+ if (!empty($field['description'])) {
+ $description = kolab_html::escape($this->translate($field['description']));
+ if ($description != $field['description']) {
+ $field['title'] = $description;
+ }
+ unset($field['description']);
+ }
+
+ if (empty($field['name'])) {
+ $field['name'] = $idx;
+ }
$form->add_element($field);
}
}
- $this->output->set_object('taskcontent', $form->output());
+ return $form->output();
}
- public function user_add()
+ private function search_form()
{
+ $form = new kolab_form();
+ return $form->output();
}
- private function user_types()
- {
- $result = $this->api->post('user_types.list');
- }
}
diff --git a/lib/functions.php b/lib/functions.php
index e09669c..00930ae 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -1,102 +1,117 @@
<?php
- ini_set('include_path', dirname(__FILE__) . PATH_SEPARATOR . ini_get('include_path'));
- ini_set('include_path', dirname(__FILE__) . "/ext/" . PATH_SEPARATOR . ini_get('include_path'));
-
- // These are just here for some statistics.
- list($usec, $sec) = explode(' ',microtime());
-
- $GLOBALS['parse_start'] = ((float)$usec + (float)$sec);
-
- // Initialize some runtime variables
- $messages = Array();
-
- require_once('Conf.php');
-
- // register autoloader
- function class_autoloader($classname) {
- $classname = preg_replace('/(Net|MDB2|HTTP)_(.+)/', "\\1/\\2", $classname);
-
- if ($fp = @fopen("$classname.php", 'r', true)) {
- include_once("$classname.php");
- fclose($fp);
- return true;
- } elseif ($fp = @fopen("api/$classname.php", 'r', true)) {
- include_once("api/$classname.php");
- fclose($fp);
- return true;
- } elseif ($fp = @fopen("client/$classname.php", 'r', true)) {
- include_once("client/$classname.php");
- fclose($fp);
- return true;
- }
-
- return false;
- }
- spl_autoload_register('class_autoloader');
+// Initialization and basic functions
- function query($query, $_conn = 'kolab_wap') {
- require_once('SQL.php');
+// application constants
+define('KADM_START', microtime(true));
+define('KADM_VERSION', '0.1');
+define('KADM_CHARSET', 'utf-8');
+define('INSTALL_PATH', dirname(__FILE__));
- $sql = SQL::get_instance($_conn);
- return $sql->query($query);
+// Check critical PHP settings here.
+$crit_opts = array(
+ 'mbstring.func_overload' => 0,
+ 'magic_quotes_runtime' => 0,
+ 'session.use_cookies' => 1,
+);
+foreach ($crit_opts as $optname => $optval) {
+ if ($optval != ini_get($optname)) {
+ die("ERROR: Wrong '$optname' option value!");
}
+}
- function need_login() {
- print "You are not logged in<br/>";
- print '<form method="post">';
- print '<input type="text" name="username" /><br/>';
- print '<input type="password" name="password" /><br/>';
- print '<input type="submit" name="submit" value="Log in"/></form>';
- echo "<pre>"; print_r($_SESSION); echo "</pre>";
- exit;
- }
+$include_path = INSTALL_PATH . PATH_SEPARATOR;
+$include_path .= INSTALL_PATH . '/client' . PATH_SEPARATOR;
+$include_path .= INSTALL_PATH . '/api' . PATH_SEPARATOR;
+$include_path .= INSTALL_PATH . '/ext' . PATH_SEPARATOR;
+$include_path .= ini_get('include_path');
- function valid_login() {
- // The $_SESSION variable is controlled through lib/User.php's
- // _authenticate()
- //
- return $_SESSION['user']->authenticated();
- }
+if (set_include_path($include_path) === false) {
+ die("Fatal error: ini_set/set_include_path does not work.");
+}
+
+ini_set('error_reporting', E_ALL&~E_NOTICE);
+ini_set('error_log', INSTALL_PATH . '/../logs/errors');
- /**
- * Prints debug info into the 'console' log
- */
- function console() {
- $args = func_get_args();
+// Set internal charset
+mb_internal_encoding(KADM_CHARSET);
+@mb_regex_encoding(KADM_CHARSET);
- $msg = array();
- foreach ($args as $arg) {
- $msg[] = !is_string($arg) ? var_export($arg, true) : $arg;
- }
+// register autoloader
+function class_autoloader($classname) {
+ $classname = preg_replace('/(Net|MDB2|HTTP)_(.+)/', "\\1/\\2", $classname);
- write_log('console', join(";\n", $msg));
+ if ($fp = @fopen("$classname.php", 'r', true)) {
+ include_once("$classname.php");
+ fclose($fp);
+ return true;
}
- /**
- * Appends a line to a log file in the logs directory.
- * Date will be added automatically to the line.
- *
- * @param string $name Name of the log file
- * @param mixed $line Line to append
- */
- function write_log($name, $line) {
- if (!is_string($line)) {
- $line = var_export($line, true);
- }
-
- $log_dir = dirname(__FILE__) . '/../logs';
- $logfile = $log_dir . '/' . $name;
- $date = date('d-M-Y H:i:s O');
- $line = sprintf("[%s](%s): %s\n", $date, session_id(), $line);
-
- if ($fp = @fopen($logfile, 'a')) {
- fwrite($fp, $line);
- fflush($fp);
- fclose($fp);
- }
+ return false;
+}
+
+spl_autoload_register('class_autoloader');
+
+function query($query, $_conn = 'kolab_wap') {
+ require_once('SQL.php');
+
+ $sql = SQL::get_instance($_conn);
+
+ return $sql->query($query);
+}
+
+function need_login() {
+ print "You are not logged in<br/>";
+ print '<form method="post">';
+ print '<input type="text" name="username" /><br/>';
+ print '<input type="password" name="password" /><br/>';
+ print '<input type="submit" name="submit" value="Log in"/></form>';
+ echo "<pre>"; print_r($_SESSION); echo "</pre>";
+ exit;
+}
+
+function valid_login() {
+ // The $_SESSION variable is controlled through lib/User.php's
+ // _authenticate()
+ //
+ return $_SESSION['user']->authenticated();
+}
+
+/**
+ * Prints debug info into the 'console' log
+ */
+function console() {
+ $args = func_get_args();
+
+ $msg = array();
+ foreach ($args as $arg) {
+ $msg[] = !is_string($arg) ? var_export($arg, true) : $arg;
}
+ write_log('console', join(";\n", $msg));
+}
+
+/**
+ * Appends a line to a log file in the logs directory.
+ * Date will be added automatically to the line.
+ *
+ * @param string $name Name of the log file
+ * @param mixed $line Line to append
+ */
+function write_log($name, $line) {
+ if (!is_string($line)) {
+ $line = var_export($line, true);
+ }
+
+ $log_dir = dirname(__FILE__) . '/../logs';
+ $logfile = $log_dir . '/' . $name;
+ $date = date('d-M-Y H:i:s O');
+ $line = sprintf("[%s](%s): %s\n", $date, session_id(), $line);
-?>
+ if ($fp = @fopen($logfile, 'a')) {
+ fwrite($fp, $line);
+ fflush($fp);
+ fclose($fp);
+ }
+}
diff --git a/lib/kolab_admin_api.php b/lib/kolab_admin_api.php
index 65d4311..99e0aa9 100644
--- a/lib/kolab_admin_api.php
+++ b/lib/kolab_admin_api.php
@@ -1,6 +1,5 @@
<?php
-require_once("HTTP/Request2.php");
class kolab_admin_api
{
@@ -17,7 +16,8 @@ class kolab_admin_api
const STATUS_OK = 0;
const STATUS_ERROR = 1;
- const ERROR_INTERNAL = 500;
+ const ERROR_INTERNAL = 100;
+ const ERROR_CONNECTION = 200;
/**
* Class constructor.
@@ -27,6 +27,14 @@ class kolab_admin_api
public function __construct($base_url)
{
$this->base_url = $base_url;
+ $this->init();
+ }
+
+ /**
+ * Initializes HTTP Request object.
+ */
+ public function init()
+ {
$this->request = new HTTP_Request2();
}
@@ -36,7 +44,7 @@ class kolab_admin_api
* @param string $username User name
* @param string $password User password
*
- * @return array Session user data (token, domain)
+ * @return kolab_admin_api_result Request response
*/
public function login($username, $password)
{
@@ -47,12 +55,7 @@ class kolab_admin_api
$response = $this->post('system.authenticate', null, $query);
- if ($token = $response->get('session_token')) {
- return array(
- 'token' => $token,
- 'domain' => $response->get('domain'),
- );
- }
+ return $response;
}
/**
@@ -74,7 +77,6 @@ class kolab_admin_api
*/
public function set_session_token($token)
{
- console("Setting X-Session-Token header to: " . $token);
$this->request->setHeader('X-Session-Token', $token);
}
@@ -162,7 +164,7 @@ class kolab_admin_api
}
catch (Exception $e) {
return new kolab_admin_api_result(null,
- self::ERROR_INTERNAL, $e->getMessage());
+ self::ERROR_CONNECTION, $e->getMessage());
}
try {
@@ -173,14 +175,13 @@ class kolab_admin_api
self::ERROR_INTERNAL, $e->getMessage());
}
-//print_r($body);
$body = @json_decode($body, true);
$err_code = null;
$err_str = null;
if (is_array($body) && (empty($body['status']) || $body['status'] != 'OK')) {
- $err_code = !empty($data['code']) ? $data['code'] : self::ERROR_INTERNAL;
- $err_str = !empty($data['reason']) ? $data['reason'] : 'Unknown error';
+ $err_code = !empty($body['code']) ? $body['code'] : self::ERROR_INTERNAL;
+ $err_str = !empty($body['reason']) ? $body['reason'] : 'Unknown error';
}
else if (!is_array($body)) {
$err_code = self::ERROR_INTERNAL;
@@ -189,4 +190,5 @@ class kolab_admin_api
return new kolab_admin_api_result($body, $err_code, $err_str);
}
+
}
diff --git a/lib/kolab_admin_api_result.php b/lib/kolab_admin_api_result.php
index 772030f..178350f 100644
--- a/lib/kolab_admin_api_result.php
+++ b/lib/kolab_admin_api_result.php
@@ -23,12 +23,12 @@ class kolab_admin_api_result
public function get_error_code()
{
- $this->error_code;
+ return $this->error_code;
}
public function get_error_str()
{
- $this->error_str;
+ return $this->error_str;
}
public function get($name = null)
diff --git a/lib/kolab_admin_client_output.php b/lib/kolab_admin_client_output.php
index 17c5e52..c6c145c 100644
--- a/lib/kolab_admin_client_output.php
+++ b/lib/kolab_admin_client_output.php
@@ -20,9 +20,9 @@ class kolab_admin_client_output
require_once 'Smarty/Smarty.class.php';
$SMARTY = new Smarty;
+
$SMARTY->template_dir = 'skins/' . $this->skin . '/templates';
- $SMARTY->compile_dir = 'cache';
- $SMARTY->plugins_dir = dirname(__FILE__) . '/Smarty/plugins/';
+ $SMARTY->compile_dir = INSTALL_PATH . '/../cache';
$SMARTY->debugging = false;
$this->tpl = $SMARTY;
diff --git a/lib/kolab_admin_client_task.php b/lib/kolab_admin_client_task.php
index 9090a66..77d9c5d 100644
--- a/lib/kolab_admin_client_task.php
+++ b/lib/kolab_admin_client_task.php
@@ -25,7 +25,7 @@ class kolab_admin_client_task
*/
public function __construct()
{
- $this->conf = Conf::get_instance();
+ $this->config_init();
$this->output_init();
$this->api_init();
@@ -58,12 +58,12 @@ class kolab_admin_client_task
$lang = $lang[0];
$lang = str_replace('-', '_', $lang);
- if (file_exists(dirname(__FILE__) . "/locale/$lang.php")) {
+ if (file_exists(INSTALL_PATH . "/locale/$lang.php")) {
$language = $lang;
break;
}
if (isset($aliases[$lang]) && ($alias = $aliases[$lang])
- && file_exists(dirname(__FILE__) . "/locale/$alias.php")
+ && file_exists(INSTALL_PATH . "/locale/$alias.php")
) {
$language = $alias;
break;
@@ -71,10 +71,10 @@ class kolab_admin_client_task
}
$LANG = array();
- @include dirname(__FILE__) . '/locale/en_US.php';
+ @include INSTALL_PATH . '/locale/en_US.php';
if (isset($language)) {
- @include dirname(__FILE__) . "/locale/$language.php";
+ @include INSTALL_PATH . "/locale/$language.php";
setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
}
else {
@@ -84,26 +84,20 @@ class kolab_admin_client_task
self::$translation = $LANG;
}
-<<<<<<< HEAD:public_html/include/kolab_admin_task.php
/**
* Configuration initialization.
*/
private function config_init()
{
- include_once INSTALL_PATH . '/config/config.php';
-
- $this->config = $CONFIG;
+ $this->config = Conf::get_instance();
}
/**
* Output initialization.
*/
-=======
->>>>>>> fa17922ff4fa6617851d6dc4147da0d8660ca2bc:lib/kolab_admin_client_task.php
private function output_init()
{
- $skin = $this->conf->get('kolab_wap', 'skin');
-
+ $skin = $this->config_get('skin', 'default');
$this->output = new kolab_admin_client_output($skin);
}
@@ -112,7 +106,7 @@ class kolab_admin_client_task
*/
private function api_init()
{
- $url = $this->conf->get('kolab_wap', 'api_url');
+ $url = $this->config_get('api_url', '');
$this->api = new kolab_admin_api($url);
}
@@ -127,23 +121,39 @@ class kolab_admin_client_task
if ($login['username']) {
$result = $this->api->login($login['username'], $login['password']);
- if ($result) {
- $this->api->set_session_token($result['token']);
+ if ($token = $result->get('session_token')) {
+ $user = array('token' => $token, 'domain' => $result->get('domain'));
+
+ $this->api->set_session_token($user['token']);
+
// find user settings
$res = $this->api->get('user.info', array('user' => $login['username']));
$res = $res->get();
if (is_array($res) && ($res = array_shift($res))) {
- $result['language'] = $res['preferredlanguage'];
- $result['fullname'] = $res['cn'];
+ $user['language'] = $res['preferredlanguage'];
+ $user['fullname'] = $res['cn'];
}
- $_SESSION['user'] = $result;
+ // Initialize list of user types
+ $this->user_types();
+
+ $_SESSION['user'] = $user;
header('Location: ?');
die;
}
else {
- $this->output->command('display_message', 'loginerror', 'error');
+ $code = $result->get_error_code();
+ $str = $result->get_error_str();
+ $label = 'loginerror';
+
+ if ($code == kolab_admin_api::ERROR_INTERNAL
+ || $code == kolab_admin_api::ERROR_CONNECTION
+ ) {
+ $label = 'internalerror';
+ $this->raise_error(500, 'Login failed. ' . $str);
+ }
+ $this->output->command('display_message', $label, 'error');
}
}
}
@@ -191,18 +201,15 @@ class kolab_admin_client_task
// Check AJAX-only tasks
if ($this->ajax_only && !$ajax) {
- $this->raise_error(500, 'Invalid request type!');
+ $this->raise_error(500, 'Invalid request type!', null, true);
}
// CSRF prevention
- $token = $ajax ? kolab_utils::get_request_header('X-KAP-Request') : $this->get_input('token');
+ $token = $ajax ? kolab_utils::request_header('X-KAP-Request') : $this->get_input('token');
$task = $this->get_task();
- console("Ajax:", $ajax, "Token:", $token, "X-KAP-Request:", kolab_utils::get_request_header('X-KAP-Request'));
- console("User session token:", $_SESSION['user']['token'], "Task:", $task);
-
if ($task != 'main' && $token != $_SESSION['user']['token']) {
- $this->raise_error(403, 'Invalid request data!');
+ $this->raise_error(403, 'Invalid request data!', null, true);
}
}
@@ -214,14 +221,14 @@ class kolab_admin_client_task
if (!empty($_SESSION['user']) && !empty($_SESSION['user']['token'])) {
$this->api->logout();
}
- unset($_SESSION['user']);
+ $_SESSION = array();
if ($this->output->is_ajax()) {
$this->output->command('main_logout');
}
else {
$this->output->assign('login', $this->get_input('login', 'POST'));
- $this->output->add_translation('loginerror');
+ $this->output->add_translation('loginerror', 'internalerror');
$this->output->send('login');
}
exit;
@@ -230,23 +237,27 @@ class kolab_admin_client_task
/**
* Error action (with error logging).
*
- * @param int $code Error code
- * @param string $msg Error message
- * @param array $args Optional arguments (type, file, line)
+ * @param int $code Error code
+ * @param string $msg Error message
+ * @param array $args Optional arguments (type, file, line)
+ * @param bool $output Enable to send output and finish
*/
- public function raise_error($code, $msg, $type = 'PHP')
+ public function raise_error($code, $msg, $args = array(), $output = false)
{
- $log_entry = sprintf("%s Error: %s%s (%s)",
+ $log_line = sprintf("%s Error: %s (%s)",
isset($args['type']) ? $args['type'] : 'PHP',
- $msg,
- isset($arg_arr['file']) ? sprintf(' in %s on line %d', $args['file'], $args['line']) : '',
+ $msg . (isset($args['file']) ? sprintf(' in %s on line %d', $args['file'], $args['line']) : ''),
$_SERVER['REQUEST_METHOD']);
- if (!write_log('errors', $log_entry)) {
+ if (!write_log('errors', $log_line)) {
// send error to PHPs error handler if write_log() didn't succeed
trigger_error($msg);
}
+ if (!$output) {
+ return;
+ }
+
if ($this->output->is_ajax()) {
header("HTTP/1.0 $code $msg");
die;
@@ -287,7 +298,6 @@ class kolab_admin_client_task
}
}
-<<<<<<< HEAD:public_html/include/kolab_admin_task.php
/**
* Returns configuration option value.
*
@@ -298,7 +308,8 @@ class kolab_admin_client_task
*/
public function config_get($name, $fallback = null)
{
- return isset($this->config[$name]) ? $this->config[$name] : $fallback;
+ $value = $this->config->get('kolab_wap', $name);
+ return $value !== null ? $value : $fallback;
}
/**
@@ -306,8 +317,6 @@ class kolab_admin_client_task
*
* @return string Translated string.
*/
-=======
->>>>>>> fa17922ff4fa6617851d6dc4147da0d8660ca2bc:lib/kolab_admin_client_task.php
public static function translate()
{
$args = func_get_args();
@@ -388,15 +397,31 @@ class kolab_admin_client_task
return '<ul>' . implode("\n", $menu) . '</ul>';
}
-<<<<<<< HEAD:public_html/include/kolab_admin_task.php
/**
* Adds watermark page definition into main page.
*/
protected function watermark($name)
-=======
- public function watermark($name)
->>>>>>> fa17922ff4fa6617851d6dc4147da0d8660ca2bc:lib/kolab_admin_client_task.php
{
$this->output->command('set_watermark', $name);
}
+
+ /**
+ * Returns list of user types.
+ *
+ * @param array List of user types
+ */
+ protected function user_types()
+ {
+ if (!isset($_SESSION['user_types'])) {
+ $result = $this->api->post('user_types.list');
+ $list = $result->get();
+
+ if (is_array($list)) {
+ $_SESSION['user_types'] = $list;
+ }
+ }
+
+ return $_SESSION['user_types'];
+ }
+
}
diff --git a/lib/kolab_form.php b/lib/kolab_form.php
index 4c67533..4a59a87 100644
--- a/lib/kolab_form.php
+++ b/lib/kolab_form.php
@@ -10,22 +10,41 @@ class kolab_form
const INPUT_RADIO = 5;
const INPUT_BUTTON = 6;
const INPUT_SUBMIT = 7;
+ const INPUT_SELECT = 8;
+ const INPUT_HIDDEN = 9;
private $attribs = array();
private $elements = array();
private $sections = array();
+ /**
+ * Class constructor.
+ *
+ * @param array $attribs Form attributes
+ */
public function __construct($attribs = array())
{
$this->attribs = $attribs;
}
+ /**
+ * Adds form section definition.
+ *
+ * @param string $index Section internal index
+ * @param string $legend Section label (fieldset's legend)
+ */
public function add_section($index, $legend)
{
$this->sections[$index] = $legend;
}
+ /**
+ * Adds form element definition.
+ *
+ * @param array $attribs Element attributes
+ * @param string $section Section index
+ */
public function add_element($attribs, $section = null)
{
if (!empty($section)) {
@@ -35,6 +54,11 @@ class kolab_form
$this->elements[] = $attribs;
}
+ /**
+ * Returns HTML output of the form.
+ *
+ * @return string HTML output
+ */
public function output()
{
$content = '';
@@ -90,7 +114,13 @@ class kolab_form
),
);
- return array('cells' => $cells);
+ $attrib = array('cells' => $cells);
+
+ if ($element['required']) {
+ $attrib['class'] = 'required';
+ }
+
+ return $attrib;
}
private function get_element($attribs)
@@ -113,8 +143,24 @@ class kolab_form
$content = kolab_html::input($attribs);
break;
+ case self::INPUT_HIDDEN:
+ $attribs['type'] = 'hidden';
+ $content = kolab_html::input($attribs);
+ break;
+
case self::INPUT_TEXTAREA:
- $content = kolab_html::textarea($attribs);
+ if (empty($attribs['rows'])) {
+ $attribs['rows'] = 5;
+ }
+ if (empty($attribs['cols'])) {
+ $attribs['cols'] = 50;
+ }
+
+ $content = kolab_html::textarea($attribs, true);
+ break;
+
+ case self::INPUT_SELECT:
+ $content = kolab_html::select($attribs);
break;
default:
@@ -126,6 +172,10 @@ class kolab_form
}
}
+ if (!empty($attribs['suffix'])) {
+ $content .= ' ' . $attribs['suffix'];
+ }
+
return $content;
}
diff --git a/lib/kolab_html.php b/lib/kolab_html.php
index d8e8d7b..6773fd0 100644
--- a/lib/kolab_html.php
+++ b/lib/kolab_html.php
@@ -119,13 +119,16 @@ class kolab_html
$content = array();
if (!empty($attribs['options']) && is_array($attribs['options'])) {
- foreach ($attribs['options'] as $option) {
-<<<<<<< HEAD:public_html/include/kolab_html.php
+ foreach ($attribs['options'] as $idx => $option) {
+ if (!is_array($option)) {
+ $option = array('content' => $option);
+ }
+ if (empty($option['value'])) {
+ $option['value'] = $idx;
+ }
if (!empty($attribs['value']) && $attribs['value'] == $option['value']) {
$option['selected'] = true;
}
-=======
->>>>>>> fa17922ff4fa6617851d6dc4147da0d8660ca2bc:lib/kolab_html.php
$content[] = self::option($option, $escape);
}
}
@@ -139,13 +142,6 @@ class kolab_html
$elem_attribs = array_merge(self::$option_attribs, self::$common_attribs);
$content = isset($attribs['content']) ? $attribs['content'] : '';
-<<<<<<< HEAD:public_html/include/kolab_html.php
-=======
-
- if ($escape) {
- $content = self::escape($content);
- }
->>>>>>> fa17922ff4fa6617851d6dc4147da0d8660ca2bc:lib/kolab_html.php
if ($escape) {
$content = self::escape($content);
diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php
index 97b8bdf..1acd4ba 100644
--- a/lib/kolab_utils.php
+++ b/lib/kolab_utils.php
@@ -1,78 +1,97 @@
<?php
- class kolab_utils {
- /**
- * Read a specific HTTP request header
- *
- * @param string $name Header name
- * @return mixed Header value or null if not available
- */
- public static function get_request_header($name) {
- if (function_exists('getallheaders')) {
- $hdrs = array_change_key_case(getallheaders(), CASE_UPPER);
- $key = strtoupper($name);
- } else {
- $key = 'HTTP_' . strtoupper(strtr($name, '-', '_'));
- $hdrs = array_change_key_case($_SERVER, CASE_UPPER);
- }
+class kolab_utils
+{
+ const REQUEST_ANY = 0;
+ const REQUEST_GET = 1;
+ const REQUEST_POST = 2;
- if (array_key_exists($key, $hdrs)) {
- return $hdrs[$key];
- } else {
- return null;
- }
+ /**
+ * Read a specific HTTP request header
+ *
+ * @param string $name Header name
+ *
+ * @return mixed Header value or null if not available
+ */
+ public static function request_header($name)
+ {
+ if (function_exists('getallheaders')) {
+ $hdrs = array_change_key_case(getallheaders(), CASE_UPPER);
+ $key = strtoupper($name);
}
-
- /**
- * Make sure the string ends with a slash
- */
- public static function slashify($str)
- {
- return self::unslashify($str).'/';
+ else {
+ $key = 'HTTP_' . strtoupper(strtr($name, '-', '_'));
+ $hdrs = array_change_key_case($_SERVER, CASE_UPPER);
}
- /**
- * Remove slash at the end of the string
- */
- public static function unslashify($str)
- {
- return preg_replace('/\/$/', '', $str);
+ return $hdrs[$key];
+ }
+
+ /**
+ * Returns input parameter value.
+ *
+ * @param string $name Parameter name
+ * @param int $type Parameter type
+ * @param bool $allow_html Enable to strip invalid/unsecure content
+ *
+ * @return mixed Input value
+ */
+ public static function get_input($name, $type = null, $allow_html = false)
+ {
+ if ($type == self::REQUEST_GET) {
+ $value = isset($_GET[$name]) ? $_GET[$name] : null;
+ }
+ else if ($type == self::REQUEST_POST) {
+ $value = isset($_POST[$name]) ? $_POST[$name] : null;
+ }
+ else {
+ $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : null;
}
- public static function get_input($name, $type = null, $allow_html = false)
- {
- if ($type == 'GET') {
- $value = isset($_GET[$name]) ? $_GET[$name] : null;
- }
- else if ($type == 'POST') {
- $value = isset($_POST[$name]) ? $_POST[$name] : null;
- }
- else {
- $value = isset($_REQUEST[$name]) ? $_REQUEST[$name] : null;
- }
+ return self::parse_input($value, $allow_html);
+ }
- return self::parse_input($value, $allow_html);
+ /**
+ * Input parsing.
+ *
+ * @param mixed $value Input value
+ * @param bool $allow_html Enable to strip invalid/unsecure content
+ *
+ * @return mixed Input value
+ */
+ public static function parse_input($value, $allow_html = false)
+ {
+ if (empty($value)) {
+ return $value;
}
- public static function parse_input($value, $allow_html = false)
- {
- if (empty($value)) {
- return $value;
+ if (is_array($value)) {
+ foreach ($value as $idx => $val) {
+ $value[$idx] = self::parse_input($val, $allow_html);
}
+ }
+ // remove HTML tags if not allowed
+ else if (!$allow_html) {
+ $value = strip_tags($value);
+ }
- if (is_array($value)) {
- foreach ($value as $idx => $val) {
- $value[$idx] = self::parse_input($val, $allow_html);
- }
- }
- // remove HTML tags if not allowed
- else if (!$allow_html) {
- $value = strip_tags($value);
- }
+ return $value;
+ }
- return $value;
- }
+ /**
+ * Make sure the string ends with a slash
+ */
+ public static function slashify($str)
+ {
+ return self::unslashify($str).'/';
+ }
+ /**
+ * Remove slash at the end of the string
+ */
+ public static function unslashify($str)
+ {
+ return preg_replace('/\/$/', '', $str);
}
-?>
+}
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index f018885..da5cdb1 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -5,6 +5,8 @@ $LANG['password'] = 'Password';
$LANG['loading'] = 'Loading...';
$LANG['error'] = 'Error';
$LANG['servererror'] = 'Server Error!';
+$LANG['loginerror'] = 'Incorrect username or password!';
+$LANG['internalerror'] = 'Internal system error!';
$LANG['search'] = 'Search';
$LANG['search.criteria'] = 'Search criteria';
@@ -62,4 +64,3 @@ $LANG['group.add'] = 'Add Group';
$LANG['MB'] = 'MB';
$LANG['days'] = 'days';
-$LANG['loginerror'] = 'Incorrect username or password!';