Simple web interface for managing CID names:
Make sure to edit /etc/sudoers accordingly, for example using ‘visudo’ add an entry like:
apache ALL = NOPASSWD: /usr/sbin/asterisk -rx database *
== cid-form.php ==
<html>
<head>
<title>Asterisk Caller ID form</title>
</head>
<body>
<h1>Asterisk phone book</h1>
<form name=”EntryForm” action=”cid-store.php” method=POST>
<table cellpadding=2>
<tr>
<td>Phone number:</td>
<td><input name=”PhoneNumber” size=30></td>
</tr>
<tr>
<td>Name:</td>
<td><input name=”PhoneName” size=30></td>
</tr>
<tr>
<td></td>
<td><div align=right>
<input type=submit value=”Save”>
</div></td>
</tr>
</table>
</form>
</body>
</html>
== cid-store.php ==
<HEAD>
<TITLE>Storing Asterisk CID data</TITLE>
</HEAD>
<BODY>
<h1>Asterisk phone book</h1>
<?php
set_time_limit(5);
if ($PhoneNumber <> “” && $PhoneName <> “”) {
// Note: this PHP script runs as user “apache”!
// system(“whoami > /tmp/info”);
system(“sudo /usr/sbin/asterisk -rx ” . escapeshellarg(“database put cidname $PhoneNumber \”$PhoneName\””) . ” &> /tmp/error”);
print “Successfully stored <b>$PhoneNumber</b> as <b>$PhoneName</b>.”;
} else {
print “Please enter both phone number and name!”;
}
?>
</BODY>
</HTML>
== cid-list.php ==
</HEAD>
<BODY>
<h1>Asterisk phone book</h1>
<?php
set_time_limit(5);
system(“sudo /usr/sbin/asterisk -rx \”database show cidname\” > /tmp/asterisk_cid-list.txt”);
$fd=fopen(“/tmp/asterisk_cid-list.txt”,”r”);
while ($line=fgets($fd,1000))
{
$alltext.=$line;
}
fclose ($fd);
print str_replace(“\n”, “<br>”, $alltext);
?>
</BODY>
</HTML>
Following the examples above you’ll not have much trouble to add a DELETE function as well.
Contributed by Philipp von Klitzing