Jonathan k. Creasy
2005-Sep-13 18:21 UTC
[Asterisk-Users] populating asterisk realtime tables from configfiles
Here is my file to parse and load extensions. No wise cracks about my code.... DB.php is the Pear DB module. (pear.php.net) <?php include('DB.php'); $db_host = ''; $db_name = ''; $db_login = ''; $db_pass = ''; $db_table = 'extensions_table'; define(DBINFO,"mysql://$db_login:$db_pass@$db_host/$db_name"); $db = DB::CONNECT(DBINFO); if(!DB::isError($db)) { //we got the db connection $extensions = file('extensions.conf'); foreach($extensions as $extension) { $application = ''; if (substr($extension,0,1)=='[') { $context=substr($extension,1,strpos($extension,']')-1); } else if (substr($extension,0,5)=='exten') { $rule=explode(',',$extension); $exten=trim(substr($rule[0],strpos($rule[0],'=>')+2)); $priority=$rule[1]; for ($i=2;$i<sizeOf($rule);$i++) { $application.=$rule[$i]; if($i<sizeOf($rule)-1) $application.=","; } if (strpos($application,'(')!=0) { $app substr($application,0,strpos($application,'(')); $appdata=substr($application,strpos($application,'(')+1); $appdata=substr($appdata,0,strpos($appdata,')')); } else { $app = $application; $appdata = ''; } } $sql=''; if ($context!=''&&$exten!=''&&$priority!=''&&$app!='') { $sql = "insert into $db_table (context,exten,priority,app,appdata) values('$context','$exten','$priority','$app','$appdata')"; $result = $db->query($sql); if(DB::isError($result)) echo $result->toString(); } } } ?> -----Original Message----- From: asterisk-users-bounces@lists.digium.com [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Jonathan k. Creasy Sent: Tuesday, September 13, 2005 8:39 PM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: [Asterisk-Users] populating asterisk realtime tables from configfiles Does any one have a script (I prefer PHP) that reads the config files, parses them and inserts data into the asterisk realtime tables for IAX, SIP, Voicemail and Extensions? I'm about to write one for each and I wanted to make sure it wasn't out there. I did a quick search and didn't find anything. I'll add them to the wiki when I'm done. -Jonathan _______________________________________________ --Bandwidth and Colocation sponsored by Easynews.com -- Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Matt
2005-Sep-14 05:02 UTC
[Asterisk-Users] populating asterisk realtime tables from configfiles
Along this same note.... has anyone gotten voicemail.conf into real-time database? I can not for the life of me get it to work. On 9/13/05, Jonathan k. Creasy <jonathan@bluegrass.net> wrote:> Here is my file to parse and load extensions. No wise cracks about my > code.... > > DB.php is the Pear DB module. (pear.php.net) > > > <?php > include('DB.php'); > > $db_host = ''; > $db_name = ''; > $db_login = ''; > $db_pass = ''; > $db_table = 'extensions_table'; > > define(DBINFO,"mysql://$db_login:$db_pass@$db_host/$db_name"); > > $db = DB::CONNECT(DBINFO); > > if(!DB::isError($db)) { > //we got the db connection > > $extensions = file('extensions.conf'); > foreach($extensions as $extension) { > $application = ''; > if (substr($extension,0,1)=='[') { > > $context=substr($extension,1,strpos($extension,']')-1); > } > else if (substr($extension,0,5)=='exten') { > $rule=explode(',',$extension); > > $exten=trim(substr($rule[0],strpos($rule[0],'=>')+2)); > $priority=$rule[1]; > for ($i=2;$i<sizeOf($rule);$i++) { > $application.=$rule[$i]; > if($i<sizeOf($rule)-1) > $application.=","; > } > if (strpos($application,'(')!=0) { > $app > substr($application,0,strpos($application,'(')); > > $appdata=substr($application,strpos($application,'(')+1); > > $appdata=substr($appdata,0,strpos($appdata,')')); > } else { > $app = $application; > $appdata = ''; > } > } > $sql=''; > if ($context!=''&&$exten!=''&&$priority!=''&&$app!='') { > $sql = "insert into $db_table > (context,exten,priority,app,appdata) > values('$context','$exten','$priority','$app','$appdata')"; > $result = $db->query($sql); > if(DB::isError($result)) > echo $result->toString(); > } > } > } > ?> > > > -----Original Message----- > From: asterisk-users-bounces@lists.digium.com > [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Jonathan > k. Creasy > Sent: Tuesday, September 13, 2005 8:39 PM > To: Asterisk Users Mailing List - Non-Commercial Discussion > Subject: [Asterisk-Users] populating asterisk realtime tables from > configfiles > > Does any one have a script (I prefer PHP) that reads the config files, > parses them and inserts data into the asterisk realtime tables for IAX, > SIP, Voicemail and Extensions? > > I'm about to write one for each and I wanted to make sure it wasn't out > there. I did a quick search and didn't find anything. > > I'll add them to the wiki when I'm done. > > -Jonathan > _______________________________________________ > --Bandwidth and Colocation sponsored by Easynews.com -- > > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users > _______________________________________________ > --Bandwidth and Colocation sponsored by Easynews.com -- > > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >
Maybe Matching Threads
- Sequential Sum in R
- icecast2 ogg vorbis client request headers
- Storeconfigs purge Perl
- Joining R Local Dataset with Table from Database
- [975] branches/wxruby2/wxwidgets_282/rake/rakemswin.rb: Correct spacing for link command; remove odbc and db_table which aren''t