/**
  *  Get array of aliases of user with given sip-uri
  *
  *  Possible options:
  *		none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	array				FALSE on error
  */
 function get_aliases_by_uri($sip_uri, $opt)
 {
     global $config;
     $errors = array();
     /* create connection to proxy where are stored data of user */
     if (isModuleLoaded('xxl') and $this->name != "get_aliases_tmp") {
         $tmp_data = CData_Layer::singleton("get_aliases_tmp", $errors);
         $tmp_data->set_xxl_user_id($sip_uri);
         $tmp_data->expect_user_id_may_not_exists();
         return $tmp_data->get_aliases_by_uri($sip_uri, $errors);
     }
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table's name */
     $tu_name =& $config->data_sql->uri->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     //parse username and domain from sip uri
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return array();
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return array();
         }
     } else {
         $did = $config->default_did;
     }
     $flags_val = $fu['DB_DISABLED'] | $fu['DB_DELETED'];
     $q = "select " . $cu->uid . " as uid\n\t\t    from " . $tu_name . "\n\t\t\twhere  " . $cu->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t\t       " . $cu->username . " = " . $this->sql_format($uname, "s") . " and \n\t\t\t\t  (" . $cu->flags . " & " . $flags_val . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
     if (!$row) {
         unset($res);
         return array();
     }
     $uid = $row['uid'];
     if (is_null($uid)) {
         return array();
     }
     $uri_handler =& URIs::singleton($uid);
     if (false === ($out = $uri_handler->get_URIs())) {
         return false;
     }
     return $out;
 }
 /**
  *	delete alias of user
  *
  *	@param string	$uid		owner of the contact 
  *	@param string	$username	username part from URI
  *	@param string	$did		domain part from URI
  *	@param string	$flags		flags of the URI
  *	@param array	$opt		various options
  *	@return bool				TRUE on success, FALSE on failure
  */
 function delete_uri($uid, $scheme, $username, $did, $flags, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return false;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     $q = "delete from " . $t_name . "\n\t\t      where " . $c->uid . "      = " . $this->sql_format($uid, "s") . " and \n\t\t            " . $c->scheme . "   = " . $this->sql_format($scheme, "s") . " and \n\t\t            " . $c->username . " = " . $this->sql_format($username, "s") . " and \n\t\t            " . $c->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t            " . $c->flags . "    = " . $this->sql_format($flags, "n");
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     if (isModuleLoaded('xxl')) {
         // get domain: $alias_d = domainname of $did
         $alias_uri = "sip:" . $username . "@" . $alias_d;
         if (false === $this->clear_proxy_xxl($alias_uri, null, $errors)) {
             ErrorHandler::add_error($errors);
             return false;
         }
     }
     return true;
 }
