function retrieve_keys($phone_type, $variables = array()) { if ($this->_user_id > 0) { $this->_keys = gs_keys_get_by_user($this->_user_name, $phone_type); } else { $this->_keys = gs_keys_get_by_profile($this->_profile_id, $phone_type); } if (isGsError($this->_keys) || !is_array($this->_keys)) { gs_log(GS_LOG_NOTICE, isGsError($this->_keys) ? $this->_keys->getMsg() : 'Failed to get softkeys'); $this->_keys = null; return false; } if (is_array($variables) && count($variables) > 0) { $search = array_keys($variables); $replace = array_values($variables); unset($variables); foreach ($this->_keys as $key_name => $key_defs) { foreach ($key_defs as $inh_slf => $key_def) { if ($this->_keys[$key_name][$inh_slf]['data'] != '') { $this->_keys[$key_name][$inh_slf]['data'] = str_replace($search, $replace, $key_def['data']); } } } } return true; }
function siemens_push_str($phone_ip, $postdata) { $prov_host = gs_get_conf('GS_PROV_HOST'); $data = "POST /server_push.html/ServerPush HTTP/1.1\r\n"; $data .= "User-Agent: Gemeinschaft\r\n"; $data .= "Host: {$phone_ip}:8085\r\n"; $data .= "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"; $data .= "Connection: keep-alive\r\n"; $data .= "Content-Type: application/x-www-form-urlencoded\r\n"; $data .= "Content-Length: " . strLen($postdata) . "\r\n\r\n"; $data .= $postdata; $socket = @fSockOpen($phone_ip, 8085, $error_no, $error_str, 4); if (!$socket) { gs_log(GS_LOG_NOTICE, "Siemens: Failed to open socket - IP: {$phone_ip}"); return 0; } stream_set_timeout($socket, 4); $bytes_written = (int) @fWrite($socket, $data, strLen($data)); @fFlush($socket); $response = @fGetS($socket); @fClose($socket); if (strPos($response, '200') === false) { gs_log(GS_LOG_WARNING, "Siemens: Failed to push to phone {$phone_ip}"); return 0; } gs_log(GS_LOG_DEBUG, "Siemens: Pushed {$bytes_written} bytes to phone {$phone_ip}"); return $bytes_written; }
function _not_found($errmsg = '') { @header('HTTP/1.0 404 Not Found', true, 404); @header('Status: 404 Not Found', true, 404); @header('Content-Type: text/plain; charset=utf-8'); echo '/* ', $errmsg ? $errmsg : 'Not found.', ' */'; gs_log(GS_LOG_DEBUG, $errmsg ? $errmsg : 'LDAP lookup: User not found'); exit(1); }
function gs_host_get_api($host_id) { if ($host_id < 1) { return '__fail_api'; } $db = gs_db_master_connect(); if (!$db) { gs_log(GS_LOG_WARNING, 'Could not connect to DB'); return '__fail_api'; } $api = $db->executeGetOne('SELECT `value` ' . 'FROM `host_params` ' . 'WHERE ' . '`host_id`=' . (int) $host_id . ' AND ' . '`param`=\'api\''); return (string) $api; }
function CanonicalPhoneNumber($number) { $this->_INTL = $this->_cnf('GS_CANONIZE_INTL_PREFIX', '00'); if ($this->_INTL === '+' || $this->_INTL == '') { $this->_INTL = '00'; } $this->_CNTR = $this->_cnf('GS_CANONIZE_COUNTRY_CODE', '49'); $this->_NATL = $this->_cnf('GS_CANONIZE_NATL_PREFIX', '0'); $this->_NINT = gs_get_conf('GS_CANONIZE_NATL_PREFIX_INTL', false); $this->_AREA = $this->_cnf('GS_CANONIZE_AREA_CODE', '251'); $this->_LOCL = $this->_cnf('GS_CANONIZE_LOCAL_BRANCH', '99999999'); $this->_CBCP = $this->_cnf('GS_CANONIZE_CBC_PREFIX', '010'); $this->_SPCL = gs_get_conf('GS_CANONIZE_SPECIAL', '//'); if (!is_valid_pcre($this->_SPCL)) { gs_log(GS_LOG_WARNING, 'Your GS_CANONIZE_SPECIAL pattern is not a valid PCRE'); $this->_SPCL = '/^1(:1[0-9]{1,5}|9222)/'; # 110, 112, 116116, 118.*, 19222 etc. } //$n = preg_replace('/[^0-9A-Z+*\-\/ ]/', '', strToUpper(trim( $number ))); //$n = preg_replace('/[ \/\-]/', ' ', $n); $n = preg_replace('/[^0-9A-Z+*]/', '', strToUpper(trim($number))); // "+" is allowed as the first char only: $n = preg_replace('/(?!^)\\+/', '', $n); $this->orig = $n; if ($this->orig != '') { $this->norm = $this->_canonize(); $this->_to_intl(); $this->_to_natl(); $this->_to_locl(); $this->_check_prv_branch(); if ($this->is_call_by_call) { $this->in_prv_branch = false; } if ($this->is_call_by_call) { $this->dial = ''; $this->errt = 'cbc'; } elseif ($this->in_prv_branch) { $this->dial = $this->extn; $this->errt = 'self'; } elseif ($this->is_special) { $this->dial = $this->orig; } else { $this->dial = $this->natl; } } else { $this->errt = 'empty'; } }
function aastra_get_expansion_modules() { $exp_mod = array(); if (@$_SERVER['HTTP_X_AASTRA_EXPMOD1']) { $exp_mod[0] = 'aastra-' . strToLower($_SERVER['HTTP_X_AASTRA_EXPMOD1']); gs_log(GS_LOG_DEBUG, 'Expansion module 1 : ' . $exp_mod[0]); } if (@$_SERVER['HTTP_X_AASTRA_EXPMOD2']) { $exp_mod[1] = 'aastra-' . strToLower($_SERVER['HTTP_X_AASTRA_EXPMOD2']); gs_log(GS_LOG_DEBUG, 'Expansion module 2 : ' . $exp_mod[1]); } if (@$_SERVER['HTTP_X_AASTRA_EXPMOD3']) { $exp_mod[2] = 'aastra-' . strToLower($_SERVER['HTTP_X_AASTRA_EXPMOD3']); gs_log(GS_LOG_DEBUG, 'Expansion module 3 : ' . $exp_mod[3]); } return $exp_mod; }
function gs_mysql_find_socket($db_host) { $socket = null; # never use socket for remote databases if (!in_array((string) $db_host, array('127.0.0.1', 'localhost', ''), true)) { return null; } /* wo der Socket liegt findet man so heraus: mysqladmin variables | grep sock oder es steht auch in der MySQL-Konfiguration: cat /etc/my.cnf | grep sock bzw. cat /etc/mysql/my.cnf | grep sock */ $err = 0; $out = array(); @exec('sed -e ' . qsa('/^\\[\\(mysqld_safe\\|safe_mysqld\\)\\]/,/^\\[/!d') . ' /etc/mysql/my.cnf 2>>/dev/null | grep \'^socket\' 2>>/dev/null', $out, $err); // Debian if ($err === 0) { $socket = _grep_mysql_socket(implode("\n", $out)); } if ($socket === null) { $err = 0; $out = array(); @exec('sed -e ' . qsa('/^\\[\\(mysqld_safe\\|safe_mysqld\\)\\]/,/^\\[/!d') . ' /etc/my.cnf 2>>/dev/null | grep \'^socket\' 2>>/dev/null', $out, $err); // CentOS if ($err === 0) { $socket = _grep_mysql_socket(implode("\n", $out)); } if ($socket === null) { $err = 0; $out = array(); @exec('mysqladmin -s variables | grep socket 2>>/dev/null', $out, $err); // should work everywhere if mysqladmin is available if ($err === 0) { $socket = _grep_mysql_socket(implode("\n", $out)); } if ($socket === null) { gs_log(GS_LOG_WARNING, 'Could not find MySQL socket'); } } } return $socket !== null ? $socket : null; }
function gs_get_listen_to_ips($primary_only = false) { /* if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { # return special address //return ($primary_only ? array('255.255.255.255') : array('255.255.255.255')); return array('255.255.255.255'); } */ //if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { if (gs_get_conf('GS_INSTALLATION_TYPE') === 'gpbx') { return array(trim(gs_keyval_get('vlan_0_ipaddr'))); } $file = GS_DIR . 'etc/listen-to-ip'; if (!@file_exists($file)) { # kann entweder passieren wenn wir ein Gemeinschaft-Node sind # (dann ist es extrem schlecht wenn die Datei fehlt) oder wenn # wir ein Web-Server ohne Asterisk sind (dann ist es ok) gs_log(GS_LOG_DEBUG, "File \"{$file}\" not found"); return false; } if (!is_array($lines = @file($file))) { gs_log(GS_LOG_DEBUG, "Failed to read \"{$file}\""); return false; } $ips = array(); foreach ($lines as $line) { $line = trim($line); if ($line == '' || @$line[0] == '#') { continue; } if (!preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/', $line, $m)) { continue; } $ips[] = normalizeIPs($m[0]); if ($primary_only) { # only return the first IP address (our main one) return $ips; } } // remove duplicates: $ips = array_flip(array_flip($ips)); sort($ips); return $ips; }
function _getUser() { $ldapproto = gs_get_conf('GS_LDAP_PROTOCOL'); $ldapuser = trim(@$_REQUEST['login_user']); $ldapdn = gs_get_conf('GS_LDAP_PROP_USER') . '=' . $ldapuser . ',' . gs_get_conf('GS_LDAP_SEARCHBASE'); $ldappass = @$_REQUEST['login_pwd']; $ldapsearchdn = gs_get_conf('GS_LDAP_BINDDN'); $ldapsearchpass = gs_get_conf('GS_LDAP_PWD'); $ldapconn = @ldap_connect(gs_get_conf('GS_LDAP_HOST')); @ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, (int) $ldapproto); if (!$ldapconn) { gs_log(GS_LOG_WARNING, 'Unable to connect to LDAP server'); return false; } if ($ldapuser == '' || $ldappass == '') { return false; } if ($ldapconn) { $ldapbind = @ldap_bind($ldapconn, $ldapsearchdn, $ldapsearchpass); if ($ldapbind) { $searchresult = @ldap_search($ldapconn, gs_get_conf('GS_LDAP_SEARCHBASE'), '(' . gs_get_conf('GS_LDAP_PROP_UID') . '=' . $ldapuser . ')', array()); $ldapinfo = ldap_get_entries($ldapconn, $searchresult); if ($ldapinfo['count'] != 1) { gs_log(GS_LOG_DEBUG, 'Number of users found in LDAP is not 1 (' . $ldapinfo['count'] . ')'); return false; } } else { gs_log(GS_LOG_DEBUG, 'Unable to bind to LDAP server as ' . $ldapsearchdn . ', ' . ldap_error($ldapconn)); return false; } } $ldapbind = @ldap_bind($ldapconn, $ldapinfo[0]['dn'], $ldappass); if ($ldapbind) { gs_log(GS_LOG_DEBUG, 'User ' . $ldapinfo[0]['dn'] . ' found!'); return $ldapuser; } else { gs_log(GS_LOG_DEBUG, 'Unable to bind to LDAP server as ' . $ldapinfo[0]['dn'] . ', ' . ldap_error($ldapconn)); return false; } }
function aastra_push_str($phone_ip, $xml) { $prov_host = gs_get_conf('GS_PROV_HOST'); //FIXME - call wget or something. this function should not block // for so long! // see _gs_prov_phone_checkcfg_by_ip_do_aastra() in // opt/gemeinschaft/inc/gs-fns/gs_prov_phone_checkcfg.php //$xml = utf8_decode($xml); if (subStr($xml, 0, 5) !== '<' . '?xml') { $xmlpi = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n"; } else { $xmlpi = ''; } $data = "POST / HTTP/1.1\r\n"; $data .= "Host: {$phone_ip}\r\n"; $data .= "Referer: {$prov_host}\r\n"; $data .= "Connection: Close\r\n"; $data .= "Content-Type: text/xml; charset=utf-8\r\n"; $data .= "Content-Length: " . (strLen('xml=') + strLen($xmlpi) + strLen($xml)) . "\r\n"; $data .= "\r\n"; $data .= 'xml=' . $xmlpi . $xml; $socket = @fSockOpen($phone_ip, 80, $error_no, $error_str, 4); if (!$socket) { gs_log(GS_LOG_NOTICE, "Aastra: Failed to open socket - IP: {$phone_ip}"); return 0; } stream_set_timeout($socket, 4); $bytes_written = (int) @fWrite($socket, $data, strLen($data)); @fFlush($socket); $response = @fGetS($socket); @fClose($socket); if (strPos($response, '200') === false) { gs_log(GS_LOG_WARNING, "Aastra: Failed to push XML to phone {$phone_ip}"); return 0; } gs_log(GS_LOG_DEBUG, "Aastra: Pushed {$bytes_written} bytes to phone {$phone_ip}"); return $bytes_written; }
gs_log( GS_LOG_WARNING, "Phone with IP \"$remote_ip\" (Grandstream) has invalid phone_model (\"". $ua ."\")" ); # don't explain this to the users _err( 'No! See log for details.' ); } # only gxv3000 if (! in_array($phone_model, array('gxv3000'), true) ) { gs_log( GS_LOG_WARNING, 'only gxp3000' ); _err( 'No! See log for details.' ); } */ # DB connect require_once GS_DIR . 'inc/db_connect.php'; $db = gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_WARNING, "Grandstream phone asks for idle screen - Could not connect to DB"); _err('Could not connect to DB.'); } # get user_id $user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `current_ip`=\'' . $db->escape($remote_ip) . '\''); function checksum($str) { $sum = 0; for ($i = 0; $i <= (strLen($str) - 1) / 2; $i++) { $sum += ord(subStr($str, 2 * $i, 1)) << 8; $sum += ord(subStr($str, 2 * $i + 1, 1)); $sum &= 0xffff; } $sum = 0x10000 - $sum; return array($sum >> 8 & 0xff, $sum & 0xff); }
@ob_end_flush(); die; } function _err($msg = '') { @ob_end_clean(); ob_start(); echo '<html>', "\n"; echo '<head><title>' . __('Fehler') . '</title></head>', "\n"; echo '<body><b>' . __('Fehler') . '</b>: ' . $msg . '</body>', "\n"; echo '</html>', "\n"; _ob_send(); } //--------------------------------------------------------------------------- if (!gs_get_conf('GS_POLYCOM_PROV_ENABLED')) { gs_log(GS_LOG_DEBUG, 'Polycom provisioning not enabled'); _err('Not enabled.'); } $user = trim(@$_REQUEST['user']); if (!preg_match('/^\\d+$/', $user)) { _err('Not a valid SIP user.'); } $type = trim(@$_REQUEST['type']); if (!in_array($type, array('in', 'out', 'missed', 'queue'), true)) { $type = false; } if (isset($_REQUEST['delete'])) { $delete = (int) $_REQUEST['delete']; } $db = gs_db_slave_connect(); //--- get user_id
gs_log(GS_LOG_WARNING, 'Failed to convert voicemail file to ' . $fmt . '. (' . trim(implode(' - ', $out)) . ')'); _server_error('Failed to convert file.'); } } elseif ($fmt === 'wav-pcm') { # signed linear PCM in WAVE container $cmd = $sox . ' -q -t al ' . qsa($origfile) . ' -r 8000 -c 1 -s -b 16 -t wav ' . qsa($outfile) . ' 1>>/dev/null'; $err = 0; $out = array(); @exec($cmd, $out, $err); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to convert voicemail file to ' . $fmt . '. (' . trim(implode(' - ', $out)) . ')'); _server_error('Failed to convert file.'); } } if (!file_exists($outfile)) { gs_log(GS_LOG_WARNING, 'Failed to convert voicemail file.'); _server_error('Failed to convert file.'); } @header('Content-Type: ' . $formats[$fmt]['mime']); $fake_filename = preg_replace('/[^0-9a-z\\-_.]/i', '', 'vm_' . $ext . '_' . date('Ymd_Hi', $info['orig_time']) . '_' . subStr(md5(date('s', $info['orig_time']) . $info['cidnum']), 0, 4) . '.' . $formats[$fmt]['ext']); @header('Content-Disposition: ' . ($attach ? 'attachment' : 'inline') . '; filename="' . $fake_filename . '"'); @header('ETag: ' . $etag); # set Content-Length to prevent Apache(/PHP?) from using # "Transfer-Encoding: chunked" which makes the sound file appear too # short in QuickTime and maybe other players @header('Transfer-Encoding: identity'); if ($fmt === 'wav-pcma') { @header('Content-Length: ' . ((int) strLen($wav_alaw_header) + (int) @fileSize($origfile))); echo $wav_alaw_header; @readFile($origfile); } else {
gs_log(GS_LOG_WARNING, 'Failed to get provisioning parameters (user)'); } else { foreach ($prov_params as $p) { if ($p['index'] === null || $p['index'] == -1) { # not an array if (!array_key_exists($p['param'], $settings)) { # don't set unknown parameters because the order is important gs_log(GS_LOG_NOTICE, "User prov. param \"{$param_name}\": Unknown parameter"); continue; } gs_log(GS_LOG_DEBUG, 'Overriding user prov. param "' . $p['param'] . '": "' . $p['value'] . '"'); //setting( $p['param'], null , $p['value'] ); psetting($p['param'], $p['value']); } else { # array gs_log(GS_LOG_NOTICE, 'User prov. param "' . $p['param'] . '"[' . $p['index'] . ']: Grandstream does not support arrays"'); //gs_log( GS_LOG_DEBUG, 'Overriding user prov. param "'.$p['param'].'"['.$p['index'].']: "'.$p['value'].'"' ); //setting( $p['param'], $p['index'], $p['value'] ); } } } unset($prov_params); ##################################################################### # create BODY ##################################################################### $body = _settings_out(); ##################################################################### # create HEADER ##################################################################### $header_length = 16; $header = array();
function gs_user_del($user, $reload = true) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get user_id, nobody_index and softkey_profile_id # $rs = $db->execute('SELECT `id`, `nobody_index`, `softkey_profile_id`, `prov_param_profile_id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\''); if (!$rs) { return new GsError('DB error.'); } if (!($r = $rs->fetchRow())) { return new GsError('Unknown user.'); } $user_id = (int) $r['id']; $softkey_profile_id = (int) $r['softkey_profile_id']; $prov_profile_id = (int) $r['prov_param_profile_id']; /* if ($r['nobody_index'] > 0) return new GsError( 'Cannot delete nobody user.' ); */ # get host_id # $host_id = (int) $db->executeGetOne('SELECT `host_id` FROM `users` WHERE `id`=' . $user_id); //if (! $host_id) // return new GsError( 'Unknown host.' ); $host = gs_host_by_id_or_ip($host_id); if (isGsError($host) || !is_array($host)) { $host = false; } # get user's sip name # $ext = $db->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=' . $user_id); # reboot phone # //$user_name = $db->executeGetOne( 'SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`='. $user_id ); //@ shell_exec( 'asterisk -rx \'sip notify snom-reboot '. $user_name .'\' >>/dev/null' ); @gs_prov_phone_checkcfg_by_user($user, true); #delete user from all groups # gs_group_members_purge_by_type('user', array($user_id)); # delete clir settings # $db->execute('DELETE FROM `clir` WHERE `user_id`=' . $user_id); # delete dial log # $db->execute('DELETE FROM `dial_log` WHERE `user_id`=' . $user_id); $db->execute('UPDATE `dial_log` SET `remote_user_id`=NULL WHERE `remote_user_id`=' . $user_id); # delete call waiting settings # $db->execute('DELETE FROM `callwaiting` WHERE `user_id`=' . $user_id); # delete call forward settings # $db->execute('DELETE FROM `callforwards` WHERE `user_id`=' . $user_id); # delete anounce files # $db->execute('DELETE FROM `vm_rec_messages` WHERE `_user_id`=' . $user_id); # delete parallel-call definition # $db->execute('DELETE FROM `cf_parallelcall` WHERE `_user_id`=' . $user_id); # delete timerules definition # $db->execute('DELETE FROM `cf_timerules` WHERE `_user_id`=' . $user_id); # delete from pickup groups # $db->execute('DELETE FROM `pickupgroups_users` WHERE `user_id`=' . $user_id); # delete from queue members # $db->execute('DELETE FROM `ast_queue_members` WHERE `_user_id`=' . $user_id); # delete external numbers # $db->execute('DELETE FROM `users_external_numbers` WHERE `user_id`=' . $user_id); # delete info about voicemail messages //FIXME - delete files? # $db->execute('DELETE FROM `vm_msgs` WHERE `user_id`=' . $user_id); # delete mailbox settings # $db->execute('DELETE FROM `vm` WHERE `user_id`=' . $user_id); # delete private phonebook # $db->execute('DELETE FROM `pb_prv` WHERE `user_id`=' . $user_id); # delete mailbox # $db->execute('DELETE FROM `ast_voicemail` WHERE `_user_id`=' . $user_id); # delete callblocking rules # $db->execute('DELETE FROM `callblocking` WHERE `user_id`=' . $user_id); # delete callerids # $db->execute('DELETE FROM `users_callerids` WHERE `user_id`=' . $user_id); # delete sip account # $db->execute('DELETE FROM `ast_sipfriends` WHERE `_user_id`=' . $user_id); # delete BOI permissions # $db->execute('DELETE FROM `boi_perms` WHERE `user_id`=' . $user_id); # delete ringtones # $db->execute('DELETE FROM `ringtones` WHERE `user_id`=' . $user_id); # delete softkeys # if ($softkey_profile_id > 0) { $db->execute('DELETE FROM `softkeys` WHERE `profile_id`=' . $softkey_profile_id); $db->execute('DELETE FROM `softkey_profiles` WHERE `id`=' . $softkey_profile_id . ' AND `is_user_profile`=1'); } # delete prov_params # if ($prov_profile_id > 0) { $db->execute('DELETE FROM `prov_params` WHERE `profile_id`=' . $prov_profile_id); $db->execute('DELETE FROM `prov_param_profiles` WHERE `id`=' . $prov_profile_id . ' AND `is_group_profile`=0'); } # delete watchlist buddies # $db->execute('DELETE FROM `user_watchlist` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `user_watchlist` WHERE `buddy_user_id`=' . $user_id); # delete instant messaging # $db->execute('DELETE FROM `instant_messaging` WHERE `user_id`=' . $user_id); # delete monitor data # $db->execute('DELETE FROM `monitor` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `monitor_queues` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `monitor_colors` WHERE `user_id`=' . $user_id); # do a clean logout from the current phone # $db->execute('UPDATE `phones` SET `user_id`=NULL WHERE `user_id`=' . $user_id); # delete huntgroup memberships # $db->execute('DELETE FROM `huntgroups` WHERE `user_id`=' . $user_id); # delete drop targets # $db->execute('DELETE FROM `user_calldrop` WHERE `user_id`=' . $user_id); # delete dnd # $db->execute('DELETE FROM `dnd` WHERE `_user_id`=' . $user_id); # delete user # $db->execute('DELETE FROM `users` WHERE `id`=' . $user_id); # astbuttond if (GS_BUTTONDAEMON_USE == true) { gs_user_remove_ui($ext); } # reload dialplan (to update hints) and prune realtime peer # if ($host_id > 0) { if (is_array($host) && !$host['is_foreign']) { @gs_asterisks_prune_peer($ext, array($host_id)); if ($reload) { @gs_asterisks_reload(array($host_id), true); } } } # delete user on foreign host # if (is_array($host) && $host['is_foreign']) { if (trim($ext) != '') { include_once GS_DIR . 'inc/boi-soap/boi-api.php'; $api = gs_host_get_api($host['id']); switch ($api) { case 'm01': case 'm02': $hp_route_prefix = (string) $db->executeGetOne('SELECT `value` FROM `host_params` ' . 'WHERE `host_id`=' . (int) $host['id'] . ' AND `param`=\'route_prefix\''); $sub_ext = subStr($ext, 0, strLen($hp_route_prefix)) === $hp_route_prefix ? subStr($ext, strLen($hp_route_prefix)) : $ext; gs_log(GS_LOG_DEBUG, "Mapping ext. {$ext} to {$sub_ext} for SOAP call"); //if (! class_exists('SoapClient')) { if (!extension_loaded('soap')) { return new GsError('Failed to delete user on foreign host (SoapClient not available).'); } include_once GS_DIR . 'inc/boi-soap/boi-soap.php'; $soap_faultcode = null; $ok = gs_boi_delete_extension($api, $host['host'], $hp_route_prefix, $sub_ext, $soap_faultcode); if (!$ok) { return new GsError('Failed to delete user on foreign host (SOAP error).'); } break; case '': # host does not provide any API gs_log(GS_LOG_NOTICE, 'Deleting user ' . $user . ' on foreign host ' . $host['host'] . ' without any API'); break; default: gs_log(GS_LOG_WARNING, 'Failed to delete user ' . $user . ' on foreign host ' . $host['host'] . ' - invalid API "' . $api . '"'); return new GsError('Failed to delete user on foreign host (Invalid API).'); } } } # update fax authentication file if fax enabled # if (gs_get_conf('GS_FAX_ENABLED')) { $ok = gs_hylafax_authfile_sync(); if (isGsError($ok)) { return new GsError($ok->getMsg()); } if (!$ok) { return new GsError('Failed to update fax authentication file.'); } } return true; }
function gs_extstate_callable($ext) { include_once GS_DIR . 'inc/db_connect.php'; $db = @gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_FATAL, 'Could not connect to slave DB!'); return AST_MGR_EXT_UNKNOWN; } //user and parallel call $rs = $db->execute('SELECT `a`.`_user_id`, `a`.`host`, `c`.`active` FROM `ast_sipfriends` `a` LEFT JOIN `callforwards` `c` ON ( `a`.`_user_id`= `c`.`user_id` AND `c`.`source`="internal" AND `c`.`case`="always") WHERE `a`.`name`="' . $ext . '"'); if (!$rs) { return new GsError('DB Error.'); } if (!($user = $rs->FetchRow())) { return new GsError('No extension ' . $ext); } if ($user['active'] == '' || $user['active'] == 'no') { //this is a user, no callforwards $state = gs_extstate($user['host'], $ext); return gs_ast_extstate_try_cc($state); } else { if ($user['active'] == 'par') { //this is a user, parallel call enabled $rs = $db->execute('SELECT `a`.`name`, `a`.`host` FROM `ast_sipfriends` `a`, `cf_parallelcall` `c` WHERE `c`.`_user_id`= ' . $user['_user_id'] . ' AND `c`.`number`=`a`.`name`'); if (!$rs) { return new GsError('DB Error.' . $ext); } $count = 0; $hosts = array(); while ($peer = $rs->FetchRow()) { $count++; $host_id = $peer['host_id']; $hosts[$host_id][] = $peer['name']; } //no callforward users if ($count == 0) { return false; } $allstates = array(); foreach ($hosts as $host => $peers) { $states = gs_extstate($host, $peers); if (is_array($states)) { $allstates = array_merge($allstates, $states); } } foreach ($allstates as $singlestate) { if ($singlestate != AST_MGR_EXT_IDLE) { return false; } } return true; } else { //any other callforward return false; } } return false; }
function _upload_ringtone($ringtonefile) { $file = '/opt/gemeinschaft-siemens/conf.php'; if (file_exists($file) && is_readable($file)) { include_once $file; } else { gs_log(GS_LOG_NOTICE, "Siemens provisioning not available"); return false; } $fileserver['wan'] = gs_get_conf('GS_PROV_SIEMENS_FTP_SERVER_WAN'); $fileserver['lan'] = gs_get_conf('GS_PROV_SIEMENS_FTP_SERVER_LAN'); //$fileserver['local'] = gs_get_conf('GS_PROV_HOST'); $ftp_path = ''; $external_ftp_path = gs_get_conf('GS_PROV_SIEMENS_FTP_RINGTONE_PATH'); if ($external_ftp_path === null) { $external_ftp_path = '/'; } include_once GS_DIR . 'inc/ftp-filesize.php'; $ftp = new GS_FTP_FileSize(); foreach ($fileserver as $file_server) { if ($file_server == '') { continue; } if (!$ftp->connect($file_server, null, gs_get_conf('GS_PROV_SIEMENS_FTP_USER'), gs_get_conf('GS_PROV_SIEMENS_FTP_PWD'))) { gs_log(GS_LOG_WARNING, 'Siemens prov.: Can\'t upload ' . $ringtonefile . ' file to ' . $file_server . ' (FTP server failed)'); } else { $ok = $ftp->upload_file($ringtonefile, $external_ftp_path); $ftp->disconnect(); if (!$ok) { gs_log(GS_LOG_WARNING, 'Failed to copy ringtone to FTP server'); } } } return true; }
_settings_err('No! See log for details.'); } $ua = trim(@$_SERVER['HTTP_USER_AGENT']); if (preg_match('/^Mozilla\\/\\d\\.\\d\\s*\\(compatible;\\s*/i', $ua, $m)) { $ua = rTrim(subStr($ua, strLen($m[0])), ' )'); } gs_log(GS_LOG_DEBUG, "Snom model {$ua} found."); if (preg_match('/snom m9/i', $ua, $m)) { $phone_model = 'm9'; } else { $phone_model = 'unknown'; } $phone_type = 'snom-' . $phone_model; # e.g. "snom-m9" # to be used when auto-adding the phone gs_log(GS_LOG_DEBUG, "Snom phone \"{$mac}\" asks for settings (UA: ...\"{$ua}\") - model: {$phone_model}"); $prov_url_snom = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT ? ':' . GS_PROV_PORT : '') . GS_PROV_PATH . 'snom/'; ##################################################################### # output ##################################################################### ob_start(); header('Content-Type: application/xml; charset=utf-8'); echo '<', '?xml version="1.0" encoding="utf-8"?', '>', "\n"; echo '<setting-files>', "\n"; echo '<file url="', $prov_url_snom, 'sw-m9-update.php?mac={mac}" />', "\n"; echo '<file url="', $prov_url_snom, 'settings-m9.php?mac={mac}" />', "\n"; echo '<file url="', $prov_url_snom, 'pb-m9.php?mac={mac}" />', "\n"; echo '</setting-files>', "\n"; if (!headers_sent()) { # avoid chunked transfer-encoding header('Content-Length: ' . (int) @ob_get_length());
if (!headers_sent()) { header('Content-Type: application/xml; charset=utf-8'); header('Content-Length: ' . (int) @ob_get_length()); } @ob_end_flush(); die; } function _err($msg = '') { @ob_end_clean(); ob_start(); echo '<?', 'xml version="1.0" encoding="utf-8"?', '>', "\n", '<TiptelIPPhoneTextScreen>', "\n", '<Title>', __('Fehler'), '</Title>', "\n", '<Text>', tiptelXmlEsc(__('Fehler') . ': ' . $msg), '</Text>', "\n", '</TiptelIPPhoneTextScreen>', "\n"; _ob_send(); } if (!gs_get_conf('GS_TIPTEL_PROV_ENABLED')) { gs_log(GS_LOG_DEBUG, "Tiptel provisioning not enabled"); _err('Not enabled.'); } $user = trim(@$_REQUEST['u']); if (!preg_match('/^\\d+$/', $user)) { _err('Not a valid SIP user.'); } $type = trim(@$_REQUEST['type']); if (!in_array($type, array('in', 'out', 'missed', 'queue'), true)) { $type = false; } $db = gs_db_slave_connect(); # get user_id # $user_id = (int) $db->executeGetOne('SELECT `_user_id` FROM `ast_sipfriends` WHERE `name`=\'' . $db->escape($user) . '\''); if ($user_id < 1) {
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. \*******************************************************************/ defined('GS_VALID') or die('No direct access.'); require_once GS_DIR . 'inc/log.php'; echo '<h2>'; if (@$MODULES[$SECTION]['icon']) { echo '<img alt=" " src="', GS_URL_PATH, str_replace('%s', '32', $MODULES[$SECTION]['icon']), '" /> '; } if (count($MODULES[$SECTION]['sub']) > 1) { echo $MODULES[$SECTION]['title'], ' - '; } echo $MODULES[$SECTION]['sub'][$MODULE]['title']; echo '</h2>', "\n"; gs_log(GS_LOG_DEBUG, 'User ' . $_SESSION['login_user'] . ' logged out (HTTP)'); $_SESSION = array(); session_destroy(); ?> <br /> <br /> <?php echo __('Sie sind jetzt abgemeldet.'); ?> <br style="clear:right" />
function distribute_remove($localfile) { global $errormsgs; $hostlist = gs_hosts_get(); $thishost = @gs_get_listen_to_ids(); foreach($hostlist as $currenthost) { unset($islocalhost); $islocalhost = FALSE; foreach($thishost as $hostid) { if($currenthost["id"] == $hostid) $islocalhost = TRUE; } if($islocalhost == FALSE) { unset($cmd); $cmd = "sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ". qsa($currenthost["host"]) ." ". qsa("rm ". qsa($localfile)); @exec($cmd ." 1>>/dev/null 2>>/dev/null", $out, $err); if($err != 0) { gs_log(GS_LOG_WARNING, "Failed to remove system recording '". $localfile ."' from ". $currenthost["host"]); $errormsgs[] = sprintf(__('Audiodatei kann nicht von Node %s gelöscht werden'), $currenthost["host"]); } } } }
$intl_lang_sounds = 'xx-XX'; $intl_ast_lang = 'xx'; } echo 'gs_lang=', $intl_lang_sounds, ';', "\n"; echo 'gs_astlang=', $intl_ast_lang, ';', "\n"; require_once GS_DIR . 'inc/get-listen-to-ips.php'; $our_ips = gs_get_listen_to_ips(true); if (count($our_ips) >= 1) { $our_ip = $our_ips[0]; } else { $err = 0; $out = array(); @exec('/opt/gemeinschaft/sbin/getnetifs/getipaddrs 2>>/dev/null', $out, $err); $addrs = array(); if ($err != 0) { gs_log(GS_LOG_NOTICE, "getipaddrs failed (exit code {$err})"); # not really a problem as we don't really need the system_ip } else { foreach ($out as $line) { if (preg_match('/[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/', $line, $m)) { $addrs[] = $m[0]; } } } //if (($addr = gs_keyval_get('vlan_0_ipaddr'))) $addrs[] = $addr; $good_addrs = array(); foreach ($addrs as $addr) { if (subStr($addr, 0, 4) === '127.') { continue; } if (subStr($addr, 0, 8) === '169.254.') {
function gs_user_change($user, $pin, $firstname, $lastname, $language, $host_id_or_ip, $force = false, $email = '', $reload = true) { if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) { return new GsError('User must be alphanumeric.'); } if (!preg_match('/^[0-9]+$/', $pin)) { return new GsError('PIN must be numeric.'); } if (strLen($pin) < 3) { return new GsError('PIN too short (min. 3 digits).'); } elseif (strLen($pin) > 10) { return new GsError('PIN too long (max. 10 digits).'); } //if (! preg_match( '/^[a-zA-Z\d.\-\_ ]+$/', $firstname )) // return new GsError( 'Invalid characters in first name.' ); $firstname = preg_replace('/\\s+/', ' ', trim($firstname)); //if (! preg_match( '/^[a-zA-Z\d.\-\_ ]+$/', $lastname )) // return new GsError( 'Invalid characters in last name.' ); $lastname = preg_replace('/\\s+/', ' ', trim($lastname)); // prepare language code $language = substr(trim($language), 0, 2); if (strlen($language) != 2) { return new GsError('Invalid language code.'); } if (!defined('GS_EMAIL_PATTERN_VALID')) { return new GsError('GS_EMAIL_PATTERN_VALID not defined.'); } if ($email != '' && !preg_match(GS_EMAIL_PATTERN_VALID, $email)) { return new GsError('Invalid e-mail address.'); } include_once GS_DIR . 'lib/utf8-normalize/gs_utf_normal.php'; # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # start transaction # gs_db_start_trans($db); # get user_id # $user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\''); if (!$user_id) { gs_db_rollback_trans($db); return new GsError('Unknown user.'); } # get old host_id # $old_host_id = (int) $db->executeGetOne('SELECT `host_id` FROM `users` WHERE `id`=' . $user_id); $old_host = gs_host_by_id_or_ip($old_host_id); if (isGsError($old_host) || !is_array($old_host)) { $old_host = false; } # get user's peer name (extension) # $ext = $db->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=' . $user_id); # check if (new) host exists # $host = gs_host_by_id_or_ip($host_id_or_ip); if (isGsError($host)) { gs_db_rollback_trans($db); return new GsError($host->getMsg()); } if (!is_array($host)) { gs_db_rollback_trans($db); return new GsError('Unknown host.'); } if ($old_host_id != $host['id'] && !$force) { gs_db_rollback_trans($db); return new GsError('Changing the host will result in loosing mailbox messages etc. and thus will not be done without force.'); } /* # check if queue with same ext exists # $num = (int)$db->executeGetOne( 'SELECT COUNT(*) FROM `ast_queues` WHERE `name`=\''. $db->escape($ext) .'\'' ); if ($num > 0) { gs_db_rollback_trans($db); return new GsError( 'A queue with that name already exists.' ); } */ # update user # $ok = $db->execute('UPDATE `users` SET `pin`=\'' . $db->escape($pin) . '\', `firstname`=\'' . $db->escape($firstname) . '\', `lastname`=\'' . $db->escape($lastname) . '\', `email`=\'' . $db->escape($email) . '\', `host_id`=' . $host['id'] . ' WHERE `id`=' . $user_id); if (!$ok) { gs_db_rollback_trans($db); return new GsError('Failed to change user.'); } # update sip account (including language code) # $calleridname = trim(gs_utf8_decompose_to_ascii($firstname . ' ' . $lastname)); $ok = $db->execute('UPDATE `ast_sipfriends` SET `callerid`=CONCAT(_utf8\'' . $db->escape($calleridname) . '\', \' <\', `name`, \'>\'), `language`=\'' . $db->escape($language) . '\' WHERE `_user_id`=' . $user_id); if (!$ok) { gs_db_rollback_trans($db); return new GsError('Failed to change SIP account.'); } # delete stuff not used for users on foreign hosts # if ($host['is_foreign']) { $db->execute('DELETE FROM `clir` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `dial_log` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `callforwards` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `pickupgroups_users` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `ast_queue_members` WHERE `_user_id`=' . $user_id); $db->execute('DELETE FROM `vm` WHERE `user_id`=' . $user_id); $db->execute('DELETE FROM `ast_voicemail` WHERE `_user_id`=' . $user_id); } # update mailbox # if (!$host['is_foreign']) { $ok = $db->execute('UPDATE `ast_voicemail` SET `password`=\'' . $db->escape($pin) . '\', `fullname`=\'' . $db->escape($firstname . ' ' . $lastname) . '\' WHERE `_user_id`=' . $user_id); if (!$ok) { gs_db_rollback_trans($db); return new GsError('Failed to change mailbox.'); } } # new host? # if ($host['id'] != $old_host_id) { # delete from queue members # $db->execute('DELETE FROM `ast_queue_members` WHERE `_user_id`=' . $user_id); # delete from pickup groups # $db->execute('DELETE FROM `pickupgroups_users` WHERE `user_id`=' . $user_id); } # get info needed for foreign hosts # if (is_array($old_host) && $old_host['is_foreign'] || $host['is_foreign']) { # get user's sip name and password $rs = $db->execute('SELECT `name`, `secret` FROM `ast_sipfriends` WHERE `_user_id`=' . $user_id); if (!$rs || !($r = $rs->fetchRow())) { gs_db_rollback_trans($db); return new GsError('DB error.'); } $ext = $r['name']; $sip_pwd = $r['secret']; } # modify user on foreign host(s) # if ($host['id'] != $old_host_id) { # host changed. delete user on old host and add on new one if (is_array($old_host) && $old_host['is_foreign']) { include_once GS_DIR . 'inc/boi-soap/boi-api.php'; $api = gs_host_get_api($old_host_id); switch ($api) { case 'm01': case 'm02': //if (! class_exists('SoapClient')) { if (!extension_loaded('soap')) { gs_db_rollback_trans($db); return new GsError('Failed to delete user on old foreign host (SoapClient not available).'); } else { $hp_route_prefix = (string) $db->executeGetOne('SELECT `value` FROM `host_params` ' . 'WHERE `host_id`=' . (int) $old_host['id'] . ' AND `param`=\'route_prefix\''); $sub_ext = subStr($ext, 0, strLen($hp_route_prefix)) === $hp_route_prefix ? subStr($ext, strLen($hp_route_prefix)) : $ext; gs_log(GS_LOG_DEBUG, "Mapping ext. {$ext} to {$sub_ext} for SOAP call"); include_once GS_DIR . 'inc/boi-soap/boi-soap.php'; $soap_faultcode = null; $ok = gs_boi_delete_extension($api, $old_host['host'], $hp_route_prefix, $sub_ext, $soap_faultcode); if (!$ok) { gs_db_rollback_trans($db); return new GsError('Failed to delete user on old foreign host (SOAP error).'); } } break; case '': # host does not provide any API gs_log(GS_LOG_NOTICE, 'Deleting user ' . $user . ' on foreign host ' . $old_host['host'] . ' without any API'); break; default: gs_log(GS_LOG_WARNING, 'Failed to delete user ' . $user . ' on foreign host ' . $old_host['host'] . ' - invalid API "' . $api . '"'); gs_db_rollback_trans($db); return new GsError('Failed to delete user on foreign host (Invalid API).'); } } if ($host['is_foreign']) { include_once GS_DIR . 'inc/boi-soap/boi-api.php'; $api = gs_host_get_api($host['id']); switch ($api) { case 'm01': case 'm02': //if (! class_exists('SoapClient')) { if (!extension_loaded('soap')) { gs_db_rollback_trans($db); return new GsError('Failed to add user on new foreign host (SoapClient not available).'); } else { $hp_route_prefix = (string) $db->executeGetOne('SELECT `value` FROM `host_params` ' . 'WHERE `host_id`=' . (int) $host['id'] . ' AND `param`=\'route_prefix\''); $sub_ext = subStr($ext, 0, strLen($hp_route_prefix)) === $hp_route_prefix ? subStr($ext, strLen($hp_route_prefix)) : $ext; gs_log(GS_LOG_DEBUG, "Mapping ext. {$ext} to {$sub_ext} for SOAP call"); include_once GS_DIR . 'inc/boi-soap/boi-soap.php'; $soap_faultcode = null; $ok = gs_boi_update_extension($api, $host['host'], $hp_route_prefix, $sub_ext, $user, $sip_pwd, $pin, $firstname, $lastname, $email, $soap_faultcode); if (!$ok) { gs_db_rollback_trans($db); return new GsError('Failed to add user on new foreign host (SOAP error).'); } } break; case '': # host does not provide any API gs_log(GS_LOG_NOTICE, 'Adding user ' . $user . ' on foreign host ' . $host['host'] . ' without any API'); break; default: gs_log(GS_LOG_WARNING, 'Failed to add user ' . $user . ' on foreign host ' . $host['host'] . ' - invalid API "' . $api . '"'); gs_db_rollback_trans($db); return new GsError('Failed to add user on foreign host (Invalid API).'); } } } else { # host did not change if ($host['is_foreign']) { include_once GS_DIR . 'inc/boi-soap/boi-api.php'; $api = gs_host_get_api($host['id']); switch ($api) { case 'm01': case 'm02': //if (! class_exists('SoapClient')) { if (!extension_loaded('soap')) { gs_db_rollback_trans($db); return new GsError('Failed to modify user on foreign host (SoapClient not available).'); } else { $hp_route_prefix = (string) $db->executeGetOne('SELECT `value` FROM `host_params` ' . 'WHERE `host_id`=' . (int) $host['id'] . ' AND `param`=\'route_prefix\''); $sub_ext = subStr($ext, 0, strLen($hp_route_prefix)) === $hp_route_prefix ? subStr($ext, strLen($hp_route_prefix)) : $ext; gs_log(GS_LOG_DEBUG, "Mapping ext. {$ext} to {$sub_ext} for SOAP call"); include_once GS_DIR . 'inc/boi-soap/boi-soap.php'; $soap_faultcode = null; $ok = gs_boi_update_extension($api, $host['host'], $hp_route_prefix, $sub_ext, $user, $sip_pwd, $pin, $firstname, $lastname, $email, $soap_faultcode); if (!$ok) { gs_db_rollback_trans($db); return new GsError('Failed to modify user on foreign host (SOAP error).'); } } break; case '': # host does not provide any API gs_log(GS_LOG_NOTICE, 'Modifying user ' . $user . ' on foreign host ' . $host['host'] . ' without any API'); break; default: gs_log(GS_LOG_WARNING, 'Failed to modify user ' . $user . ' on foreign host ' . $host['host'] . ' - invalid API "' . $api . '"'); gs_db_rollback_trans($db); return new GsError('Failed to modify user on foreign host (Invalid API).'); } } } # commit transaction # if (!gs_db_commit_trans($db)) { return new GsError('Failed to modify user.'); } # new host? # if ($host['id'] != $old_host_id) { # reload dialplan (hints!) # if (is_array($old_host) && !$old_host['is_foreign']) { $ok = @gs_asterisks_prune_peer($ext, array($old_host_id)); if ($reload) { @gs_asterisks_reload(array($old_host_id), true); } } if (!$host['is_foreign']) { if ($reload) { @gs_asterisks_reload(array($host['id']), true); } } } else { $ok = @gs_asterisks_prune_peer($ext, array($host['id'])); } # reboot the phone # //@ shell_exec( 'asterisk -rx \'sip notify snom-reboot '. $ext .'\' >>/dev/null' ); @gs_prov_phone_checkcfg_by_ext($ext, true); # update fax authentication file if fax enabled # if (gs_get_conf('GS_FAX_ENABLED')) { $ok = gs_hylafax_authfile_sync(); if (isGsError($ok)) { return new GsError($ok->getMsg()); } if (!$ok) { return new GsError('Failed to update fax authentication file.'); } } return true; }
die_not_allowed('You are not allowed to send a fax.'); } $user_id = 0; $tsi = trim(@$_REQUEST['tsi']); $to = trim(@$_REQUEST['to']); $resolution = (int) trim(@$_REQUEST['res']); $user = trim(@$_REQUEST['user']); $sidnum = trim(@$_REQUEST['cidnum']); $local_file = trim(@$_REQUEST['file']); if ($user != '') { $user_id = get_user_id($user); } # check if user is known to GS # if ($user_id < 1) { gs_log(GS_LOG_NOTICE, "User \"{$user}\" unknown"); die_not_allowed('You are not allowed to send a fax.'); } # get email address and PIN # $email = gs_user_email_address_get($user); $pin = gs_user_pin_get($user); # use default fax TSI if not provided in http request # if ($tsi == '') { $fax_tsis_global = explode(',', gs_get_conf('GS_FAX_TSI')); if (array_key_exists(0, $fax_tsis_global) && $fax_tsis_global[0] != '') { $tsi = $fax_tsis_global[0]; } else { $tsi = '0'; }
@ob_flush(); @flush(); passThru('sudo ' . qsa(GS_DIR . 'sbin/start-asterisk'), $err); echo "\n", '→ <b>', $err == 0 ? 'OK' : 'ERR', '</b>', "\n\n"; $rs = $DB->execute('SELECT `host` FROM `hosts` WHERE `is_foreign` = 0'); while ($r = $rs->fetchRow()) { /* if ($r['host'] === '127.0.0.1') { //FIXME gs_log(GS_LOG_DEBUG, "Reloading local Asterisk"); echo "Reloading <b>local</b> Asterisk\n"; @ob_flush(); @flush(); passThru( 'sudo '. qsa(GS_DIR.'sbin/start-asterisk'), $err ); } else { */ gs_log(GS_LOG_DEBUG, "Reloading Asterisk on " . $r['host']); echo "Reloading Asterisk on <b>", $r['host'], "</b>\n"; @ob_flush(); @flush(); passThru('sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=8 -l root ' . qsa($r['host']) . ' ' . qsa(GS_DIR . 'sbin/start-asterisk'), $err); /* } */ echo "\n", '→ <b>', $err == 0 ? 'OK' : 'ERR', '</b>', "\n\n"; } @ob_implicit_flush(0); echo '</pre>'; } /* elseif ($action === 'shutdown' && $shutdown_enabled) { ?>
##################################################################### # Override provisioning parameters (user profile) ##################################################################### $prov_params = @gs_user_prov_params_get($user['user'], $phone_type); if (!is_array($prov_params)) { gs_log(GS_LOG_WARNING, 'Failed to get provisioning parameters (user)'); } else { $param_count = $param_count + count($prov_params); foreach ($prov_params as $p) { if ($p['index'] === null || $p['index'] == -1) { # not an array gs_log(GS_LOG_DEBUG, 'Overriding user prov. param "' . $p['param'] . '": "' . $p['value'] . '"'); setting($p['param'], null, $p['value']); } else { # array gs_log(GS_LOG_DEBUG, 'Overriding user prov. param "' . $p['param'] . '"[' . $p['index'] . ']: "' . $p['value'] . '"'); setting($p['param'], $p['index'], $p['value']); } } } unset($prov_params); } # ignore parameters of other users on the same gateway if ($param_count > 0) { break; } } ##################################################################### # output ##################################################################### ob_start();
$msg_close = '</script>' . '.' . "\n"; // padding for the stupid MSIE: $msie_pad = str_repeat(' ', 256 - 1) . "\n"; $sock = @fSockOpen($host, $port, $err, $errMsg, 5); if (!is_resource($sock)) { header('HTTP/1.0 500 Internal Server Error', true, 500); header('Status: 500 Internal Server Error', true, 500); echo $html_start; echo $msg_open; echo 'e("daemondown");', "\n"; echo $msie_pad; echo $msg_close; echo $html_end; @ob_flush(); @flush(); gs_log(GS_LOG_NOTICE, 'Extension state daemon not running.'); sleep(1); die; } @stream_set_blocking($sock, false); $tStart = time(); $cnt_no_data = 0; $buf = ''; echo $html_start; echo $msg_open; echo 'e("");', "\n"; # everything is fine echo $msie_pad; echo $msg_close; @ob_flush(); @flush();
die; } function getUserID($ext) { global $db; if (!preg_match('/^\\d+$/', $ext)) { snom_textscreen(__('Fehler'), snom_xml_esc(__('Ungültiger Benutzername'))); } $user_id = (int) $db->executeGetOne('SELECT `_user_id` FROM `ast_sipfriends` WHERE `name`=\'' . $db->escape($ext) . '\''); if ($user_id < 1) { snom_textscreen(__('Fehler'), __('Benutzer unbekannt')); } return $user_id; } if (!gs_get_conf('GS_SNOM_PROV_ENABLED')) { gs_log(GS_LOG_DEBUG, "Snom provisioning not enabled"); snom_textscreen(__('Fehler'), __('Nicht aktiviert')); } $type = trim(@$_REQUEST['t']); if (!in_array($type, array(), true)) { $type = false; } $db = gs_db_slave_connect(); $user = trim(@$_REQUEST['u']); $user_id = getUserID($user); // setup i18n stuff gs_setlang(gs_get_lang_user($db, $user, GS_LANG_FORMAT_GS)); gs_loadtextdomain("gemeinschaft-gui"); gs_settextdomain("gemeinschaft-gui"); $tmp = array(); if (gs_get_conf('GS_PB_IMPORTED_ENABLED')) {
$DB->execute('DELETE FROM `gate_params` WHERE `gate_id`=' . $gwid . ' AND `param`=\'' . $DB->escape('permit') . '\''); if ($v !== null) { $DB->execute('INSERT INTO `gate_params` (`gate_id`, `param`, `value`)' . ' VALUES (' . $gwid . ', \'' . $DB->escape('permit') . '\', \'' . $DB->escape($v) . '\')'); } $v = @$_REQUEST['gw-param-codecs']; if (!is_array($v) || count($v) < 1) { $v = array('alaw' => 1); gs_log(GS_LOG_WARNING, 'You did not allow any codecs for gateway ' . $iax_friend_name . '. Allowing G.711a by default.'); } $v = array_keys($v); $DB->execute('DELETE FROM `gate_params` WHERE `gate_id`=' . $gwid . ' AND `param`=\'' . $DB->escape('allow') . '\''); $DB->execute('INSERT INTO `gate_params` (`gate_id`, `param`, `value`)' . ' VALUES (' . $gwid . ', \'' . $DB->escape('allow') . '\', \'' . $DB->escape(implode(',', $v)) . '\')'); $v = @$_REQUEST['gw-param-auth']; if (!is_array($v) || count($v) < 1) { $v = array('plaintext' => 1); gs_log(GS_LOG_WARNING, 'You did not allow any codecs for gateway ' . $iax_friend_name . '. Allowing G.711a by default.'); } $v = array_keys($v); $v = array_reverse($v); $DB->execute('DELETE FROM `gate_params` WHERE `gate_id`=' . $gwid . ' AND `param`=\'' . $DB->escape('auth') . '\''); $DB->execute('INSERT INTO `gate_params` (`gate_id`, `param`, `value`)' . ' VALUES (' . $gwid . ', \'' . $DB->escape('auth') . '\', \'' . $DB->escape(implode(',', $v)) . '\')'); $cmd = '/opt/gemeinschaft/sbin/start-asterisk 1>>/dev/null 2>>/dev/null'; @exec('sudo sh -c ' . qsa($cmd) . ' 1>>/dev/null 2>>/dev/null'); $action = ''; } ##################################################################### ##################################################################### if ($action === 'del') { $gwid = (int) @$_REQUEST['gw-id']; $DB->execute('DELETE FROM `gate_params` WHERE `gate_id`=' . $gwid); $DB->execute('DELETE FROM `gates` WHERE `id`=' . $gwid);
function gs_queue_status($host, $ext, $getMembers, $getCallers) { static $hosts = array(); if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $host = '127.0.0.1'; } if (!isset($hosts[$host])) { $hosts[$host] = array('sock' => null, 'lasttry' => 0); } if (!is_resource($hosts[$host]['sock'])) { if ($hosts[$host]['lasttry'] > time() - 60) { # we have tried less than a minute ago $hosts[$host]['lasttry'] = time(); return false; } $hosts[$host]['lasttry'] = time(); $sock = @fSockOpen($host, 5038, $err, $errMsg, 2); if (!is_resource($sock)) { gs_log(GS_LOG_WARNING, 'Connection to AMI on ' . $host . ' failed'); return false; } $data = _sock_read($sock, 3, '/[\\r\\n]/'); if (!preg_match('/^Asterisk [^\\/]+\\/(\\d(?:\\.\\d)?)/mis', $data, $m)) { gs_log(GS_LOG_WARNING, 'Incompatible Asterisk manager interface on ' . $host); $m = array(1 => '0.0'); } else { if ($m[1] > '1.1') { # Asterisk 1.4: manager 1.0 # Asterisk 1.6: manager 1.1 gs_log(GS_LOG_NOTICE, 'Asterisk manager interface on ' . $host . ' speaks a new protocol version (' . $m[1] . ')'); # let's try anyway and hope to understand it } } $hosts[$host]['sock'] = $sock; $req = "Action: Login\r\n" . "Username: "******"gscc" . "\r\n" . "Secret: " . "gspass" . "\r\n" . "Events: off\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $data = _sock_read2($sock, 5, '/\\r\\n\\r\\n/S'); if (!preg_match('/Authentication accepted/i', $data)) { gs_log(GS_LOG_WARNING, 'Authentication to AMI on ' . $host . ' failed'); $hosts[$host]['sock'] = null; return false; } } else { $sock = $hosts[$host]['sock']; } $queue_stats = array('maxlen' => null, 'calls' => null, 'holdtime' => null, 'completed' => null, 'abandoned' => null, 'sl' => null, 'slp' => null); if ($getMembers) { $queue_stats['members'] = array(); } if ($getCallers) { $queue_stats['callers'] = array(); } $default_member = array('dynamic' => null, 'calls' => null, 'lastcall' => null, 'devstate' => null, 'paused' => null); $default_caller = array('channel' => null, 'cidnum' => null, 'cidname' => null, 'wait' => null); $req = "Action: QueueStatus\r\n" . "Queue: " . $ext . "\r\n" . "\r\n"; @fWrite($sock, $req, strLen($req)); @fFlush($sock); $resp = trim(_sock_read2($sock, 2, '/Event:\\s*QueueStatusComplete\\r\\n\\r\\n/i')); //echo "\n$resp\n\n"; if (!preg_match('/^Response:\\s*Success/is', $resp)) { return false; } $resp = preg_split('/\\r\\n\\r\\n/S', $resp); /* echo "<pre>"; print_r($resp); echo "</pre>"; */ $manager_ok = false; foreach ($resp as $pkt) { $pkt = lTrim($pkt); if (preg_match('/^Event:\\s*QueueParams/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } //echo $pkt, "\n\n"; if (preg_match('/^Max:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['maxlen'] = (int) $m[1] > 0 ? (int) $m[1] : null; } if (preg_match('/^Calls:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['calls'] = (int) $m[1]; } if (preg_match('/^Holdtime:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['holdtime'] = (int) $m[1]; } if (preg_match('/^Completed:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['completed'] = (int) $m[1]; } if (preg_match('/^Abandoned:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['abandoned'] = (int) $m[1]; } if (preg_match('/^ServiceLevel:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['sl'] = (int) $m[1]; } if (preg_match('/^ServiceLevelPerf:\\s*(\\d+?(\\.\\d+)?)/mis', $pkt, $m)) { $queue_stats['slp'] = (double) $m[1]; } $manager_ok = true; } elseif ($getMembers && preg_match('/^Event:\\s*QueueMember/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } if (!preg_match('/^Location:\\s*([A-Z\\d\\/]+)/mis', $pkt, $m)) { continue; } $loc = $m[1]; $queue_stats['members'][$loc] = $default_member; //echo $pkt, "\n\n"; if (preg_match('/^Membership:\\s*([a-z]+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['dynamic'] = $m[1] != 'static'; } if (preg_match('/^CallsTaken:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['calls'] = (int) $m[1]; } if (preg_match('/^LastCall:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['lastcall'] = (int) $m[1]; } if (preg_match('/^Status:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['devstate'] = (int) $m[1]; } if (preg_match('/^Paused:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['members'][$loc]['paused'] = (int) $m[1] > 0; } } elseif ($getCallers && preg_match('/^Event:\\s*QueueEntry/is', $pkt)) { if (!preg_match('/^Queue:\\s*' . $ext . '/mis', $pkt)) { continue; } if (!preg_match('/^Position:\\s*(\\d+)/mis', $pkt, $m)) { continue; } $pos = (int) $m[1]; $queue_stats['callers'][$pos] = $default_caller; //echo $pkt, "\n\n"; if (preg_match('/^Channel:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['dynamic'] = trim($m[1]); } if (preg_match('/^CallerID:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['cidnum'] = strToLower(trim($m[1])) != 'unknown' ? trim($m[1]) : null; } if (preg_match('/^CallerIDName:\\s*([^\\n\\r]+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['cidname'] = strToLower(trim($m[1])) != 'unknown' ? trim($m[1]) : null; } if (preg_match('/^Wait:\\s*(\\d+)/mis', $pkt, $m)) { $queue_stats['callers'][$pos]['wait'] = (int) $m[1]; } } } if (!$manager_ok && $getMembers) { # failed to get information about the queue from the manager # interface. this happens after a reload of Asterisk when # no call has entered the queue using Queue() yet $queue_stats['calls'] = 0; $queue_stats['completed'] = 0; $queue_stats['abandoned'] = 0; $queue_stats['holdtime'] = 0; include_once GS_DIR . 'inc/db_connect.php'; $db = @gs_db_slave_connect(); if (!$db) { return $queue_stats; } $maxlen = (int) $db->executeGetOne('SELECT `maxlen` FROM `ast_queues` WHERE `name`=\'' . $db->escape($ext) . '\''); $queue_stats['maxlen'] = $maxlen > 0 ? $maxlen : null; $rs = $db->execute('SELECT `interface` FROM `ast_queue_members` WHERE `queue_name`=\'' . $db->escape($ext) . '\''); $queue_members = array(); while ($r = $rs->fetchRow()) { if (strToUpper(subStr($r['interface'], 0, 4)) == 'SIP/') { $queue_members[] = subStr($r['interface'], 4); } else { $queue_members[] = $r['interface']; } } if (count($queue_members) < 1) { return $queue_stats; } foreach ($queue_members as $queue_member) { $queue_stats['members']['SIP/' . $queue_member] = $default_member; } $ext_states = @gs_extstate($host, $queue_members); if (!is_array($ext_states)) { return $queue_stats; } foreach ($queue_members as $queue_member) { $queue_stats['members']['SIP/' . $queue_member]['devstate'] = extstate_to_devstate(@$ext_states[$queue_member]); } } /* echo "<pre>"; print_r($queue_stats); echo "</pre>"; */ return $queue_stats; }