Example #1
0
function main(&$errors)
{
    global $config, $_SERWEB;
    $dh =& Domains::singleton();
    if (false === ($domains = $dh->get_all_dids())) {
        return false;
    }
    foreach ($domains as $did) {
        if (false === update_domain_dir($did)) {
            return false;
        }
    }
    /* update vhosts dir */
    if ($config->apache_vhosts_dir) {
        $target = realpath($_SERWEB["serwebdir"]);
        $local_links = array();
        /* get list of local symlinks */
        $d = dir($config->apache_vhosts_dir);
        while (false !== ($entry = $d->read())) {
            if (is_link($config->apache_vhosts_dir . $entry) and realpath(readlink($config->apache_vhosts_dir . $entry)) == $target) {
                $local_links[] = $entry;
            }
            /* this is need for testing on windows
              			if ($entry != "." and $entry != ".."){
            				$local_links[] = substr($entry, 0, -4);
            			}
             */
        }
        $d->close();
        /* get list of domain names */
        $dom_names = array();
        if (false === ($domains = $dh->get_domains())) {
            return false;
        }
        foreach ($domains as $k => $v) {
            $dom_names[] = $k;
        }
        /* synchronize links in vhosts dir with DB */
        $d_lnk = array_diff($local_links, $dom_names);
        $c_lnk = array_diff($dom_names, $local_links);
        foreach ($d_lnk as $v) {
            remove_vhost_symlink($v);
        }
        foreach ($c_lnk as $v) {
            create_vhost_symlink($v);
        }
    }
    return true;
}
Example #2
0
 /**
  *	Get domain id of domain 
  *	
  *	@static
  *	@param	string	$realm		
  *	@param	array	$opt		
  *	@return	string				domain ID, FALSE on error
  */
 function find_out_did($realm, $opt)
 {
     global $config;
     if (!$config->multidomain) {
         return $config->default_did;
     }
     $dh =& Domains::singleton();
     if (false === ($did = $dh->get_did($realm))) {
         return false;
     }
     if (is_null($did)) {
         return null;
     }
     return $did;
     /*	
     	global $data_auth, $lang_str, $config;
     
     	$data_auth->add_method('get_did_by_realm');
     	
     	$opt = array('check_disabled_flag' => false);
     	if (false === $did = $data_auth->get_did_by_realm($realm, $opt)) return false;
     
     	if (is_null($did)){
     		sw_log("find_out_did: domain id for realm '".$realm."' not found", PEAR_LOG_INFO);
     		ErrorHandler::add_error($lang_str['domain_not_found']);
     		return false;
     	}
     	
     	return $did;
     */
 }
 function validate_form(&$errors)
 {
     global $lang_str, $data, $config;
     if (false === parent::validate_form($errors)) {
         return false;
     }
     $an =& $config->attr_names;
     $d_h =& Domains::singleton();
     if (is_null($this->opt['register_in_domain']) and is_null($this->opt['create_new_domain'])) {
         if (!isset($_POST['domain']) or $_POST['domain'] === "") {
             $errors[] = $lang_str['fe_domain_not_selected'];
             return false;
         }
         $this->did = $_POST['domain'];
         if (!isset($this->domain_names[$this->did])) {
             $errors[] = "You haven't access to domain which you selected: " . $d_h->get_domain_name($this->did);
             return false;
         }
     } elseif (!is_null($this->opt['register_in_domain'])) {
         $this->did = $this->opt['register_in_domain'];
     } else {
         $this->did = null;
     }
     /* vhen user do not have admin privilege, check username assignment mode */
     if (!$this->opt['admin_priv']) {
         if (false === ($this->uname_assign_mode = $this->get_uname_assign_mode($this->did))) {
             return false;
         }
         switch ($this->uname_assign_mode) {
             case "adminonly":
                 $errors[] = "Only admins could register users in this domain";
                 return false;
                 break;
             case "email":
                 //email verification
                 $email_parts = explode("@", $_POST['email'], 2);
                 $email_username = $email_parts[0];
                 $email_domain = $email_parts[1];
                 //set username by the email username
                 $_POST['uname'] = $email_username;
                 if ($this->opt['create_new_domain'] and $email_domain != $this->opt['create_new_domain']) {
                     $errors[] = $lang_str["err_domain_of_email_not_match"];
                     return false;
                 } else {
                     if (false === ($domain_names = $d_h->get_domain_names($this->did))) {
                         return false;
                     }
                     if (!in_array($email_domain, $domain_names)) {
                         $errors[] = $lang_str["err_domain_of_email_not_match"];
                         return false;
                     }
                 }
                 /* confirmation of registration is always required in this case */
                 $this->opt['require_confirmation'] = true;
                 break;
             case "fcfs":
                 //first come first served
                 break;
             default:
                 ErrorHandler::log_errors(PEAR::raiseError("Unknown value of username assignment mode: '" . $this->uname_assign_mode . "'"));
                 return false;
         }
     }
     if (is_null($this->opt['create_new_domain'])) {
         if (0 === ($user_exists = $data->is_user_exists($_POST['uname'], $this->did))) {
             return false;
         }
         if ($user_exists < 0) {
             $errors[] = $lang_str['fe_uname_already_choosen_1'] . " '" . $_POST['uname'] . "' " . $lang_str['fe_uname_already_choosen_2'];
             return false;
         }
     }
     if ($this->opt['choose_passw'] and $_POST['passwd'] != $_POST['passwd_r']) {
         $errors[] = $lang_str['fe_passwords_not_match'];
         return false;
     }
     if ($this->opt['terms_file'] and empty($_POST['accept'])) {
         $errors[] = $lang_str['fe_not_accepted_terms'];
         return false;
     }
     //check values of attributes
     $opt = array();
     if (false === Attributes::validate_form_attrs($this->attributes, $opt, $errors)) {
         return false;
     }
     /* Check email for the case somebody makes the attribute optional.
      * We need it.
      */
     if (!$_POST[$an['email']]) {
         $errors[] = $lang_str['fe_not_valid_email'];
         return false;
     }
     return true;
 }
 function to_smarty()
 {
     global $config;
     $f =& $config->data_sql->credentials->flag_values;
     $dh =& Domains::singleton();
     if (false === ($domainname = $dh->get_domain_name($this->get_did()))) {
         return false;
     }
     return array("uid" => $this->uid, "uname" => $this->uname, "did" => $this->get_did(), "domainname" => $domainname, "realm" => $this->realm, "password" => $this->password, "ha1" => $this->ha1, "ha1b" => $this->ha1b, "for_ser" => $this->flags & $f['DB_LOAD_SER'], "for_serweb" => $this->flags & $f['DB_FOR_SERWEB']);
 }
 /**
  *  Mark domain as deleted
  *
  *  Possible options:
  *
  *    - did		(int)   - REQUIRED - id of domain which will be deleted 
  *                        (default: null)
  *	  - undelete (bool) - undelete domain, setting this to true will 
  *                        undelete only domain names and domain attrs. Not
  *                        URIs and credentials within the domain
  *                        (default: false)
  *      
  *	@param array $opt		associative array of options
  *	@return bool			TRUE on success, FALSE on failure
  */
 function mark_domain_deleted($opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $td_name =& $config->data_sql->domain->table_name;
     $ta_name =& $config->data_sql->domain_attrs->table_name;
     $tu_name =& $config->data_sql->uri->table_name;
     $tc_name =& $config->data_sql->credentials->table_name;
     /* col names */
     $cd =& $config->data_sql->domain->cols;
     $ca =& $config->data_sql->domain_attrs->cols;
     $cu =& $config->data_sql->uri->cols;
     $cc =& $config->data_sql->credentials->cols;
     /* flags */
     $fd =& $config->data_sql->domain->flag_values;
     $fa =& $config->data_sql->domain_attrs->flag_values;
     $fu =& $config->data_sql->uri->flag_values;
     $fc =& $config->data_sql->credentials->flag_values;
     $an =& $config->attr_names;
     $o_did = isset($opt['did']) ? $opt['did'] : null;
     $o_undelete = isset($opt['undelete']) ? (bool) $opt['undelete'] : false;
     if (is_null($o_did)) {
         ErrorHandler::log_errors(PEAR::raiseError('domain for mark as deleted is not specified'));
         return false;
     }
     /* if 'did' column in credentials table is not used, make list of all
          realms matching this domain
        */
     if (!$config->auth['use_did']) {
         $dh =& Domains::singleton();
         if (false === ($dom_names = $dh->get_domain_names($o_did))) {
             return false;
         }
         $da =& Domain_Attrs::singleton($o_did);
         if (false === ($realm = $da->get_attribute($config->attr_names['digest_realm']))) {
             return false;
         }
         $realms_w = array();
         if (!is_null($realm)) {
             $realms_w[] = $cc->realm . " = " . $this->sql_format($realm, "s");
         }
         foreach ($dom_names as $v) {
             $realms_w[] = $cc->realm . " = " . $this->sql_format($v, "s");
         }
     }
     if (false === $this->transaction_start()) {
         return false;
     }
     $domain_attrs =& Domain_Attrs::singleton($o_did);
     if ($o_undelete) {
         if (false === $domain_attrs->unset_attribute($an['deleted_ts'])) {
             $this->transaction_rollback();
             return false;
         }
     } else {
         if (false === $domain_attrs->set_attribute($an['deleted_ts'], time())) {
             $this->transaction_rollback();
             return false;
         }
     }
     $q = "update " . $td_name . " set ";
     if ($o_undelete) {
         $q .= $cd->flags . " = " . $cd->flags . " & ~" . $fd['DB_DELETED'];
     } else {
         $q .= $cd->flags . " = " . $cd->flags . " | " . $fd['DB_DELETED'];
     }
     $q .= " where " . $cd->did . " = " . $this->sql_format($o_did, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     $q = "update " . $ta_name . " set ";
     if ($o_undelete) {
         $q .= $ca->flags . " = " . $ca->flags . " & ~" . $fa['DB_DELETED'];
     } else {
         $q .= $ca->flags . " = " . $ca->flags . " | " . $fa['DB_DELETED'];
     }
     $q .= " where " . $ca->did . " = " . $this->sql_format($o_did, "s");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         $this->transaction_rollback();
         return false;
     }
     if (!$o_undelete) {
         $q = "update " . $tu_name . " set ";
         $q .= $cu->flags . " = " . $cu->flags . " | " . $fu['DB_DELETED'];
         $q .= " where " . $cu->did . " = " . $this->sql_format($o_did, "s");
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             $this->transaction_rollback();
             return false;
         }
         $q = "update " . $tc_name . " set ";
         $q .= $cc->flags . " = " . $cc->flags . " | " . $fc['DB_DELETED'];
         if ($config->auth['use_did']) {
             $q .= " where " . $cc->did . " = " . $this->sql_format($o_did, "s");
         } else {
             if (!$realms_w) {
                 $q .= " where " . $this - sql_format(false, "b");
             } else {
                 $q .= " where " . implode($realms_w, " or ");
             }
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             $this->transaction_rollback();
             return false;
         }
     }
     if (false === $this->transaction_commit()) {
         return false;
     }
     return true;
 }
 /**
  *  Generate DID for new domain
  *
  *  @static
  *  @param  string  domainname  new name of domain
  *  @return string              did or FALSE on error
  */
 function generate_new_did($domainname)
 {
     global $data, $config;
     $an =& $config->attr_names;
     $errors = array();
     /* get format of did to generate */
     $ga =& Global_attrs::singleton();
     if (false === ($format = $ga->get_attribute($an['did_format']))) {
         return false;
     }
     switch ($format) {
         /* numeric DID */
         case 1:
             $data->add_method('get_new_domain_id');
             if (false === ($did = $data->get_new_domain_id(null, $errors))) {
                 ErrorHandler::add_error($errors);
                 return false;
             }
             break;
             /* UUID by rfc4122 */
         /* UUID by rfc4122 */
         case 2:
             $did = rfc4122_uuid();
             /* check if did doesn't exists */
             $dh =& Domains::singleton();
             if (false === ($dids = $dh->get_all_dids())) {
                 return false;
             }
             while (in_array($did, $dids, true)) {
                 $did = rfc4122_uuid();
             }
             break;
             /* DID as 'domainname' */
         /* DID as 'domainname' */
         case 0:
         default:
             /* if format of UIDs is not set, assume the first choice */
             if (!$domainname) {
                 $domainname = "default_domain";
             }
             // if domain name is not provided
             $did = $domainname;
             /* check if did doesn't exists */
             $dh =& Domains::singleton();
             if (false === ($dids = $dh->get_all_dids())) {
                 return false;
             }
             $i = 0;
             while (in_array($did, $dids, true)) {
                 $did = $domainname . "_" . $i++;
             }
             break;
     }
     return $did;
 }
