Upgrade 3CX to v18 and get it hosted free!

Asterisk tips managing CID names

Author image

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 ==

<HTML>
<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


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.