Esempio n. 3
0
 /**
  *	create instance of xml rpc client 
  */
 function connect_to_xml_rpc($opt, &$errors)
 {
     global $config, $sess_data_conn;
     $cfg =& $config->ser_rpc;
     if (isset($opt['cluster'])) {
         $proxy = "sip:" . $config->ser_rpc['host'];
     } else {
         if (isset($opt['uri'])) {
             $proxy = $opt['uri'];
         } else {
             if (!$sess_data_conn[$this->name]['proxy']) {
                 if (isModuleLoaded('xxl')) {
                     if (false === $this->get_home_proxy($errors)) {
                         return false;
                     }
                 } else {
                     $this->set_home_proxy("sip:" . $config->ser_rpc['host']);
                 }
             }
             $proxy = $sess_data_conn[$this->name]['proxy'];
         }
     }
     if ($this->rpc and $this->rpc->path == '/' . $proxy) {
         return $this->rpc;
     }
     $this->rpc = $this->make_rpc_client('/' . $proxy);
     return $this->rpc;
 }
    var toolboxToolbar = "<div class='toolboxToolbar'>This is the \"Toolbox Toolbar\"<a class='save'></a><a class='delete'></a></div>";
    <?php 
}
if (isModuleLoaded('drawModule')) {
    echo 'cVars["drawModule"] = [];';
    echo 'cVars["drawModule"]["size"] = [' . $moduleSettings['drawModule']['width'] . ',' . $moduleSettings['drawModule']['height'] . '];';
}
if (isModuleLoaded('assaultModule')) {
    echo 'cVars["assaultModule"] = [];';
    echo 'cVars["assaultModule"]["size"] = [' . $moduleSettings['assaultModule']['width'] . ',' . $moduleSettings['assaultModule']['height'] . '];';
}
if (isModuleLoaded('rigorMortisModule')) {
    echo 'cVars["rigorMortisModule"] = [];';
    echo 'cVars["rigorMortisModule"]["size"] = [' . $moduleSettings['rigorMortisModule']['width'] . ',' . $moduleSettings['rigorMortisModule']['height'] . '];';
}
if (isModuleLoaded('chatModule')) {
    ?>
    cVars["chatModule"] = [];
    
    function chatMinimize(min) {
        if (typeof min == 'undefined') min = true;
        $('chatArea').style.display = (min)?"none":"block";
        $('chatModule').style.top = (min)?"<?php 
    echo $moduleSettings['chatModule']['top'] + $moduleSettings['chatModule']['height'] - 24;
    ?>
px":"<?php 
    echo $moduleSettings['chatModule']['top'];
    ?>
px";
        $('chatModule').style.height = (min)?"24px":"<?php 
    echo $moduleSettings['chatModule']['height'];
Esempio n. 5
0
$_required_apu = array('apu_subscribers', 'apu_sorter', 'apu_filter');
/** include all others necessary files */
require "prepend.php";
$perm->check("admin,hostmaster");
if (!$sess->is_registered('sess_admin')) {
    $sess->register('sess_admin');
    $sess_admin = 1;
}
if (isset($_GET['m_pr_updated'])) {
    $controler->add_message(array('short' => $lang_str['msg_privileges_updated_s'], 'long' => $lang_str['msg_privileges_updated_l']));
}
$sc = new apu_subscribers();
$sr = new apu_sorter();
$filter = new apu_filter();
$filter->set_opt('partial_match', false);
$filter->set_opt('filter_name', 'list_of_admins');
$sc->set_filter($filter);
$sc->set_sorter($sr);
$smarty->assign('domain', $config->domain);
$smarty->assign('xxl_support', isModuleLoaded('xxl'));
$smarty->assign('change_domain_admin', $config->multidomain and $perm->have_perm('hostmaster'));
$sc->set_opt('use_chk_adminsonly', true);
$sc->set_opt('def_chk_adminsonly', true);
if (!$perm->have_perm('hostmaster')) {
    $sc->set_opt('only_from_administrated_domains', true);
}
$controler->add_apu($sc);
$controler->add_apu($sr);
$controler->add_apu($filter);
$controler->set_template_name('a_list_of_admins.tpl');
$controler->start();
 function action_register(&$errors)
 {
     global $config, $data, $lang_str;
     $an =& $config->attr_names;
     /* generate confirmation string */
     $confirm = md5(uniqid(rand()));
     /* obtain password */
     if ($this->opt['choose_passw']) {
         $password = $_POST['passwd'];
     } else {
         /* generate new password */
         $password = substr(md5(uniqid('')), 0, 5);
     }
     if (!$this->opt['create_new_domain']) {
         /* get domain name */
         $domains =& Domains::singleton();
         if (false === ($domain_name = $domains->get_domain_name($this->did))) {
             $data->transaction_rollback();
             return false;
         }
     } else {
         $domain_name = $this->opt['create_new_domain'];
     }
     /* set value of option 'require_confirmation' */
     if (is_null($this->opt['require_confirmation'])) {
         $o = array();
         /* if creating new domain we does not know the DID */
         if (!$this->opt['create_new_domain']) {
             $o['did'] = $this->did;
         }
         if (false === ($this->opt['require_confirmation'] = Attributes::get_attribute($an['require_conf'], $o))) {
             return false;
         }
     }
     if (false === $data->transaction_start()) {
         return false;
     }
     if ($this->opt['create_new_domain']) {
         $sem = new Shm_Semaphore(__FILE__, "s", 1, 0600);
         /* set semaphore to be sure there will not be generated same 
            domain id for two domains */
         if (!$sem->acquire()) {
             $data->transaction_rollback();
             return false;
         }
         if (false === ($this->did = Domains::generate_new_did($this->opt['create_new_domain']))) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         $opt = array("enabled" => !$this->opt['require_confirmation']);
         if (false === DomainManipulator::add_alias($this->did, $this->opt['create_new_domain'], $opt)) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         $a_vals = array("alias" => $this->opt['create_new_domain']);
         if (false === DomainManipulator::update_domain_attrs($this->did, $a_vals)) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         $sem->release();
     }
     /* prepare array of attributes */
     $opt = array();
     $attrs = Attributes::post_attrs_to_array($this->attributes, $opt);
     /* add subscriber */
     $opts = array("disabled" => $this->opt['require_confirmation']);
     if (false === Registration::add_subscriber($_POST['uname'], $this->did, $password, $attrs, $opts)) {
         $data->transaction_rollback();
         return false;
     }
     $uid = $opts['uid'];
     $realm = $opts['realm'];
     $serweb_user =& SerwebUser::instance($uid, $_POST['uname'], $this->did, $realm);
     $user_param = $serweb_user->to_get_param();
     /* get handler of user attrs */
     $ua =& User_Attrs::singleton($uid);
     /* get handler of domain attrs */
     $da =& Domain_Attrs::singleton($this->did);
     if (!is_null($this->opt['set_lang_attr'])) {
         $u_lang = $this->opt['set_lang_attr'];
         /* get the attr_type of the lang attribute */
         $at_handler =& Attr_types::singleton();
         if (false === ($lang_type = $at_handler->get_attr_type($an['lang']))) {
             $data->transaction_rollback();
             return false;
         }
         if (is_null($lang_type)) {
             ErrorHandler::add_error("Type of attribute 'lang' doesn't exists");
             $data->transaction_rollback();
             return false;
         }
         /* format the value */
         $lang_type->check_value($u_lang);
         /* store lang into DB */
         if (false === $ua->set_attribute($an['lang'], $u_lang)) {
             $data->transaction_rollback();
             return false;
         }
     }
     if ($this->opt['create_new_domain']) {
         /* when creating new domain, set admin privilege for the user */
         if (false === $ua->set_attribute($an['is_admin'], "1")) {
             $data->transaction_rollback();
             return false;
         }
         /* and assign user as admin of the domain */
         if (false === $da->set_attribute($an['admin'], array($uid))) {
             $data->transaction_rollback();
             return false;
         }
     }
     if ($this->opt['require_confirmation']) {
         if (false === $ua->set_attribute($an['confirmation'], $confirm)) {
             $data->transaction_rollback();
             return false;
         }
         if (false === $ua->set_attribute($an['pending_ts'], time())) {
             $data->transaction_rollback();
             return false;
         }
         if ($this->opt['create_new_domain']) {
             if (false === $da->set_attribute($an['confirmation'], $confirm)) {
                 $data->transaction_rollback();
                 return false;
             }
             if (false === $da->set_attribute($an['pending_ts'], time())) {
                 $data->transaction_rollback();
                 return false;
             }
         }
     }
     if ($this->opt['create_numeric_alias']) {
         $sem = new Shm_Semaphore(__FILE__, "s", 1, 0600);
         /* set semaphore to be sure there will not be same aliases for two users */
         if (!$sem->acquire()) {
             $data->transaction_rollback();
             return false;
         }
         // generate alias number
         if (false === ($alias = $data->get_new_alias_number($this->did, null))) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         /* store alias to URI table */
         $o = array('disabled' => $this->opt['require_confirmation'], 'canon' => false);
         if (false === $data->add_uri($uid, 'sip', $alias, $this->did, $o)) {
             $data->transaction_rollback();
             $sem->release();
             return false;
         }
         /* reset the semaphore */
         if (!$sem->release()) {
             $data->transaction_rollback();
             return false;
         }
     }
     $sip_address = "sip:" . $_POST['uname'] . "@" . $domain_name;
     $login_url = $config->root_uri . ($this->opt['admin_login'] ? $config->admin_pages_path : $config->user_pages_path) . $this->opt['login_script'];
     $admin_url = $config->root_uri . $config->admin_pages_path . $this->opt['login_script'];
     $username = $config->fully_qualified_name_on_login ? $_POST['uname'] . "@" . $domain_name : $_POST['uname'];
     $confirmation_url = $config->root_uri . $config->user_pages_path . $this->opt['confirmation_script'] . "?nr=" . $confirm . (isModuleLoaded('xxl') ? "&pr=" . RawURLEncode(base64_encode($proxy['proxy'])) : "");
     if (is_null($this->opt['mail_file_conf'])) {
         $this->opt['mail_file_conf'] = $this->opt['mail_file'];
     }
     if ($this->opt['create_new_domain']) {
         if ($this->opt['require_confirmation']) {
             $mail_file = $this->opt['mail_file_domain_conf'];
         } else {
             $mail_file = $this->opt['mail_file_domain'];
         }
     } else {
         if ($this->opt['require_confirmation']) {
             $mail_file = $this->opt['mail_file_conf'];
         } else {
             $mail_file = $this->opt['mail_file'];
         }
     }
     $mail = read_lang_txt_file($mail_file, "txt", $_SESSION['lang'], array(array("domain", $domain_name), array("sip_address", $sip_address), array("login_url", $login_url), array("admin_url", $admin_url), array("confirmation_url", $confirmation_url), array("username", $username), array("password", $password), array("email", isset($_POST[$an['email']]) ? $_POST[$an['email']] : ""), array("first_name", isset($_POST[$an['fname']]) ? $_POST[$an['fname']] : ""), array("last_name", isset($_POST[$an['lname']]) ? $_POST[$an['lname']] : "")));
     if ($mail === false) {
         /* needn't write message to log. It's written by function read_lang_txt_file */
         $errors[] = $lang_str['err_sending_mail'];
         $data->transaction_rollback();
         return false;
     }
     $o = array('did' => $this->did);
     if (false === ($from_header = Attributes::get_attribute($an['contact_email'], $o))) {
         return false;
     }
     if ($from_header) {
         $mail['headers']['from'] = $from_header;
     }
     if (!send_mail($_POST[$an['email']], $mail['body'], $mail['headers'])) {
         $errors[] = $lang_str['err_sending_mail'];
         $this->controler->_form_load_defaults();
         $data->transaction_rollback();
         return false;
     }
     if (false === $data->transaction_commit()) {
         return false;
     }
     if ($this->opt['redirect_on_register']) {
         $this->controler->change_url_for_reload($this->opt['redirect_on_register']);
     }
     return array("m_user_registered=" . RawURLEncode($this->opt['instance_id']), "reg_sip_adr=" . RawURLEncode($sip_address), "require_conf=" . RawURLEncode($this->opt['require_confirmation']), $user_param);
     //$user_param sets the user_id holding ny controller
 }
            <?php 
    echo 'width: ' . $moduleSettings['chatModule']['width'] . 'px; height: ' . $moduleSettings['chatModule']['height'] . 'px;';
    ?>
            <?php 
    echo 'left: ' . $moduleSettings['chatModule']['left'] . 'px; top: ' . $moduleSettings['chatModule']['top'] . 'px;';
    ?>
        }
        #chatArea {
            height: <?php 
    echo $moduleSettings['chatModule']['height'] - 24;
    ?>
px;
        }
        #chatModule input#chatInput { width: <?php 
    echo $moduleSettings['chatModule']['width'] - 182;
    ?>
