From: Michael K. <mic...@ip...> - 2007-04-22 10:54:35
|
Tom or anyone As I use the DB for a large part of my configuration, this piece of PHP code will come in very handy. I have it all working except that any DB entry that has a / in it does not display any characters after the /. As I am not a very experienced programmer, could someone let me know how to fix this problem. I am sure it is a syntax problem in this line: preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, $temp); Anyones help is very much appreciated. Regards Michael Knill -----Original Message----- From: ast...@ja... [mailto:ast...@ja...]On Behalf Of Tom Lynn Sent: Tuesday, 14 November 2006 7:00 AM To: Discussion of AstLinux - Asterisk on Compact Flash Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse Turns out the script was scrubbed off of my e-mail. Here it is for anybody that is interested. <html> <head> <?php import_request_variables("GP"); ?> <META http-equiv="Content-Style-Type" content="text/css"> <link href="default.css" rel="stylesheet" type="text/css"> <? if ($mode == "put"){ echo '<meta http-equiv="Refresh" Content="2; URL='.$self.'?mode=show">';} ?> </head> <BODY> <?php include "header.php"; ?> <? // ----------------------------------------------------------------------- begin ast db show if(!isset($mode)|| $mode == 'show') { echo 'Asterisk Database Maintenance<P><a href="'.$self.'?mode=form">New Entry</a> - Or edit existing below<P>'; $man_name = "php"; $man_pword = "supersecret"; $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); // open a connection to the manager interface fputs($socket, "Action: Login\r\n"); // login fputs($socket, "UserName: $man_name\r\n"); // send username fputs($socket, "Secret: $man_pword\r\n\r\n"); // send password fputs($socket, "Action: Command\r\n"); // tell it a command is coming fputs($socket, "Command: database show\r\n\r\n"); // ask for the contents of the database fputs($socket, "Action: Logoff\r\n\r\n"); // logoff while (!feof($socket)) { $dbentries .= fread($socket, 8192); // read the entire output into $dbentries } fclose($socket); // close the socket $array = preg_split("/\n/",$dbentries, -1, PREG_SPLIT_NO_EMPTY); // split $dbentries on newline characters and store in $array for ($i = 1; $i < 7; $i++) { array_shift($array); // get rid of 7 lines of useless garbage (need a test for this) } $bgcolor='white'; // set a background color for the table $color_state=true; // use it when $color_state = true ?> <table border="0" cellspacing="2"> <tr bgcolor="#EEEEEE"> <td>Family</td> <td>Key</td> <td>Value</td> </tr> <? foreach($array as $value) { if (strncmp($value, '--END COMMAND', 13) == 0) { // look for the end of the output break; // stop showing records at this point } preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, $temp); // isolate Family, Key and Value into $temp[] array_shift($temp); // shift off the matched portion $querystring = 'mode=form&family='.urlencode($temp[0]).'&key='.urlencode($temp[1]).'&value= '.urlencode($temp[2]); // build some of the URI for this value ?> <tr bgcolor=<? echo("$bgcolor");?>> <td><? echo '<a href="'.$self.'?'.htmlspecialchars($querystring).'">'.$temp[0].'</a>';?></td > <td><? echo($temp[1]); ?></td> <td><? echo($temp[2]); ?></td> </tr> <? $color_state = !$color_state; // flip the color state if ($color_state) { $bgcolor = 'white'; // if true use lightblue; } else { $bgcolor = '#EEEEEE'; // else use wheat } } } //------------------------------------------------------------------------ end ast db show // ------------------------------------------------------------------------- begin ast db form if ($mode == "form") { ?> <P><P><P></P> <FORM ACTION="<? echo "$self"; ?>" METHOD="POST"> <table border="0" width="60%"> <tr> <td width="20%" valign="top"><b>Family</b></td> <td width="80%" valign="top"><INPUT TYPE="text" NAME="family" value="<? echo htmlspecialchars(stripslashes($family));?>" SIZE=40><br><br> </td> </tr> <tr> <td width="20%" valign="top"><b>Key</b></td> <td width="80%" valign="top"><INPUT TYPE="text" NAME="key" value="<? echo htmlspecialchars(stripslashes($key));?>" SIZE=40><br><br> </td> </tr> <tr> <td width="20%" valign="top"><b>Value</b></td> <td width="80%" valign="top"><INPUT TYPE="text" NAME="value" value="<? echo htmlspecialchars(stripslashes($value));?>" SIZE=40><br><br> </td> </tr> <tr> <td width="30%"></td> <td width="80%"><INPUT TYPE="submit" name="verb" VALUE="Submit"></td> </tr> <tr> <td width="30%"></td> <td width="80%"><INPUT TYPE="submit" name="verb" VALUE="DELETE"> <input type="hidden" name="mode" value="put"> </tr> </table> </FORM> <? } // ------------------------------------------------------------------------- end ast db form // ------------------------------------------------------------------------- -- begin ast db put if ($mode == "put") { if ($verb == "Submit") { $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: php\r\n"); fputs($socket, "Secret: supersecret\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: database put $family $key $value\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)) { $response .= fread($socket, 8192); // read the entire output into $response } fclose($socket); // close the socket if (strpos($response, 'Updated database successfully')) { print("Your data has been INSERTED.\r\n"); } else print("INSERT Error...."); } if ($verb == "DELETE") { $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: php\r\n"); fputs($socket, "Secret: supersecret\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: database del $family $key\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)) { $response .= fread($socket, 8192); // read the entire output into $response } fclose($socket); // close the socket if (strpos($response, 'Database entry removed')) { print("Your data has been DELETED.\r\n"); } else print("Delete Error...."); } } // ------------------------------------------------------------------------ end ast db put ?> <?php include "footer.php"; ?> </body> </html> _______________________________________________ Astlinux-users mailing list Ast...@li... http://lists.kriscompanies.com/mailman/listinfo/astlinux-users Donations to support AstLinux are graciously accepted via PayPal to pa...@kr.... -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.430 / Virus Database: 268.14.5/533 - Release Date: 13/11/2006 8:56 PM -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 5:56 PM |
From: Tom L. <the...@gm...> - 2007-05-20 23:24:11
|
Michael, I'll look into this when I get some time. I've got a newborn at home. On 4/22/07, Michael Knill <mic...@ip...> wrote: > Tom or anyone > > As I use the DB for a large part of my configuration, this piece of PHP code > will come in very handy. I have it all working except that any DB entry that > has a / in it does not display any characters after the /. > > As I am not a very experienced programmer, could someone let me know how to > fix this problem. > I am sure it is a syntax problem in this line: > > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, $temp); > > Anyones help is very much appreciated. > > Regards > Michael Knill > > -----Original Message----- > From: ast...@ja... > [mailto:ast...@ja...]On Behalf Of Tom Lynn > Sent: Tuesday, 14 November 2006 7:00 AM > To: Discussion of AstLinux - Asterisk on Compact Flash > Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse > > > Turns out the script was scrubbed off of my e-mail. Here it is for > anybody that is interested. > > <html> > <head> > > <?php > import_request_variables("GP"); > > ?> > <META http-equiv="Content-Style-Type" content="text/css"> > <link href="default.css" rel="stylesheet" type="text/css"> > > <? > if ($mode == "put"){ echo '<meta http-equiv="Refresh" Content="2; > URL='.$self.'?mode=show">';} > ?> > > </head> > <BODY> > <?php include "header.php"; ?> > <? > // ----------------------------------------------------------------------- > begin ast db show > if(!isset($mode)|| $mode == 'show') { > echo 'Asterisk Database Maintenance<P><a > href="'.$self.'?mode=form">New Entry</a> - Or edit existing below<P>'; > > $man_name = "php"; > $man_pword = "supersecret"; > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, > $timeout); // open a connection to the manager interface > > fputs($socket, "Action: Login\r\n"); // login > fputs($socket, "UserName: $man_name\r\n"); // send username > fputs($socket, "Secret: $man_pword\r\n\r\n"); // send password > > fputs($socket, "Action: Command\r\n"); // tell it a command is coming > fputs($socket, "Command: database show\r\n\r\n"); // ask for the > contents of the database > fputs($socket, "Action: Logoff\r\n\r\n"); // logoff > > while (!feof($socket)) { > $dbentries .= fread($socket, 8192); // read the entire output > into $dbentries > } > fclose($socket); // close the socket > > $array = preg_split("/\n/",$dbentries, -1, PREG_SPLIT_NO_EMPTY); // > split $dbentries on newline characters and store in $array > for ($i = 1; $i < 7; $i++) { > array_shift($array); // get rid of 7 lines of useless garbage > (need a test for this) > } > > $bgcolor='white'; // set a background color for the table > $color_state=true; // use it when $color_state = true > ?> > <table border="0" cellspacing="2"> > <tr bgcolor="#EEEEEE"> > <td>Family</td> > <td>Key</td> > <td>Value</td> > </tr> > <? > foreach($array as $value) { > if (strncmp($value, '--END COMMAND', 13) == 0) { // look for the > end of the output > break; // stop showing records at this point > } > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, > $temp); // isolate Family, Key and Value into $temp[] > array_shift($temp); // shift off the matched portion > $querystring = > 'mode=form&family='.urlencode($temp[0]).'&key='.urlencode($temp[1]).'&value= > '.urlencode($temp[2]); > // build some of the URI for this value > ?> > <tr bgcolor=<? echo("$bgcolor");?>> > <td><? echo '<a > href="'.$self.'?'.htmlspecialchars($querystring).'">'.$temp[0].'</a>';?></td > > > <td><? echo($temp[1]); ?></td> > <td><? echo($temp[2]); ?></td> > </tr> > <? > $color_state = !$color_state; // flip the color state > if ($color_state) { > $bgcolor = 'white'; // if true use lightblue; > } else { > $bgcolor = '#EEEEEE'; // else use wheat > } > } > } //------------------------------------------------------------------------ > end ast db show > > // ------------------------------------------------------------------------- > begin ast db form > > if ($mode == "form") { > ?> > > <P><P><P></P> > <FORM ACTION="<? echo "$self"; ?>" METHOD="POST"> > <table border="0" width="60%"> > <tr> > <td width="20%" valign="top"><b>Family</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="family" > value="<? echo htmlspecialchars(stripslashes($family));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="20%" valign="top"><b>Key</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="key" > value="<? echo htmlspecialchars(stripslashes($key));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="20%" valign="top"><b>Value</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="value" > value="<? echo htmlspecialchars(stripslashes($value));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="30%"></td> > <td width="80%"><INPUT TYPE="submit" name="verb" > VALUE="Submit"></td> > </tr> > <tr> > <td width="30%"></td> > <td width="80%"><INPUT TYPE="submit" name="verb" VALUE="DELETE"> > <input type="hidden" name="mode" value="put"> > </tr> > </table> > </FORM> > > <? > } > // ------------------------------------------------------------------------- > end ast db form > > // ------------------------------------------------------------------------- > -- > begin ast db put > > if ($mode == "put") { > if ($verb == "Submit") { > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); > fputs($socket, "Action: Login\r\n"); > fputs($socket, "UserName: php\r\n"); > fputs($socket, "Secret: supersecret\r\n\r\n"); > > fputs($socket, "Action: Command\r\n"); > fputs($socket, "Command: database put $family $key $value\r\n\r\n"); > fputs($socket, "Action: Logoff\r\n\r\n"); > > while (!feof($socket)) { > $response .= fread($socket, 8192); // read the entire output > into $response > } > fclose($socket); // close the socket > if (strpos($response, 'Updated database successfully')) { > print("Your data has been INSERTED.\r\n"); > } else print("INSERT Error...."); > } > if ($verb == "DELETE") { > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); > fputs($socket, "Action: Login\r\n"); > fputs($socket, "UserName: php\r\n"); > fputs($socket, "Secret: supersecret\r\n\r\n"); > > fputs($socket, "Action: Command\r\n"); > fputs($socket, "Command: database del $family $key\r\n\r\n"); > fputs($socket, "Action: Logoff\r\n\r\n"); > > while (!feof($socket)) { > $response .= fread($socket, 8192); // read the entire output > into $response > } > fclose($socket); // close the socket > if (strpos($response, 'Database entry removed')) { > print("Your data has been DELETED.\r\n"); > } else print("Delete Error...."); > } > } > // ------------------------------------------------------------------------ > end ast db put > ?> > <?php include "footer.php"; ?> > </body> > </html> > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > http://lists.kriscompanies.com/mailman/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to > pa...@kr.... > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.430 / Virus Database: 268.14.5/533 - Release Date: 13/11/2006 > 8:56 PM > > -- > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 > 5:56 PM > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to pa...@kr.... > |
From: Tom L. <the...@gm...> - 2007-05-21 02:40:59
|
As long as you only plan to use the / character in the 'value' field, changing the preg_match to read: preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@\/]*)/", $value, $temp); should fix your problem. I'm still struggling with how to distinguish the intention of the / if it appears in the tree or key names since Asterisk uses that same slash to delimit the fields. On 4/22/07, Michael Knill <mic...@ip...> wrote: > Tom or anyone > > As I use the DB for a large part of my configuration, this piece of PHP code > will come in very handy. I have it all working except that any DB entry that > has a / in it does not display any characters after the /. > > As I am not a very experienced programmer, could someone let me know how to > fix this problem. > I am sure it is a syntax problem in this line: > > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, $temp); > > Anyones help is very much appreciated. > > Regards > Michael Knill > > -----Original Message----- > From: ast...@ja... > [mailto:ast...@ja...]On Behalf Of Tom Lynn > Sent: Tuesday, 14 November 2006 7:00 AM > To: Discussion of AstLinux - Asterisk on Compact Flash > Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse > > > Turns out the script was scrubbed off of my e-mail. Here it is for > anybody that is interested. > > <html> > <head> > > <?php > import_request_variables("GP"); > > ?> > <META http-equiv="Content-Style-Type" content="text/css"> > <link href="default.css" rel="stylesheet" type="text/css"> > > <? > if ($mode == "put"){ echo '<meta http-equiv="Refresh" Content="2; > URL='.$self.'?mode=show">';} > ?> > > </head> > <BODY> > <?php include "header.php"; ?> > <? > // ----------------------------------------------------------------------- > begin ast db show > if(!isset($mode)|| $mode == 'show') { > echo 'Asterisk Database Maintenance<P><a > href="'.$self.'?mode=form">New Entry</a> - Or edit existing below<P>'; > > $man_name = "php"; > $man_pword = "supersecret"; > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, > $timeout); // open a connection to the manager interface > > fputs($socket, "Action: Login\r\n"); // login > fputs($socket, "UserName: $man_name\r\n"); // send username > fputs($socket, "Secret: $man_pword\r\n\r\n"); // send password > > fputs($socket, "Action: Command\r\n"); // tell it a command is coming > fputs($socket, "Command: database show\r\n\r\n"); // ask for the > contents of the database > fputs($socket, "Action: Logoff\r\n\r\n"); // logoff > > while (!feof($socket)) { > $dbentries .= fread($socket, 8192); // read the entire output > into $dbentries > } > fclose($socket); // close the socket > > $array = preg_split("/\n/",$dbentries, -1, PREG_SPLIT_NO_EMPTY); // > split $dbentries on newline characters and store in $array > for ($i = 1; $i < 7; $i++) { > array_shift($array); // get rid of 7 lines of useless garbage > (need a test for this) > } > > $bgcolor='white'; // set a background color for the table > $color_state=true; // use it when $color_state = true > ?> > <table border="0" cellspacing="2"> > <tr bgcolor="#EEEEEE"> > <td>Family</td> > <td>Key</td> > <td>Value</td> > </tr> > <? > foreach($array as $value) { > if (strncmp($value, '--END COMMAND', 13) == 0) { // look for the > end of the output > break; // stop showing records at this point > } > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, > $temp); // isolate Family, Key and Value into $temp[] > array_shift($temp); // shift off the matched portion > $querystring = > 'mode=form&family='.urlencode($temp[0]).'&key='.urlencode($temp[1]).'&value= > '.urlencode($temp[2]); > // build some of the URI for this value > ?> > <tr bgcolor=<? echo("$bgcolor");?>> > <td><? echo '<a > href="'.$self.'?'.htmlspecialchars($querystring).'">'.$temp[0].'</a>';?></td > > > <td><? echo($temp[1]); ?></td> > <td><? echo($temp[2]); ?></td> > </tr> > <? > $color_state = !$color_state; // flip the color state > if ($color_state) { > $bgcolor = 'white'; // if true use lightblue; > } else { > $bgcolor = '#EEEEEE'; // else use wheat > } > } > } //------------------------------------------------------------------------ > end ast db show > > // ------------------------------------------------------------------------- > begin ast db form > > if ($mode == "form") { > ?> > > <P><P><P></P> > <FORM ACTION="<? echo "$self"; ?>" METHOD="POST"> > <table border="0" width="60%"> > <tr> > <td width="20%" valign="top"><b>Family</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="family" > value="<? echo htmlspecialchars(stripslashes($family));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="20%" valign="top"><b>Key</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="key" > value="<? echo htmlspecialchars(stripslashes($key));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="20%" valign="top"><b>Value</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="value" > value="<? echo htmlspecialchars(stripslashes($value));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="30%"></td> > <td width="80%"><INPUT TYPE="submit" name="verb" > VALUE="Submit"></td> > </tr> > <tr> > <td width="30%"></td> > <td width="80%"><INPUT TYPE="submit" name="verb" VALUE="DELETE"> > <input type="hidden" name="mode" value="put"> > </tr> > </table> > </FORM> > > <? > } > // ------------------------------------------------------------------------- > end ast db form > > // ------------------------------------------------------------------------- > -- > begin ast db put > > if ($mode == "put") { > if ($verb == "Submit") { > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); > fputs($socket, "Action: Login\r\n"); > fputs($socket, "UserName: php\r\n"); > fputs($socket, "Secret: supersecret\r\n\r\n"); > > fputs($socket, "Action: Command\r\n"); > fputs($socket, "Command: database put $family $key $value\r\n\r\n"); > fputs($socket, "Action: Logoff\r\n\r\n"); > > while (!feof($socket)) { > $response .= fread($socket, 8192); // read the entire output > into $response > } > fclose($socket); // close the socket > if (strpos($response, 'Updated database successfully')) { > print("Your data has been INSERTED.\r\n"); > } else print("INSERT Error...."); > } > if ($verb == "DELETE") { > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); > fputs($socket, "Action: Login\r\n"); > fputs($socket, "UserName: php\r\n"); > fputs($socket, "Secret: supersecret\r\n\r\n"); > > fputs($socket, "Action: Command\r\n"); > fputs($socket, "Command: database del $family $key\r\n\r\n"); > fputs($socket, "Action: Logoff\r\n\r\n"); > > while (!feof($socket)) { > $response .= fread($socket, 8192); // read the entire output > into $response > } > fclose($socket); // close the socket > if (strpos($response, 'Database entry removed')) { > print("Your data has been DELETED.\r\n"); > } else print("Delete Error...."); > } > } > // ------------------------------------------------------------------------ > end ast db put > ?> > <?php include "footer.php"; ?> > </body> > </html> > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > http://lists.kriscompanies.com/mailman/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to > pa...@kr.... > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.430 / Virus Database: 268.14.5/533 - Release Date: 13/11/2006 > 8:56 PM > > -- > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 > 5:56 PM > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to pa...@kr.... > |
From: Michael K. <mic...@ip...> - 2007-05-21 09:19:30
|
Thanks Tom very much. Unfortunately I have some values with multiple '/' characters so I only catch the first one with this change. Not that experienced with regular expressions Im afraid. I actually use the ASTDB for most of my extensions.conf configuration. This means that I can make many changes without a reload and also make my extensions configuration very modular. The Family / Key format is quite logical as I can group all the configuration for an extension under a single family eg: 100/channel, 100/natimer, 100/busytrigger etc. and display with 'database show 100'. Probably the only helpful thing other than the multiple '/' is a family filter for the main list. Thanks Tom for the great little script. Hope bub is going well. Regards Mike -----Original Message----- From: ast...@li... [mailto:ast...@li...]On Behalf Of Tom Lynn Sent: Monday, 21 May 2007 12:41 PM To: AstLinux Users Mailing List Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse As long as you only plan to use the / character in the 'value' field, changing the preg_match to read: preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@\/]*)/", $value, $temp); should fix your problem. I'm still struggling with how to distinguish the intention of the / if it appears in the tree or key names since Asterisk uses that same slash to delimit the fields. On 4/22/07, Michael Knill <mic...@ip...> wrote: > Tom or anyone > > As I use the DB for a large part of my configuration, this piece of PHP code > will come in very handy. I have it all working except that any DB entry that > has a / in it does not display any characters after the /. > > As I am not a very experienced programmer, could someone let me know how to > fix this problem. > I am sure it is a syntax problem in this line: > > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, $temp); > > Anyones help is very much appreciated. > > Regards > Michael Knill > > -----Original Message----- > From: ast...@ja... > [mailto:ast...@ja...]On Behalf Of Tom Lynn > Sent: Tuesday, 14 November 2006 7:00 AM > To: Discussion of AstLinux - Asterisk on Compact Flash > Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse > > > Turns out the script was scrubbed off of my e-mail. Here it is for > anybody that is interested. > > <html> > <head> > > <?php > import_request_variables("GP"); > > ?> > <META http-equiv="Content-Style-Type" content="text/css"> > <link href="default.css" rel="stylesheet" type="text/css"> > > <? > if ($mode == "put"){ echo '<meta http-equiv="Refresh" Content="2; > URL='.$self.'?mode=show">';} > ?> > > </head> > <BODY> > <?php include "header.php"; ?> > <? > // ----------------------------------------------------------------------- > begin ast db show > if(!isset($mode)|| $mode == 'show') { > echo 'Asterisk Database Maintenance<P><a > href="'.$self.'?mode=form">New Entry</a> - Or edit existing below<P>'; > > $man_name = "php"; > $man_pword = "supersecret"; > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, > $timeout); // open a connection to the manager interface > > fputs($socket, "Action: Login\r\n"); // login > fputs($socket, "UserName: $man_name\r\n"); // send username > fputs($socket, "Secret: $man_pword\r\n\r\n"); // send password > > fputs($socket, "Action: Command\r\n"); // tell it a command is coming > fputs($socket, "Command: database show\r\n\r\n"); // ask for the > contents of the database > fputs($socket, "Action: Logoff\r\n\r\n"); // logoff > > while (!feof($socket)) { > $dbentries .= fread($socket, 8192); // read the entire output > into $dbentries > } > fclose($socket); // close the socket > > $array = preg_split("/\n/",$dbentries, -1, PREG_SPLIT_NO_EMPTY); // > split $dbentries on newline characters and store in $array > for ($i = 1; $i < 7; $i++) { > array_shift($array); // get rid of 7 lines of useless garbage > (need a test for this) > } > > $bgcolor='white'; // set a background color for the table > $color_state=true; // use it when $color_state = true > ?> > <table border="0" cellspacing="2"> > <tr bgcolor="#EEEEEE"> > <td>Family</td> > <td>Key</td> > <td>Value</td> > </tr> > <? > foreach($array as $value) { > if (strncmp($value, '--END COMMAND', 13) == 0) { // look for the > end of the output > break; // stop showing records at this point > } > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, > $temp); // isolate Family, Key and Value into $temp[] > array_shift($temp); // shift off the matched portion > $querystring = > 'mode=form&family='.urlencode($temp[0]).'&key='.urlencode($temp[1]).'&value= > '.urlencode($temp[2]); > // build some of the URI for this value > ?> > <tr bgcolor=<? echo("$bgcolor");?>> > <td><? echo '<a > href="'.$self.'?'.htmlspecialchars($querystring).'">'.$temp[0].'</a>';?></td > > > <td><? echo($temp[1]); ?></td> > <td><? echo($temp[2]); ?></td> > </tr> > <? > $color_state = !$color_state; // flip the color state > if ($color_state) { > $bgcolor = 'white'; // if true use lightblue; > } else { > $bgcolor = '#EEEEEE'; // else use wheat > } > } > } //------------------------------------------------------------------------ > end ast db show > > // ------------------------------------------------------------------------- > begin ast db form > > if ($mode == "form") { > ?> > > <P><P><P></P> > <FORM ACTION="<? echo "$self"; ?>" METHOD="POST"> > <table border="0" width="60%"> > <tr> > <td width="20%" valign="top"><b>Family</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="family" > value="<? echo htmlspecialchars(stripslashes($family));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="20%" valign="top"><b>Key</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="key" > value="<? echo htmlspecialchars(stripslashes($key));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="20%" valign="top"><b>Value</b></td> > <td width="80%" valign="top"><INPUT TYPE="text" NAME="value" > value="<? echo htmlspecialchars(stripslashes($value));?>" > SIZE=40><br><br> > </td> > </tr> > <tr> > <td width="30%"></td> > <td width="80%"><INPUT TYPE="submit" name="verb" > VALUE="Submit"></td> > </tr> > <tr> > <td width="30%"></td> > <td width="80%"><INPUT TYPE="submit" name="verb" VALUE="DELETE"> > <input type="hidden" name="mode" value="put"> > </tr> > </table> > </FORM> > > <? > } > // ------------------------------------------------------------------------- > end ast db form > > // ------------------------------------------------------------------------- > -- > begin ast db put > > if ($mode == "put") { > if ($verb == "Submit") { > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); > fputs($socket, "Action: Login\r\n"); > fputs($socket, "UserName: php\r\n"); > fputs($socket, "Secret: supersecret\r\n\r\n"); > > fputs($socket, "Action: Command\r\n"); > fputs($socket, "Command: database put $family $key $value\r\n\r\n"); > fputs($socket, "Action: Logoff\r\n\r\n"); > > while (!feof($socket)) { > $response .= fread($socket, 8192); // read the entire output > into $response > } > fclose($socket); // close the socket > if (strpos($response, 'Updated database successfully')) { > print("Your data has been INSERTED.\r\n"); > } else print("INSERT Error...."); > } > if ($verb == "DELETE") { > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); > fputs($socket, "Action: Login\r\n"); > fputs($socket, "UserName: php\r\n"); > fputs($socket, "Secret: supersecret\r\n\r\n"); > > fputs($socket, "Action: Command\r\n"); > fputs($socket, "Command: database del $family $key\r\n\r\n"); > fputs($socket, "Action: Logoff\r\n\r\n"); > > while (!feof($socket)) { > $response .= fread($socket, 8192); // read the entire output > into $response > } > fclose($socket); // close the socket > if (strpos($response, 'Database entry removed')) { > print("Your data has been DELETED.\r\n"); > } else print("Delete Error...."); > } > } > // ------------------------------------------------------------------------ > end ast db put > ?> > <?php include "footer.php"; ?> > </body> > </html> > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > http://lists.kriscompanies.com/mailman/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to > pa...@kr.... > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.430 / Virus Database: 268.14.5/533 - Release Date: 13/11/2006 > 8:56 PM > > -- > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 > 5:56 PM > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to pa...@kr.... > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Astlinux-users mailing list Ast...@li... https://lists.sourceforge.net/lists/listinfo/astlinux-users Donations to support AstLinux are graciously accepted via PayPal to pa...@kr.... No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.467 / Virus Database: 269.7.6/813 - Release Date: 20/05/2007 7:54 AM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.467 / Virus Database: 269.7.6/813 - Release Date: 20/05/2007 7:54 AM |
From: Tom L. <the...@gm...> - 2007-05-21 13:33:55
|
Multiple / characters in the value field aren't a problem. And they do insert well into the tree and key fields. However, pulling them out for display and editing are still a worry. On 5/21/07, Michael Knill <mic...@ip...> wrote: > Thanks Tom very much. > Unfortunately I have some values with multiple '/' characters so I only > catch the first one with this change. Not that experienced with regular > expressions Im afraid. > > I actually use the ASTDB for most of my extensions.conf configuration. > This means that I can make many changes without a reload and also make my > extensions configuration very modular. > The Family / Key format is quite logical as I can group all the > configuration for an extension under a single family eg: 100/channel, > 100/natimer, 100/busytrigger etc. and display with 'database show 100'. > > Probably the only helpful thing other than the multiple '/' is a family > filter for the main list. > > Thanks Tom for the great little script. > Hope bub is going well. > > Regards > Mike > > -----Original Message----- > From: ast...@li... > [mailto:ast...@li...]On Behalf Of Tom Lynn > Sent: Monday, 21 May 2007 12:41 PM > To: AstLinux Users Mailing List > Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse > > > As long as you only plan to use the / character in the 'value' field, > changing the preg_match to read: > > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@\/]*)/", $value, $temp); > > should fix your problem. I'm still struggling with how to distinguish > the intention of the / if it appears in the tree or key names since > Asterisk uses that same slash to delimit the fields. > > On 4/22/07, Michael Knill <mic...@ip...> wrote: > > Tom or anyone > > > > As I use the DB for a large part of my configuration, this piece of PHP > code > > will come in very handy. I have it all working except that any DB entry > that > > has a / in it does not display any characters after the /. > > > > As I am not a very experienced programmer, could someone let me know how > to > > fix this problem. > > I am sure it is a syntax problem in this line: > > > > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, $temp); > > > > Anyones help is very much appreciated. > > > > Regards > > Michael Knill > > > > -----Original Message----- > > From: ast...@ja... > > [mailto:ast...@ja...]On Behalf Of Tom Lynn > > Sent: Tuesday, 14 November 2006 7:00 AM > > To: Discussion of AstLinux - Asterisk on Compact Flash > > Subject: Re: [Astlinux-users] PHP page for maintaining asterisk databse > > > > > > Turns out the script was scrubbed off of my e-mail. Here it is for > > anybody that is interested. > > > > <html> > > <head> > > > > <?php > > import_request_variables("GP"); > > > > ?> > > <META http-equiv="Content-Style-Type" content="text/css"> > > <link href="default.css" rel="stylesheet" type="text/css"> > > > > <? > > if ($mode == "put"){ echo '<meta http-equiv="Refresh" Content="2; > > URL='.$self.'?mode=show">';} > > ?> > > > > </head> > > <BODY> > > <?php include "header.php"; ?> > > <? > > // ----------------------------------------------------------------------- > > begin ast db show > > if(!isset($mode)|| $mode == 'show') { > > echo 'Asterisk Database Maintenance<P><a > > href="'.$self.'?mode=form">New Entry</a> - Or edit existing below<P>'; > > > > $man_name = "php"; > > $man_pword = "supersecret"; > > > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, > > $timeout); // open a connection to the manager interface > > > > fputs($socket, "Action: Login\r\n"); > // login > > fputs($socket, "UserName: $man_name\r\n"); > // send username > > fputs($socket, "Secret: $man_pword\r\n\r\n"); > // send password > > > > fputs($socket, "Action: Command\r\n"); > // tell it a command is coming > > fputs($socket, "Command: database show\r\n\r\n"); > // ask for the > > contents of the database > > fputs($socket, "Action: Logoff\r\n\r\n"); > // logoff > > > > while (!feof($socket)) { > > $dbentries .= fread($socket, 8192); > // read the entire output > > into $dbentries > > } > > fclose($socket); > // close the socket > > > > $array = preg_split("/\n/",$dbentries, -1, PREG_SPLIT_NO_EMPTY); > // > > split $dbentries on newline characters and store in $array > > for ($i = 1; $i < 7; $i++) { > > array_shift($array); > // get rid of 7 lines of useless garbage > > (need a test for this) > > } > > > > $bgcolor='white'; > // set a background color for the table > > $color_state=true; > // use it when $color_state = true > > ?> > > <table border="0" cellspacing="2"> > > <tr bgcolor="#EEEEEE"> > > <td>Family</td> > > <td>Key</td> > > <td>Value</td> > > </tr> > > <? > > foreach($array as $value) { > > if (strncmp($value, '--END COMMAND', 13) == 0) > { // look for the > > end of the output > > break; > // stop showing records at this point > > } > > preg_match("/^\/(.*)\/([\w]*)\s*:\s*([\w\.:@]*)/", $value, > > $temp); // isolate Family, Key and Value into $temp[] > > array_shift($temp); > // shift off the matched portion > > $querystring = > > > 'mode=form&family='.urlencode($temp[0]).'&key='.urlencode($temp[1]).'&value= > > '.urlencode($temp[2]); > > // build some of the URI for this value > > ?> > > <tr bgcolor=<? echo("$bgcolor");?>> > > <td><? echo '<a > > > href="'.$self.'?'.htmlspecialchars($querystring).'">'.$temp[0].'</a>';?></td > > > > > <td><? echo($temp[1]); ?></td> > > <td><? echo($temp[2]); ?></td> > > </tr> > > <? > > $color_state = !$color_state; > // flip the color state > > if ($color_state) { > > $bgcolor = 'white'; > // if true use lightblue; > > } else { > > $bgcolor = '#EEEEEE'; > // else use wheat > > } > > } > > } > //------------------------------------------------------------------------ > > end ast db show > > > > > // ------------------------------------------------------------------------- > > begin ast db form > > > > if ($mode == "form") { > > ?> > > > > <P><P><P></P> > > <FORM ACTION="<? echo "$self"; ?>" METHOD="POST"> > > <table border="0" width="60%"> > > <tr> > > <td width="20%" valign="top"><b>Family</b></td> > > <td width="80%" valign="top"><INPUT TYPE="text" > NAME="family" > > value="<? echo htmlspecialchars(stripslashes($family));?>" > > SIZE=40><br><br> > > </td> > > </tr> > > <tr> > > <td width="20%" valign="top"><b>Key</b></td> > > <td width="80%" valign="top"><INPUT TYPE="text" NAME="key" > > value="<? echo htmlspecialchars(stripslashes($key));?>" > > SIZE=40><br><br> > > </td> > > </tr> > > <tr> > > <td width="20%" valign="top"><b>Value</b></td> > > <td width="80%" valign="top"><INPUT TYPE="text" > NAME="value" > > value="<? echo htmlspecialchars(stripslashes($value));?>" > > SIZE=40><br><br> > > </td> > > </tr> > > <tr> > > <td width="30%"></td> > > <td width="80%"><INPUT TYPE="submit" name="verb" > > VALUE="Submit"></td> > > </tr> > > <tr> > > <td width="30%"></td> > > <td width="80%"><INPUT TYPE="submit" name="verb" > VALUE="DELETE"> > > <input type="hidden" name="mode" value="put"> > > </tr> > > </table> > > </FORM> > > > > <? > > } > > > // ------------------------------------------------------------------------- > > end ast db form > > > > > // ------------------------------------------------------------------------- > > -- > > begin ast db put > > > > if ($mode == "put") { > > if ($verb == "Submit") { > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, > $timeout); > > fputs($socket, "Action: Login\r\n"); > > fputs($socket, "UserName: php\r\n"); > > fputs($socket, "Secret: supersecret\r\n\r\n"); > > > > fputs($socket, "Action: Command\r\n"); > > fputs($socket, "Command: database put $family $key > $value\r\n\r\n"); > > fputs($socket, "Action: Logoff\r\n\r\n"); > > > > while (!feof($socket)) { > > $response .= fread($socket, 8192); > // read the entire output > > into $response > > } > > fclose($socket); > // close the socket > > if (strpos($response, 'Updated database successfully')) { > > print("Your data has been INSERTED.\r\n"); > > } else print("INSERT Error...."); > > } > > if ($verb == "DELETE") { > > > > $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, > $timeout); > > fputs($socket, "Action: Login\r\n"); > > fputs($socket, "UserName: php\r\n"); > > fputs($socket, "Secret: supersecret\r\n\r\n"); > > > > fputs($socket, "Action: Command\r\n"); > > fputs($socket, "Command: database del $family > $key\r\n\r\n"); > > fputs($socket, "Action: Logoff\r\n\r\n"); > > > > while (!feof($socket)) { > > $response .= fread($socket, 8192); > // read the entire output > > into $response > > } > > fclose($socket); > // close the socket > > if (strpos($response, 'Database entry removed')) { > > print("Your data has been DELETED.\r\n"); > > } else print("Delete Error...."); > > } > > } > > > // ------------------------------------------------------------------------ > > end ast db put > > ?> > > <?php include "footer.php"; ?> > > </body> > > </html> > > _______________________________________________ > > Astlinux-users mailing list > > Ast...@li... > > http://lists.kriscompanies.com/mailman/listinfo/astlinux-users > > > > Donations to support AstLinux are graciously accepted via PayPal to > > pa...@kr.... > > > > -- > > No virus found in this incoming message. > > Checked by AVG Free Edition. > > Version: 7.5.430 / Virus Database: 268.14.5/533 - Release Date: 13/11/2006 > > 8:56 PM > > > > -- > > No virus found in this outgoing message. > > Checked by AVG Free Edition. > > Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 19/04/2007 > > 5:56 PM > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Astlinux-users mailing list > > Ast...@li... > > https://lists.sourceforge.net/lists/listinfo/astlinux-users > > > > Donations to support AstLinux are graciously accepted via PayPal to > pa...@kr.... > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to > pa...@kr.... > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.467 / Virus Database: 269.7.6/813 - Release Date: 20/05/2007 > 7:54 AM > > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.467 / Virus Database: 269.7.6/813 - Release Date: 20/05/2007 > 7:54 AM > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Astlinux-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/astlinux-users > > Donations to support AstLinux are graciously accepted via PayPal to pa...@kr.... > |