Beispiel #1
0
function gs_host_del($host, $force = FALSE)
{
    if (!preg_match('/^[0-9\\.]+$/', $host)) {
        return new GsError('Host must be a numeric ID or IP address.');
    }
    $host = gs_host_by_id_or_ip($host);
    if (isGsError($host)) {
        return new GsError($host->getMsg());
    }
    if (!is_array($host)) {
        return new GsError('Cannot retrieve host ID.');
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    $count_users = $db->executeGetOne('SELECT COUNT(`id`) FROM `users` WHERE `host_id`=\'' . $db->escape($host['id']) . '\'');
    if ($count_users > 0) {
        return new GsError('Cannot delete host. Delete ' . $count_users . ' user(s) on this host first.');
    }
    #delete host from all groups
    #
    gs_group_members_purge_by_type('host', array($host['id']));
    # delete host
    #
    $rs = $db->execute('DELETE from `hosts` WHERE `id`=\'' . $db->escape($host['id']) . '\'');
    if (!$rs) {
        return new GsError('Could not delete host ' . $host['id']);
    }
    return true;
}
Beispiel #2
0
 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 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_prov_group_del($id)
{
    $id = (int) $id;
    if ($id < 1) {
        return new GsError('Invalid group ID.');
    }
    $DB = gs_db_master_connect();
    if (!$DB) {
        return new GsError('Could not connect to database.');
    }
    $mptt = new YADB_MPTT($DB, 'user_groups', 'lft', 'rgt', 'id');
    if (GS_BUTTONDAEMON_USE == false) {
        return $mptt->delete($id, true);
    } else {
        $ret = $mptt->delete($id, true);
        if (!isGsError($ret) && $ret) {
            gs_usergroup_remove_ui($id);
        }
        return $ret;
    }
}
Beispiel #5
0
function gs_ivr_target($typ, $value)
{
    $cmd = '';
    if ($typ == 'announce') {
        $announce_file = gs_sysrec_hash_get($value);
        if (!isGsError($announce_file)) {
            $cmd = 'Background(/opt/gemeinschaft/sys-rec/' . $announce_file . ');';
        }
    } else {
        if ($typ == 'extension') {
            if ($value != '0' && strlen($value) > 0) {
                $cmd = 'goto to-internal-users|' . $value . '|1;';
            }
        } else {
            if ($typ == 'repeat') {
                $cmd = 'jump loop;';
            } else {
                $cmd = 'jump h;';
            }
        }
    }
    return $cmd;
}
function gs_asterisks_prune_peer($peer, $host_ids = false)
{
    if (!$host_ids || !is_array($host_ids)) {
        $host_ids = false;
    }
    # check peer
    if ($peer === 'all' || $peer == '') {
        $peer = 'all';
    } elseif (!preg_match('/^[1-9][0-9]{1,9}$/', $peer)) {
        return new GsError('Invalid peer name.');
    }
    # 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 = 'asterisk -rx \'sip prune realtime ' . $peer . '\' ';
            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 prune peer "' . $peer . '".');
    }
    return true;
}
Beispiel #7
0
function gs_ldap_get_first($ldap_conn, $base, $filter = '', $props = array())
{
    $list = gs_ldap_get_list($ldap_conn, $base, $filter, $props, 1);
    if (isGsError($list)) {
        return new GsError($list->getMsg());
    }
    if (!is_array($list)) {
        return new GsError('Failed to get LDAP entries.');
    }
    return reset($list);
}
Beispiel #8
0
			# delete unnecessary (inherited) entries
			$DB->execute(
				'DELETE FROM `softkeys` '.
				'WHERE '.
					'`phone_type`=\''. $DB->escape($phone_type) .'\' AND '.
					'`function`=\'\'' );
		}
		unset($save_keys);
		if (! $ok) {
			echo '<div class="errorbox">', __('Fehler beim Speichern') ,'</div>' ,"\n";
		}
	}
	
	if ($action === 'save-and-resync') {
		$ret = gs_prov_phone_checkcfg_by_user( @$_SESSION['sudo_user']['name'], false );
		if (isGsError($ret) || ! $ret) {
			// does not happen
			echo '<div class="errorbox">', __('Fehler beim Aktualisieren des Telefons') ,'</div>' ,"\n";
		}
	}
	
	$action = '';  # view
}
#####################################################################
# save }
#####################################################################