Example #7
0
 /**
  *  create html form 
  *
  *  @param array $errors    array with error messages
  *  @return null            FALSE on failure
  */
 function create_html_form(&$errors)
 {
     parent::create_html_form($errors);
     global $lang_str, $data, $config, $sess;
     $f =& $config->data_sql->uri->flag_values;
     $domains =& Domains::singleton();
     if (false === ($this->domain_names = $domains->get_id_name_pairs())) {
         return false;
     }
     /* create a list of allowed domain names for the form */
     if (is_array($this->opt['allowed_domains'])) {
         $alowed_domain_names = array();
         foreach ($this->opt['allowed_domains'] as $v) {
             $alowed_domain_names[$v] = $this->domain_names[$v];
         }
     } else {
         $alowed_domain_names =& $this->domain_names;
     }
     $dom_options = array();
     foreach ($alowed_domain_names as $k => $v) {
         $dom_options[] = array("label" => $v, "value" => $k);
     }
     $reg =& Creg::singleton();
     if ($this->action['action'] == "edit" or $this->action['action'] == "update") {
         $opt = array();
         $opt['filter']['username'] = new Filter("username", $this->edit['un'], "=", false, false);
         $opt['filter']['did'] = new Filter("did", $this->edit['did'], "=", false, false);
         $opt['filter']['flags'] = new Filter("flags", $this->edit['flags'], "=", false, false);
         $opt['filter']['scheme'] = new Filter("scheme", $this->edit['scheme'], "=", false, false);
         if (false === ($uri = $data->get_uris($this->controler->user_id->get_uid(), $opt))) {
             return false;
         }
         if (!count($uri)) {
             $uri = new URI($this->controler->user_id->get_uid(), "", "", $f['DB_CANON']);
             $errors[] = $lang_str['tcssr_err_rs_prefix_to_edit_not_found'];
         } else {
             //get first (and only) element of array
             $uri = reset($uri);
         }
         $this->edit_uri =& $uri;
         $edit = true;
     } else {
         $uri = new URI($this->controler->user_id->get_uid(), "", "", &$config->data_sql->uri->flag_values['DB_CANON']);
         $this->edit_uri =& $uri;
         $edit = false;
     }
     $this->f->add_element(array("type" => "text", "name" => "uri_un", "value" => $this->edit_uri->username, "js_trim_value" => true, "size" => 16, "maxlength" => 64, "minlength" => 1, "valid_regex" => "^" . $reg->user . "\$", "valid_e" => $lang_str['fe_not_valid_username'], "length_e" => $lang_str['fe_not_filled_username'], "value" => $this->edit_uri->username, "extrahtml" => "onkeyup='alias_ctl.onAliasChange();' oncut='alias_ctl.onAliasChange();' onpaste='alias_ctl.onAliasChange();'"));
     $this->f->add_element(array("type" => "select", "name" => "uri_did", "options" => $dom_options, "value" => $this->edit_uri->did, "size" => 1, "extrahtml" => "onchange='alias_ctl.onAliasChange();' onkeyup='alias_ctl.onAliasChange();'"));
     $this->f->add_element(array("type" => "checkbox", "name" => "uri_is_canon", "checked" => (bool) ($this->edit_uri->flags & $f['DB_CANON']), "value" => 1));
     if ($this->action['action'] == "edit" or $this->action['action'] == "update") {
         $this->f->add_element(array("type" => "hidden", "name" => "uri_un_edit", "value" => $this->edit_uri->username));
         $this->f->add_element(array("type" => "hidden", "name" => "uri_did_edit", "value" => $this->edit_uri->did));
         $this->f->add_element(array("type" => "hidden", "name" => "uri_flags_edit", "value" => $this->edit_uri->flags));
     }
     $onload_js = "\n            var alias_ctl;\n            alias_ctl = new Aliases_ctl('alias_ctl');\n            alias_ctl.init('" . $this->opt['form_name'] . "', 'uri_un', 'uri_did');\n            alias_ctl.onAliasChangeUrl='" . $sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&uri_usage=1") . "';\n            alias_ctl.aliasSuggestUrl='" . $sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&uri_suggest=1") . "';\n            alias_ctl.aliasGenerateUrl='" . $sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&uri_generate=1") . "';\n            alias_ctl.lang_str.no_suggestions='" . js_escape($lang_str['no_suggestions']) . "'                \n        ";
     $this->controler->set_onload_js($onload_js);
 }
 /**
  *  Get array of uids which URIs and credentials asociated ONLY with 
  *  the domain. And not with any other domain.
  *
  *  Possible options:
  *   - none
  *
  *  @param  string  $did        Domain ID
  *  @param  array   $opt        array of options
  *  @return array               FALSE on error
  */
 function get_uid_of_domain($did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tu_name =& $config->data_sql->uri->table_name;
     $tc_name =& $config->data_sql->credentials->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     $cc =& $config->data_sql->credentials->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     $fc =& $config->data_sql->credentials->flag_values;
     /* if 'did' column in credentials table is not used, make list of all
          realms matching this domain
        */
     if (!$config->auth['use_did']) {
         $dh =& Domains::singleton();
         if (false === ($dom_names = $dh->get_domain_names($did))) {
             return false;
         }
         $da =& Domain_Attrs::singleton($did);
         if (false === ($realm = $da->get_attribute($config->attr_names['digest_realm']))) {
             return false;
         }
         $realms_w1 = array();
         $realms_w2 = array();
         if (!is_null($realm)) {
             $realms_w1[] = $cc->realm . " = " . $this->sql_format($realm, "s");
             $realms_w2[] = $cc->realm . " != " . $this->sql_format($realm, "s");
         }
         foreach ($dom_names as $v) {
             $realms_w1[] = $cc->realm . " = " . $this->sql_format($v, "s");
             $realms_w2[] = $cc->realm . " != " . $this->sql_format($v, "s");
         }
     }
     $uids = array();
     /* get list of UIDs which have URI asociated with the domain */
     $q = "select distinct " . $cu->uid . " as uid\n            from " . $tu_name . "\n            where  " . $cu->did . " = " . $this->sql_format($did, "s") . " and \n                  (" . $cu->flags . " & " . $fu['DB_DISABLED'] . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     /* add the list to UIDs array */
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $uids[$row['uid']] = true;
     }
     /* get list of UIDs which have credentials asociated with the domain */
     if ($config->auth['use_did']) {
         $q = "select distinct " . $cc->uid . " as uid\n                from " . $tc_name . "\n                where  " . $cc->did . " = " . $this->sql_format($did, "s") . " and \n                      (" . $cc->flags . " & " . $fc['DB_DISABLED'] . ") = 0";
     } else {
         if (!$realms_w1) {
             $realms_w1 = array($this - sql_format(false, "b"));
         }
         $q = "select distinct " . $cc->uid . " as uid\n                from " . $tc_name . "\n                where  (" . implode($realms_w1, " or ") . ") and \n                      (" . $cc->flags . " & " . $fc['DB_DISABLED'] . ") = 0";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     /* add the list to UIDs array */
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $uids[$row['uid']] = true;
     }
     /* get list of UIDs which have URI asociated with other domains */
     $q = "select distinct " . $cu->uid . " as uid\n            from " . $tu_name . "\n            where  " . $cu->did . " != " . $this->sql_format($did, "s") . " and \n                  (" . $cu->flags . " & " . $fu['DB_DISABLED'] . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     /* and remove them from UIDs array */
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         if (isset($uids[$row['uid']])) {
             unset($uids[$row['uid']]);
         }
     }
     /* get list of UIDs which have credentials asociated with other domains */
     if ($config->auth['use_did']) {
         $q = "select distinct " . $cc->uid . " as uid\n                from " . $tc_name . "\n                where  " . $cc->did . " != " . $this->sql_format($did, "s") . " and \n                      (" . $cc->flags . " & " . $fc['DB_DISABLED'] . ") = 0";
     } else {
         if (!$realms_w2) {
             $realms_w1 = array($this - sql_format(true, "b"));
         }
         $q = "select distinct " . $cc->uid . " as uid\n                from " . $tc_name . "\n                where  (" . implode($realms_w2, " and ") . ") and \n                      (" . $cc->flags . " & " . $fc['DB_DISABLED'] . ") = 0";
     }
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     /* and remove them from UIDs array */
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         if (isset($uids[$row['uid']])) {
             unset($uids[$row['uid']]);
         }
     }
     return array_keys($uids);
 }
 /**
  *	create html form 
  *
  *	@param array $errors	array with error messages
  *	@return null			FALSE on failure
  */
 function create_html_form(&$errors)
 {
     parent::create_html_form($errors);
     global $data, $lang_str, $config;
     /* get list of credentials */
     if (false === ($this->credentials = $data->get_credentials($this->controler->user_id->get_uid(), null))) {
         return false;
     }
     $did = $uname = $realm = $password = null;
     $for_ser = $for_serweb = true;
     if ($this->action['action'] == 'edit') {
         foreach ($this->credentials as $k => $v) {
             if ($v->get_uname() == $this->edit_uname and $v->get_realm() == $this->edit_realm and (!$config->auth['use_did'] or $v->get_did() == $this->edit_did)) {
                 $uname = $v->get_uname();
                 $realm = $v->get_realm();
                 $did = $v->get_did();
                 $password = $v->get_password();
                 $for_ser = $v->is_for_ser();
                 $for_serweb = $v->is_for_serweb();
                 break;
             }
         }
     }
     $domains =& Domains::singleton();
     if (false === ($domain_names = $domains->get_id_name_pairs())) {
         return false;
     }
     $dom_options = array();
     foreach ($domain_names as $k => $v) {
         $dom_options[] = array("label" => $v, "value" => $k);
     }
     $this->f->add_element(array("type" => "text", "name" => "cr_uname", "size" => 16, "maxlength" => 64, "value" => $uname, "minlength" => 1, "length_e" => $lang_str['fe_not_filled_username'], "valid_regex" => $config->username_regex, "valid_e" => $lang_str['fe_uname_not_follow_conventions']));
     $this->f->add_element(array("type" => "select", "name" => "cr_domain", "options" => $dom_options, "value" => $did, "size" => 1));
     $this->f->add_element(array("type" => "text", "name" => "cr_passw", "size" => 16, "maxlength" => 28, "value" => $password));
     $this->f->add_element(array("type" => "checkbox", "name" => "cr_for_ser", "value" => "1", "checked" => $for_ser));
     $this->f->add_element(array("type" => "checkbox", "name" => "cr_for_serweb", "value" => "1", "checked" => $for_serweb));
     $this->f->add_element(array("type" => "hidden", "name" => "cr_e_un", "value" => $this->edit_uname));
     $this->f->add_element(array("type" => "hidden", "name" => "cr_e_re", "value" => $this->edit_realm));
     $this->f->add_element(array("type" => "hidden", "name" => "cr_e_did", "value" => $this->edit_did));
     if (!$config->clear_text_pw) {
         $this->js_before .= "\n\t\t\t\tif (f.cr_e_un.value != '' &&   //perform this check only when modifing credential, not when creating new one\n\t\t\t\t    f.cr_e_did.value != f.cr_domain[f.cr_domain.selectedIndex].value &&\n\t\t\t\t    f.cr_passw.value == ''){\n\t\t\t\t\t\n\t\t\t\t\talert('" . addslashes($lang_str['err_credential_changed_domain']) . "');\n\t\t\t\t\tf.cr_passw.focus();\n\t\t\t\t\treturn (false);\n\t\t\t\t}\n\t\t\t\n\t\t\t";
     }
 }
