File: /home/posscale/subdomains/3pcc/rcci_updateconfig.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
-----------------------------------------------------------------------------
* .FILE NAME:
* rcci.php
*
* .FUNCTION:
* Remote Call Control Interface
*
* .Notice: Set implicit_flush = On in php.ini file
-----------------------------------------------------------------------------
-->
<?php
include "XMLCalls_inc.php";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Remote Call Control Interface</title>
</head>
<LINK rel="stylesheet" type="text/css" href="styles/styles.css">
<script language='javascript' >
function runUpdate()
{
this.document.forms['call_control'].elements['updconfig'].value="boot";
this.document.forms['call_control'].submit();
}
function runGetInfo()
{
this.document.forms['call_control'].elements['GetInfo'].value="boot";
this.document.forms['call_control'].submit();
}
function runchksoc()
{
this.document.forms['call_control'].elements['chksoc'].value="boot";
this.document.forms['call_control'].submit();
}
</script>
<center><font size='6' class="title">Remote Call Control Interface</font></center>
<br>
<form name='call_control' method='post' target="_self">
<table class="table_border" align="center">
<tr>
<td class="inp_header" colspan="2" align="center">Connection parameters</td>
</tr>
<tr>
<td class="td_pad">Quadro IP</td>
<td class="td_pad"><input type='text' class="input" name='ip' maxlength='15' size='15' value='<?php echo !empty($_POST['ip']) ? $_POST['ip'] : ''; ?>'></td>
<tr>
<td class="td_pad">Port</td>
<td class="td_pad"><input type='text' class="input" name='port' maxlength='4' size='15' value='4849'></td>
<tr>
<td class="td_pad">User Name</td>
<td class="td_pad"><input type='text' class="input" name='user_name' maxlength='10' size='15' value='134'></td>
<tr>
<td class="td_pad">Password</td>
<td class="td_pad"><input type='password' class="input" name='password' maxlength='10' size='15' value='974082974082'></td>
<?php
if( (!empty($_POST['updconfig']) && ($_POST['updconfig'] == "boot")) || ( !empty($_POST['GetInfo']) && ($_POST['GetInfo'] == "boot"))){
$addr = $_POST['ip'];
$port = $_POST['port'];
$user_name = $_POST['user_name'];
$password = $_POST['password'];
if (msConnectSocket("121.50.208.90",4849,30))
{
print "Entre Socket Connection ...True..";
exit(0);
}
//echo $addr."---".$port."---".$user_name."---".$password;
if ( checkConnectFields() )
{
$net = new XMLCalls($addr, $port, $user_name, $password );
if( !$net->Authenticate() ) {
?>
<tr>
<td class="td_pad">Connection Status</td>
<td class="td_pad"><input type='text' class="input" size='35' value='Wrong username or password'></td>
<?php
exit(0);
} else {
?>
<tr>
<td class="td_pad">Connection Status</td>
<td class="td_pad"><input type='text' class="input" size='35' value='Connected'></td>
<?php
}
}
}
?>
</table>
<br>
<table class="table_border" align="center">
<tr>
<td class="inp_header" colspan="2" align="center">Upload legible configuration </td>
</tr>
<tr>
<td class="td_pad">Filename</td>
<td class="td_pad"><input type='text' class="input" name='filename' maxlength='50' size='50' value=''></td>
</table>
<br>
<center>
<input type='button' value='Upload' class="button" onclick="runUpdate()">
</center>
<br>
<input type='hidden' name="updconfig" value="">
<br>
<center>
<input type='button' value='PBX Info' class="button" onclick="runGetInfo()">
</center>
<br>
<input type='hidden' name="GetInfo" value="">
<br>
<center>
<input type='button' value='Check Sockit' class="button" onclick="Runchksoc">
</center>
<br>
<input type='hidden' name="ChkSoc" value="">
</form>
<?php
function msConnectSocket($remote, $port, $timeout = 30) {
# this works whether $remote is a hostname or IP
print "Entered msConnectSocket Function";
print "Remote: " && $remote;
print "Port: " && $port;
print "Entered msConnectSocket Function";
$ip = "";
if( !preg_match('/^\d+\.\d+\.\d+\.\d+$/', $remote) ) {
$ip = gethostbyname($remote);
if ($ip == $remote) {
print "Error Connecting Socket: Unknown host";
return NULL;
}
} else $ip = $remote;
if (!($SOCK = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
print "Error Creating Socket: ".socket_strerror(socket_last_error());
return NULL;
}
socket_set_nonblock($SOCK);
$error = NULL;
$attempts = 0;
$timeout *= 1000; // adjust because we sleeping in 1 millisecond increments
$connected;
while (!($connected = @socket_connect($SOCK, $remote, $port+0)) && $attempts++ < $timeout) {
$error = socket_last_error();
if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
print "Error Connecting Socket: ".socket_strerror($error);
socket_close($SOCK);
return NULL;
}
usleep(1000);
}
if (!$connected) {
print"Error Connecting Socket: Connect Timed Out After $timeout seconds. ".socket_strerror(socket_last_error());
socket_close($SOCK);
return NULL;
}
socket_set_block($SOCK);
return 1;
}
function checkConnectFields()
{
if( empty($_POST['ip']) ) {
?>
<script language="javascript">
alert("Please, enter Quadro IP address.");
</script>
<?php
return false;
}
if( empty($_POST['port']) ) {
?>
<script language="javascript">
alert("Please, enter port number.");
</script>
<?php
return false;
}
return true;
}
function checkFileName()
{
if( empty($_POST['filename']) ) {
?>
<script language="javascript">
alert("Please, fill 'FileName' field.");
</script>
<?php
return false;
}
return true;
}
if( !empty($_POST['filename']) && $_POST['updconfig'] == "boot" ) {
if(checkFileName() && checkConnectFields()) {
$net->UpdateConfig($_POST['filename']);
}
}
if( $_POST['GetInfo'] == "boot" ) {
if(checkConnectFields()) {
$net->GetPBXInfo();
}
}
?>
</body>
</html>