#####################################################################
# delete {
#####################################################################
if ($action === 'delete') {
Beispiel #9
0
function gs_group_members_get_names($group, $includes = true)
{
    $members = gs_group_members_get(array($group), $includes);
    if (isGsError($members)) {
        gs_script_error($members->getMsg());
    }
    if (!$members) {
        return array();
    }
    $db_slave = gs_db_slave_connect();
    if (!$db_slave) {
        return new GsError('Could not connect to database.');
    }
    if (!$members) {
        return array();
    }
    $type = $db_slave->executeGetOne('SELECT `type` FROM `groups` WHERE `id` = ' . $group . ' LIMIT 1');
    switch ($type) {
        case 'user':
            $sql_query = 'SELECT `user` AS `member` FROM `users` WHERE `id` IN (' . implode(',', $members) . ')';
            break;
        case 'queue':
            $sql_query = 'SELECT `name` AS `member` FROM `ast_queues` WHERE `_id` IN (' . implode(',', $members) . ')';
            break;
        case 'host':
            $sql_query = 'SELECT `host` AS `member` FROM `hosts` WHERE `id` IN (' . implode(',', $members) . ')';
            break;
        default:
            $sql_query = false;
            break;
    }
    $members_a = array();
    if ($sql_query === false) {
        foreach ($members as $member) {
            $r = array();
            $r['type'] = $type;
            $r['member'] = $member;
            $members_a[] = $r;
        }
    } else {
        $rs = $db_slave->execute($sql_query);
        if ($rs) {
            while ($r = $rs->fetchRow()) {
                $r['type'] = $type;
                $members_a[] = $r;
            }
        }
    }
    return $members_a;
}
Beispiel #10
0
    gs_log(GS_LOG_DEBUG, $errmsg ? $errmsg : 'LDAP lookup: User not found');
    exit(1);
}
if (!is_array($_SESSION) || !@array_key_exists('sudo_user', @$_SESSION) || !@array_key_exists('info', @$_SESSION['sudo_user']) || !@array_key_exists('id', @$_SESSION['sudo_user']['info'])) {
    _not_allowed();
}
if ($_SESSION['real_user']['name'] !== 'sysadmin' && !gs_user_is_admin(@$_SESSION['real_user']['name'])) {
    _not_allowed();
}
if (!array_key_exists('u', $_REQUEST)) {
    _not_found('Username not specified.');
}
$user = $_REQUEST['u'];
include_once GS_DIR . 'inc/gs-fns/gs_ldap_user_search.php';
$user_info = gs_ldap_user_search($user);
if (isGsError($user_info)) {
    _server_error($user_info->getMsg());
}
if (!is_array($user_info)) {
    _server_error('Failed to look up user "' . $user . '" in LDAP.');
}
require_once GS_DIR . 'lib/utf8-normalize/gs_utf_normal.php';
@header('Content-Type: application/json');
# RFC 4627
ob_start();
echo "{\n";
$i = 0;
foreach ($user_info as $k => $v) {
    if ($i > 0) {
        echo ",\n";
    }
function gs_user_external_number_add($user, $number)
{
    if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) {
        return new GsError('User must be alphanumeric.');
    }
    if (!preg_match('/^[\\d]+$/', $number)) {
        return new GsError('Number must be numeric.');
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # get user_id
    #
    $user_id = $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\'');
    if ($user_id < 1) {
        return new GsError('Unknown user.');
    }
    # add number
    #
    switch (GS_EXTERNAL_NUMBERS_BACKEND) {
        case 'ldap':
            $ldap = gs_ldap_connect();
            if (!$ldap) {
                return new GsError('Could not connect to LDAP server.');
            }
            # find ldap user name
            #
            if (GS_LDAP_PROP_UID === GS_LDAP_PROP_USER) {
                $ldap_uid = $user;
                if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) {
                    $user = preg_replace('/^0+/', '', $user);
                    # if the usernames in your LDAP are integers without
                    # a leading "0"
                }
            } else {
                if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) {
                    $user = preg_replace('/^0+/', '', $user);
                    # if the usernames in your LDAP are integers without
                    # a leading "0"
                }
                $userArr = gs_ldap_get_first($ldap, GS_LDAP_SEARCHBASE, GS_LDAP_PROP_USER . '=' . $user, array(GS_LDAP_PROP_UID));
                if (isGsError($userArr)) {
                    return new GsError($userArr->getMsg());
                }
                if (!is_array($userArr)) {
                    return new GsError('Could not find user by "' . GS_LDAP_PROP_USER . '=' . $user . '" in search base "' . GS_LDAP_SEARCHBASE . '" in LDAP.');
                }
                $ldap_uid = @$userArr[strToLower(GS_LDAP_PROP_UID)][0];
                if (strLen($ldap_uid) < 1) {
                    return new GsError('Could not find user by "' . GS_LDAP_PROP_USER . '=' . $user . '" in search base "' . GS_LDAP_SEARCHBASE . '" in LDAP.');
                }
            }
            $dn = GS_LDAP_PROP_UID . '=' . $ldap_uid . ',' . GS_LDAP_SEARCHBASE;
            $ok = @ldap_mod_add($ldap, $dn, array(GS_EXTERNAL_NUMBERS_LDAP_PROP => $number));
            if (!$ok && @ldap_errNo($ldap) != 20) {
                // err #20 is: "Type or value exists"
                return new GsError('Failed to add number to LDAP user "' . $dn . '". - ' . gs_get_ldap_error($ldap));
                return false;
            }
            break;
        case 'db':
        default:
            $ok = $db->execute('REPLACE INTO `users_external_numbers` (`user_id`, `number`) VALUES (' . $user_id . ', \'' . $db->escape($number) . '\')');
            if (!$ok) {
                return new GsError('Failed to add external number.');
            }
            break;
    }
    return true;
}
Beispiel #12
0
function _gui_monitor_which_peers_lvm($sudo_user)
{
    $kks = @_get_kostenstellen_lvm($sudo_user);
    if ($kks === false || !is_array($kks)) {
        return false;
    }
    $kostenstelle_prop = 'lvmkostenstelle';
    $limit = 100;
    $filter = '';
    foreach ($kks as $ks) {
        $filter .= '(' . $kostenstelle_prop . '=' . subStr($ks, 0, 2) . '*)';
    }
    $filter = '(|' . $filter . ')';
    //echo $filter, "<br />\n";
    $ldap = gs_ldap_connect();
    $matches = gs_ldap_get_list($ldap, GS_LDAP_SEARCHBASE, $filter, array(GS_LDAP_PROP_USER), (int) $limit);
    if (isGsError($matches)) {
        return false;
    }
    if (!is_array($matches)) {
        return false;
    }
    /*
    echo "<pre>";
    print_r($matches);
    echo "</pre>";
    */
    $lc_GS_LDAP_PROP_USER = strToLower(GS_LDAP_PROP_USER);
    $peers = array();
    foreach ($matches as $match) {
        if (!is_array($match[$lc_GS_LDAP_PROP_USER])) {
            continue;
        }
        foreach ($match[$lc_GS_LDAP_PROP_USER] as $mm) {
            //if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) {
            // this check is not really needed as this is a custom function anyway
            $mm = str_pad($mm, 6, '0', STR_PAD_LEFT);
            # without leading "0" in their LDAP database
            //}
            $peers[] = $mm;
        }
    }
    /*
    echo "<pre>";
    print_r($peers);
    echo "</pre>";
    */
    return $peers;
}
Beispiel #13
0
 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']);
                 }
             }
         }
     }
     /*
     # get the pickup groups
     #
     $pgroups = array();
     $rs = $this->_db->execute(
     	'SELECT DISTINCT(`p`.`id`) `id`, `p`.`title` '.
     	'FROM '.
     		'`pickupgroups_users` `pu` JOIN '.
     		'`pickupgroups` `p` ON (`p`.`id`=`pu`.`group_id`) '.
     	'WHERE `pu`.`user_id`='. ((int)$this->_user_id) .' '.
     	'ORDER BY `p`.`id` '.
     	'LIMIT 10' );
     while ($r = $rs->fetchRow()) {
     	$pgroups[$r['id']] = $r['title'];
     }
     */
     # fix some key definitions
     #
     /*
     foreach ($this->_keys as $key_name => $key_defs) {
     foreach ($key_defs as $inh_slf => $key_def) {
     	
     	# make sure the user does not set keys for pickup groups
     	# which he/she does not belong to
     	#
     	if (in_array($key_def['function'], array('dest', 'blf'), true)     //FIXME for Siemens
     	&&  subStr($key_def['data'],0,2) === '*8') {
     		if (preg_match('/(?:^|[:])\*8\*([0-9]+)/S', $key_def['data'], $m)) {
     			$pgrpid = (int)lTrim($m[1],'0');
     		} else {
     			$pgrpid = 0;
     		}
     		if ($pgrpid > 0) {
     			if (! array_key_exists($pgrpid, $pgroups))
     				$pgrpid = 0;
     		}
     		if ($pgrpid < 1) {
     			unset($this->_keys[$key_name][$inh_slf]);
     		} else {
     			$this->_keys[$key_name][$inh_slf]['data' ] =
     				'*8*'. str_pad($pgrpid,5,'0',STR_PAD_LEFT);
     			$title = mb_subStr(trim($pgroups[$pgrpid]),0,20);
     			$this->_keys[$key_name][$inh_slf]['label'] =
     				'Grp. '. ($title != '' ? $title : $pgrpid);
     			unset($pgroups[$pgrpid]);
     		}
     	}
     }
     }
     */
     //FIXME
     # find free keys for the remaining pickup groups (if any)
     #
     //FIXME ?
     return true;
 }
