function eval_size($aSize) { if ($aSize == 0) { $ret_val = Config::Lang('pOverview_unlimited'); } elseif ($aSize < 0) { $ret_val = Config::Lang('pOverview_disabled'); } else { $ret_val = $aSize; } return $ret_val; }
protected function _validate_src_server($field, $val) { if ($val == '') { $msg = Config::Lang('pFetchmail_server_missing'); } else { $msg = check_domain($val); } if ($msg == '') { return true; } else { $this->errormsg[$field] = $msg; return false; } }
/** * actually view something * * @param string address to view */ protected function __handle($address) { $handler = new $this->handler_to_use($this->new); if (!$handler->init($address)) { $this->err($handler->errormsg); return; } if (!$handler->view()) { $this->err($handler->errormsg); return; } $result = $handler->result(); $struct = $handler->getStruct(); foreach (array_keys($struct) as $field) { if (isset($struct[$field]) && empty($struct[$field]['label'])) { # $struct[$field]['label'] = "--- $field ---"; $struct[$field]['display_in_list'] = 0; } if ($struct[$field]['display_in_list'] == 0) { # do nothing } else { $value = $result[$field]; $func = "_formatted_" . $field; if (method_exists($handler, $func)) { $value = $handler->{$func}($result); # call _formatted_$fieldname() } if ($struct[$field]['type'] == 'txtl') { # $value = join("\n" . str_repeat(" ", 20 + 2), $value); # multiline, one item per line $value = join(", ", $value); # one line, comma-separated } elseif ($struct[$field]['type'] == 'bool') { $value = Config::Lang($value ? 'YES' : 'NO'); } $this->out(sprintf("%20s: %s", $struct[$field]['label'], $value)); } } }
/** * @return boolean true on success; false on failure * @param string $old_password * @param string $new_passwords * @param bool $match = true * * All passwords need to be plain text; they'll be hashed appropriately * as per the configuration in config.inc.php */ public function change_pw($new_password, $old_password, $match = true) { list(, $domain) = explode('@', $this->id); if ($match == true) { if (!$this->login($this->id, $old_password)) { db_log($domain, 'edit_password', "MATCH FAILURE: " . $this->id); $this->errormsg[] = Config::Lang('pPassword_password_current_text_error'); return false; } } $set = array('password' => pacrypt($new_password)); $result = db_update('mailbox', 'username', $this->id, $set); if ($result != 1) { db_log($domain, 'edit_password', "FAILURE: " . $this->id); $this->errormsg[] = Config::lang('pEdit_mailbox_result_error'); return false; } db_log($domain, 'edit_password', $this->id); return true; }
/** * build_select_query * * helper function to build the inner part of the select query * can be used by read_from_db() and for generating the pagebrowser * * @param array or string - condition (an array will be AND'ed using db_where_clause, a string will be directly used) * (if you use a string, make sure it is correctly escaped!) * - WARNING: will be changed to array only in the future, with an option to include a raw string inside the array * @param array searchmode - operators to use (=, <, >) if $condition is an array. Defaults to = if not specified for a field. * @return array - contains query parts */ protected function build_select_query($condition, $searchmode) { $select_cols = array(); $yes = escape_string(Config::lang('YES')); $no = escape_string(Config::lang('NO')); if (db_pgsql()) { $formatted_date = "TO_DATE(text(###KEY###), '" . escape_string(Config::Lang('dateformat_pgsql')) . "')"; $base64_decode = "DECODE(###KEY###, 'base64')"; } elseif (db_sqlite()) { $formatted_date = "strftime(###KEY###, '" . escape_string(Config::Lang('dateformat_mysql')) . "')"; $base64_decode = "base64_decode(###KEY###)"; } else { $formatted_date = "DATE_FORMAT(###KEY###, '" . escape_string(Config::Lang('dateformat_mysql')) . "')"; $base64_decode = "FROM_BASE64(###KEY###)"; } $colformat = array('ts' => "{$formatted_date} AS ###KEY###, ###KEY### AS _###KEY###", 'bool' => "CASE ###KEY### WHEN '" . db_get_boolean(true) . "' THEN '1' WHEN '" . db_get_boolean(false) . "' THEN '0' END as ###KEY###," . "CASE ###KEY### WHEN '" . db_get_boolean(true) . "' THEN '{$yes}' WHEN '" . db_get_boolean(false) . "' THEN '{$no}' END as _###KEY###", 'b64p' => "{$base64_decode} AS ###KEY###"); # get list of fields to display $extrafrom = ""; foreach ($this->struct as $key => $row) { if (($row['display_in_list'] != 0 || $row['display_in_form'] != 0) && $row['not_in_db'] == 0) { if ($row['select'] != '') { $key = $row['select']; } if ($row['extrafrom'] != '') { $extrafrom = $extrafrom . " " . $row['extrafrom'] . "\n"; } if (isset($colformat[$row['type']])) { $select_cols[] = str_replace('###KEY###', $key, $colformat[$row['type']]); } else { $select_cols[] = $key; } } } $cols = join(',', $select_cols); $table = table_by_key($this->db_table); $additional_where = ''; if ($this->domain_field != "") { $additional_where .= " AND " . db_in_clause($this->domain_field, $this->allowed_domains); } # if logged in as user, restrict to the items the user is allowed to see if (!$this->is_admin && $this->user_field != '') { $additional_where .= " AND " . $this->user_field . " = '" . escape_string($this->username) . "' "; } if (is_array($condition)) { if (isset($condition['_']) && count($this->searchfields) > 0) { $simple_search = array(); foreach ($this->searchfields as $field) { $simple_search[] = "{$field} LIKE '%" . escape_string($condition['_']) . "%'"; } $additional_where .= " AND ( " . join(" OR ", $simple_search) . " ) "; unset($condition['_']); } $where = db_where_clause($condition, $this->struct, $additional_where, $searchmode); } else { if ($condition == "") { $condition = '1=1'; } $where = " WHERE ( {$condition} ) {$additional_where}"; } return array('select_cols' => " SELECT {$cols} ", 'from_where_order' => " FROM {$table} {$extrafrom} {$where} ORDER BY " . $this->order_by); }
/** * @return true on success false on failure */ public function delete() { if (!$this->view()) { $this->errormsg[] = Config::Lang($this->msg['error_does_not_exist']); return false; } db_delete('domain_admins', $this->id_field, $this->id); db_delete($this->db_table, $this->id_field, $this->id); db_log('admin', 'delete_admin', $this->id); # TODO delete_admin is not a valid db_log keyword yet, and 'admin' is not displayed in viewlog.php $this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->id); return true; }
$gen_show_status_mailbox = array(); $divide_quota = array('current' => array(), 'quota' => array()); if (is_array($tMailbox) and sizeof($tMailbox) > 0) { for ($i = 0; $i < sizeof($tMailbox); $i++) { $gen_show_status_mailbox[$i] = gen_show_status($tMailbox[$i]['username']); if (isset($tMailbox[$i]['current'])) { $divide_quota['current'][$i] = divide_quota($tMailbox[$i]['current']); } if (isset($tMailbox[$i]['quota'])) { $divide_quota['quota'][$i] = divide_quota($tMailbox[$i]['quota']); } if (isset($tMailbox[$i]['quota']) && isset($tMailbox[$i]['current'])) { $divide_quota['percent'][$i] = min(100, round($divide_quota['current'][$i] / max(1, $divide_quota['quota'][$i]) * 100)); $divide_quota['quota_width'][$i] = $divide_quota['percent'][$i] / 100 * 120; } else { $divide_quota['current'][$i] = Config::Lang('unknown'); $divide_quota['quota_width'][$i] = 0; # TODO: use special value? } } } class cNav_bar { var $count, $title, $limit, $page_size, $pages, $search; //* arguments var $url; //* manually var $fInit, $arr_prev, $arr_next, $arr_top; //* internal var $anchor; function cNav_bar($aTitle, $aLimit, $aPage_size, $aPages, $aSearch)
/** * @return true on success false on failure */ public function delete() { if (!$this->view()) { $this->errormsg[] = Config::Lang('alias_does_not_exist'); return false; } if ($this->result['is_mailbox']) { $this->errormsg[] = Config::Lang('mailbox_alias_cant_be_deleted'); return false; } db_delete('alias', 'address', $this->id); list(, $domain) = explode('@', $this->id); db_log($domain, 'delete_alias', $this->id); $this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->id); return true; }
/** * db_log * Action: Logs actions from admin * Call: db_log (string domain, string action, string data) * Possible actions are defined in $LANG["pViewlog_action_$action"] */ function db_log($domain, $action, $data) { $REMOTE_ADDR = getRemoteAddr(); $username = authentication_get_username(); if (Config::Lang("pViewlog_action_{$action}") == '') { die("Invalid log action : {$action}"); // could do with something better? } if (Config::bool('logging')) { $logdata = array('username' => "{$username} ({$REMOTE_ADDR})", 'domain' => $domain, 'action' => $action, 'data' => $data); $result = db_insert('log', $logdata, array('timestamp')); if ($result != 1) { return false; } else { return true; } } }
require_once 'common.php'; if (safeget('token') != $_SESSION['PFA_token']) { die('Invalid token!'); } $username = authentication_get_username(); # enforce login $id = safeget('id'); $table = safeget('table'); $active = safeget('active'); $handlerclass = ucfirst($table) . 'Handler'; if (!preg_match('/^[a-z]+$/', $table) || !file_exists("model/{$handlerclass}.php")) { # validate $table die("Invalid table name given!"); } $handler = new $handlerclass(0, $username); $formconf = $handler->webformConfig(); authentication_require_role($formconf['required_role']); if ($handler->init($id)) { # errors will be displayed as last step anyway, no need for duplicated code ;-) if ($active != '0' && $active != '1') { die(Config::Lang('invalid_parameter')); } if ($handler->set(array('active' => $active))) { $handler->store(); } } flash_error($handler->errormsg); flash_info($handler->infomsg); header("Location: " . $formconf['listview']); exit; /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
/** * @return true on success false on failure */ public function delete() { # TODO: check for _can_delete instead if (!$this->is_superadmin) { $this->errormsg[] = Config::Lang_f('no_delete_permissions', $this->id); return false; } if (!$this->view()) { $this->errormsg[] = Config::Lang('domain_does_not_exist'); # TODO: can users hit this message at all? init() should already fail... return false; } if (Config::bool('alias_domain')) { # check if this domain is an alias domain target - if yes, do not allow to delete it $handler = new AliasdomainHandler(0, $this->admin_username); $handler->getList("target_domain = '" . escape_string($this->id) . "'"); $aliasdomains = $handler->result(); if (count($aliasdomains) > 0) { $this->errormsg[] = Config::Lang_f('delete_domain_aliasdomain_target', $this->id); return false; } } # the correct way would be to recursively delete mailboxes, aliases, alias_domains, fetchmail entries # with *Handler before deleting the domain, but this would be terribly slow on domains with many aliases etc., # so we do it the fast way on the database level # cleaning up all tables doesn't hurt, even if vacation or displaying the quota is disabled # some tables don't have a domain field, so we need a workaround $like_domain = "LIKE '" . escape_string('%@' . $this->id) . "'"; db_delete('domain_admins', 'domain', $this->id); db_delete('alias', 'domain', $this->id); db_delete('mailbox', 'domain', $this->id); db_delete('alias_domain', 'alias_domain', $this->id); db_delete('vacation', 'domain', $this->id); db_delete('vacation_notification', 'on_vacation', $this->id, "OR on_vacation {$like_domain}"); db_delete('quota', 'username', $this->id, "OR username {$like_domain}"); db_delete('quota2', 'username', $this->id, "OR username {$like_domain}"); db_delete('fetchmail', 'mailbox', $this->id, "OR mailbox {$like_domain}"); db_delete('log', 'domain', $this->id); # TODO: should we really delete the log? # finally delete the domain db_delete($this->db_table, $this->id_field, $this->id); if (!$this->domain_postdeletion()) { $this->error_msg[] = $PALANG['domain_postdel_failed']; } db_log($this->id, 'delete_domain', $this->id); # TODO delete_domain is not a valid db_log keyword yet $this->infomsg[] = Config::Lang_f('pDelete_delete_success', $this->id); return true; }
$Admin_role = 0; $Return_url = "main.php"; authentication_require_role('user'); $fUsername = authentication_get_username(); } // is vacation support enabled in $CONF ? if ($CONF['vacation'] == 'NO') { header("Location: {$Return_url}"); exit(0); } date_default_timezone_set(@date_default_timezone_get()); # Suppress date.timezone warnings $vh = new VacationHandler($fUsername); $choice_of_reply = Config::read('vacation_choice_of_reply'); foreach (array_keys($choice_of_reply) as $key) { $choice_of_reply[$key] = Config::Lang($choice_of_reply[$key]); } if ($_SERVER['REQUEST_METHOD'] == "GET") { $tSubject = ''; $tBody = ''; $tActiveFrom = ''; $tActiveUntil = ''; $tUseremail = $fUsername; $tInterval_Time = ''; $details = $vh->get_details(); if ($details != false) { $tSubject = $details['subject']; $tBody = $details['body']; $tInterval_Time = $details['interval_time']; $tActiveFrom = $details['activeFrom']; $tActiveUntil = $details['activeUntil'];