kickConf.php 1.36 KB
#!/usr/bin/php
<?php
$db = mysqli_connect("localhost", "root", "yb9738z", "fullerton");

for ($i=0; $i < 6; $i++) { 
	$sql = $db->query("SELECT d.conf FROM diallines d JOIN sipids s ON d.conf = concat('1000',s.id) WHERE s.status=0");
	$confs = $sql->fetch_all();

	foreach($confs as $conf){
		print_r($conf);
		exec('/usr/sbin/asterisk -rx "confbridge kick '.$conf[0].' all"');
	}

	$sql = $db->query("SELECT channel FROM diallines WHERE status IN ('Inbound','Auto') AND conf='' AND UNIX_TIMESTAMP(updated_at) <= (".time()." - 60)");
	$channels = $sql->fetch_all();

	foreach($channels as $channel){
		print_r($channel);
		exec('/usr/sbin/asterisk -rx "confbridge kick '.$channel[0].' all"');
	}

	$sipIdStr = "'0'";
	exec("/usr/sbin/asterisk -rx 'confbridge list'",$activeConfs);
	foreach($activeConfs as $activeConf){
		$activeConfArr = explode(" ", preg_replace('!\s+!', ' ', $activeConf) );
		$sipConf = $activeConfArr[0];

		if(!empty($sipConf) && !(strpos($sipConf, '1000')===false) ){
			$sipIdStr .= ",'".substr($sipConf, 4)."'";
		}
	}

	$sql = $db->query("select * from sipids where status=0 and id in ($sipIdStr)");
	$sipids = $sql->fetch_all();

	foreach($sipids as $sipid){
		print_r('1000'. $sipid[0]);
		exec('/usr/sbin/asterisk -rx "channel request hangup '.$sipid[0].'"');
		exec('/usr/sbin/asterisk -rx "confbridge kick 1000'.$sipid[0].' all"');
	}

	usleep(1000*1000*9);
}
?>