/**
  *  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;
 }
 /**
  *  Get array of uids asociated with given uri
  *
  *  Possible options:
  *	 - none
  *
  *	@param	string	$sip_uri	URI of user
  *	@param	array	$opt		array of options
  *	@return	array				FALSE on error
  */
 function get_uid_of_uri($sip_uri, $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;
     /* 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           " . $cu->flags . " as flags\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;
     }
     $out = array();
     for ($i = 0; $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $i++) {
         $out[$i]['uid'] = $row['uid'];
         $out[$i]['is_to'] = (bool) ($row['flags'] & $fu['DB_IS_TO']);
         $out[$i]['is_from'] = (bool) ($row['flags'] & $fu['DB_IS_FROM']);
     }
     return $out;
 }
 function get_location($sip_adr, &$errors)
 {
     global $config;
     $reg =& Creg::singleton();
     $domainname = $reg->get_domainname($sip_adr);
     if (!$this->connect_to_db($errors)) {
         return false;
     }
     $q = "select location from " . $config->data_sql->table_netgeo_cache . " where domainname='" . $domainname . "'";
     $res = $this->db->query($q);
     /* if this query failed netgeo is probably not installed -- ignore */
     if (DB::isError($res)) {
         return "n/a";
     }
     $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
     $res->free();
     if (!$row) {
         return "n/a";
     }
     return $row->location;
 }
Ejemplo n.º 4
0
 /**
  *	Set proxy in session variable $sess_data_conn 
  *	by uri returned from function lookup_proxy()
  *
  *	@param string $proxy	sip uri of proxy
  *	@return bool			TRUE on success, FALSE on bad format of $sip_uri
  *	@access private
  */
 function set_sess_data_proxy($proxy)
 {
     global $config, $sess, $sess_data_conn;
     if (!$sess->is_registered('sess_data_conn')) {
         $sess->register('sess_data_conn');
     }
     /* get instance of Creg class */
     $reg = Creg::singleton();
     $sess_data_conn[$this->name]['proxy'] = $proxy;
     /* parse parameters from sip uri of proxy */
     $params = $reg->get_parameters($proxy);
     if (isset($params['expire'])) {
         /* if sip uri contain parameter 'expire', use it for calculate new expiration time */
         $sess_data_conn[$this->name]['expire'] = time() + $params['expire'];
         sw_log("Expiration time of proxy assigment is set by uri parameter to " . $params['expire'] . " seconds", PEAR_LOG_DEBUG);
     } else {
         /* else use config variable for calculation expiration time */
         $sess_data_conn[$this->name]['expire'] = time() + $config->XXL_proxy_asigment_lifetime;
         sw_log("Expiration time of proxy assigment is set by config variable to " . $config->XXL_proxy_asigment_lifetime . " seconds", PEAR_LOG_DEBUG);
     }
     return true;
 }
Ejemplo n.º 5
0
	function get_location($sip_adr, &$errors){
		global $config;
		static $reg;
		
		$reg = new Creg();
		
		$domainname=$reg->get_domainname($sip_adr);
		
		switch($this->container_type){
		case 'sql':
			$q="select location from ".$config->data_sql->table_netgeo_cache.
				" where domainname='".$domainname."'";
			$res=$this->db->query($q);
			/* if this query failed netgeo is probably not installed -- ignore */
			if (DB::isError($res)) {return "n/a";}
			$row = $res->fetchRow(DB_FETCHMODE_OBJECT);
			$res->free();
		
			if (!$row) return "n/a";
			return $row->location;

		case 'ldap':
			die('NOT IMPLEMENTED: '.__FILE__.":".__LINE__);
		}
	}
 function page_conroler()
 {
     $this->reg = Creg::singleton();
     // create regular expressions class
     $eh =& ErrorHandler::singleton();
     $eh->set_errors_ref($this->errors);
     $this->errors_from_get_param();
     $this->messages_from_get_param();
     $this->session_init();
     $this->init_this_uid_and_did();
     $this->set_interapu_vars();
 }
