The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Re: xAP and PHP



--------------080704030203050400030805
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

A long time ago i was playing with phpnuke and xAP. It didn't get very
far but could happily send xAP messages from php directly. It does
assume the socket support is loaded in php but on the whole it is.
Below is, i think, all the bits of code that did the actual sending.
Shout if i missed any!

hth
James

//First section of IP of local net
$localip="192.168.0.";
//Broadcast address for sending xAP
$broadcastip="192.168.0.255";
$remoteip=getenv(REMOTE_ADDR);



function SendxAP($xapclass,$xaptarget,$xapbody){
global $localip,$broadcastip;
$xap="xap-header".chr(10)
."{".chr(10)
."v=12".chr(10)
."hop=1".chr(10)
."uid=FF401000".chr(10)
."class=$xapclass".chr(10)
."source=mi4.php.nuke".chr(10);
if
($xaptarget!=""){$xap.="target=$xaptarget".chr(10);};
$xap.="}".chr(10)
.$xapbody;


$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($s == false) {
echo "Error creating socket!\n";
echo "Error:".socket_strerror(socket_last_error($s));
} else {
if (phpversion()<"4.3"){
$opt_ret =  socket_setopt($s, 1, 6, TRUE);
}
else
{
$opt_ret =  socket_set_option($s, 1, 6, TRUE);
};
$e = socket_sendto($s, $xap, strlen($xap), 0, $broadcastip, 3639);
socket_close($s);
};

example send

$xap="Display.Text".chr(10)
."{".chr(10)
."line1=".$line1.chr(10)
."line2=".$line2.chr(10)
."duration=10".chr(10)
."}".chr(10)
."Display.look".chr(10)
."{".chr(10)
."Align=".$align.chr(10)
."}";
SendxAP("message.display",$vfdtarget,$xap);


return 0;
};
Mark Harrison (Groups) wrote:
> On Sat, 2005-12-17 at 01:10 +0000, Andrew Jones wrote:
>
>> Hi everyone. Is it possible to run xAP Send from a PHP page? At
the
>> moment I have the following code:
>>
>> <?php
>> system("C:\Program Files\xAPFramework.net\xAP Send\Send.exe
on.xap")
>> ?>
>>
>> ...which does nothing. I've put '> null' at the end but it
doesn't
>> help. I don't know PHP so it's probably completely wrong :)
>>
>> Any ideas? By the way, I'm using IIS 4, and phpinfo() shows the
>> information it should, so PHP looks like it's ok.
>>
>
> I use Apache2 and Perl, and the code I have is in a routine called
> xap.cgi which takes the name of a pre-canned xap file as the argument:
>
> ------------------------------------------
>
> print "Cotent-type: text/plan\n\n";
> print "<HEAD>";
> $xapcall="xap-send.exe ".$ENV("QUERY_STRING")
> print "<META-EQUIV=\"Refresh\"
Content=\"0;URL=\\lounge.html/">";
> system $xapcall > null;
> print "\n<\HEAD>";
>
> ------------------------------------------
>
>
> Apart from the obvious "different context" issues, there is
the
> difference that I ended up putting xap-send in the path rather than
> trying to reference it by location.
>
>
> In debugging, ISTR that I had to work out whether it was a PERL issue
or
> a xAP issue, and that the way I did that was putting replacing
> "xap-send.exe" with a call to "notepad.exe" and
watch for whether
> notepad appeared on the server console :-)
>
> Mark
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>


--------------080704030203050400030805
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">


A long time ago i was playing with phpnuke and xAP. It didn't get very
far but could happily send xAP messages from php directly. It does
assume the socket support is loaded in php but on the whole it
is.&nbsp;
Below is, i think, all the bits of code that did the actual sending.
Shout if i missed any!<br>
<br>
hth<br>
James<br>
<br>
//First section of IP of local net<br>
$localip="192.168.0.";<br>
//Broadcast address for sending xAP<br>
$broadcastip="192.168.0.255";<br>
$remoteip=getenv(REMOTE_ADDR);<br>
<br>
<br>
<br>
function SendxAP($xapclass,$xaptarget,$xapbody){<br>
global $localip,$broadcastip;<br>
$xap="xap-header".chr(10)<br>
."{".chr(10)<br>
."v=12".chr(10)<br>
."hop=1".chr(10)<br>
."uid=FF401000".chr(10)<br>
."class=$xapclass".chr(10)<br>
."source=mi4.php.nuke".chr(10);<br>
if
($xaptarget!=""){$xap.="target=$xaptarget".chr(10);};<br>
$xap.="}".chr(10)<br>
.$xapbody;<br>
<br>
<br>
&nbsp; $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);<br>
&nbsp; if ($s == false) {<br>
&nbsp;&nbsp; echo "Error creating socket!\n";<br>
&nbsp;&nbsp; echo
"Error:".socket_strerror(socket_last_error($s));<br>
&nbsp; } else { <br>
if (phpversion()&lt;"4.3"){<br>
$opt_ret =&nbsp; socket_setopt($s, 1, 6, TRUE);<br>
}<br>
else<br>
{<br>
$opt_ret =&nbsp; socket_set_option($s, 1, 6, TRUE);<br>
};<br>
$e = socket_sendto($s, $xap, strlen($xap), 0, $broadcastip,
3639);&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp; socket_close($s);<br>
};<br>
<br>
example send<br>
<br>
$xap="Display.Text".chr(10)<br>
."{".chr(10)<br>
."line1=".$line1.chr(10)<br>
."line2=".$line2.chr(10)<br>
."duration=10".chr(10)<br>
."}".chr(10)<br>
."Display.look".chr(10)<br>
."{".chr(10)<br>
."Align=".$align.chr(10)<br>
."}";<br>
SendxAP("message.display",$vfdtarget,$xap);<br>
<br>
<br>
return 0;<br>
};<br>
Mark Harrison (Groups) wrote:
<blockquote cite="mid1134816589.15879.140.camel@xxxxxxx"
type="cite">
<pre wrap="">On Sat, 2005-12-17 at 01:10 +0000, Andrew
Jones wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi everyone. Is it possible to run xAP Send
from a PHP page? At the
moment I have the following code:

&lt;?php
system("C:\Program Files\xAPFramework.net\xAP Send\Send.exe
on.xap")
?&gt;

...which does nothing. I've put '&gt; null' at the end but it doesn't
help. I don't know PHP so it's probably completely wrong :)

Any ideas? By the way, I'm using IIS 4, and phpinfo() shows the
information it should, so PHP looks like it's ok.
</pre>
</blockquote>
<pre wrap=""><!---->
I use Apache2 and Perl, and the code I have is in a routine called
xap.cgi which takes the name of a pre-canned xap file as the argument:

------------------------------------------

print "Cotent-type: text/plan\n\n";
print "&lt;HEAD&gt;";
$xapcall="xap-send.exe ".$ENV("QUERY_STRING")
print "&lt;META-EQUIV=\"Refresh\"
Content=\"0;URL=\\lounge.html/"&gt;";
system $xapcall &gt; null;
print "\n&lt;\HEAD&gt;";

------------------------------------------


Apart from the obvious "different context" issues, there is the
difference that I ended up putting xap-send in the path rather than
trying to reference it by location.


In debugging, ISTR that I had to work out whether it was a PERL issue or
a xAP issue, and that the way I did that was putting replacing
"xap-send.exe" with a call to "notepad.exe" and watch
for whether
notepad appeared on the server console :-)

Mark




xAP_Automation Main Index | xAP_Automation Thread Index | xAP_Automation Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.