/** * reload domains table of SER from DB * * Possible options parameters: * none * * @param array $opt associative array of options * @param array $errors error messages * @return bool TRUE on success, FALSE on failure */ function reload_domains($opt, &$errors) { global $config; $ga_h =& Global_Attrs::singleton(); /* get current timestamp on DB server */ if (false === ($now = $this->get_DB_time(null))) { return false; } /* update attribute holding timestamp of last data change */ if (false === $ga_h->set_attribute($config->attr_names['domain_data_version'], $now)) { return false; } /* If notifing of sip proxies to reload the data is disabled, * finish here */ if (empty($config->domain_reload_ser_notify)) { return true; } /* If SER does not caches domain table, the reload is not needed * (and also is not possible) */ if (empty($config->ser_domain_cache)) { return true; } if ($config->use_rpc) { // if (!$this->connect_to_xml_rpc(null, $errors)) return false; $params = array(); $msg = new XML_RPC_Message('domain.reload', $params); $res = $this->rpc_send_to_all($msg, array('break_on_error' => false)); if (!$res->ok) { $cache_varning = false; foreach ($res->results as $v) { if (PEAR::isError($v)) { ErrorHandler::log_errors($v); if ($v->getCode() == 400) { $cache_varning = true; } } } if ($cache_varning) { sw_log("Domain reload failed. May be the domain cache in SER is disabled. " . "Try either enable the cache by set modparam(\"domain\", \"db_mode\", 1) " . "in your ser.cfg or disable reloading domains in serweb by setting " . "\$config->ser_domain_cache = false in config_data_layer.php", PEAR_LOG_ERR); } return false; } return true; } else { /* construct FIFO command */ $fifo_cmd = ":domain_reload:" . $config->reply_fifo_filename . "\n"; $message = write2fifo($fifo_cmd, $errors, $status); if ($errors) { return false; } if (substr($status, 0, 1) != "2") { $errors[] = $status; return false; } } return true; }
/** * reload domains table of SER from DB * * Possible options parameters: * none * * @param array $opt associative array of options * @param array $errors error messages * @return bool TRUE on success, FALSE on failure */ function reload_global_attrs($opt, &$errors) { global $config; $ga_h =& Global_Attrs::singleton(); /* get current timestamp on DB server */ if (false === ($now = $this->get_DB_time(null))) { return false; } /* update attribute holding timestamp of last data change */ if (false === $ga_h->set_attribute($config->attr_names['gattr_timestamp'], $now)) { return false; } /* If notifing of sip proxies to reload the data is disabled, * finish here */ if (empty($config->g_attrs_reload_ser_notify)) { return true; } if ($config->use_rpc) { // if (!$this->connect_to_xml_rpc(null, $errors)) return false; $params = array(); $msg = new XML_RPC_Message('gflags.reload', $params); $res = $this->rpc_send_to_all($msg, array('break_on_error' => false)); if (!$res->ok) { foreach ($res->results as $v) { if (PEAR::isError($v)) { ErrorHandler::log_errors($v); } } return false; } return true; } else { /* construct FIFO command */ $fifo_cmd = ":gflags.reload:" . $config->reply_fifo_filename . "\n"; $message = write2fifo($fifo_cmd, $errors, $status); if ($errors) { return false; } if (substr($status, 0, 1) != "2") { $errors[] = $status; return false; } } return true; }
/** * Get value of attribute * * This function search in order uri, user, domain and global tracks * for attribute value and return value from the first track where find it. * * Alowed options: * - uid (string) - uid of user track * - did (string) - did of domain track * - uri (array) - identifies uri track. Have to have three * components: scheme, username and did * * @param string $name name of the attribute * @param array $opt options * @return mixed value of attribute or FALSE on error */ function get_attribute($name, $opt) { /* set default values for options */ $opt_uid = isset($opt["uid"]) ? $opt["uid"] : null; $opt_did = isset($opt["did"]) ? $opt["did"] : null; $opt_uri = isset($opt["uri"]) ? $opt["uri"] : null; if (!is_null($opt_uri)) { $attrs =& Uri_Attrs::singleton($opt_uri['scheme'], $opt_uri['username'], $opt_uri['did']); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } } if (!is_null($opt_uid)) { $attrs =& User_Attrs::singleton($opt_uid); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } } if (!is_null($opt_did)) { $attrs =& Domain_Attrs::singleton($opt_did); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } } $attrs =& Global_Attrs::singleton(); if (false === ($attr = $attrs->get_attribute($name))) { return false; } if (!is_null($attr)) { return $attr; } /* attribute not found */ return null; }
/** * add new domain alias * * Keys of associative array $values: * id * name * * Possible options parameters: * * set_canon (bool) default: false * set domain alias canonical * * @param array $values values * @param array $opt associative array of options * @param array $errors error messages * @return bool TRUE on success, FALSE on failure */ function add_domain_alias($values, $opt, &$errors) { global $config; if (!$this->connect_to_db($errors)) { return false; } /* table's name */ $td_name =& $config->data_sql->domain->table_name; /* col names */ $cd =& $config->data_sql->domain->cols; /* flags */ $fd =& $config->data_sql->domain->flag_values; $ca =& $config->attr_names; $opt['set_canon'] = empty($opt['set_canon']) ? false : true; $opt['disabled'] = empty($opt['disabled']) ? false : true; $global_attrs =& Global_Attrs::singleton(); if (false === ($flags = $global_attrs->get_attribute($ca['domain_default_flags']))) { return false; } if (!is_numeric($flags)) { ErrorHandler::log_errors(PEAR::raiseError("Attribute '" . $ca['domain_default_flags'] . "' is not defined or is not a number")); return false; } if ($opt['set_canon']) { $flags = $flags | $fd['DB_CANON']; } if ($opt['disabled']) { $flags = $flags | $fd['DB_DISABLED']; } $q = "insert into " . $td_name . " (\n\t\t\t\t " . $cd->did . ",\n\t\t\t\t " . $cd->name . ",\n\t\t\t\t " . $cd->flags . "\n\t\t ) \n\t\t\tvalues (\n\t\t\t\t " . $this->sql_format($values['id'], "s") . ", \n\t\t\t\t " . $this->sql_format($values['name'], "s") . ",\n\t\t\t\t " . $this->sql_format($flags, "n") . "\n\t\t\t )"; $res = $this->db->query($q); if (DB::isError($res)) { log_errors($res, $errors); return false; } return true; }
/** * Function read array of URIs and for each URI get the domain id, * obtain value of attribute 'send_missed_calls'. If at least one attribute * is true, this function return 1. Otherwise return 0. * * If no domain has the attribute set, the output of function depends on global * attribute 'send_missed_calls' * * @param array $uris * @return int or FALSE on error */ function get_send_mc_of_dom($uris, &$mail_from) { global $config; $an = $config->attr_names; $send = null; $mail_from = null; foreach ($uris as $uri) { $da =& Domain_Attrs::singleton($uri->get_did()); if (false === ($s = $da->get_attribute($an['send_mc']))) { return false; } if (is_null($send)) { $send = $s; } else { $send = ($send or $s); } if ($s and !$mail_from) { $o = array('did' => $uri->get_did()); if (false === ($from_header = Attributes::get_attribute($an['contact_email'], $o))) { return false; } if ($from_header) { $mail_from = $from_header; } } } if (is_null($send)) { $ga =& Global_Attrs::singleton(); if (false === ($send = $ga->get_attribute($an['send_mc']))) { return false; } } return $send ? 1 : 0; }
function create_html_form(&$errors) { global $data, $config; parent::create_html_form($errors); $attr_types =& Attr_types::singleton(); //get list of attributes if (false === ($this->attr_types =& $attr_types->get_attr_types())) { return false; } switch ($this->opt['attrs_kind']) { case "uri": // get uri_attrs $this->uri_attrs =& Uri_Attrs::singleton($this->uri_scheme, $this->uri_uname, $this->uri_did); if (false === ($uri_attrs = $this->uri_attrs->get_attributes())) { return false; } case "user": // get user_attrs $this->user_attrs =& User_Attrs::singleton($this->uid); if (false === ($user_attrs = $this->user_attrs->get_attributes())) { return false; } case "domain": // get domain_attrs $this->domain_attrs =& Domain_Attrs::singleton($this->did); if (false === ($domain_attrs = $this->domain_attrs->get_attributes())) { return false; } case "global": // get global_attrs $this->global_attrs =& Global_Attrs::singleton(); if (false === ($global_attrs = $this->global_attrs->get_attributes())) { return false; } } $this->attr_values = array(); foreach ($this->attr_types as $k => $v) { if ($this->opt['attrs_kind'] == 'uri' and !$this->attr_types[$k]->is_for_URIs()) { continue; } elseif ($this->opt['attrs_kind'] == 'user' and !$this->attr_types[$k]->is_for_users()) { continue; } elseif ($this->opt['attrs_kind'] == 'domain' and !$this->attr_types[$k]->is_for_domains()) { continue; } elseif ($this->opt['attrs_kind'] == 'global' and !$this->attr_types[$k]->is_for_globals()) { continue; } switch ($this->opt['attrs_kind']) { case "uri": if (isset($uri_attrs[$k])) { $this->attr_values[$k] = $uri_attrs[$k]; break; } case "user": if (isset($user_attrs[$k])) { $this->attr_values[$k] = $user_attrs[$k]; break; } case "domain": if (isset($domain_attrs[$k])) { $this->attr_values[$k] = $domain_attrs[$k]; break; } case "global": if (isset($global_attrs[$k])) { $this->attr_values[$k] = $global_attrs[$k]; break; } } /* * If the value of attribute is not found, set it as null */ if (!isset($this->attr_values[$k])) { $this->attr_values[$k] = null; } } // if option 'atributes' is not given, that mean we will work with all attributes if (empty($this->opt['attributes'])) { foreach ($this->attr_values as $k => $v) { // work only with attributes which have access to read if ($this->access_to_read($k)) { $this->opt['attributes'][] = $k; } } } else { foreach ($this->opt['attributes'] as $k => $v) { if (!array_key_exists($v, $this->attr_values)) { log_errors(PEAR::RaiseError("Attribute named '" . $v . "' does not exists"), $errors); unset($this->opt['attributes'][$k]); } } } //except unwanted arguments $this->opt['attributes'] = array_diff($this->opt['attributes'], $this->opt['exclude_attributes']); //save avaiable attrs before are filtered by group $this->all_avaiable_attrs = $this->opt['attributes']; if (!empty($this->opt['attrs_group'])) { foreach ($this->opt['attributes'] as $k => $v) { // work only with attributes from specified group if ($this->attr_types[$v]->get_group() != $this->opt['attrs_group']) { unset($this->opt['attributes'][$k]); } } } //set options to attributes foreach ($this->opt['attributes'] as $att) { if (isset($this->opt['attrs_options'][$att]) and is_array($this->opt['attrs_options'][$att])) { foreach ($this->opt['attrs_options'][$att] as $k => $v) { $this->attr_types[$att]->set_opt($k, $v); } } } // add elements to form object foreach ($this->opt['attributes'] as $att) { if (!$this->access_to_change($att)) { continue; } //if attribute cannot be changed, do not add it ot the form $opt = array(); $opt['err_msg'] = isset($this->opt['error_messages'][$att]) ? $this->opt['error_messages'][$att] : null; $this->attr_types[$att]->form_element($this->f, $this->attr_values[$att], $opt); $this->js_on_subm .= $this->attr_types[$att]->validation_js_before(); $this->js_on_subm_2 .= $this->attr_types[$att]->validation_js_after(); } if (!empty($this->opt['validate_js_funct'])) { $this->js_on_subm_2 .= $this->opt['validate_js_funct']; } }