Ejemplo n.º 7
0
 /**
  *	create html form 
  *
  *	@param array $errors	array with error messages
  *	@return null			FALSE on failure
  */
 function create_html_form(&$errors)
 {
     global $lang_str, $data;
     parent::create_html_form($errors);
     if ($this->action['action'] == 'edit') {
         $opt = array('single' => $this->act_id);
         if (false === ($customer = $data->get_customers($opt, $errors))) {
             return false;
         }
         $this->customer = reset($customer);
         //return first value of array
     }
     $reg = Creg::singleton();
     $this->f->add_element(array("type" => "text", "name" => "cu_name", "size" => 16, "maxlength" => 128, "value" => isset($this->customer['name']) ? $this->customer['name'] : "", "minlength" => 1, "length_e" => $lang_str['fe_not_customer_name']));
     $this->f->add_element(array("type" => "text", "name" => "cu_address", "size" => 16, "maxlength" => 255, "value" => isset($this->customer['address']) ? $this->customer['address'] : ""));
     $this->f->add_element(array("type" => "text", "name" => "cu_phone", "size" => 16, "maxlength" => 64, "value" => isset($this->customer['phone']) ? $this->customer['phone'] : ""));
     $this->f->add_element(array("type" => "text", "name" => "cu_email", "size" => 16, "maxlength" => 255, "value" => isset($this->customer['email']) ? $this->customer['email'] : "", "valid_regex" => "(" . $reg->email . ")|(^\$)", "valid_e" => $lang_str['fe_not_valid_email']));
     $this->f->add_element(array("type" => "hidden", "name" => "cu_id", "value" => $this->act_id));
 }
 /**
  *  Validate given value to IPv4 address and mask {IP}/{mask}
  *  
  *  @param  string  $value      the value to validate
  *  @param  string  $err_msg    error message to display
  *  @param  string  $var_name   name of variable (to be used in the err_msg)
  *  @return bool                 
  */
 function validate_IPv4mask($value, $err_msg, $var_name = null)
 {
     $reg =& Creg::singleton();
     // get instance of Creg class
     if (empty($value)) {
         return false;
     }
     $value_a = explode("/", $value, 2);
     if (!isset($value_a[1])) {
         $value_a[1] = "";
     }
     if (!self::validate_IPv4($value_a[0], $err_msg, $var_name)) {
         return false;
     }
     if (!$reg->check_netmask($value_a[1])) {
         ErrorHandler::add_error(str_replace(array("#VALUE#", "<name>"), array($value, $var_name), $err_msg));
         return false;
     }
     return true;
 }
Ejemplo n.º 9
0
if (!$serweb_config) {
    echo "Not specified serweb_config parameter\n";
    echo "usage: send_metar.php?serweb_config=path/to/serweb/config/file/config.php\n";
    exit(1);
}
$serweb_dir = dirname($serweb_config);
require $serweb_config;
require "phpweather/phpweather.php";
require "phpweather/output/pw_text_en.php";
require $serweb_dir . "/functions.php";
$db = connect_to_db();
if (!$db) {
    echo "can´t connect to sql server";
    exit(1);
}
$reg = new Creg();
//create phpweather objects
$weather = new phpweather();
$language = "en";
$text_type = 'pw_text_' . $language;
//get users which have subscribed this service
$q = "select username from " . $config->table_event . " where uri='" . $config->metar_event_uri . "'";
$res = mySQL_query($q);
if (!$res) {
    echo "error in SQL query, line: " . __LINE__ . "\n";
    exit(1);
}
while ($row = MySQL_Fetch_Object($res)) {
    //for each user get contacts
    $q = "select contact from " . $config->table_location . " where username='******'";
    $res2 = mySQL_query($q);
Ejemplo n.º 10
0
 /**
  *  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";
     }
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 function page_conroler()
 {
     $this->reg = Creg::singleton();
     // create regular expressions class
     $eh =& ErrorHandler::singleton();
     $eh->set_errors_ref($this->errors);
     $this->errors_from_get_param();
     $this->session_init();
     $this->xxl_init();
     $this->init_this_uid_and_did();
     $this->set_interapu_vars();
     // if $data_selected_proxy was not set, reference it to $data_auth
     if (!isset($GLOBALS['data_selected_proxy']) or !$GLOBALS['data_selected_proxy']) {
         $GLOBALS['data_selected_proxy'] =& $GLOBALS['data_auth'];
     }
 }
Ejemplo n.º 13
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);
     }
 }