[asterisk-users] recreating extensions.conf from live dialplan ?

Steve Edwards asterisk.org at sedwards.com
Wed Apr 13 12:26:35 CDT 2016


On Wed, 13 Apr 2016, Jeremy Kister wrote:

> Between my older backup and dialplan show, I guess that's my best shot.

This should get you close:

         sudo asterisk -r -x 'dialplan show' >extensions.wip

and then feed extensions.wip through:

#!/usr/bin/env php
<?php

// declare variables
 	$tokens = array();

// loop through stdin
 	while	($line = fgets(STDIN))
 		{

// blank line
 		if	("\n" == $line)
 			{
 			printf("\n");
 			continue;
 			}

// remove 'features'
 		$line = str_replace('[features]', '', $line);

// remove 'pbx_config'
 		$line = str_replace('[pbx_config]', '', $line);

// context
 		if	('[' == substr($line, 0, 1))
 			{
 			$tokens = explode("'", $line);
 			printf("[%s]\n", $tokens[1]);
 			continue;
 			}

// extension
 		if	("'" == substr($line, 2, 1))
 			{
 			$tokens = explode("'", $line);
 			$line = substr($line, strpos($line, ' ', 20) + 1, 255);
 			printf("\texten = %s,1,\t\t\t%s", $tokens[1], $line);
 			continue;
 			}

// label
 		if	('[' == substr($line, 5, 1))
 			{
 			$line = str_replace(']', '[', $line);
 			$tokens = explode('[', $line);
 			printf("\tsame = n(%s),\t\t\t%s", $tokens[1], $line);
 			continue;
 			}

// anything else
 		$line = substr($line, strpos($line, ' ', 20) + 1, 255);
 		printf("\tsame = n,\t\t\t%s", $line);

 		}

// (end)?>

(I'm not all that hot of a PHP programmer, so if anybody has some 
constructive criticism, please jump it.)

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
             https://www.linkedin.com/in/steve-edwards-4244281



More information about the asterisk-users mailing list