I'm trying to use LISTSERV's "API" in PHP. L-Soft calls this TCPGUI, and essentially, you can request data like over Telnet. To do this, I'm using PHP's TCP socket functions.
I've seen this done in other languages but can't quite convert it to PHP. I can connect, I can change set ASCII or BINARY mode. But I can never quite craft the header packet the way I need to authenticate, so I'm thinking I'm messing up my conversion.
C: http://www.lsoft.com/manuals/16.0/htmlhelp/advanced%20topics/TCPGUI.html#2334328
$origin = '
[email protected]';
$pwd = 'password';
$host = "example.com";
$port = 2306;
$email = "
[email protected]";
$list = "mailinglist";
$command = "Query $list FOR $email";
$fp = stream_socket_client("tcp://$host:$port", $errno, $errstr, 30);
$cmd = $command . " PW=" . $pwd;
$len = strlen($cmd);
$orglen = strlen($origin);
$n = $len + $orglen + 1;
$headerPacket[0] = "1";
$headerPacket[1] = "B";
$headerPacket[2] = "\r";
$headerPacket[3] = "\n";
$headerPacket[4] = ord($n / 256);
$headerPacket[5] = ord($n + 255);
$headerPacket[6] = ord($orglen);
for ($i = 0; $i < $orglen; $i++) {
$headerPacket[$i + 7] = ord($origin[$i]);
}
for ($i = 0; $i < $len; $i++) {
$cmdPacket[$i] = ord($cmd[$i]);
}
fwrite($fp, implode($headerPacket));
while (!feof($fp)) {
echo fgets($fp, 1024);
}
Any thoughts on where I'm going wrong? I'd much appreciate it if anyone could point me toward some code to do this, days of googling and searching here on SO has only lead me to examples in other languages.
Of course, if you know C (or Java or Perl as linked below in my comment to bypass the spam filter), PHP, and socket programming fairly well, you could probably rewrite the whole of the code in an hour, maybe a few minutes. You'd have my eternal thanks for that.