px; height: 18px; margin-left: 12px; }
    <?php 
}
if (isModuleLoaded('drawModule')) {
    ?>
        #drawModule {
            <?php 
    echo 'width: ' . $moduleSettings['drawModule']['width'] . 'px; height: ' . $moduleSettings['drawModule']['height'] . 'px;';
    ?>
        }
    <?php 
}
?>

</style>
 function action_send_pass(&$errors)
 {
     global $data, $config, $lang_str;
     if (isset($_GET['pr'])) {
         $proxy = base64_decode($_GET['pr']);
         if ($proxy and isModuleLoaded('xxl')) {
             if (false === $data->set_home_proxy($proxy)) {
                 return false;
             }
         }
     }
     if (isModuleLoaded('xxl') and !$proxy) {
         $errors[] = $lang_str['err_reg_conf_not_exists_conf_num'];
         return false;
     }
     if (empty($_GET['u'])) {
         $errors[] = $lang_str['err_reg_conf_not_exists_conf_num'];
         return false;
     }
     $an =& $config->attr_names;
     /* get uid */
     $o = array('name' => $an['confirmation'], 'value' => $this->nr);
     if (false === ($attrs = $data->get_attr_by_val("user", $o))) {
         return false;
     }
     if (empty($attrs[0]['id'])) {
         ErrorHandler::add_error($lang_str['err_reg_conf_not_exists_conf_num']);
         return false;
     }
     $uid = $attrs[0]['id'];
     /* recreate instance of SerwebUser class from get param */
     $serweb_user =& SerwebUser::recreate_from_get_param($_GET['u']);
     /* and compare if uid obtained from user_attrs match to uid inside $serweb_user object */
     if ($uid != $serweb_user->get_uid()) {
         ErrorHandler::add_error($lang_str['err_reg_conf_not_exists_conf_num']);
         return false;
     }
     /* get email address of user */
     $user_attrs =& User_Attrs::singleton($uid);
     if (false === ($email = $user_attrs->get_attribute($an['email']))) {
         return false;
     }
     /* generate new password */
     $password = substr(md5(uniqid('')), 0, 5);
     if (false === $data->set_password_to_user($serweb_user, $password, $errors)) {
         return false;
     }
     $mail = read_lang_txt_file($this->opt['mail_file_pass'], "txt", $_SESSION['lang'], array(array("domain", $this->opt['domain']), array("password", $password)));
     if ($mail === false) {
         /* needn't write message to log. It's written by function read_lang_txt_file */
         $errors[] = $lang_str['err_sending_mail'];
         return false;
     }
     if (false === $this->set_from_header($mail['headers'])) {
         return false;
     }
     if (!send_mail($email, $mail['body'], $mail['headers'])) {
         $errors[] = $lang_str['err_sending_mail'];
         return false;
     }
     /* unset attribute confirmation */
     if (false === $user_attrs->unset_attribute($an['confirmation'])) {
         return false;
     }
     return array("m_fp_pass_sended=" . RawURLEncode($this->opt['instance_id']));
 }
