
| Code: |
| root> apt-get update |
| Code: |
| root> apt-get install mysql-server mysql-client php5-mysql
root> apt-get install apache2 php5 libapache2-mod-php5 |
| Code: |
| root> apt-get install ntp |
| Code: |
| root> apt-get install php5-cli |
| Code: |
| root> apt-get install pdns-server |
| Code: |
| root> apt-get install pdns-backend-mysql |
| Code: |
| root> nano /etc/powerdns/pdns.conf |
| Code: |
| root> mysql -u root |
| Code: |
| MySQL> GRANT ALL PRIVILEGES ON *.* TO 'pdns'@'localhost' IDENTIFIED BY '[PASSWORD YOU CHOSE]' WITH GRANT OPTION; |
| Code: |
| MySQL> create database pdns; |
| Code: |
| MySQL> create table domains (
id INT auto_increment, name VARCHAR(255) NOT NULL, master VARCHAR(128) DEFAULT NULL, last_check INT DEFAULT NULL, type VARCHAR(6) NOT NULL, notified_serial INT DEFAULT NULL, account VARCHAR(40) DEFAULT NULL, primary key (id) )type=InnoDB; CREATE UNIQUE INDEX name_index ON domains(name); CREATE TABLE records ( id INT auto_increment, domain_id INT DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, type VARCHAR(6) DEFAULT NULL, content VARCHAR(255) DEFAULT NULL, ttl INT DEFAULT NULL, prio INT DEFAULT NULL, change_date INT DEFAULT NULL, primary key(id) )type=InnoDB; CREATE INDEX rec_name_index ON records(name); CREATE INDEX nametype_index ON records(name,type); CREATE INDEX domain_id ON records(domain_id); create table supermasters ( ip VARCHAR(25) NOT NULL, nameserver VARCHAR(255) NOT NULL, account VARCHAR(40) DEFAULT NULL ); GRANT SELECT ON supermasters TO pdns; GRANT ALL ON domains TO pdns; GRANT ALL ON records TO pdns; |
| Code: |
| MySQL> INSERT INTO records (domain_id, name, content, type,ttl,prio)
VALUES (1,'e164.mydomain.net','ns.mydomain.net','NS',86400,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'e164.mydomain.net','ns2.mydomain.net','NS',86400,NULL); |
| Code: |
| MySQL> INSERT INTO records (domain_id, name, content, type,ttl,prio)
VALUES (1,'ns.mydomain.net','[IP Address of the ENUM server you're building]','A',120,NULL); |
| Code: |
| MySQL> INSERT INTO records (domain_id, name, content, type,ttl,prio)
VALUES (1,'ns2.mydomain.net','[IP Address of the ENUM server you're building]','A',120,NULL); |
| Code: |
| MySQL> INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'mydomain.net','localhost hostmaster<at>mydomain.net 2008082803','SOA',86400,NULL); |
| Code: |
| MySQL> INSERT INTO `records` VALUES (16, 1, '0.0.1.e164.mydomain.net', 'NAPTR', '100 10 "u" "E2U+sip" "!^.*$!sip:hello@mydomain.net!" .', 600, NULL, NULL); |
| Code: |
| root> dig 0.0.1.e164.mydomain.net ANY
; <<>> DiG 9.4.2-P1 <<>> 0.0.1.e164.mydomain.net ANY ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9906 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;0.0.1.e164.mydomain.net IN ANY ;; ANSWER SECTION: 0.0.1.e164.mydomain.net. 591 IN NAPTR 100 10 "u" "E2U+sip" "!^.*$!sip:hello@mydomain.net!" . ;; Query time: 107 msec ;; SERVER: 192.168.1.254#53(192.168.1.254) ;; WHEN: Sat Aug 16 15:36:01 2008 ;; MSG SIZE rcvd: 100 |
| Code: |
|
<?php /////////////////////////////////////////////////////////////////////////////////////////////// // // ENUM webservices API functions // // Version 0.1 by Dean Elwood 1st August 2008 // // A set of functions to add, delete and update records in a central ENUM database. // // Released under GNU Public licence http://www.gnu.org/licenses/gpl.txt // /////////////////////////////////////////////////////////////////////////////////////////////// // EDIT THIS $database_password = "[SET THIS TO YOUR DB PASSWORD]"; $logfile_path = "[SET THIS TO YOUR LOGFILE PATH]"; // AND DON'T FORGET TO CHANGE ALL REFERENCES TO mydomain.net TO YOUR OWN DOMAIN function getEnumDatabaseConnection () { $connection = mysql_connect("localhost", "pdns", $database_password) or die ("Cannot make the connection"); $db = mysql_selectdb("pdns", $connection) or die ("Cannot connect to the database"); return $db; } function logThis($text) { if (!$fp = fopen($logfile_path, 'a')) { $result = "0"; } else { flock ($fp, LOCK_SH); $result = fwrite($fp, date("y-m-d G.i:s", time())." ".$text."\n"); flock($fp, LOCK_UN); fclose($fp); } return $result; } function cleanUpNumber($number) { // Strip leading chars $number = trim($number); // Strip non-numerics $number = preg_replace ("/[^0-9]/", "", $number); // Strip leading zeros while ( $number[0] == "0" ) { $number = ltrim($number, "0"); } return $number; } function enumFormat($number) { // Takes an e164 formatted number and returns ENUM formatted $number = cleanUp($number); $e164 = ereg_replace("[^0-9]", "", $number); // Reverse the order of our e164 number and put dots in between $rev_e164 = ""; for ($i = strlen($e164); $i >= 0; $i-- ) { $rev_e164 .= $e164[$i]; if ( $i != strlen($e164) ) { $rev_e164 .= "."; } } // Shove our private tree tail on the end $rev_e164 .= "e164.mydomain.net"; return $rev_e164; } function getEnumRecord($number) { $enum = enumFormat($number); $db = getEnumDatabaseConnection(); $sql = "SELECT * FROM `records` WHERE `name` = '$enum' LIMIT 1"; $result = mysql_query($sql); if ($result) { $row = mysql_fetch_row($result); $response = $row['0']; } else { $response = False; } return $response; } function addEnumRecord($sipUri, $number) { // Check it doesn't already exist... logThis("Trying to add $sipUri as destination for $number"); if ( getEnumRecord($number) ) { $response = False; } else { $enum = enumFormat($number); $content = "100 10 \"u\" \"E2U+sip\" \"!^.*$!sip:".$sipUri."!\" ."; // Shove it in the DB as a new NAPTR record $db = getEnumDatabaseConnection(); $sql = "INSERT INTO `records` values('', '10', '$enum', 'NAPTR', '$content', '600', NULL, UNIX_TIMESTAMP());"; $response = mysql_query($sql); if (!$response) { logThis("Database insert failed trying to add enum record."); } else { logThis("Added $number to ENUM routing to $sipUri"); } } return $response; } function updateEnumRecord($number, $sipUri) { $enum = enumFormat($number); $content = "100 10 \"u\" \"E2U+sip\" \"!^.*$!sip:".$sipUri."!\""; $db = getEnumDatabaseConnection(); $sql = "UPDATE `records` SET `content` = '$content' WHERE `name` ='$enum' LIMIT 1"; $response = mysql_query($sql); if (!$response) { logThis("Database insert failed trying to update enum record."); } return $response; } function deleteEnumRecord($recordId) { $db = getEnumDatabaseConnection(); $sql = "DELETE FROM `records` WHERE `id` = '$recordId'"; $response = mysql_query($sql); if (!$response) { logThis("Database insert failed trying to delete enum record."); } return $response; } ?> |
| Code: |
|
<?php /////////////////////////////////////////////////////////////////////////////////////////////// // // ENUM Webservice API // // Version 0.1 by Dean Elwood 1st August 2008 // // Released under GNU Public licence http://www.gnu.org/licenses/gpl.txt // // /////////////////////////////////////////////////////////////////////////////////////////////// // EDIT THIS LINE include_once('[/path/to/the/functions/file/above]'); $todo = $_GET['todo']; $number = $_GET['number']; $sipuri = $_GET['sipuri']; $success = false; switch ($todo) { case "add" : $success = addEnumRecord($sipuri, $number); break; case "delete" : $recordId = getEnumRecord($number); if ( $recordId > 0 ) { $success = deleteEnumRecord($recordId); } else { $success = False; } break; case "update" : $success = updateEnumRecord($sipuri, $number); break; default : echo "Nothing to do?\n"; break; } if ( $success ) { echo $success; } else { print_r($_GET); } ?> |
| Code: |
| http://mydomain.net/webservice.php?todo=add&number=200&sipuri=hello2@mydomain.net |
| Code: |
|
# enum section # - This snippet should be placed in your local number routing block # - ENUM_REGEX_VAL should be replaced with a valid regex to suit your environment # - e164.voipuser.org should be replaced with your enum server if ( (method=="INVITE" || method=="CANCEL") && uri=~"ENUM_REGEX_VAL") { xlog("SCRIPT: trying enum lookup for [$ru]\n"); if (enum_query("e164.mydomain.net")) { xlog("SCRIPT: enum lookup [ => $ru]\n"); if (!(uri==myself )) { append_hf("P-hint: ENUM-OUTBOUND\r\n"); return(-1); } } } |
| Code: |
| [enum]
; enum lookup. ;The folllowing may need regionalising if your international numbers dont start 00 when dialing. exten=> _740XXX.,1,Set(enum_m=${EXTEN:2:2}) exten=> _740XXX.,n,GotoIf($["${enum_m}" = "00"]?3:120) exten=> _740XXX.,n,Set(enum_d=${EXTEN:4}) exten=> _740XXX.,n,Set(enum_n=${ENUMLOOKUP(+${enum_d},,,e164.mydomain.net)}) exten=> _740XXX.,n,Set(enum_c=${ENUMLOOKUP(+${enum_d},,c,e164.mydomain.net)}) exten=> _740XXX.,n,NoOp(${enum_c}) exten=> _740XXX.,n,GotoIf($["${enum_c}" = "0"]?102) exten=> _740XXX.,n,GotoIf($["${enum_c}" = ""]?102) exten=> _740XXX.,n,NoOp(SIP/${enum_n}) exten=> _740XXX.,n,Dial(SIP/${enum_n}) exten=> _740XXX.,n,Hangup() exten=> _740XXX.,102,Dial,${TRUNKout}/${EXTEN:2} exten=> _740XXX.,103,Hangup() exten=> _740XXX.,111,Hangup() exten=> _740XXX.,120,Set(enum_d=44${EXTEN:3}) ; You need to make sure your national code is here |
| Forum Rules and Guidelines | About VoIP User | Privacy Policy |
All logos and trademarks in this site are property of their respective owner. Comments and posts are property of the poster, all the rest (c) 2003-2008 VoIP User Limited. VoIP User Limited is incorporated in England and Wales under Company Number 6694577. No part of this site may be reproduced without our prior consent. |