Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
function distribute_remove($localfile)
{
	global $errormsgs;

	$hostlist = gs_hosts_get();
	$thishost = @gs_get_listen_to_ids();

	foreach($hostlist as $currenthost)
	{
		unset($islocalhost);
		$islocalhost = FALSE;

		foreach($thishost as $hostid)
		{
			if($currenthost["id"] == $hostid) $islocalhost = TRUE;
		}

		if($islocalhost == FALSE)
		{
			unset($cmd);
			$cmd = "sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ". qsa($currenthost["host"]) ." ". qsa("rm ". qsa($localfile));
			@exec($cmd ." 1>>/dev/null 2>>/dev/null", $out, $err);
			if($err != 0)
			{
				gs_log(GS_LOG_WARNING, "Failed to remove system recording '". $localfile ."' from ". $currenthost["host"]);
				$errormsgs[] = sprintf(__('Audiodatei kann nicht von Node %s gelöscht werden'), $currenthost["host"]);
			}
		}
	}
}
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;
}
Ejemplo n.º 4
0
ob_implicit_flush(1);
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)) {
Ejemplo n.º 5
0
}
@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($user['host_id'], $our_host_ids);
} else {
    $user_is_on_this_host = true;
}
if ($is_LVM_agenturmitarbeiter) {
    $hosts = gs_hosts_get();
    if (isGsError($hosts) || !is_array($hosts) || count($hosts) < 1) {
        die_error('Could not get hosts.');
    }
    //$host = $hosts[rand(0,count($hosts)-1)];
    $host = $hosts[0];
    $user['host_id'] = $host['id'];
    $user['host'] = $host['host'];
}
if ($user_is_on_this_host) {
    # the Asterisk of this user and the web server both run on this host
    //$ok = @rename( $filename, $spoolfile );
    $err = 0;
    $out = array();
    @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
    if ($err != 0) {
function _gs_prov_phone_checkcfg_by_ext_do_polycom($ext, $reboot = true)
{
    $sip_notify = "polycom-check-cfg";
    @exec('sudo asterisk -rx \'sip notify ' . $sip_notify . ' ' . $ext . '\' >>/dev/null 2>>/dev/null &', $out, $err);
    $hosts = @gs_hosts_get(false);
    if (isGsError($hosts)) {
        gs_log(GS_LOG_WARNING, 'Failed to get hosts - ' . $hosts->getMsg());
    } elseif (!is_array($hosts)) {
        gs_log(GS_LOG_WARNING, 'Failed to get hosts');
    } else {
        $cmd = 'asterisk -rx \'sip notify ' . $sip_notify . ' ' . $ext . '\'';
        foreach ($hosts as $host) {
            @exec('sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($host['host']) . ' ' . qsa($cmd) . ' >>/dev/null 2>>/dev/null &');
        }
    }
}