Esempio n. 9
0
 function validate_form(&$errors)
 {
     global $config, $lang_str;
     $uid = null;
     $did = null;
     $realm = null;
     $perms = null;
     // don't display logout mesage in case that form was submited
     if (isset($_GET['logout'])) {
         unset($_GET['logout']);
     }
     if (isset($_GET["redir_id"]) and isModuleLoaded('xxl') and $this->opt['xxl_redirect_after_login']) {
         $this->username = $_GET['uname'];
         $domain = $_GET['realm'];
         $this->password = $_GET['pass'];
     } else {
         if (false === parent::validate_form($errors)) {
             return false;
         }
         $this->password = $_POST['passw'];
         sw_log("User login: values from login form: username: "******", password: "******"^([^@]+)@(.+)", $_POST['uname'], $regs)) {
                 $this->username = $regs[1];
                 $domain = $regs[2];
             } else {
                 sw_log("User login: authentication failed: unsuported format of username. Can't parse username and realm part", PEAR_LOG_INFO);
                 $errors[] = $lang_str['bad_username'];
                 return false;
             }
         } else {
             $this->username = $_POST['uname'];
             $domain = $config->domain;
         }
     }
     sw_log("User login: looking for did of domain: " . $domain, PEAR_LOG_DEBUG);
     /* get did */
     $opt = array();
     $did = call_user_func_array(array($this->opt['auth_class'], 'find_out_did'), array($domain, &$opt));
     if (false === $did) {
         return false;
     }
     if (is_null($did)) {
         sw_log("User login: did not found for domain name: " . $domain, PEAR_LOG_DEBUG);
         ErrorHandler::add_error($lang_str['domain_not_found']);
         return false;
     }
     sw_log("User login: checking password of user with username: "******", did: " . $did, PEAR_LOG_DEBUG);
     /* validate credentials */
     $opt = array();
     $uid = call_user_func_array(array($this->opt['auth_class'], 'validate_credentials'), array($this->username, $did, $this->password, &$opt));
     if (false === $uid) {
         return false;
     }
     if (isset($opt['realm'])) {
         $realm = $opt['realm'];
     }
     /* set_permissions */
     $perms = call_user_func_array(array($this->opt['auth_class'], 'find_out_perms'), array($uid, array()));
     if (false === $perms) {
         return false;
     }
     if ($this->opt['check_admin_privilege']) {
         if (!in_array('admin', $perms)) {
             $errors[] = $lang_str['bad_username'];
             sw_log("User login: authentication failed: user hasn't admin privileges", PEAR_LOG_INFO);
             return false;
         }
     }
     $this->uid = $uid;
     $this->did = $did;
     $this->realm = $realm;
     $this->perms = $perms;
     sw_log("User login: authentication succeeded, uid: " . $this->uid, PEAR_LOG_DEBUG);
     return true;
 }
 /**
  *	check if user exists
  */
 function is_user_exists($uname, $did)
 {
     global $config;
     if (isModuleLoaded('xxl')) {
         die('method is_user_exists not correctly implemented in XXL mode');
         if (!$this->connect_to_xml_rpc(array("uri" => "sip:" . $uname . "@" . $udomain), $errors)) {
             return false;
         }
         $params = array(new XML_RPC_Value("sip:" . $uname . "@" . $udomain, 'string'));
         $msg = new XML_RPC_Message('get_proxy', $params);
         $res = $this->rpc->send($msg);
         if ($this->rpc_is_error($res)) {
             if ($res->getCode() == "404") {
                 return 1;
             }
             log_errors($res, $errors);
             return 0;
         }
         return -3;
     } else {
         $errors = array();
         if (!$this->connect_to_db($errors)) {
             ErrorHandler::add_error($errors);
             return 0;
         }
         /* table's name */
         $tc_name =& $config->data_sql->credentials->table_name;
         $tu_name =& $config->data_sql->uri->table_name;
         /* col names */
         $cc =& $config->data_sql->credentials->cols;
         $cu =& $config->data_sql->uri->cols;
         /* flags */
         $fc =& $config->data_sql->credentials->flag_values;
         $fu =& $config->data_sql->uri->flag_values;
         $an =& $config->attr_names;
         /* get digest realm of given domain */
         $opt = array("did" => $did);
         if (false === ($d_realm = Attributes::get_attribute($an['digest_realm'], $opt))) {
             return false;
         }
         $q = "select count(*) from " . $tc_name . " \n\t\t\t    where lower(" . $cc->uname . ")=lower(" . $this->sql_format($uname, "s") . ") and \n\t\t\t\t      " . $cc->realm . " = " . $this->sql_format($d_realm, "s");
         if ($config->auth['use_did']) {
             $q .= " and " . $cc->did . " = " . $this->sql_format($did, "s");
         }
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             return 0;
         }
         $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
         $res->free();
         if ($row[0]) {
             sw_log("Credentials for user (username, did) - (" . $uname . ", " . $did . ") already exists", PEAR_LOG_DEBUG);
             return -1;
         }
         /* 
          *	Credentials not found, check uri table 
          */
         $q = "select count(*) from " . $tu_name . " \n\t\t\t    where lower(" . $cu->username . ")=lower(" . $this->sql_format($uname, "s") . ") and \n\t\t\t\t      lower(" . $cu->did . ")=lower(" . $this->sql_format($did, "s") . ")";
         $res = $this->db->query($q);
         if (DB::isError($res)) {
             ErrorHandler::log_errors($res);
             return 0;
         }
         $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
         $res->free();
         if ($row[0]) {
             sw_log("Uri for user (username, did) - (" . $uname . ", " . $did . ") already exists", PEAR_LOG_DEBUG);
             return -2;
         }
         return 1;
     }
 }