Beispiel #14
0
			<img alt=" " src="<?php 
    echo GS_URL_PATH, 'crystal-svg/16/app/yast_route.png';
    ?>
" />&nbsp;
			<a href="<?php 
    echo gs_url('forwards', 'forwards');
    ?>
"><?php 
    echo __('Rufumleitung');
    ?>
</a>
		</div>
		<div class="td" style="padding:0.0em;">
			<?php 
    $callforwards = gs_callforward_get($_SESSION['sudo_user']['name']);
    if (isGsError($callforwards)) {
        echo $callforwards->getMsg();
    } else {
        /*
        echo "<pre>\n";
        print_r($callforwards);
        echo "</pre>\n";
        */
        $actives = array();
        $internal_always = false;
        $external_always = false;
        foreach ($callforwards as $src => $cfs) {
            foreach ($cfs as $case => $cf) {
                if ($cf['active'] == 'no' || $cf['active'] == '') {
                    continue;
                }
</td>
	<td>
		<input type="text" name="num-var" id="ipt-num-var"<?php 
echo $disabled;
?>
 value="<?php 
echo htmlEnt($number_var);
?>
" size="25" style="width:200px;" maxlength="25" />
		<div id="ext-num-select-var" style="display:none;">
		&larr;<select name="_ignore-2" id="sel-num-var" onchange="gs_num_sel(this);"<?php 
echo $disabled;
?>
>
<?php 
if (!isGsError($e_numbers) && is_array($e_numbers)) {
    echo '<option value="">', __('einf&uuml;gen &hellip;'), '</option>', "\n";
    foreach ($e_numbers as $e_number) {
        //echo '<option value="', htmlEnt($e_number) ,'">', htmlEnt($e_number) ,'</option>' ,"\n";
        echo '<option value="0', htmlEnt($e_number), '">0', htmlEnt($e_number), '</option>', "\n";
    }
}
?>
		</select>
		</div>
	</td>
</tr>
</tbody>
</table>

<script type="text/javascript">
Beispiel #16
0
function gs_queue_add($name, $title, $maxlen, $host_id_or_ip)
{
    if (!preg_match('/^[\\d]+$/', $name)) {
        return new GsError('Queue extension must be numeric.');
    }
    if (!preg_match('/^[1-9][0-9]{1,5}$/', $name)) {
        return new GsError('Please use 2-5 digit extension.');
    }
    $title = trim($title);
    $maxlen = (int) $maxlen;
    if ($maxlen < 0) {
        return new GsError('Maxlen must be 0 or more.');
    }
    if ($maxlen > 255) {
        return new GsError('Maxlen must be 255 or less.');
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # check if queue exists
    #
    $num = (int) $db->executeGetOne('SELECT COUNT(*) FROM `ast_queues` WHERE `name`=\'' . $db->escape($name) . '\'');
    if ($num > 0) {
        return new GsError('A queue with that extension already exists.');
    }
    # check if SIP user with same name exists
    #
    $num = (int) $db->executeGetOne('SELECT COUNT(*) FROM `ast_sipfriends` WHERE `name`=\'' . $db->escape($name) . '\'');
    if ($num > 0) {
        return new GsError('A SIP user with that extension already exists.');
    }
    # check if host exists
    #
    $host = gs_host_by_id_or_ip($host_id_or_ip);
    if (isGsError($host)) {
        return new GsError($host->getMsg());
    }
    if (!is_array($host)) {
        return new GsError('Unknown host.');
    }
    # add queue
    #
    $ok = $db->execute('INSERT INTO `ast_queues` (
	`_id`,
	`name`,
	`_host_id`,
	`_title`,
	`musicclass`,
	`timeout`,
	`autopause`,
	`setinterfacevar`,
	`periodic_announce_frequency`,
	`announce_frequency`,
	`announce_holdtime`,
	`retry`,
	`maxlen`,
	`strategy`,
	`joinempty`,
	`leavewhenempty`,
	`ringinuse`,
	`early_media`
) VALUES (
	NULL,
	\'' . $db->escape($name) . '\',
	' . (int) $host['id'] . ',
	\'' . $db->escape($title) . '\',
	\'default\',
	15,
	\'no\',
	\'yes\',
	60,
	90,
	\'yes\',
	3,
	' . $maxlen . ',
	\'rrmemory\',
	\'strict\',
	\'yes\',
	\'no\',
	\'' . $db->escape($early_media) . '\'
)');
    if (!$ok) {
        return new GsError('Failed to add queue.');
    }
    return true;
}
            echo '<a href="', gs_url($SECTION, $MODULE, null, 'page=' . ($page + 1)), '" title="', __('weiterbl&auml;ttern'), '" id="arr-next">', '<img alt="', __('weiter'), '" src="', GS_URL_PATH, 'crystal-svg/16/act/next.png" />', '</a>', "\n";
        } else {
            echo '<img alt="', __('weiter'), '" src="', GS_URL_PATH, 'crystal-svg/16/act/next_notavail.png" />', "\n";
        }
        ?>
	</th>
</tr>
</thead>
<tbody>

<?php 
        foreach ($groups as $key => $group) {
            $sort_key[$key] = $group['name'];
        }
        array_multisort($sort_key, SORT_ASC, SORT_STRING, $groups);
        if (isGsError($groups)) {
            echo '<tr><td colspan="5">', $groups->getMsg(), '</td></tr>';
        } else {
            $i = 1;
            foreach ($groups as $group) {
                if ($i > $per_page * ($page + 1) || $i < $per_page * $page + 1) {
                    $i++;
                    continue;
                }
                $groups_same_type = gs_group_info_get(false, $group['type']);
                $group_includes_ids = gs_group_includes_get(array($group['id']), true, true);
                $group_includes = gs_group_info_get(array_diff($group_includes_ids, array($group['id'])));
                echo '<tr class="', $i % 2 === 0 ? 'odd' : 'even', '">', "\n";
                echo '<td class="l nobr">';
                echo $group['name'], '</td>', "\n";
                echo '<td>', $group['title'], '</td>', "\n";
        }
        if (isGsError($ok)) {
            $errMsgs[] = $ok->getMsg();
        } elseif (!$ok) {
            $errMsgs[] = __('Fehler beim Setzen des eigenen Klingeltons.');
        }
    }
    if ($action === 'save-and-resync') {
        $ret = gs_prov_phone_checkcfg_by_user(@$_SESSION['sudo_user']['name'], false);
        if (isGsError($ret) || !$ret) {
            $errMsgs[] = __('Fehler beim Aktualisieren des Telefons');
        }
    }
}
$ringtones = gs_ringtones_get($_SESSION['sudo_user']['name']);
if (isGsError($ringtones)) {
    echo __('Fehler beim Abfragen.'), '<br />', $ringtones->getMsg();
    die;
}
//$cur_phone_type = $DB->executeGetOne( 'SELECT `type` FROM `phones` WHERE `user_id`='. (int)@$_SESSION['sudo_user']['info']['id'] );
?>

<div style="max-width:600px;">
	<img alt=" " src="<?php 
echo GS_URL_PATH;
?>
crystal-svg/16/act/info.png" class="fl" />
	<p style="margin-left:22px;">
		<?php 
echo __('Bitte beachten Sie, da&szlig; die unterst&uuml;tzten Klingelt&ouml;ne stark von dem Endger&auml;t abh&auml;ngig sind, auf dem Sie sich anmelden. Ggf. wird also ein anderer als der hier eingestellte Klingelton gespielt.');
?>
Beispiel #19
0
function gs_user_rename($username, $new_username)
{
    if (!preg_match('/^[a-z0-9\\-_.]+$/', $username)) {
        return new GsError('Username must be alphanumeric.');
    }
    $ret = gs_user_is_valid_name($new_username);
    if (isGsError($ret)) {
        return $ret;
    } elseif (!$ret) {
        return new GsError('Invalid new username.');
    }
    if ($new_username === $username) {
        //return new GsError( 'New username = old username.' );
        return true;
    }
    # 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($username) . '\'');
    if (!$user_id) {
        gs_db_rollback_trans($db);
        return new GsError("Unknown user \"{$username}\".");
    }
    # check if new username exists
    #
    $user_id_new_test = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($new_username) . '\'');
    if ($user_id_new_test) {
        gs_db_rollback_trans($db);
        return new GsError("A user with username \"{$new_username}\" already exists.");
    }
    # get host
    #
    $host_id = (int) $db->executeGetOne('SELECT `host_id` FROM `users` WHERE `id`=' . $user_id);
    $host = gs_host_by_id_or_ip($host_id);
    if (isGsError($host) || !is_array($host)) {
        gs_db_rollback_trans($db);
        return new GsError('Host not found.');
    }
    # get info needed for foreign users
    #
    if ($host['is_foreign']) {
        # get user's extension 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'];
        # get user info
        $rs = $db->execute('SELECT `pin`, `firstname`, `lastname`, `email` FROM `users` WHERE `id`=' . $user_id);
        if (!$rs || !($user_info = $rs->fetchRow())) {
            gs_db_rollback_trans($db);
            return new GsError('DB error.');
        }
    } else {
        $ext = null;
    }
    # update user
    #
    $ok = $db->execute('UPDATE `users` SET `user`=\'' . $db->escape($new_username) . '\' WHERE `id`=' . $user_id);
    if (!$ok) {
        @$db->execute('UPDATE `users` SET `user`=\'' . $db->escape($username) . '\' WHERE `id`=' . $user_id);
        gs_db_rollback_trans($db);
        return new GsError('Failed to rename user.');
    }
    # rename user on foreign host
    #
    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 (!extension_loaded('soap')) {
                    @$db->execute('UPDATE `users` SET `user`=\'' . $db->escape($username) . '\' WHERE `id`=' . $user_id);
                    gs_db_rollback_trans($db);
                    return new GsError('Failed to rename 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, $new_username, $sip_pwd, $user_info['pin'], $user_info['firstname'], $user_info['lastname'], $user_info['email'], $soap_faultcode);
                    if (!$ok) {
                        @$db->execute('UPDATE `users` SET `user`=\'' . $db->escape($username) . '\' WHERE `id`=' . $user_id);
                        gs_db_rollback_trans($db);
                        return new GsError('Failed to rename user on foreign host (SOAP error).');
                    }
                }
                break;
            case '':
                # host does not provide any API
                gs_log(GS_LOG_NOTICE, 'Renaming user on foreign host ' . $host['host'] . ' without any API');
                break;
            default:
                gs_log(GS_LOG_WARNING, 'Failed to rename user on foreign host ' . $host['host'] . ' - invalid API "' . $api . '"');
                @$db->execute('UPDATE `users` SET `user`=\'' . $db->escape($username) . '\' WHERE `id`=' . $user_id);
                gs_db_rollback_trans($db);
                return new GsError('Failed to rename user on foreign host (Invalid API).');
        }
    }
    # commit transaction
    #
    if (!gs_db_commit_trans($db)) {
        @$db->execute('UPDATE `users` SET `user`=\'' . $db->escape($username) . '\' WHERE `id`=' . $user_id);
        return new GsError('Failed to rename user.');
    }
    # reboot the phone
    #
    if ($ext === null) {
        # get user's extension
        $ext = $db->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=' . $user_id);
    }
    @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;
}
Beispiel #20
0
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', __("Importiert")));
}
kSort($tmp);
foreach ($tmp as $arr) {
    $typeToTitle[$arr['k']] = $arr['v'];
}
$url_snom_extnumbers = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT == 80 ? '' : ':' . GS_PROV_PORT) . GS_PROV_PATH . 'snom/extnumbers.php';
$url_snom_menu = GS_PROV_SCHEME . '://' . GS_PROV_HOST . (GS_PROV_PORT ? ':' . GS_PROV_PORT : '') . GS_PROV_PATH . 'snom/menu.php';
#################################### INITIAL SCREEN {
if (!$type) {
    $mac = preg_replace('/[^\\dA-Z]/', '', strToUpper(trim(@$_REQUEST['m'])));
    $user_name = $db->executeGetOne('SELECT `user` FROM `users` WHERE `id`=\'' . $db->escape($user_id) . '\'');
    $enumbers = gs_user_external_numbers_get($user_name);
    if (isGsError($enumbers)) {
        _err('Fehler beim Abfragen.');
    }
    ob_start();
    echo '<?', 'xml version="1.0" encoding="utf-8"?', '>', "\n", '<SnomIPPhoneMenu>', "\n", '<Title>' . __("externe Nummern") . '</Title>', "\n\n";
    foreach ($enumbers as $extnumber) {
        echo '<MenuItem>', "\n", '<Name>', snom_xml_esc($extnumber), '</Name>', "\n", '<URL>', $url_snom_menu, '?t=forward&m=', $mac, '&u=', $user, '</URL>', "\n", '</MenuItem>', "\n\n";
        # in XML the & must normally be encoded as &amp; but not for
        # the stupid Snom!
    }
    defineBackMenu();
    echo '</SnomIPPhoneMenu>', "\n";
    _ob_send();
}
#################################### INITIAL SCREEN }
function defineBackMenu()
Beispiel #21
0
psetting('aoc_amount_display', 'off');
# off | charged | balance
psetting('aoc_pulse_currency', '');
# e.g. "EUR" | "USD" | "$"
psetting('aoc_cost_pulse', '1');
# e.g. 0.02
psetting('max_boot_delay', '0');
# ? in seconds, default: 0
psetting('mailbox_active', 'off');
# pay attention to the mailbox of the
# active identity only?
psetting('speaker_dialer', 'on');
psetting('no_dnd', 'off');
$dnd_mode = 'off';
$cf = gs_callforward_get($user['user']);
if (!isGsError($cf) && is_array($cf)) {
    if (@$cf['internal']['always']['active'] != 'no' || @$cf['external']['always']['active'] != 'no') {
        $dnd_mode = 'on';
        //FIXME - bad hack!
    }
}
psetting('dnd_mode', $dnd_mode, true);
psetting('dnd_on_code', 'dnd-on');
psetting('dnd_off_code', 'dnd-off');
psetting('preselection_nr', '');
#####################################################################
#  Redirection
#####################################################################
psetting('redirect_event', 'none');
# Umleitung nicht auf dem Tel. machen
psetting('redirect_number', '');
Beispiel #22
0
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;
}
Beispiel #23
0
if ($cidnum === $user['ext']) {
    $cidnum = null;
} else {
    $cidnum_obj = new CanonicalPhoneNumber($cidnum);
    if ($cidnum_obj->intl === $user_ext_obj->intl) {
        $cidnum = null;
    }
    unset($cidnum_obj);
    # cidnum might be modified later
}
if ($cidnum) {
    if (!$is_foreign) {
        # get external numbers
        if (!is_array($user_external_numbers)) {
            $user_external_numbers = @gs_user_external_numbers_get($user_code);
            if (isGsError($user_external_numbers)) {
                gs_log(GS_LOG_WARNING, $user_external_numbers->getMsg());
                $user_external_numbers = array();
            }
            if (!is_array($user_external_numbers)) {
                $user_external_numbers = array();
            }
        }
        # check if number in external numbers
        if (!in_array($cidnum, $user_external_numbers, true)) {
            $cidnum_obj = new CanonicalPhoneNumber($cidnum);
            if ($cidnum_obj->errt != '' && $cidnum_obj->errt !== 'self') {
                gs_log(GS_LOG_WARNING, 'Problem with phone number "' . $cidnum . '" (' . $cidnum_obj->errt . ').');
                $in_external_numbers = false;
            } else {
                if (in_array($cidnum_obj->intl, $user_external_numbers, true)) {
Beispiel #24
0
function _run_topology_tests($hosts)
{
    if (gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
        trigger_error("Not allowed on single server systems.\n", E_USER_ERROR);
        exit(1);
    }
    $conf = '/etc/gemeinschaft/topology.php';
    if (!file_exists($conf)) {
        trigger_error("Config file \"{$conf}\" not found!\n", E_USER_ERROR);
        exit(1);
    } else {
        if (@(include $conf) === false) {
            // () around the include are important!
            trigger_error("Could not include config file \"{$conf}\"!\n", E_USER_ERROR);
            exit(1);
        }
    }
    echo "Current EDPC (de: RZ): ", $CUR_RZ, "\n";
    echo "Stage 1: Trying to reach each system via SSH ...\n";
    foreach ($hosts as $host) {
        echo $host['desc'], "... ";
        $ok = _try_ssh($host['host']);
        if (isGsError($ok)) {
            echo $ok->getMsg(), "\n";
            exit(1);
        } elseif (!$ok) {
            echo 'Error', "\n";
            exit(1);
        }
        echo "ok.\n";
    }
    echo "SSH seems to be working.\n\n";
    echo "============================\n\n";
    echo "Stage 2: Trying to reach each system via MySQL ...\n";
    foreach ($hosts as $key => $info) {
        echo $info['desc'], "... ";
        $ok = false;
        if ($key === 'DB_MASTER_SERVER1' && $CUR_RZ === 'A') {
            $hosts[$key]['con'] = null;
            $ok = gs_db_connect($hosts[$key]['con'], 'master', $hosts[$key]['host'], $SUPER_MYSQL_USER, $SUPER_MYSQL_PASS, GS_DB_MASTER_DB, 1);
        } elseif ($key === 'DB_MASTER_SERVER2' && $CUR_RZ === 'B') {
            $hosts[$key]['con'] = null;
            $ok = gs_db_connect($hosts[$key]['con'], 'master', $hosts[$key]['host'], $SUPER_MYSQL_USER, $SUPER_MYSQL_PASS, GS_DB_MASTER_DB, 1);
        } else {
            $hosts[$key]['con'] = null;
            $ok = gs_db_connect($hosts[$key]['con'], 'slave', $hosts[$key]['host'], $SUPER_MYSQL_USER, $SUPER_MYSQL_PASS, GS_DB_SLAVE_DB, 1);
        }
        if (!$ok) {
            echo "Could not connect to " . $hosts[$key]['host'] . "\n";
            exit(1);
        }
        echo "ok.\n";
    }
    echo "MySQL connections seems to be working.\n\n";
    echo "============================\n\n";
    echo "Stage 3: Checking replication process on each system via MySQL ...\n";
    $warningcounter = 0;
    foreach ($hosts as $key => $host) {
        if ($key === 'DB_MASTER_SERVER1' && $CUR_RZ === 'A') {
            echo "(MASTER) ", $host['desc'], "... ";
            $rs = $host['con']->execute('SHOW MASTER STATUS');
            if (!$rs) {
                echo "Could not execute SHOW MASTER STATUS on ", $host['host'], "\n";
                exit(1);
            }
            $master_status = $rs->fetchRow();
            if (!isset($master_status['Position']) || !isset($master_status['File'])) {
                echo "Error. Master not running on ", $host['host'], "\n";
                exit(1);
            }
            echo "ok.\n";
        } elseif ($key == 'DB_MASTER_SERVER2' && $CUR_RZ === 'B') {
            echo "(MASTER) ", $host['desc'], "... ";
            $rs = $host['con']->execute('SHOW MASTER STATUS');
            if (!$rs) {
                echo "Could not execute SHOW MASTER STATUS on ", $host['host'], "\n";
                exit(1);
            }
            $master_status = $rs->fetchRow();
            if (!isset($master_status['Position']) || !isset($master_status['File'])) {
                echo "Error. Master not running on ", $host['host'], "\n";
                exit(1);
            }
            echo "ok.\n";
        } else {
            $bOk = true;
            echo $host['desc'], "... ";
            if ($CUR_RZ === 'A' && $host['host'] === $DB_MASTER_SERVER1) {
                echo "Skipping, because it's the same host as DB_MASTER_SERVER1_SERVICE_IP.\n";
                echo "This host does not need to be a slave to himself.\n";
                continue;
            }
            if ($CUR_RZ === 'B' && $host['host'] === $DB_MASTER_SERVER2) {
                echo "Skipping, because it's the same host as DB_MASTER_SERVER2_SERVICE_IP.\n";
                echo "This host does not need to be a slave to himself.\n";
                continue;
            }
            $rs = $host['con']->execute('SHOW SLAVE STATUS');
            if (!$rs) {
                echo "Could not execute SHOW SLAVE STATUS on ", $host['host'], "\n";
                exit(1);
            }
            $slave_status = $rs->fetchRow();
            if (@$slave_status['Slave_IO_State'] == '') {
                echo "WARNING: Slave on ", $host['host'], " is not running!\n";
                $bOk = false;
                ++$warningcounter;
            }
            if ($CUR_RZ === 'A' && @$slave_status['Master_Host'] != $DB_MASTER_SERVER1_SERVICE_IP) {
                echo "WARNING: Slave on ", $host['host'], " has the wrong Master!\n";
                echo "The Master on that host is: ", $slave_status["Master_Host"], "\n";
                echo "but should be ", $hosts['DB_MASTER_SERVER1']['host'], "\n";
                echo "You may want to execute:\n";
                echo "gs-db-slave-replication-setup", " --master=", qsa($hosts['DB_MASTER_SERVER1']['host']), " --slave=", qsa($host['host']), " --user="******" --pass="******"\n";
                $bOk = false;
                ++$warningcounter;
            }
            if ($CUR_RZ === 'B' && @$slave_status['Master_Host'] != $DB_MASTER_SERVER2_SERVICE_IP) {
                echo "WARNING: Slave on ", $host['host'], " has the wrong Master!\n";
                echo "The Master on that host is: ", $slave_status["Master_Host"], "\n";
                echo "but should be ", $hosts['DB_MASTER_SERVER2']['host'], "\n";
                echo "You may want to execute:\n";
                echo "gs-db-slave-replication-setup", " --master=", qsa($hosts['DB_MASTER_SERVER2']['host']), " --slave=", qsa($host['host']), " --user="******" --pass="******"\n";
                $bOk = false;
                ++$warningcounter;
            }
            if ($bOk) {
                echo "ok.\n";
            } else {
                echo "a warning occurred.\n";
            }
        }
    }
    // foreach ($hosts as $key => $host)
    if ($warningcounter > 0) {
        echo "Found ", $warningcounter, " warnings. Please try to fix them!\n";
        exit(1);
    }
    echo "Replication seems to be working.\n\n";
    echo "============================\n\n";
    echo "Stage 4: Checking gemeinschaft.php for variable DB_MASTER_HOST on each system ...\n";
    $master_host = null;
    if ($CUR_RZ === 'A') {
        $master_host = $DB_MASTER_SERVER1_SERVICE_IP;
    } elseif ($CUR_RZ === 'B') {
        $master_host = $DB_MASTER_SERVER2_SERVICE_IP;
    } else {
        echo "Error.\n";
        exit(1);
    }
    foreach ($hosts as $host) {
        echo $host['desc'], "... ";
        $ok = _check_etc_gemeinschaft_php($host['host'], $master_host);
        if (isGsError($ok)) {
            echo $ok->getMsg(), "\n";
            exit(1);
        } elseif (!$ok) {
            echo 'Error', "\n";
            exit(1);
        }
        echo "ok.\n";
    }
    echo "The DB_MASTER_HOST setting in gemeinschaft.php on each host seems to be ok.\n\n";
    echo "All systems should be up and running properly.\n";
    //TODO: add test of topology.php on each server
    //TODO: add test to check if the Virtual Interfaces exists
    //TODO: add test to check if Web services are running
    //TODO: add test to check if Voice services are running
    //TODO: add test for the listen-to-ip file
    return true;
}
Beispiel #25
0
	</td>
</tr>
<tr class="even">
	<td><?php 
echo __('Tempor&auml;re Nummer');
?>
</td>
	<td>
		<input type="text" name="num-var" id="ipt-num-var" value="<?php 
echo htmlEnt($number_var);
?>
" size="30" style="width:220px;" maxlength="25" />
		<div id="num-select-var" style="display:none;">
		&larr;<select width='100' style="width: 100px" id="sel-num-var" onchange="gs_num_sel(this);">
<?php 
if (!isGsError($announce) && is_array($announce)) {
    echo '<option value="">', __('Audiodateien'), '</option>', "\n";
    foreach ($announce as $number) {
        echo '<option value="', htmlEnt('sysrec' . $number), '">', htmlEnt($number . ' ' . $announce_name[$number]), '</option>', "\n";
    }
}
?>
		</select>
		</div>

	</td>
</tr>
<tr class="even">
	<td><?php 
echo __('AB-Nummer (interner Nutzer)');
?>
Beispiel #26
0
error_reporting(0);
require_once dirName(__FILE__) . '/../../inc/conf.php';
require_once GS_DIR . 'inc/util.php';
require_once GS_DIR . 'inc/log.php';
set_error_handler('err_handler_quiet');
if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
    require_once GS_DIR . 'inc/get-listen-to-ids.php';
    require_once GS_DIR . 'inc/gs-lib.php';
    include_once GS_DIR . 'inc/gs-fns/gs_hosts_get.php';
    $our_ids = @gs_get_listen_to_ids();
    if (!is_array($our_ids)) {
        $our_ids = array();
    }
    //echo 'OUR IDS: ', implode(', ', $our_ids), "\n";
    $hosts = @gs_hosts_get();
    if (isGsError($hosts)) {
        $hosts = array();
    }
    if (!$hosts) {
        $hosts = array();
    }
    //echo "HOSTS:\n"; print_r($hosts);
    $min_our_ids = count($our_ids) > 0 ? min($our_ids) : 0;
    if ($min_our_ids < 1) {
        gs_log(GS_LOG_WARNING, 'This server is not configured to be a Gemeinschaft node. Not registering to other nodes.');
    } else {
        $outUser = '******' . str_pad($min_our_ids, 4, '0', STR_PAD_LEFT);
        $out = '';
        foreach ($hosts as $host) {
            if (in_array((int) $host['id'], $our_ids)) {
                //echo "SKIPPING ", $host['id'], "\n";
Beispiel #27
0
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_user_external_number_del($user, $number)
{
    if (!preg_match('/^[a-z0-9\\-_.]+$/', $user)) {
        return new GsError('User must be alphanumeric.');
    }
    if (!preg_match('/^[\\d]+$/', $number)) {
        return new GsError('Number must be numeric.');
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # get user_id
    #
    $user_id = $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\'');
    if ($user_id < 1) {
        return new GsError('Unknown user.');
    }
    switch (GS_EXTERNAL_NUMBERS_BACKEND) {
        case 'ldap':
            $ldap = gs_ldap_connect();
            if (!$ldap) {
                return new GsError('Could not connect to LDAP server.');
            }
            # check if number exists (to return proper err msg)
            #
            /*
            $numbers = gs_user_external_numbers_get( $user );
            if (isGsError($numbers))
            	return new GsError( $numbers->getMsg() );
            if (! is_array($numbers))
            	return new GsError( 'Failed to get numbers from LDAP' );
            if (! in_array($number, $numbers, true))
            	return new GsError( 'No such number.' );
            */
            # find ldap user name
            #
            if (GS_LDAP_PROP_UID === GS_LDAP_PROP_USER) {
                $ldap_uid = $user;
                if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) {
                    $user = preg_replace('/^0+/', '', $user);
                    # if the usernames in your LDAP are integers without
                    # a leading "0"
                }
            } else {
                if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) {
                    $user = preg_replace('/^0+/', '', $user);
                    # if the usernames in your LDAP are integers without
                    # a leading "0"
                }
                $userArr = gs_ldap_get_first($ldap, GS_LDAP_SEARCHBASE, GS_LDAP_PROP_USER . '=' . $user, array(GS_LDAP_PROP_UID));
                if (isGsError($userArr)) {
                    return new GsError($userArr->getMsg());
                }
                if (!is_array($userArr)) {
                    return new GsError('Could not find user by "' . GS_LDAP_PROP_USER . '=' . $user . '" in search base "' . GS_LDAP_SEARCHBASE . '" in LDAP.');
                }
                $ldap_uid = @$userArr[strToLower(GS_LDAP_PROP_UID)][0];
                if (strLen($ldap_uid) < 1) {
                    return new GsError('Could not find user by "' . GS_LDAP_PROP_USER . '=' . $user . '" in search base "' . GS_LDAP_SEARCHBASE . '" in LDAP.');
                }
            }
            $dn = GS_LDAP_PROP_UID . '=' . $ldap_uid . ',' . GS_LDAP_SEARCHBASE;
            # delete number
            #
            $ok = @ldap_mod_del($ldap, $dn, array(GS_EXTERNAL_NUMBERS_LDAP_PROP => $number));
            if (!$ok) {
                if (@ldap_errNo($ldap) == 16) {
                    // err #16 is: "No such attribute"
                    return new GsError('No such number.');
                }
                return new GsError('Failed to delete number for LDAP user "' . $dn . '". - ' . gs_get_ldap_error($ldap));
            }
            break;
        case 'db':
        default:
            # check if number exists (to return proper err msg)
            #
            $num = (int) $db->executeGetOne('SELECT COUNT(*) FROM `users_external_numbers` WHERE `user_id`=' . $user_id . ' AND `number`=\'' . $db->escape($number) . '\'');
            if ($num < 1) {
                return new GsError('No such number.');
            }
            # delete number
            #
            $ok = $db->execute('DELETE FROM `users_external_numbers` WHERE `user_id`=' . $user_id . ' AND `number`=\'' . $db->escape($number) . '\'');
            if (!$ok) {
                return new GsError('Failed to delete external number.');
            }
            break;
    }
    return true;
}
 if ($extnum) {
     $ret = gs_user_external_number_add($edit_user, $extnum);
     if (isGsError($ret)) {
         echo '<div class="errorbox">', $ret->getMsg(), '</div>', "\n";
     }
 }
 if ($u_pgrp_ed) {
     $sql_query = 'DELETE `p` ' . 'FROM `pickupgroups_users` `p` , `users` `u` ' . 'WHERE ' . '`p`.`user_id` = `u`.`id` AND ' . '`u`.`user` = \'' . $DB->escape($edit_user) . '\'';
     $ok = $DB->execute($sql_query);
     if (is_array($u_pgrps)) {
         foreach ($u_pgrps as $u_pgrp) {
             if ($u_pgrp < 1) {
                 continue;
             }
             $ret = gs_pickupgroup_user_add($u_pgrp, $edit_user);
             if (isGsError($ret)) {
                 echo '<div class="errorbox">', $ret->getMsg(), '</div>', "\n";
             }
         }
     }
 }
 if ($u_prv_grp_ed) {
     $query = 'UPDATE `users` SET ' . '`group_id`=' . ($u_prv_grp_id > 0 ? $u_prv_grp_id : 'NULL') . ' ' . 'WHERE `user`=\'' . $DB->escape($edit_user) . '\'';
     $ok = $DB->execute($query);
 }
 if ($bp_add_h > 0) {
     $user_id = (int) $DB->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $DB->escape($edit_user) . '\'');
     if ($user_id > 0) {
         $host_exists = $DB->executeGetOne('SELECT 1 FROM `hosts` WHERE `id`=' . $bp_add_h);
         if ($host_exists) {
             $query = 'REPLACE INTO `boi_perms` (`user_id`, `host_id` , `roles`) VALUES (' . $user_id . ', ' . $bp_add_h . ', \'l\')';
function gs_ringtone_set($user, $src, $bellcore, $change_file = false, $file = null)
{
    if (!preg_match('/^[a-zA-Z\\d]+$/', $user)) {
        return new GsError('User must be alphanumeric.');
    }
    if (!in_array($src, array('internal', 'external'), true)) {
        return new GsError('Source must be internal|external.');
    }
    $bellcore = (int) $bellcore;
    if ($bellcore < 0 || $bellcore > 10) {
        return new GsError('Bellcore must be between 1 and 10 or 0 for silent.');
    }
    if (!$change_file) {
        $file = null;
    } else {
        if (!$file) {
            # to remove a custom ringer
            $file = null;
        } else {
            $file = @realPath($file);
            if (!@file_exists($file)) {
                $file = @realPath(@$_ENV['PWD'] . '/' . $file);
                if (!@file_exists($file)) {
                    return new GsError('File not found.');
                }
            }
            //if (strToLower(subStr($file,-4)) != '.mp3')
            //	return new GsError( 'File is not an mp3.' );
        }
    }
    # connect to db
    #
    $db = gs_db_master_connect();
    if (!$db) {
        return new GsError('Could not connect to database.');
    }
    # get user_id
    #
    $user_id = (int) $db->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $db->escape($user) . '\'');
    if (!$user_id) {
        return new GsError('Unknown user.');
    }
    # make sure there is an entry in the db and set the bellcore ringer
    #
    $num = (int) $db->executeGetOne('SELECT COUNT(*) `num` FROM `ringtones` WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
    if ($num < 1) {
        $ok = $db->execute('INSERT INTO `ringtones` (`user_id`, `src`, `bellcore`, `file`) VALUES (' . $user_id . ', \'' . $src . '\', ' . $bellcore . ', NULL)');
    } else {
        $ok = $db->execute('UPDATE `ringtones` SET `bellcore`=' . $bellcore . ' WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
    }
    if (!$ok) {
        return new GsError('DB error.');
    }
    if (!$change_file) {
        return true;
    }
    # are we the web server?
    #
    if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
        $our_host_ips = @gs_get_listen_to_ips();
        if (!is_array($our_host_ips)) {
            return new GsError('Failed to get our host IPs.');
        }
        $we_are_the_webserver = in_array(GS_PROV_HOST, $our_host_ips);
    } else {
        $we_are_the_webserver = true;
    }
    # remove old ringer from htdocs/prov/ringtones/ dir
    #
    if ($we_are_the_webserver) {
        # local
        @exec('sudo rm -rf ' . GS_DIR . 'htdocs/prov/ringtones/' . $user . '-' . subStr($src, 0, 3) . '-* 1>>/dev/null 2>>/dev/null');
    } else {
        # remotely
        $cmd = 'rm -rf /opt/gemeinschaft/htdocs/prov/ringtones/' . $user . '-' . subStr($src, 0, 3) . '-* 1>>/dev/null 2>>/dev/null &';
        @exec('sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa('root@' . GS_PROV_HOST) . ' ' . qsa($cmd) . ' 1>>/dev/null 2>>/dev/null');
    }
    # just remove custom ringer?
    #
    if (!$file) {
        $ok = $db->execute('UPDATE `ringtones` SET `file`=NULL WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
        if (!$ok) {
            return new GsError('DB error.');
        }
        return true;
    }
    # convert sound file to the formats needed for each phone type
    #
    $to_sox_format = array('alaw' => 'al', 'ulaw' => 'ul');
    $pinfo = pathInfo($file);
    //$base = $pinfo['basename'];
    $ext = strToLower(@$pinfo['extension']);
    if (array_key_exists($ext, $to_sox_format)) {
        $ext = $to_sox_format[$ext];
    }
    $rand = base_convert(rand(1296, 46655), 10, 36);
    # 100(36) - zzz(36)
    $tmpbase = '/tmp/gs-ring-' . $user . '-' . $rand;
    $infile = $tmpbase . '-in.' . $ext;
    $outbase = $tmpbase . '-out';
    $ok = @copy($file, $infile);
    @chmod($infile, 0666);
    if (!$ok) {
        return new GsError('Failed to copy file to "' . $infile . '".');
    }
    include_once GS_DIR . 'inc/phone-capability.php';
    $phone_types = glob(GS_DIR . 'htdocs/prov/*/capability.php');
    if (!is_array($phone_types)) {
        $phone_types = array();
    }
    for ($i = 0; $i < count($phone_types); ++$i) {
        $phone_types[$i] = baseName(dirName($phone_types[$i]));
    }
    gs_log(GS_LOG_DEBUG, 'Ringtone conversion: Found phone types: ' . implode(', ', $phone_types));
    $errors = array();
    $new_ringer_basename = $user . '-' . subStr($src, 0, 3) . '-' . $rand;
    foreach ($phone_types as $phone_type) {
        include_once GS_DIR . 'htdocs/prov/' . $phone_type . '/capability.php';
        $class = 'PhoneCapability_' . $phone_type;
        if (!class_exists($class)) {
            gs_log(GS_LOG_WARNING, $phone_type . ': Class broken.');
            $errors[] = $phone_type . ': Class broken.';
            continue;
        }
        $PhoneCapa = new $class();
        $outfile = $PhoneCapa->conv_ringtone($infile, $outbase);
        if (isGsError($outfile)) {
            gs_log(GS_LOG_WARNING, 'Ringtone conversion: ' . $phone_type . ': ' . $outfile->getMsg());
            $errors[] = $phone_type . ': ' . $outfile->getMsg();
        } elseif ($outfile === null) {
            gs_log(GS_LOG_DEBUG, 'Ringtone conversion: ' . $phone_type . ': Not implemented.');
            continue;
        } elseif (!$outfile) {
            gs_log(GS_LOG_WARNING, 'Ringtone conversion: ' . $phone_type . ': Failed to convert file.');
            $errors[] = $phone_type . ': ' . 'Failed to convert file.';
            continue;
        }
        if (!file_exists($outfile)) {
            gs_log(GS_LOG_WARNING, 'Ringtone conversion: ' . $phone_type . ': Failed to convert file.');
            $errors[] = $phone_type . ': ' . 'Failed to convert file.';
            continue;
        }
        gs_log(GS_LOG_DEBUG, 'Ringtone conversion: ' . $phone_type . ': Converted.');
        @chmod($outfile, 0666);
        $pinfo = pathInfo($outfile);
        $ext = strToLower(@$pinfo['extension']);
        $newbase = $new_ringer_basename . '-' . $phone_type . '.' . $ext;
        if ($phone_type === 'siemens' && !gs_get_conf('GS_SIEMENS_PROV_PREFER_HTTP')) {
            # if this is a Siemens phone, push the file on the FTP server
            @copy($infile, '/tmp/' . $newbase);
            //FIXME - why?
            $ok = $PhoneCapa->_upload_ringtone('/tmp/' . $newbase);
            if (!$ok) {
                gs_log(GS_LOG_WARNING, 'Failed to upload ringtone to FTP server.');
            }
            if (is_file('/tmp/' . $newbase)) {
                @unlink('/tmp/' . $newbase);
            }
        } else {
            if ($we_are_the_webserver) {
                # local
                //rename( $outfile, GS_DIR .'htdocs/prov/ringtones/'. $newbase );
                @exec('sudo mv ' . qsa($outfile) . ' ' . qsa(GS_DIR . 'htdocs/prov/ringtones/' . $newbase), $out, $err);
            } else {
                # remotely
                @exec('sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($outfile) . ' ' . qsa('root@' . GS_PROV_HOST . ':/opt/gemeinschaft/htdocs/prov/ringtones/' . $newbase) . ' >>/dev/null 2>>/dev/null', $out, $err);
                //@exec( 'sudo rm -f '. qsa($outfile) .' >>/dev/null 2>&1' );
                @unlink($outfile);
            }
            if ($err != 0) {
                gs_log(GS_LOG_WARNING, 'Failed to mv ringtone.');
            }
        }
    }
    if (is_file($infile)) {
        @unlink($infile);
    }
    @exec('rm -rf ' . $tmpbase . '-* 1>>/dev/null 2>>/dev/null &');
    if (count($errors) > 0) {
        return new GsError("Failed to convert ringtone for some or all phone types: " . implode(", ", $errors));
    }
    $ok = $db->execute('UPDATE `ringtones` SET `file`=\'' . $db->escape($new_ringer_basename) . '\' WHERE `user_id`=' . $user_id . ' AND `src`=\'' . $src . '\'');
    if (!$ok) {
        return new GsError('DB error.');
    }
    return true;
    // OLD STUFF:
    /*
    # remove old ringer
    #
    $files = @glob( GS_DIR .'htdocs/prov/ringtones/'. $user .'/'. $src .'-*' );
    if (is_array($files)) {
    	foreach ($files as $f) {
    		unlink();
    	}
    }
    die();
    
    
    shell_exec( 'rm -f /opt/ast/htdocs/prov/ringtones/'. $ext .'-*' );
    
    # get SIP name
    #
    $ext = $db->executeGetOne( 'SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`='. $user_id );
    if (! $ext)
    	return new GsError( 'DB error.' );
    
    
    if ($file) {
    	
    	$rand = rand(10000,99999).time();
    	
    	shell_exec( 'mpg123 -m -r 8000 -w - -n 500 -q \''. $file .'\' > \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $rand .'.wav\'' );
    	shell_exec( 'sox \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $rand .'.wav\' -r 8000 -c 1 -w \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $ext .'-'. time() .'.wav\'' );
    	shell_exec( 'rm \'/opt/gemeinschaft/htdocs/prov/ringtones/'. $rand .'.wav\'' );
    	
    } else {
    	//shell_exec( 'rm -f /opt/gemeinschaft/htdocs/prov/ringtones/'. $ext .'-*' );
    }
    
    return true;
    */
}