Example #10
0
/**
 *	Get domain ID of domain of current virtualhost (the value in $config->domain)
 *	
 *	If domain ID is not found, this function return NULL
 *	
 *	@return	string		domain ID or FALSE on error
 */
function get_did_of_virtualhost()
{
    global $config;
    if (isset($_SESSION['get_did_of_virtualhost']['domain']) and $_SESSION['get_did_of_virtualhost']['domain'] == $config->domain and isset($_SESSION['get_did_of_virtualhost']['did'])) {
        return $_SESSION['get_did_of_virtualhost']['did'];
    }
    $dh =& Domains::singleton();
    if (false === ($did = $dh->get_did($config->domain))) {
        return false;
    }
    if (is_null($did)) {
        return null;
    }
    $_SESSION['get_did_of_virtualhost']['did'] = $did;
    $_SESSION['get_did_of_virtualhost']['domain'] = $config->domain;
    return $did;
}
Example #11
0
 function create_html_form(&$errors)
 {
     parent::create_html_form($errors);
     global $lang_str, $config, $sess;
     $domains =& Domains::singleton();
     if (false === ($this->domain_names = $domains->get_id_name_pairs())) {
         return false;
     }
     if ($this->opt['allow_edit']) {
         $an =& $config->attr_names;
         $f =& $config->data_sql->uri->flag_values;
         /* create a list of allowed domain names for the form */
         if (is_array($this->opt['allowed_domains'])) {
             $alowed_domain_names = array();
             foreach ($this->opt['allowed_domains'] as $v) {
                 $alowed_domain_names[$v] = $this->domain_names[$v];
             }
         } else {
             $alowed_domain_names =& $this->domain_names;
         }
         /* if flags is not set, get the default flags */
         if (!isset($this->act_alias['flags'])) {
             $ga_handler =& Global_attrs::singleton();
             if (false === ($this->act_alias['flags'] = $ga_handler->get_attribute($an['uri_default_flags']))) {
                 return false;
             }
             if (!is_numeric($this->act_alias['flags'])) {
                 ErrorHandler::log_errors(PEAR::raiseError("Global attribute '" . $an['uri_default_flags'] . "' is not defined or is not a number Can't create URI."));
                 return false;
             }
             /* if user ha not aliases set he 'canon' flag to true */
             if (false === $this->get_aliases($errors)) {
                 return false;
             }
             if (!count($this->aliases)) {
                 $this->act_alias['flags'] |= $f['DB_CANON'];
             }
         }
         $f_canon = (bool) ($this->act_alias['flags'] & $f['DB_CANON']);
         $f_is_to = (bool) ($this->act_alias['flags'] & $f['DB_IS_TO']);
         $f_is_from = (bool) ($this->act_alias['flags'] & $f['DB_IS_FROM']);
         $dom_options = array();
         foreach ($alowed_domain_names as $k => $v) {
             $dom_options[] = array("label" => $v, "value" => $k);
         }
         $reg =& Creg::singleton();
         $this->f->add_element(array("type" => "text", "name" => "al_username", "size" => 16, "maxlength" => 64, "minlength" => 1, "valid_regex" => "^" . $reg->user . "\$", "valid_e" => $lang_str['fe_not_valid_username'], "length_e" => $lang_str['fe_not_filled_username'], "value" => isset($this->act_alias['username']) ? $this->act_alias['username'] : "", "extrahtml" => "onkeyup='alias_ctl.onAliasChange();' oncut='alias_ctl.onAliasChange();' onpaste='alias_ctl.onAliasChange();'"));
         $this->f->add_element(array("type" => "select", "name" => "al_domain", "options" => $dom_options, "value" => isset($this->act_alias['did']) ? $this->act_alias['did'] : $this->user_id->get_did(), "size" => 1, "extrahtml" => "onchange='alias_ctl.onAliasChange();' onkeyup='alias_ctl.onAliasChange();'"));
         $this->f->add_element(array("type" => "checkbox", "name" => "al_is_canon", "checked" => $f_canon, "value" => 1));
         $this->f->add_element(array("type" => "checkbox", "name" => "al_is_from", "checked" => $f_is_from, "value" => 1));
         $this->f->add_element(array("type" => "checkbox", "name" => "al_is_to", "checked" => $f_is_to, "value" => 1));
         $this->f->add_element(array("type" => "hidden", "name" => "al_id_u", "value" => isset($this->act_alias['username']) ? $this->act_alias['username'] : ""));
         $this->f->add_element(array("type" => "hidden", "name" => "al_id_d", "value" => isset($this->act_alias['did']) ? $this->act_alias['did'] : ""));
         $this->f->add_element(array("type" => "hidden", "name" => "al_id_f", "value" => $this->act_alias['flags']));
         $onload_js = "\n                var alias_ctl;\n                alias_ctl = new Aliases_ctl('alias_ctl');\n                alias_ctl.init('" . $this->opt['form_name'] . "', 'al_username', 'al_domain');\n                alias_ctl.onAliasChangeUrl='" . $sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&uri_usage=1") . "';\n                alias_ctl.aliasSuggestUrl='" . $sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&uri_suggest=1") . "';\n                alias_ctl.aliasGenerateUrl='" . $sess->url($_SERVER['PHP_SELF'] . "?kvrk=" . uniqID("") . "&uri_generate=1") . "';\n                alias_ctl.lang_str.no_suggestions='" . js_escape($lang_str['no_suggestions']) . "'                \n            ";
         $this->controler->set_onload_js($onload_js);
     }
 }