Example #1
0
 /**
  * check if old password is correct
  */
 protected function _validate_oldpass($field, $val)
 {
     if ($this->login($this->id, $val)) {
         return true;
     }
     $this->errormsg[$field] = Config::lang('pPassword_password_current_text_error');
     return false;
 }
Example #2
0
 public function setConfigs()
 {
     if ($lang = Libs_Session::start()->getParam($this->KEY_LANG)) {
         Config::$lang = $lang;
         return true;
     } else {
         return false;
     }
 }
 /**
  * @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;
 }
Example #4
0
 /**
  * compare two password fields
  * typically called from _validate_password2()
  * @param string $field1 - "password" field
  * @param string $field2 - "repeat password" field
  */
 protected function compare_password_fields($field1, $field2)
 {
     if ($this->RAWvalues[$field1] == $this->RAWvalues[$field2]) {
         unset($this->errormsg[$field2]);
         # no need to warn about too short etc. passwords - it's enough to display this message at the 'password' field
         return true;
     }
     $this->errormsg[$field2] = Config::lang('pEdit_mailbox_password_text_error');
     return false;
 }
Example #5
0
 protected function read_from_db_postprocess($db_result)
 {
     foreach ($db_result as $key => $row) {
         # convert 'domains' field to an array
         if ($row['domains'] == '') {
             $db_result[$key]['domains'] = array();
         } else {
             $db_result[$key]['domains'] = explode(',', $row['domains']);
         }
         if ($row['superadmin']) {
             $db_result[$key]['domain_count'] = Config::lang('super_admin');
         }
     }
     return $db_result;
 }
Example #6
0
 protected function _validate_src_password($field, $val)
 {
     if ($val == '') {
         $this->errormsg[$field] = Config::lang('pFetchmail_password_missing');
         return false;
     }
     return true;
 }
Example #7
0
 protected function _validate_goto($field, $val)
 {
     if (count($val) == 0) {
         # empty is ok for mailboxes - this is checked in setmore() which can clear the error message
         $this->errormsg[$field] = Config::lang('pEdit_alias_goto_text_error1');
         return false;
     }
     $errors = array();
     foreach ($val as $singlegoto) {
         if (substr($this->id, 0, 1) == '@' && substr($singlegoto, 0, 1) == '@') {
             # domain-wide forward - check only the domain part
             # only allowed if $this->id is a catchall
             # Note: alias domains are better, but we should keep this way supported for backward compatibility
             #       and because alias domains can't forward to external domains
             list(, $domain) = explode('@', $singlegoto);
             $domain_check = check_domain($domain);
             if ($domain_check != '') {
                 $errors[] = "{$singlegoto}: {$domain_check}";
             }
         } else {
             $email_check = check_email($singlegoto);
             if ($email_check != '') {
                 $errors[] = "{$singlegoto}: {$email_check}";
             }
         }
     }
     if (count($errors)) {
         $this->errormsg[$field] = join("   ", $errors);
         # TODO: find a way to display multiple error messages per field
         return false;
     } else {
         return true;
     }
 }
Example #8
0
            $fielderror[$key] = $errormsg[$key];
            unset($errormsg[$key]);
        } else {
            $fielderror[$key] = '';
        }
        if (isset($values[$key])) {
            $smarty->assign("value_{$key}", $values[$key]);
        } else {
            $smarty->assign("value_{$key}", $form_fields[$key]['default']);
        }
    }
}
if (count($errormsg)) {
    flash_error($errormsg);
}
# display the remaining error messages (not related to a field) with flash_error
if ($new) {
    $smarty->assign('mode', 'create');
    $smarty->assign('formtitle', Config::lang($formconf['formtitle_create']));
    $smarty->assign('submitbutton', Config::lang($formconf['create_button']));
} else {
    $smarty->assign('mode', 'edit');
    $smarty->assign('formtitle', Config::lang($formconf['formtitle_edit']));
    $smarty->assign('submitbutton', Config::lang('save'));
}
$smarty->assign('struct', $form_fields);
$smarty->assign('fielderror', $fielderror);
$smarty->assign('table', $table);
$smarty->assign('smarty_template', 'editform');
$smarty->display('index.tpl');
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
Example #9
0
/**
 * Check if a password is strong enough based on the conditions in $CONF['password_validation']
 * @param String $password
 * @return array of error messages, or empty array if the password is ok
 */
function validate_password($password)
{
    $val_conf = Config::read('password_validation');
    $result = array();
    $minlen = (int) Config::read('min_password_length');
    # used up to 2.3.x - check it for backward compatibility
    if ($minlen > 0) {
        $val_conf['/.{' . $minlen . '}/'] = "password_too_short {$minlen}";
    }
    foreach ($val_conf as $regex => $message) {
        if (!preg_match($regex, $password)) {
            $msgparts = preg_split("/ /", $message, 2);
            if (count($msgparts) == 1) {
                $result[] = Config::lang($msgparts[0]);
            } else {
                $result[] = sprintf(Config::lang($msgparts[0]), $msgparts[1]);
            }
        }
    }
    return $result;
}
Example #10
0
 /**
  * validate target_domain field - it must be != $this->id to avoid a loop
  */
 protected function _validate_target_domain($field, $val)
 {
     if ($val == $this->id) {
         $this->errormsg[$field] = Config::lang('alias_domain_to_itsself');
         return false;
     }
     return true;
 }
 /**
  * called by $this->store() after storing $this->values in the database
  * can be used to update additional tables, call scripts etc.
  */
 protected function storemore()
 {
     if ($this->new && $this->values['default_aliases']) {
         foreach (Config::read('default_aliases') as $address => $goto) {
             $address = $address . "@" . $this->id;
             # if $goto doesn't contain @, let the alias point to the same domain
             if (!strstr($goto, '@')) {
                 $goto = $goto . "@" . $this->id;
             }
             # TODO: use AliasHandler->add instead of writing directly to the alias table
             $arr = array('address' => $address, 'goto' => $goto, 'domain' => $this->id);
             $result = db_insert('alias', $arr);
             # TODO: error checking
         }
     }
     if ($this->new) {
         if (!$this->domain_postcreation()) {
             $this->errormsg[] = Config::lang('domain_postcreate_failed');
         }
     } else {
         # we don't have domain_postedit()
     }
     return true;
     # TODO: don't hardcode
 }