Esempio n. 11
0
function loadModule($module, $arguments = false)
{
    if (!$module) {
        return false;
    }
    global $moduleSettings, $modulesLoaded;
    if ($module == 'headerModule') {
        //Must specify which modules we will be loading in the body with the arguments array,
        //    this allows required javascript/css prerequisites to be loaded.
        $modulesLoaded = $arguments['modules'];
        echo '<title>' . $arguments['title'] . '</title>';
        echo '<meta charset="UTF-8" />';
        //iPhone Mobile Viewport. Will lock screen, remove
        ///echo '<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />';
        //echo '<meta name="apple-mobile-web-app-capable" content="yes" />';
        //echo '<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />';
        echo '<meta http-equiv="X-UA-Compatible" content="IE=9" >';
        // Keeps IE9 from going ugly mode
        echo '<link rel="icon" href="favicon.ico" type="image/x-icon" />';
        // Load static global dependancies
        echo '<link href="style/style.css" type="text/css" media="all" rel="stylesheet" charset="utf-8"/>';
        echo '<link href="style/mobile.css" type="text/css" media="mobile, screen and (max-width: 400px)" rel="stylesheet" charset="utf-8"/>';
        echo '<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=320.1"/>';
        echo '<meta name="apple-mobile-web-app-capable" content="yes" />';
        echo '<meta name="apple-mobile-web-app-status-bar-style" content="black" />';
        /*
        echo '<link rel="apple-touch-icon" href="iphon_tetris_icon.png"/>';
        echo '<link rel="apple-touch-startup-image" href="startup.png" />';
        */
        echo '<script src="script/main.js" type="text/javascript"></script>';
        // Load dynamic global dependancies that must not be cached.
        require "style/dynamicStyle.php";
        require "script/dynamicMain.php";
        // Load static module dependancies
        if (isModuleLoaded('drawModule')) {
            echo '<script src="script/draw.js"></script>';
        }
        if (isModuleLoaded('chatModule')) {
            echo '<script src="script/chat.js"></script>';
        }
        if (isModuleLoaded('assaultModule')) {
            echo '<script src="script/assault.js"></script>';
        }
        if (isModuleLoaded('rigorMortisModule')) {
            echo '<script src="script/rigorMortis/rmMain.js"></script>';
        }
        //Transpose loaded modules to javascript
        //if (isModuleLoaded('drawModule')) { echo '<script src="script/draw.js"></script>'; loadCSS('drawModule'); }
        //if (isModuleLoaded('chatModule')) { loadCSS('chatModule'); }
    } elseif ($module == 'drawModule') {
        echo '<div id="drawModule" width="' . $moduleSettings[$module]['width'] . '" height="' . $moduleSettings[$module]['height'] . '">';
        //echo '<div id="drawPanel"><input type="button" id="drawBtnClear" value="Clear"></div>';
        echo '<canvas id="drawModuleMain" width="' . $moduleSettings[$module]['width'] . '" height="' . $moduleSettings[$module]['height'] . '">Your browser does not support the &lt;canvas&gt; tag.<br>Please upgrade to the latest edition of one of these compatible browsers:<br>Google Chrome, Mozilla Firefox, Opera, Safari, IE9+</canvas>';
        echo '</div>';
    } elseif ($module == 'assaultModule') {
        echo '<div id="assaultModule" width="' . $moduleSettings[$module]['width'] . '" height="' . $moduleSettings[$module]['height'] . '">';
        echo '<a href="#" id="assaultModulePause"><div></div><div></div></a>';
        echo '<canvas id="assaultModuleMain" width="' . $moduleSettings[$module]['width'] . '" height="' . $moduleSettings[$module]['height'] . '">Your browser does not support the &lt;canvas&gt; tag.<br>Please upgrade to the latest edition of one of these compatible browsers:<br>Google Chrome, Mozilla Firefox, Opera, Safari, IE9+</canvas>';
        echo '</div>';
    } elseif ($module == 'rigorMortisModule') {
        echo '<div id="rigorMortisModule" width="' . $moduleSettings[$module]['width'] . '" height="' . $moduleSettings[$module]['height'] . '">';
        //echo '<a href="#" id="rigorMortisModulePause"><div></div><div></div></a>';
        echo '<canvas id="rigorMortisModuleMain" width="' . $moduleSettings[$module]['width'] . '" height="' . $moduleSettings[$module]['height'] . '">Your browser does not support the &lt;canvas&gt; tag.<br>Please upgrade to the latest edition of one of these compatible browsers:<br>Google Chrome, Mozilla Firefox, Opera, Safari, IE9+</canvas>';
        echo '</div>';
    } elseif ($module == 'chatModule') {
        ?>
        <div id="chatModule">
            <?php 
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
            ?>
            <div id="chatDisconnected">
                <input type="image" class="chatButton" src="image/chatMin.png" onclick="$('chatModule').style.top = '624px';$('chatModule').style.height='16px';$('chatBtnMin').style.display=$('chatDisconnected').style.display='none';$('chatIE').style.display='block';">
                <strong style="color:#F00;">HovelChat does not currently support IE. Please use another browser.</strong><br>
                <br>Nickname:<input type="text" size="15" maxlength="15" id="chatName" disabled="">
                <br><input type="button" id="chatConnect" value="Connect" disabled="">
                <br><br>(Only alphanumeric, dashes, &amp; underscores are allowed)
            </div>
            <div id="chatIE"><strong style="color:#F00;">HovelChat disabled (Unsupported on IE)</strong></div>
            <?php 
        } else {
            ?>
            <div id="chatDisconnected">
                <strong>You are not connected to the chat server.</strong>
                <br>Nickname:<input type="text" size="15" maxlength="15" id="chatName">
                <br><br><input type="button" id="chatConnect" value="Connect">
                <br><br>(Only alphanumeric, dashes, &amp; underscores are allowed)
                <br><br>If you are running Opera you must <a href="opera:config#Enable%20WebSockets">enable WebSockets</a>
            </div>
            <?php 
        }
        ?>
            <div id="chatConnected">
                <div id="chatBtnMin" class="chatButton"></div><div id="chatBtn" class="chatButton"></div>
                <div id="chatArea"></div>
                <input type="button" id="chatDisconnect" value="Disconnect"><input type="text" id="chatInput" maxlength="253"><input type="button" id="chatSend" value="Send">
            </div>
        </div>
        <?php 
    } elseif ($module == 'toolboxModule') {
        ?>
        <div id="toolboxModule">
            <div class="toolboxGroup">
                <span class="toolboxTitle">Containers</span>
                <table>
                    <tr><td><input type="image" alt="add" id="toolboxBtnAdd"></td><td><input type="image"></td></tr>
                    <tr><td><input type="image"></td><td><input type="image"></td></tr>
                </table>
            </div>
            <div class="toolboxGroup">
                <span class="toolboxTitle">Modules</span>
                <table>
                    <tr><td><input type="image"></td><td><input type="image"></td></tr>
                    <tr><td><input type="image"></td><td><input type="image"></td></tr>
                </table>
            </div>
            <b>Sandbox Mode</b>
        </div>
        <?php 
    } else {
        echo 'Error: Attempting to load unknown module "' . $module . '".';
    }
}
 /**
  *  Get status of user specified by sip-uri
  *
  *	Return status: 'unknown', 'nonlocal', 'notexists', 'offline', 'online'
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	string				FALSE on error
  */
 function get_status($sip_uri, $opt)
 {
     global $config;
     /* create connection to proxy where are stored data of user */
     if (isModuleLoaded('xxl') and $this->name != "get_status_tmp") {
         $tmp_data =& CData_Layer::singleton("get_status_tmp", $errors);
         $tmp_data->set_xxl_user_id($sip_uri);
         //$tmp_data->expect_user_id_may_not_exists(); //need this?
         return $tmp_data->get_status($sip_uri, $errors);
     }
     $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;
     $tl_name =& $config->data_sql->location->table_name;
     /* col names */
     $cu =& $config->data_sql->uri->cols;
     $cl =& $config->data_sql->location->cols;
     /* flags */
     $fu =& $config->data_sql->uri->flag_values;
     $an =& $config->attr_names;
     $reg =& Creg::singleton();
     $uname = $reg->get_username($sip_uri);
     $realm = $reg->get_domainname($sip_uri);
     if (!$uname or !$realm) {
         return "unknown";
     }
     if ($config->multidomain) {
         if (false === ($did = $this->get_did_by_realm($realm, null))) {
             return false;
         }
         if (is_null($did)) {
             return "nonlocal";
         }
     } else {
         if ($realm != $config->domain) {
             return "nonlocal";
         }
         $did = $config->default_did;
     }
     $flags_val = $fu['DB_DISABLED'] | $fu['DB_DELETED'];
     $q = "select " . $cu->uid . " as uid\n\t\t    from " . $tu_name . "\n\t\t\twhere  " . $cu->did . " = '" . $did . "' and \n\t\t\t       " . $cu->username . " = " . $this->sql_format($uname, "s") . " and \n\t\t\t\t  (" . $cu->flags . " & " . $flags_val . ") = 0";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
     if (!$row) {
         unset($res);
         return "notexists";
     }
     $uid = $row['uid'];
     $o = array("uid" => $uid, "did" => $did);
     if (false === ($show = Attributes::get_attribute($an['show_status'], $o))) {
         return false;
     }
     if (!$show) {
         return 'unknown';
     }
     $q = "select count(*)\n\t\t    from " . $tl_name . "\n\t\t\twhere  " . $cl->uid . " = '" . $uid . "'";
     $res = $this->db->query($q);
     if (DB::isError($res)) {
         ErrorHandler::log_errors($res);
         return false;
     }
     if (!($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
         ErrorHandler::log_errors(PEAR::raiseError("Can't fetch data from DB"));
         return false;
     }
     if ($row[0]) {
         return "online";
     } else {
         return "offline";
     }
 }
 /**
  *	generate new alias number
  */
 function get_new_alias_number($did, $opt)
 {
     global $config;
     $errors = array();
     if (!$this->connect_to_db($errors)) {
         ErrorHandler::add_error($errors);
         return 0;
     }
     /* table name */
     $t_name =& $config->data_sql->uri->table_name;
     /* col names */
     $c =& $config->data_sql->uri->cols;
     /* flags */
     $f =& $config->data_sql->uri->flag_values;
     if ($config->alias_generation == 'rand' or isModuleLoaded('xxl')) {
         //random alias generation
         $retries = 0;
         do {
             //create alias
             $alias = $config->alias_prefix;
             for ($i = 0; $i < $config->alias_lenght; $i++) {
                 $alias .= mt_rand(0, 9);
             }
             $alias .= $config->alias_postfix;
             //check if alias isn't used
             $q = "select count(username) \n\t\t\t\t    from " . $t_name . " \n\t\t\t\t\twhere " . $c->did . "      = " . $this->sql_format($did, "s") . " and \n\t\t\t\t\t      " . $c->username . " = " . $this->sql_format($alias, "s");
             $res = $this->db->query($q);
             if (DB::isError($res)) {
                 ErrorHandler::log_errors($res);
                 return false;
             }
             $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
             $res->free();
             if ($row[0] == 0) {
                 break;
             }
             $retries++;
         } while ($retries < $config->alias_generation_retries);
         if ($retries < $config->alias_generation_retries) {
             return $alias;
         } else {
             ErrorHandler::log_errors(PEAR::raiseError("can't find any unused alias number"));
             return false;
         }
     } else {
         //incremental alias generation
         // get value for new alias
         $o = array('did' => $did);
         if (false === ($alias = Attributes::get_Attribute($config->attr_names['highest_alias_number'], $o))) {
             return false;
         }
         $alias = (int) $alias;
         // if value is not set, use the config value
         if (!$alias or $alias < $config->first_alias_number) {
             $alias = $config->first_alias_number;
         }
         do {
             // check if the username is aready used
             $q = "select count(*) \n                    from " . $t_name . " \n                    where " . $c->did . " = " . $this->sql_format($did, "s") . " and \n                        " . $c->username . " = " . $this->sql_format($alias, "n");
             $res = $this->db->query($q);
             if (DB::isError($res)) {
                 ErrorHandler::log_errors($res);
                 return false;
             }
             $row = $res->fetchRow(DB_FETCHMODE_ORDERED);
             $res->free();
             // if is used, increment it and try again
             if ($row[0]) {
                 $alias++;
             }
         } while ($row[0]);
         $da_h =& Domain_Attrs::singleton($did);
         if (false === $da_h->set_attribute($config->attr_names['highest_alias_number'], $alias)) {
             return false;
         }
         return $alias;
     }
 }
 function action_confirm_reg(&$errors)
 {
     global $data, $config, $lang_str;
     if (isset($_GET['pr'])) {
         $proxy['proxy'] = base64_decode($_GET['pr']);
         if ($proxy['proxy']) {
             if (false === $data->set_home_proxy($proxy['proxy'])) {
                 return false;
             }
         }
     }
     if (isModuleLoaded('xxl') and !$proxy['proxy']) {
         $errors[] = $lang_str['err_reg_conf_not_exists_conf_num'];
         return false;
     }
     $an =& $config->attr_names;
     /* get uid */
     $o = array('name' => $an['confirmation'], 'value' => $this->nr);
     if (false === ($attrs = $data->get_attr_by_val("user", $o))) {
         return false;
     }
     if (empty($attrs[0]['id'])) {
         $this->wrong_nr = true;
         ErrorHandler::add_error($lang_str['err_reg_conf_not_exists_conf_num']);
         return false;
     }
     $uid = $attrs[0]['id'];
     /* get did - for the case that domain has been created during registration */
     $o = array('name' => $an['confirmation'], 'value' => $this->nr);
     if (false === ($attrs = $data->get_attr_by_val("domain", $o))) {
         return false;
     }
     $did = null;
     if (!empty($attrs[0]['id'])) {
         $did = $attrs[0]['id'];
     }
     if (false === $data->transaction_start()) {
         return false;
     }
     // first enable domain
     if (!is_null($did)) {
         $dm_h =& DomainManipulator::singleton($did);
         if (false === $dm_h->enable_domain(true)) {
             return false;
         }
         $domain_attrs =& Domain_Attrs::singleton($did);
         if (false === $domain_attrs->unset_attribute($an['confirmation'])) {
             $data->transaction_rollback();
             return false;
         }
         if (false === $domain_attrs->unset_attribute($an['pending_ts'])) {
             $data->transaction_rollback();
             return false;
         }
     }
     $o = array("uid" => $uid, "disable" => false);
     if (false === $data->enable_user($o)) {
         $data->transaction_rollback();
         return false;
     }
     $user_attrs =& User_Attrs::singleton($uid);
     if (false === $user_attrs->unset_attribute($an['confirmation'])) {
         $data->transaction_rollback();
         return false;
     }
     if (false === $user_attrs->unset_attribute($an['pending_ts'])) {
         $data->transaction_rollback();
         return false;
     }
     if (false === $data->transaction_commit()) {
         return false;
     }
     if ($this->opt['setup_jabber_account']) {
         ErrorHandler::add_error("Registration in jabber not maintained, please set \$config->setup_jabber_account=false in config file.");
         # Jabber Gateway registration
         $res = reg_jab($user_id->uname);
         if ($res != 0) {
             $res = $res + 1;
             log_errors(PEAR::raise_error("jabber registration failed: <" . $user_id->uname . "> [" . $res . "]"), $errors);
             return array("confirmation_ok=1", "conf_jabber_failed=1");
         }
     }
     return array("confirmation_ok=1");
 }
Esempio n. 15
0
 function xxl_init()
 {
     global $sess, $sess_xxl_selected_proxy, $perm;
     // register session variable sess_xxl_selected_proxy
     if (!$sess->is_registered('sess_xxl_selected_proxy')) {
         $sess->register('sess_xxl_selected_proxy');
     }
     if (!isset($sess_xxl_selected_proxy)) {
         $sess_xxl_selected_proxy = null;
     }
     // get $user_id if admin want work with some setting of user
     if (isset($perm) and $perm->have_perm("admin")) {
         // set initial value of sess_xxl_selected_proxy to same proxy where user has account
         if (isModuleLoaded('xxl') and is_null($sess_xxl_selected_proxy)) {
             if (false !== ($proxy_uri = $GLOBALS['data_auth']->get_home_proxy($this->errors))) {
                 $sess_xxl_selected_proxy = array('proxy' => $proxy_uri);
             }
         }
         // in XXL version and if is set sess_xxl_selected_proxy
         // create new instance of data_layer binded to seleceted proxy
         // note that data_layer binded to currently logged user is still
         // in variable $data_auth
         if (isModuleLoaded('xxl') and $sess_xxl_selected_proxy) {
             $GLOBALS['data_selected_proxy'] = CData_Layer::singleton("selected_proxy", $this->errors);
             $GLOBALS['data_selected_proxy']->setup_by_another_instance($GLOBALS['data_auth']);
             if (false === $GLOBALS['data_selected_proxy']->set_home_proxy($sess_xxl_selected_proxy['proxy'])) {
                 die("Can't connect to DB");
                 break;
             }
             $GLOBALS['data'] =& $GLOBALS['data_selected_proxy'];
         }
     }
 }