Hey dude,
Here's the code.. Just as a proviso - i'm sure i'm doing some very obvious basic things wrong. im new to php and have struggled with it.. as someone who has written in other programming languages I'm not very happy with my structure!!!!
I.E version is 7.0.5730.13
Sindarin... can i use an image if i have the type as button rather than submit? i know i can change size etc. but i didnt think i could use an image?
code is as follows:
Code: Select all
<html><head><title>PhoneRemote</title>
<style type='text/css'>
div#Loginfields {position: absolute; left: 0px; top: 0px; width: 100%; height: 450; background: gray; padding: 5px;}
div#Info {position: absolute; left: 0px; top: 100px; padding: 5px}
div#LineKeys {position: absolute; left: 477px; top: 27px; height 234px; width: 19px; z-index:1; padding: 0px;}
div#Softkeys {position: absolute; left: 175px; top: 218px; height: 20px; width: 320px; z-index:1; padding: 0px;}
div#Refresh {position: absolute; left: 505px; top: 225px; height: 234px; width: 320px;}
div#Keypad {position: absolute; left: 170px; top: 250px; background: gray; height:150; width:145; padding: 5px;}
div#FunctionkeysL {position: absolute; left: 330px; top: 250px; background: gray; height:50; width:145; padding: 5px;}
div#FunctionkeysR {position: absolute; left: 410px; top: 250px; background: gray; height:50; width:145; padding: 5px;}
div#Volume {position: absolute; left: 350px; top: 328px; background: gray; height:50; width:145;}
div#Soundkeys {position: absolute; left: 359px; top: 355px; background: gray; height:50; width:200; padding: 5px;}
div#Dialkey {position: absolute; left: 330px; top: 395px; background: gray; height:50; width:200; padding: 5px;}
</style>
</head>
<?php
$publisher="10.0.200.10";
$username="root";
$password="xerxes22";
$database="phonedb";
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// if text boxes are blank display instructions
if (!isset($ip))
{
$ip="Enter IP";
}
if (!isset($userid))
{
$userid="Enter User ID";
}
if (!isset($pin))
{
$pin="Enter PIN";
}
if (!isset($dial))
{
$dial="Enter number to dial";
}
// keeps values in the text boxes on submit click
if (isset($_POST['IP']) && isset($_POST['USERID']) && isset($_POST['PIN'])&& isset($_POST['DIAL']) && isset($_POST['MAC']) && isset($_POST['SWITCH']) && isset($_POST['PORT']))
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$dial = $_POST['DIAL'];
$macadd = $_POST['MAC'];
$switchip = $_POST['SWITCH'];
$portno = $_POST['PORT'];
$status = $_POST['STATUS'];
}
//if dblookup is clicked
if (isset($_POST['dblookup']))
{
$query = "SELECT * FROM phones WHERE USERID = '$userid'";
$result = mysql_query($query);
$thisrow=mysql_fetch_row($result);
if ($thisrow) //if the results of the query are not null
{
$ip=$thisrow[1];
$userid=$thisrow[2];
$pin=$thisrow[3];
$xml="";
}
else
{
$pin="USER NOT FOUND";
$ip="IN DB";
}
}
//if any keypad buttons are clicked
if (isset($_POST['keypad']))
//if (isset($_POST['keypad_x']))
{
echo "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
echo "hit it";
$keypad=$_POST['keypad'];
echo $keypad;
// if ($keypad=="*")
// {
// $keypad = "Star";
// }
// if ($keypad=="#")
// {
// $keypad = "Pound";
// }
$xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:KeyPad".$keypad."'/></CiscoIPPhoneExecute>";
EXECUTE($xml);
DEVICEINFO($xml);
}
// if any other key buttons are clicked
if (isset($_POST['key']))
{
$key=$_POST['key'];
$xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:".$key."'/></CiscoIPPhoneExecute>";
EXECUTE($xml);
DEVICEINFO($xml);
}
// if dial button is clicked
if (isset($_POST['dialclick']))
{
$xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Dial:".$dial."'/></CiscoIPPhoneExecute>";
EXECUTE($xml);
DEVICEINFO($xml);
}
// if form is submitted by Connect
if (isset($_POST['auth']))
{
$xml = "";
EXECUTE($xml);
PORT($xml);
DEVICEINFO($xml);
}
if (isset($_POST['refresh']))
{
$xml = "";
EXECUTE($xml);
PORT($xml);
DEVICEINFO($xml);
}
if (isset($_POST['login']))
{
$xml = "";
LOGIN($xml);
//DEVICEINFO($xml);
}
if (isset($_POST['logout']))
{
$xml = "";
LOGOUT($xml);
//DEVICEINFO($xml);
}
// function to send XML to phone
function EXECUTE($xml)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$curl = curl_init("http://".$ip."/CGI/Execute");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "XML=".urlencode($xml));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $userid.":".$pin);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER,1);
$response = curl_exec($curl);
global $status;
if (strpos($response, '<CiscoIPPhoneError Number="1">') !== false || strpos($response, 'Success') !== false)
{
$status="Connected";
$query = "SELECT * FROM phones WHERE USERID = '$userid'";
$result = mysql_query($query);
$thisrow=mysql_fetch_row($result);
if (!$thisrow)
{
$query = "INSERT INTO phones VALUES ('','$ip','$userid','$pin')";
mysql_query($query);
}
}
else
{
$status="Authentication error";
}
return $response;
}
function PORT($xml)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$curl = curl_init("http://".$ip."/CGI/Java/Serviceability?adapter=device.statistics.port.network");
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER,1);
$response = curl_exec($curl);
global $macadd;
$macpos=strrpos($response,"SEP");
if ($macpos>0)
{
$macadd=substr($response,$macpos,15);
}
if(preg_match('@CDP Neighbor IP Address</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$switch))
{
global $switchip;
$switchip=$switch[1];
}
if(preg_match('@CDP Neighbor Port</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$port))
{
global $portno;
$portno=$port[1];
}
return $response;
}
function DEVICEINFO($xml)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$curl = curl_init("http://".$ip."/DeviceInformation");
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER,1);
$response = curl_exec($curl);
if(preg_match('@Message Waiting</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$message))
{
global $messageon;
global $colour;
$messageon=$message[1];
if ($messageon=="Yes")
{
$colour="crimson";
}
else
{
$colour="black";
}
}
return $response;
}
function LOGIN($xml)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$macadd = $_POST['MAC'];
$curl = curl_init("http://10.0.200.10/emapp/EMAppServlet?device=".$macadd."&userid=".$userid."&seq=".$pin."");
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER,1);
$response = curl_exec($curl);
if (strpos($response, 'Login Successful') !== false)
{
usleep(5500000);
global $status;
$status="Login Successful";
$xml = "";
EXECUTE($xml);
PORT($xml);
DEVICEINFO($xml);
}
return $response;
}
function LOGOUT($xml)
{
$ip = $_POST['IP'];
$userid = $_POST['USERID'];
$pin = $_POST['PIN'];
$macadd = $_POST['MAC'];
$curl = curl_init("http://10.0.200.10/emapp/EMAppServlet?device=".$macadd."&doLogout=true");
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER,1);
$response = curl_exec($curl);
if (strpos($response, 'Logout Successful') !== false)
{
global $status;
$status="Logged Out";
}
return $response;
}
// HTML Form stored in php variable
$form =
"
<body>
<form method='post' action='curl.php'>
<div id='Loginfields'>
<input name= 'USERID' type= 'text' value= '$userid' onFocus='clearMe(this)'/><BR>
<input name= 'PIN' width='15' type= 'text' value= '$pin' onFocus='clearMe(this)'/><BR>
<input name= 'IP' type= 'text' value= '$ip' onFocus='clearMe(this)'/><BR>
<input type= 'submit' name= 'auth' value='Connect'/>
<input type= 'submit' name= 'dblookup' value='Lookup'/>
</div>
<div id='Info'>
<input name= 'MAC' type= 'text' value= '$macadd'/><BR>
<input name= 'SWITCH' type= 'text' value= '$switchip'/><BR>
<input name= 'PORT' type= 'text' value= '$portno'/><BR>
<input name= 'STATUS' type= 'text' value= '$status'/><BR>
<input name= 'PUBLISHER' type= 'text' value= '$publisher'/><BR>
<input type= 'submit' name= 'login' value='Login'/>
<input type= 'submit' name= 'logout' value='Logout'/>
</div>
<div id='LineKeys'>
<input type= 'image' name= 'key' value='Line1' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line2' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line3' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line4' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line5' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line6' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line7' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line8' SRC='images/linebutton.png'/>
</div>
<div style='position: absolute; left: 170px; top: 0px; height: 234px; width: 320px; background: black; border-color: $colour; border-style:solid; border-width:5px;'>
<img src='screenshot.php?userid=$userid&pin=$pin&ip=$ip' width='320' height='234'/>
</div>
<div id='Refresh'>
<input type= 'image' name= 'refresh' value='refresh' SRC='images/RefreshUP.png'/>
</div>
<div id='Softkeys'>
<input type= 'image' name= 'key' value='Soft1' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft2' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft3' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft4' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft5' SRC='images/70Softkey.png'/>
</div>
<div id='Keypad'>
<input type= 'image' name= 'keypad' value='1' SRC='images/1UP.png'/>
<input type= 'image' name= 'keypad' value='2' SRC='images/2UP.png'/>
<input type= 'image' name= 'keypad' value='3' SRC='images/3UP.png'/>
<input type= 'image' name= 'keypad' value='4' SRC='images/4UP.png'/>
<input type= 'image' name= 'keypad' value='5' SRC='images/5UP.png'/>
<input type= 'image' name= 'keypad' value='6' SRC='images/6UP.png'/>
<input type= 'image' name= 'keypad' value='7' SRC='images/7UP.png'/>
<input type= 'image' name= 'keypad' value='8' SRC='images/8UP.png'/>
<input type= 'image' name= 'keypad' value='9' SRC='images/9UP.png'/>
<input type= 'image' name= 'keypad' value='Star' SRC='images/STARUP.png'/>
<input type= 'image' name= 'keypad' value='0' SRC='images/0UP.png'/>
<input type= 'image' name= 'keypad' value='Pound' SRC='images/HASHUP.png'/>
</div>
<div id='FunctionkeysL'>
<input type= 'image' name= 'key' value='Messages' SRC='images/MessagesUP.png'/>
<input type= 'image' name= 'key' value='Services' SRC='images/ServicesUP.png'/>
</div>
<div id='FunctionkeysR'>
<input type= 'image' name= 'key' value='Directories' SRC='images/DirectoriesUP.png'/>
<input type= 'image' name= 'key' value='Settings' SRC='images/SettingsUP.png'/>
</div>
<div id='Volume'>
<input type= 'image' name= 'key' value='VolDwn' SRC='images/volumerampUPLEFT.png'/><input type= 'image' name= 'key' value='VolUp' SRC='images/volumerampUPRIGHT.png'/>
</div>
<div id='Soundkeys'>
<input type= 'image' name= 'key' value='Headset' SRC='images/HeadsetUP.png'/>
<input type= 'image' name= 'key' value='Mute' SRC='images/MICUP.png'/>
<input type= 'image' name= 'key' value='Speaker' SRC='images/SpeakerUP.png'/>
</div>
<div id='Dialkey'>
<input name= 'DIAL' type= 'text' value= '$dial' onfocus='clearMe(this)'/><input type= 'submit' name= 'dialclick' value='Dial'/>
</div>
</form>
</body>
";
echo $form;
?>
<script type="text/javascript">
function clearMe(formfield){
if (formfield.defaultValue==formfield.value)
formfield.value = ""
}
</script>