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 InitRecordCall($filename, $index, $comment) { //FIXME $user = gs_user_get($_SESSION['sudo_user']['name']); $call = "Channel: SIP/" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: vm-rec-multiple\n" . "Extension: webdialrecord\n" . "Callerid: {$comment} <Aufnahme>\n" . "Setvar: __user_id=" . $_SESSION['sudo_user']['info']['id'] . "\n" . "Setvar: __user_name=" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user="******"\n" . "Setvar: __record_file=" . $filename . "\n"; $filename = '/tmp/gs-' . $_SESSION['sudo_user']['info']['id'] . '-' . _pack_int(time()) . rand(100, 999) . '.call'; $cf = @fOpen($filename, 'wb'); if (!$cf) { gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"'); echo 'Failed to write call file.'; die; } @fWrite($cf, $call, strLen($call)); @fClose($cf); @chmod($filename, 0666); $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename); if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $our_host_ids = @gs_get_listen_to_ids(); if (!is_array($our_host_ids)) { $our_host_ids = array(); } $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids); } else { $user_is_on_this_host = true; } if ($user_is_on_this_host) { # the Asterisk of this user and the web server both run on this host $err = 0; $out = array(); @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { @unlink($filename); gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . '/var/spool/asterisk/outgoing/' . baseName($filename) . '"'); echo 'Failed to move call file.'; die; } } else { $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); @unlink($filename); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']); echo 'Failed to scp call file.'; die; } //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo! $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile)); //echo $cmd, "\n"; @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); if ($err != 0) { gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"'); echo 'Failed to mv call file on remote host.'; die; } } }
function gs_asterisks_reload($host_ids, $dialplan_only) { $dialplan_only = !!$dialplan_only; if (!$host_ids || !is_array($host_ids)) { $host_ids = false; } # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } # get hosts # $hosts = @gs_hosts_get(); if (isGsError($hosts)) { return new GsError($hosts->getMsg()); } if (!is_array($hosts)) { return new GsError('Failed to get hosts.'); } $GS_INSTALLATION_TYPE_SINGLE = gs_get_conf('GS_INSTALLATION_TYPE_SINGLE'); if (!$GS_INSTALLATION_TYPE_SINGLE) { # get our host IDs # $our_host_ids = @gs_get_listen_to_ids(); if (isGsError($our_host_ids)) { return new GsError($our_host_ids->getMsg()); } if (!is_array($our_host_ids)) { return new GsError('Failed to get our host IDs.'); } } # are we root? do we have to sudo? # $uid = @posix_geteuid(); $uinfo = @posix_getPwUid($uid); $uname = @$uinfo['name']; $sudo = $uname == 'root' ? '' : 'sudo '; $ok = true; foreach ($hosts as $host) { if (!$host_ids || in_array($host['id'], $host_ids)) { $cmd = '/opt/gemeinschaft/sbin/start-asterisk' . ($dialplan_only ? ' --dialplan' : ''); if (!$GS_INSTALLATION_TYPE_SINGLE && !in_array($host['id'], $our_host_ids)) { # this is not the local node $cmd = $sudo . 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($host['host']) . ' ' . qsa($cmd); } @exec($sudo . $cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err); $ok = $ok && $err == 0; } } if (!$ok) { return new GsError('Failed to reload Asterisks.'); } return true; }
function gs_get_listen_to_ids($primary_only = false) { /* if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { # return special host ID return array(-1); } */ $GS_INSTALLATION_TYPE_SINGLE = gs_get_conf('GS_INSTALLATION_TYPE_SINGLE'); if (!$GS_INSTALLATION_TYPE_SINGLE) { # get our IPs # $ips = @gs_get_listen_to_ips($primary_only); if (!is_array($ips)) { # 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, "Failed to get our IP addresses"); return array(); } if (count($ips) < 1) { gs_log(GS_LOG_DEBUG, "We're not configured to listen to any IP addresses"); return array(); } } # connect to db # must be to slave db so we can tell our IDs even if the master is down # $db = gs_db_slave_connect(); if (!$db) { gs_log(GS_LOG_WARNING, "Failed to connect to the database!"); return array(); } if (!$GS_INSTALLATION_TYPE_SINGLE) { # find the corresponding IDs # $ips_escaped = array(); foreach ($ips as $ip) { $ips_escaped[] = '\'' . $db->escape($ip) . '\''; } // count($ips) guaranteed to be > 0 $query = 'SELECT `id` FROM `hosts` WHERE `host` IN (' . implode(',', $ips_escaped) . ')'; } else { $query = 'SELECT `id` FROM `hosts`'; } $rs = $db->execute($query); if (!$rs) { gs_log(GS_LOG_WARNING, "Database error!"); return array(); } $ids = array(); while ($r = $rs->fetchRow()) { $ids[] = (int) $r['id']; } return $ids; }
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() { $user_entered = strToLower(trim(@$_REQUEST['login_user'])); $pwd_entered = @$_REQUEST['login_pwd']; if ($user_entered == '' || $pwd_entered == '') { return false; } if ($user_entered === 'sysadmin' && in_array(gs_get_conf('GS_INSTALLATION_TYPE'), array('gpbx', 'single'), true)) { //FIXME //Quickhack: sysadmin only valid for /gemeinschaft/setup $pin = false; } else { $db = gs_db_slave_connect(); if (!$db) { return false; } $pin = $db->executeGetOne('SELECT `pin` FROM `users` WHERE `user`=\'' . $db->escape($user_entered) . '\''); } return $pin === $pwd_entered ? $user_entered : false; }
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; }
echo 'PHP >= 5 required.'; return; } require_once GS_DIR . 'inc/cn_hylafax.php'; include_once GS_DIR . 'inc/util.php'; include_once GS_DIR . 'inc/gs-fns/gs_user_pin_get.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"; $per_page = (int) gs_get_conf('GS_GUI_NUM_RESULTS'); $page = (int) @$_REQUEST['page']; $delete = trim(@$_REQUEST['delete']); if ($delete) { fax_kill_job($delete); } echo '<script type="text/javascript" src="', GS_URL_PATH, 'js/arrnav.js"></script>', "\n"; ?> <table cellspacing="1"> <thead> <tr> <?php $jobs_send = fax_get_jobs_send($_SESSION['sudo_user']['name'], gs_user_pin_get($_SESSION['sudo_user']['name'])); $recdate = array();
} @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();
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; }
} elseif ($key_idx >= 7) { # gxp2010 psetting('P' . (($key_idx - 7) * 4 + 353), subStr($key_def['function'], 1)); //psetting('P'.(($key_idx-7)*4+354), ''); //psetting('P'.(($key_idx-7)*4+355), ''); psetting('P' . (($key_idx - 7) * 4 + 356), $key_def['data']); } } } ##################################################################### # Override provisioning parameters (group profile) ##################################################################### $prov_params = null; $GS_ProvParams = gs_get_prov_params_obj($phone_type); if ($GS_ProvParams->set_user($user['user'])) { if ($GS_ProvParams->retrieve_params($phone_type, array('{GS_PROV_HOST}' => gs_get_conf('GS_PROV_HOST'), '{GS_P_PBX}' => $pbx, '{GS_P_EXTEN}' => $user_ext, '{GS_P_ROUTE_PREFIX}' => $hp_route_prefix, '{GS_P_USER}' => $user['user']))) { $prov_params = $GS_ProvParams->get_params(); } } if (!is_array($prov_params)) { gs_log(GS_LOG_WARNING, 'Failed to get provisioning parameters (group)'); } else { foreach ($prov_params as $param_name => $param_arr) { foreach ($param_arr as $param_index => $param_value) { if ($param_index == -1) { # not an array if (!array_key_exists($param_name, $settings)) { # don't set unknown parameters because the order is important gs_log(GS_LOG_NOTICE, "Group prov. param \"{$param_name}\": Unknown parameter"); continue; }
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_single($ext) { if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { 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; } $host = $db->executeGetOne('SELECT `h`.`host` FROM `ast_sipfriends` `s` JOIN `users` `u` ON (`u`.`id`=`s`.`_user_id`) JOIN `hosts` `h` ON (`h`.`id`=`u`.`host_id`) WHERE `s`.`name`=\'' . $db->escape($ext) . '\''); if (!$host) { # not a user return AST_MGR_EXT_UNKNOWN; } } else { $host = '127.0.0.1'; } return gs_extstate($host, $ext); }
function _snomCnfXmlEsc($str) { return str_replace(array('&', '<', '>', '"'), array('&', '<', '>', '\'\''), $str); } function _settings_err($msg = '') { @ob_start(); echo '<!-- // ', _snomCnfXmlEsc($msg != '' ? str_replace('--', '- -', $msg) : 'Error'), ' // -->', "\n"; if (!headers_sent()) { header('Content-Type: text/plain; charset=utf-8'); header('Content-Length: ' . (int) @ob_get_length()); } @ob_end_flush(); exit(1); } if (gs_get_conf('GS_SNOM_PROV_M9_ACCOUNTS') < 1) { gs_log(GS_LOG_DEBUG, "Snom M9 provisioning not enabled"); _settings_err('Not enabled.'); } $requester = gs_prov_check_trust_requester(); if (!$requester['allowed']) { _settings_err('No! See log for details.'); } $mac = preg_replace('/[^0-9A-F]/', '', strToUpper(@$_REQUEST['mac'])); if (strLen($mac) !== 12) { gs_log(GS_LOG_NOTICE, "Snom M9 provisioning: Invalid MAC address \"{$mac}\" (wrong length)"); # don't explain this to the users _settings_err('No! See log for details.'); } if (hexDec(subStr($mac, 0, 2)) % 2 == 1) { gs_log(GS_LOG_NOTICE, "Snom M9 provisioning: Invalid MAC address \"{$mac}\" (multicast address)");
function _err($msg = '') { aastra_textscreen('Error', $msg != '' ? $msg : 'Unknown error'); exit(1); } function _get_userid() { global $_SERVER, $db; $remote_addr = @$_SERVER['REMOTE_ADDR']; $user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `current_ip`=\'' . $db->escape($remote_addr) . '\''); if ($user_id < 1) { _err('Unknown user.'); } return $user_id; } if (!gs_get_conf('GS_AASTRA_PROV_ENABLED')) { gs_log(GS_LOG_NOTICE, 'Aastra provisioning not enabled'); _err('Not enabled.'); } $db = gs_db_master_connect(); $prov_url_aastra = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT ? ':' . GS_PROV_PORT : '') . GS_PROV_PATH . 'aastra/'; $ua = trim(@$_SERVER['HTTP_USER_AGENT']); if (preg_match('/\\sMAC:(00-08-5D-\\w{2}-\\w{2}-\\w{2})\\s/', $ua, $m)) { $mac = preg_replace('/[^0-9A-F]/', '', strToUpper($m[1])); } $user = trim(@$_REQUEST['u']); $user_id = _get_userid($user); $user_id_check = $db->executeGetOne("SELECT `user_id` FROM `phones` WHERE `mac_addr`='" . $db->escape($mac) . "'"); if ($user_id != $user_id_check) { _err("Not authorized"); }
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; }
/> <label for="ipt-callwaiting-0"><?php echo __('aus'); ?> </label> </td> <td> <small><?php echo __('Das Verhalten ist ggf. von Ihrem Endgerät abhängig.'); ?> </small> </td> </tr> <?php if (gs_get_conf('GS_USER_SELECT_CALLERID')) { echo "<tr>\n"; $numbers = gs_user_callerids_get($_SESSION['sudo_user']['name']); if (isGsError($numbers)) { echo $numbers->getMsg(); } $sel = " selected"; foreach ($numbers as $number) { if ($number['dest'] != 'external') { continue; } if ($number['selected'] == 1) { $sel = ""; } } echo "<td>", __('Angezeigte Rufnummer extern'), "</td>\n";
{ 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) . '\'');
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.') { continue; } $good_addrs[] = $addr; } unset($addrs); if (count($good_addrs) > 0) { $our_ip = $good_addrs[0]; } else { $our_ip = '0.0.0.0'; } } echo 'system_ip=', $our_ip, ';', "\n"; # not really useful for technical purposes. # more like a "system name" $connid_enabled = gs_get_conf('GS_DP_CONNID'); echo 'connid_enabled=', $connid_enabled ? '1' : '0', ';', "\n"; $call_recording_auto = gs_get_conf('GS_CALL_RECORDING_AUTO'); echo 'call_recording_auto=', $call_recording_auto ? '1' : '0', ';', "\n";
# (TSI = Transmitting Subscriber Identification) _gscnf('FAX_HYLAFAX_HOST', '127.0.0.1'); _gscnf('FAX_HYLAFAX_PORT', 4559); $FAX_HYLAFAX_ADMIN = preg_replace('/[^a-z0-9\\-_.]/i', '', @$FAX_HYLAFAX_ADMIN); _gscnf('FAX_HYLAFAX_ADMIN', ''); $FAX_HYLAFAX_PASS = preg_replace('/[^a-z0-9\\-_.]/i', '', @$FAX_HYLAFAX_PASS); _gscnf('FAX_HYLAFAX_PASS', ''); _gscnf('FAX_HYLAFAX_PATH', '/var/spool/hylafax/'); _gscnf('FAX_INIT_DOCDIR', '/tmp/'); _gscnf('FAX_NOAUTH_LOCALHOST', false); _gscnf('BOI_ENABLED', false); _gscnf('BOI_API_DEFAULT', 'm01'); _gscnf('BOI_BRANCH_NETMASK', '/24'); _gscnf('BOI_BRANCH_PBX', '0.0.0.130'); _gscnf('BOI_NOBODY_EXTEN_PATTERN', '95xxxx'); _gscnf('BOI_GUI_REVERSE_PROXY', 'http://' . gs_get_conf('GS_PROV_HOST') . ':8080/'); _gscnf('BOI_GUI_HOME_USER', 'information/praesenzmonitor'); _gscnf('BOI_GUI_HOME_ADMIN', 'information/status'); _gscnf('SBSERVER_HOSTS', '127.0.0.1'); _gscnf('SBSERVER_PORT', '18771'); _gscnf('LOG_TO', 'file'); _gscnf('LOG_FILE', '/var/log/gemeinschaft/gs.log'); _gscnf('LOG_GMT', true); _gscnf('LOG_SYSLOG_FACILITY', 'local5'); $LOG_LEVEL = strToUpper(@$LOG_LEVEL); if (!in_array($LOG_LEVEL, array('FATAL', 'WARNING', 'NOTICE', 'DEBUG'), true)) { $LOG_LEVEL = 'NOTICE'; } define('GS_LOG_LEVEL', constant('GS_LOG_' . $LOG_LEVEL)); if (function_exists('date_default_timezone_set')) { # PHP >= 5.1.0
<table cellspacing="1"> <tbody> <tr> <th style="width:150px;"></th> <th style="width:350px;"></th> </tr> <?php echo "<tr>\n"; echo '<th>', __('Senderkennung'), '</th>', "\n"; echo '<td>'; echo '<select name="tsi">', "\n"; if (gs_get_conf('GS_FAX_TSI_PREFIX')) { echo '<option value="', gs_get_conf('GS_FAX_TSI_PREFIX'), $_SESSION['sudo_user']['info']['ext'], '">', gs_get_conf('GS_FAX_TSI_PREFIX'), $_SESSION['sudo_user']['info']['ext'], '</option>', "\n"; } $fax_tsis_global = explode(',', gs_get_conf('GS_FAX_TSI')); foreach ($fax_tsis_global as $fax_tsi_global) { echo '<option value="', trim($fax_tsi_global), '">', trim($fax_tsi_global), '</option>', "\n"; } echo "</select>\n"; echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo '<th>', __('Faxnummer'), '</th>', "\n"; echo '<td>'; echo '<input name="faxnumber" type="text" value="' . $faxnumber . '" style="width:250px;" />'; echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo '<th>', __('Auflösung'), '</th>', "\n"; echo '<td>';
define('GS_VALID', true); /// this is a parent file require_once dirName(__FILE__) . '/../../../inc/conf.php'; include_once GS_DIR . 'inc/gettext.php'; require_once GS_DIR . 'inc/netmask.php'; require_once GS_DIR . 'inc/db_connect.php'; //set_error_handler('err_handler_die_on_err'); require_once GS_DIR . 'inc/string.php'; header('Pragma: no-cache'); header('Cache-Control: private, no-cache, must-revalidate'); header('Expires: 0'); header('Vary: *'); header('Content-Type: text/html; charset=utf-8'); $remote_ip = @$_SERVER['REMOTE_ADDR']; $allowed = false; $networks = explode(',', gs_get_conf('GS_MONITOR_FROM_NET')); foreach ($networks as $net) { if (ip_addr_in_network($remote_ip, trim($net))) { $allowed = true; break; } } if (!$allowed) { @header('HTTP/1.0 403 Forbidden', true, 403); @header('Status: 403 Forbidden', true, 403); @header('Content-Type: text/plain; charset=utf-8'); echo "Not allowed for {$remote_ip}.\nSee config.\n"; die; } ?>
$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'; } } # if no local file is specified check if ist's provided in http request # if ($local_file == '' && is_array($_FILES) && array_key_exists('file', $_FILES) && $_FILES['file']['error'] == 0 && $_FILES['file']['size'] > 0) { $local_file = $_FILES['file']['tmp_name']; } # invoke function from the fax library # if ($local_file != '') { $local_file = gs_get_conf('GS_FAX_INIT_DOCDIR', '') . '/' . preg_replace('/\\.\\./', '', $local_file); if (file_exists($local_file)) { $fax_job_id = fax_send($user_id, $user, $to, $tsi, $local_file, $email, $resolution, $pin); } } # result # if (isset($fax_job_id) && $fax_job_id >= 1) { die_ok('Fax job sent with id: ' . $fax_job_id); } else { die_error('Fax job not accepted'); }
`m`.`file`=\'' . $DB->escape($file) . '\''); $info = $rs->fetchRow(); if (!$info) { _not_found(); } $etag = gmDate('Ymd') . '-' . md5($user_id . '-' . $fld . '-' . $file . '-' . $info['host_id'] . '-' . $info['orig_time'] . '-' . $info['dur'] . '-' . $info['cidnum']) . '-' . $fmt; $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']); if (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag) { _not_modified($etag, $attach, $fake_filename); } if ($info['dur'] > 900) { # 900 s = 15 min gs_log(GS_LOG_NOTICE, 'Voicemail too long for web.'); _server_error('File too long.'); } if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) { $our_host_ids = @gs_get_listen_to_ids(); if (!is_array($our_host_ids)) { gs_log(GS_LOG_WARNING, 'Failed to get our host IDs.'); _server_error('Failed to get our host IDs.'); } $vmmsg_is_on_this_host = in_array($info['host_id'], $our_host_ids, true); } else { $vmmsg_is_on_this_host = true; } $vm_dir = '/var/spool/asterisk/voicemail/'; $origorigfile = $vm_dir . 'default/' . $ext . '/' . $fld . '/' . $file . '.alaw'; $tmpfile_base = '/tmp/gs-vm-' . preg_replace('/[^0-9]/', '', $ext) . '-' . $fld . '-' . $file; # delete files like /tmp/gs-vm-* with mtime < time()-10 minutes # @exec('find \'/tmp/\' -maxdepth 1 -name \'gs-vm-*\' -type f -mmin +10 | xargs rm -f 1>>/dev/null 2>>/dev/null');
function gs_host_add($host_ip_or_name, $comment, $foreign = false, $group_id = null, $boi_prefix = '', $sip_proxy_from_wan = null, $sip_sbc_from_wan = null) { if (!$host_ip_or_name) { return new GsError('Invalid host.'); } $host = normalizeIPs($host_ip_or_name); if (!preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $host)) { # not an IP address. => resolve hostname $addresses = @gethostbynamel($host); if (count($addresses) < 1) { return new GsError('Could not resolve hostname: ' . $host); } elseif (count($addresses) > 1) { return new GsError('Hostname ' . $host . ' cannot be used because it\'s resolved to more than one IP addr.'); } elseif (count($addresses) == 1) { if (strlen($addresses[0]) == 0) { return new GsError('Could not resolve hostname: ' . $host); } $host = $addresses[0]; } } else { $host = $host_ip_or_name; } $group_id = (int) $group_id; if ($group_id < 1) { $group_id = null; } if (!$foreign) { if ($boi_prefix != '') { return new GsError('Route prefix not allowed for non-foreign hosts.'); } } else { if ($boi_prefix != '' && !preg_match('/^[1-9][0-9]*$/', $boi_prefix)) { return new GsError('Route prefix must be numeric.'); } } if ($sip_proxy_from_wan != '' && !preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $sip_proxy_from_wan)) { return new GsError('Invalid IP address of SIP proxy from WAN.'); } if ($sip_sbc_from_wan != '' && !preg_match('/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/', $sip_sbc_from_wan)) { return new GsError('Invalid IP address of SIP SBC from WAN.'); } if ($foreign) { $api = gs_get_conf('GS_BOI_API_DEFAULT'); } else { $api = ''; } # connect to db # $db = gs_db_master_connect(); if (!$db) { return new GsError('Could not connect to database.'); } $db->execute('OPTIMIZE TABLE `hosts`'); # recalculate next auto-increment value $db->execute('ANALYZE TABLE `hosts`'); $sql_query = 'INSERT INTO `hosts` ( `id`, `host`, `comment`, `is_foreign`, `group_id` ) VALUES ( NULL, \'' . $db->escape($host) . '\', \'' . $db->escape($comment) . '\', ' . ($foreign ? 1 : 0) . ', ' . (int) $group_id . ' )'; $ok = $db->execute($sql_query); if (!$ok) { return new GsError('Failed to add host ' . $host); } $host_id = (int) $db->getLastInsertId(); if ($host_id < 1) { return new GsError('Failed to add host ' . $host); } $db->execute('REPLACE INTO `host_params` (`host_id`, `param`, `value`) VALUES (' . $host_id . ', \'api\', \'' . $db->escape($api) . '\')'); if ($sip_proxy_from_wan != '') { $db->execute('REPLACE INTO `host_params` (`host_id`, `param`, `value`) VALUES (' . $host_id . ', \'sip_proxy_from_wan\', \'' . $db->escape($sip_proxy_from_wan) . '\')'); } if ($sip_sbc_from_wan != '') { $db->execute('REPLACE INTO `host_params` (`host_id`, `param`, `value`) VALUES (' . $host_id . ', \'sip_server_from_wan\', \'' . $db->escape($sip_sbc_from_wan) . '\')'); } if ($foreign) { $db->execute('REPLACE INTO `host_params` (`host_id`, `param`, `value`) VALUES (' . $host_id . ', \'route_prefix\', \'' . $db->escape($boi_prefix) . '\')'); } return true; }
echo '<input type="text" name="extnum" value="" size="20" maxlength="40" />'; echo "</td>\n"; echo "<td>\n"; /* echo '<button type="submit" title="', __('Speichern') ,'" class="plain">', "\n"; echo '<img alt="', __('Speichern') ,'" src="', GS_URL_PATH ,'crystal-svg/16/act/filesave.png" />', "\n"; echo "</button>\n"; */ echo "</td>\n"; echo "</tr>\n"; ?> </tbody> </table> <?php if (gs_get_conf('GS_BOI_ENABLED')) { ?> <br /> <table cellspacing="1"> <thead> <tr> <th style="width:180px;"> <?php echo __('Lokale Admin-Rechte'); ?> </th> <th style="width:217px;" colspan="2"> <?php echo __('Anlage'); ?>
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; }
} $type = trim(@$_REQUEST['t']); if (!in_array($type, array('gs', 'prv', 'imported', 'gss', 'prvs', 'importeds'), true)) { $type = false; } $page = (int) trim(@$_REQUEST['p']); $entry = (int) trim(@$_REQUEST['e']); $search = trim(@$_REQUEST['s']); $name_search = trim(@$_REQUEST['n']); //$per_page = (int)gs_get_conf('GS_AASTRA_PROV_PB_NUM_RESULTS', 10); $per_page = 4; $db = gs_db_slave_connect(); $tmp = array(15 => array('k' => 'gs', 'v' => gs_get_conf('GS_PB_INTERNAL_TITLE', __("Intern"))), 25 => array('k' => 'prv', 'v' => gs_get_conf('GS_PB_PRIVATE_TITLE', __("Persönlich")))); if (gs_get_conf('GS_PB_IMPORTED_ENABLED')) { $pos = (int) gs_get_conf('GS_PB_IMPORTED_ORDER', 9) * 10; $tmp[$pos] = array('k' => 'imported', 'v' => gs_get_conf('GS_PB_IMPORTED_TITLE', __("Extern"))); } kSort($tmp); foreach ($tmp as $arr) { $typeToTitle[$arr['k']] = $arr['v']; } $url_aastra_pb = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT ? ':' . GS_PROV_PORT : '') . GS_PROV_PATH . 'aastra/pb.php'; #################################### SEARCH SCREEN { if ($search) { $xml = '<AastraIPPhoneInputScreen type = "string">' . "\n"; $xml .= '<Title>' . __('Suchen') . '</Title>' . "\n"; $xml .= '<Prompt>' . __('Name') . ':</Prompt>' . "\n"; $xml .= '<URL>' . $url_aastra_pb . '?t=' . $type . '</URL>' . "\n"; $xml .= '<Parameter>n</Parameter>' . "\n"; $xml .= '<Default></Default>' . "\n"; $xml .= '<SoftKey index="1">' . "\n";
if (!gs_get_conf('GS_POLYCOM_PROV_ENABLED')) { gs_log(GS_LOG_DEBUG, 'Polycom provisioning not enabled'); _err('Not enabled.'); } $type = trim(@$_REQUEST['t']); if (!in_array($type, array('internal', 'external', 'std', 'var', 'timeout'), 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(15 => array('k' => 'internal', 'v' => gs_get_conf('GS_CLIR_INTERNAL', __('von intern'))), 25 => array('k' => 'external', 'v' => gs_get_conf('GS_CLIR_EXTERNAL', __('von extern')))); ksort($tmp); foreach ($tmp as $arr) { $typeToTitle[$arr['k']] = $arr['v']; } $url_polycom_provdir = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT ? ':' . GS_PROV_PORT : '') . GS_PROV_PATH . 'polycom/'; $url_polycom_callforward = $url_polycom_provdir . 'callforward.php'; $url_polycom_menu = $url_polycom_provdir . 'configmenu.php'; $cases = array('always' => __('immer'), 'busy' => __('besetzt'), 'unavail' => __('keine Antw.'), 'offline' => __('offline')); $actives = array('no' => __('Aus'), 'std' => __('Std.'), 'var' => __('Tmp.')); ################################## SET FEATURE { if ($type != false && isset($_REQUEST['value'])) { $value = trim(@$_REQUEST['value']); $user_name = $db->executeGetOne('SELECT `user` FROM `users` WHERE `id`=\'' . $db->escape($user_id) . '\''); $timeout = (int) $db->executeGetOne('SELECT `timeout` FROM `callforwards` WHERE `user_id`=\'' . $user_id . '\' AND `case`=\'unavail\' AND `source`=\'internal\''); $num['std'] = $db->executeGetOne('SELECT `number_std` FROM `callforwards` WHERE `user_id`=\'' . $user_id . '\' AND `case`=\'unavail\' AND `source`=\'internal\'');