Sendpage hack
By Mike on January 29th, 2007
sendPage is UNIX based utility to send alphanumeric pages via TAP. It is great as a means to send “out of band” Nagios alerts. A simple PHP script is included in the distribution to allow you to send pages via a simple web page. But in order to send the pages you need to remember the recipient address in the form number@PC (PC stands for Paging Central – see the sendPage documentation for more information). Since I already have too many things to remember I wrote a quick and dirty hack to the sendpage.php script to list the valid recipients from the sendpage.conf file in /etc as a table at the top of the form. Your web server will need to be able to read /etc/sendpage.conf, so be sure to check permissions.
> sendpage.php
<html>
<head>
<title>Send Page</title>
</head>
<body>
<!--
$Id: sendpage.php,v 1.2 2004/01/16 02:03:20 nemies Exp $
# Copyright (C) 2000,2001 Kees Cook
# kees@outflux.net, http://outflux.net/
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html
-->
<h1>Send Page</h1>
<?php
if (isset($_POST[pageto]) && $_POST[pageto] != "" &&
isset($_POST[pagefrom]) && $_POST[pagefrom] != "" &&
isset($_POST[pagetext]) && $_POST[pagetext] != "") {
$pageto = $_POST[pageto];
$pagefrom = $_POST[pagefrom];
$pagetext = $_POST[pagetext];
?>
<ul>
<hr>
<?php
$snpp = popen ("/usr/bin/snpp -f ".EscapeShellCmd($pagefrom)." ".EscapeShellCmd($pageto),"w");
if ($snpp) {
fwrite ($snpp,$pagetext);
$ret=(pclose($snpp)>>8)&0xFF;
$snpp=($ret == 0);
}
if (!$snpp) {
?>Sorry, an error occured sending your page!<?php
}
else {
?>
Page sent:<br>
<pre>
To: <?php echo stripslashes($pageto) ?>
From: <?php echo stripslashes($pagefrom) ?>
Text:
<?php echo stripslashes($pagetext) ?>
</pre>
<?php
}
?>
<hr>
</ul>
<?php
}
$recipstart = 0;
echo "<p>Possible destinations (use the Destination text in the To field):\\n";
echo "<table border=1><th align=left>Recipient</th><th align=left>Destination</th>";
$cfgfile = file("/etc/sendpage.cf");
foreach ($cfgfile as $line) {
if (substr($line, 0, 7) == "[recip:") {
$recipname = substr($line, 7, strpos($line, "]")-7);
echo "<tr><td>$recipname</td>";
$recipstart = 1;
}
if (($recipstart == 1) && (substr($line, 0, 4) == "dest")) {
$esign = strpos($line, "=");
$dest = substr($line, $esign+1);
echo "<td>$dest</td></tr>";
$recipstart = 0;
}
}
echo "</table></p><p>";
?>
<p>
<form method="POST" action="<?php print $SCRIPT_NAME ?>">
Please fill out the following information to send a page....
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td><font<?php if ($pageto=="" && isset($send)) print ' color="#FF0000"'; ?>>To:</font></td>
<td><input type=text name="pageto" value="<?php echo $pageto ?>" columns="15"><br></td>
</tr>
<tr>
<td><font<?php if ($pagefrom=="" && isset($send)) print ' color="#FF0000"'; ?>>From:</font></td>
<td><input type=text name="pagefrom" value="<?php echo $pagefrom ?>" columns="40"><br></td>
</tr>
<tr>
<td><font<?php if ($pagetext=="" && isset($send)) print ' color="#FF0000"'; ?>>Text:</font><br></td>
<td><TEXTAREA NAME="pagetext" ROWS="4" COLS="40" WRAP="SOFT"><?php echo stripslashes($pagetext) ?></TEXTAREA></td>
</tr>
</table>
<p>
<input type="submit" name="send" value="Send">
</form>
<hr>
</body>
</html>
Leave a Response