Created
April 21, 2014 12:41
-
-
Save nonoo/11141669 to your computer and use it in GitHub Desktop.
Procmail config and PHP script for sending email source address and subject to given callsigns through APRS-IS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#LOGFILE=/home/nonoo/procmail.log | |
#VERBOSE=YES | |
:0 | |
* ^List-ID: <aprs.nonoo.hu>$ | |
| /home/nonoo/bin/mail2aprs.php | |
:0 | |
* ^List-ID: <aprs.nonoo.hu>$ | |
/dev/null | |
:0: | |
! [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php5 | |
<?php | |
$aprs_callsign = 'CALLSIGN-15'; | |
$aprs_passcode = 0; | |
$aprs_dsts = array('CALLSIGN-1', 'CALLSIGN-2'); | |
// Reading the message from stdin | |
$f = fopen('php://stdin', 'r'); | |
while ($line = fgets($f)) { | |
if (preg_match('/^Subject:/', $line)) | |
$msg = trim(str_replace('Subject: ', '', $line)); | |
if (preg_match('/^X-Original-Sender:/', $line)) | |
$from = trim(str_replace('X-Original-Sender: ', '', $line)); | |
if (isset($msg) && isset($from)) | |
break; | |
} | |
fclose($f); | |
if (!isset($msg) || !isset($from)) | |
die(); | |
$msg = "$from: $msg"; | |
$msg = substr($msg, 0, 67); // Trimming string to max. 67 chars | |
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
if ($socket) { | |
$result = socket_connect($socket, 'hun.aprs2.net', 14580); | |
if ($result) { | |
// Authenticating | |
$tosend = "user $aprs_callsign pass $aprs_passcode\n"; | |
socket_write($socket, $tosend, strlen($tosend)); | |
$authstartat = time(); | |
$authenticated = false; | |
while ($msgin = socket_read($socket, 1000, PHP_NORMAL_READ)) { | |
if (strpos($msgin, "$aprs_callsign verified") !== FALSE) { | |
$authenticated = true; | |
break; | |
} | |
// Timeout handling | |
if (time()-$authstartat > 5) | |
break; | |
} | |
if ($authenticated) { | |
foreach ($aprs_dsts as $dst) { | |
$tosend = "$aprs_callsign>APRS,TCPIP*::" . str_pad($dst, 9, ' ') . ":$msg\n"; | |
socket_write($socket, $tosend, strlen($tosend)); | |
} | |
} | |
} | |
socket_close($socket); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment