even when i try to interface using the asterisk database … it turn out to a disaster…
the array cannot display the intended …
below are my codes… can tell me what is wrong with it ? thanks
<?php
import_request_variables("GP");
?>
<?
if ($mode == "put"){ echo '';}
?>
<?
// ----------------------------------------------------------------------- begin ast db show
if(!isset($mode)|| $mode == 'show') {
echo 'Asterisk Database Maintenance
New Entry - Or edit existing below
';
$man_name = “myasterisk”;
$man_pword = “mycode”;
$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, 5038); // 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
//$array = preg_split("/\n/",$dbentries, -1);
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
?>
Family |
Key |
Value |
<? echo($array); ?> |
<? echo ($dbentries); ?> |
<?
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($temp0).'&key='.urlencode($temp1).'&value='.urlencode($temp2); // build some of the URI for this value
?>
>
<? echo ''.$temp0.'';?> |
<? echo($temp1); ?>123 |
<? echo($temp2); ?>123 |
<? echo($dbentries); ?> |
<?
$color_state = !$color_state; // flip the color state
if ($color_state) {
$bgcolor = 'white'; // if true use white;
} else {
$bgcolor = 'blue'; // else use grey
}
}
} //------------------------------------------------------------------------ end ast db show
// ------------------------------------------------------------------------- begin ast db form
if ($mode == “form”) {
?>
" METHOD="POST">
<?
} // ------------------------------------------------------------------------- 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: myasterisk\r\n");
fputs($socket, "Secret: mycode\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: myasterisk\r\n");
fputs($socket, "Secret: mycode\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
?>