OpenWrt Forum Archive

Topic: webif: asterisk simple managment and configuration. My contribution...

The content of this topic has been archived on 3 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

#!/usr/bin/webif-page
<?
. /usr/lib/webif/webif.sh
header "Status" "Asterisk" "Asterisk Simple Managment"

conf_path="/etc/asterisk"

echo '<center>'
echo '<a href="'$SCRIPT_NAME'">Version</a>'
echo '<a href="'$SCRIPT_NAME'?action=sip_peers">SIP/Peers</a>'
echo '<a href="'$SCRIPT_NAME'?action=sip_channels">SIP/Channels</a>'
echo '<a href="'$SCRIPT_NAME'?action=sip_registry">SIP/Registry</a>'
echo '<a href="'$SCRIPT_NAME'?action=iax_peers">IAX/Peers</a>'
echo '<a href="'$SCRIPT_NAME'?action=iax_channels">IAX/Channels</a>'
echo '<a href="'$SCRIPT_NAME'?action=iax_registry">IAX/Registry</a>'
echo '<a href="'$SCRIPT_NAME'?action=modules">Global/Modules</a>'
echo '<a href="'$SCRIPT_NAME'?action=cust_com">Custom/Command</a>'
echo '<a href="'$SCRIPT_NAME'?action=editor">.conf Editor</a>'
echo '<a href="'$SCRIPT_NAME'?action=reload">Reload</a>'
echo '<br /><br /><br />'
echo '<table><tr><td align=left border=0>'
echo '<pre>'
if [ "$FORM_action" = "reload" ]; then
   echo "<h3>Reloading...</h3>"
   asterisk -r -x 'reload'
elif [ "$FORM_action" = "sip_peers" ]; then
   echo "<h3>SIP/Peers</h3>"
   asterisk -r -x 'sip show peers'
elif [ "$FORM_action" = "sip_channels" ]; then
   echo "<h3>SIP/Channels</h3>"
   asterisk -r -x 'sip show channels'
elif [ "$FORM_action" = "sip_registry" ]; then
   echo "<h3>SIP/Registry</h3>"
   asterisk -r -x 'sip show registry'
elif [ "$FORM_action" = "iax_peers" ]; then
   echo "<h3>IAX/Peers</h3>"
   asterisk -r -x 'iax2 show peers'
elif [ "$FORM_action" = "iax_channels" ]; then
   echo "<h3>IAX/Channels</h3>"
   asterisk -r -x 'iax2 show channels'
elif [ "$FORM_action" = "iax_registry" ]; then
   echo "<h3>IAX/Registration</h3>"
   asterisk -r -x 'iax2 show registry'
elif [ "$FORM_action" = "modules" ]; then
   echo "<h3>Global/Modules</h3>"
   asterisk -r -x 'show modules'
elif [ "$FORM_action" = "execute" ]; then
   echo "<h3>$FORM_exec_com</h3>"
   asterisk -r -x "$FORM_exec_com"
elif [ "$FORM_action" = "" ]; then
   asterisk -r -x 'show version'
fi
echo '</pre>'
echo '</td></tr></table>'
echo '</center>'
if [ "$FORM_action" = "cust_com" ]; then
   echo '<form action="'$SCRIPT_NAME'" method=POST>'
   echo '<center>'
   echo '<INPUT type=text name="exec_com" value="'$FORM_exec_com'" size="25" maxlength="150">'
   echo '<br /><br /><INPUT type="submit" value="@TR<<Accept>>">'
   echo '<INPUT name="action" type="hidden" value="execute">'
   echo "<br /><br />Enter 'help' for commands details."
   echo '</center>'
   echo '</form>'
fi
if [ "$FORM_action" = "editor" ]; then
   echo '<center><form action="'$SCRIPT_NAME'" method=POST>'
   echo '<table style="width: 25%; text-align: left;" border="0" cellpadding="2" cellspacing="2" align="center">'
   ls $conf_path/.  | awk -F' ' '
   {
   link=$1
   gsub(/\+/,"%2B",link)
   print "<tr><td><a href=\"'$SCRIPT_NAME'?action=edit&target=" link "\">@TR<<Edit>></td><td>" $1 "</td></tr></a>"
   }'
   echo '</table></form></center>'
fi
if [ "$FORM_conf" != "" ]; then
   echo "$FORM_conf" | tr -d '\r' > $conf_path/$FORM_target
fi
if [ "$FORM_action" = "edit" ]; then
   conf_file="$( cat $conf_path/$FORM_target )"
   echo '<form action="'$SCRIPT_NAME'" method=POST>'
   echo '<center>'
   echo '<TEXTAREA name="conf" rows="30" cols="100">'
   echo -n "$conf_file"
   echo '</TEXTAREA>'
   echo '<INPUT name="target" type="hidden" value="'$FORM_target'">'
   echo '<br /><INPUT type="submit" value="@TR<<Save Changes>>">'
   echo '</center>'
   echo '</form>'
fi
footer ?>
<!--
##WEBIF:name:Status:7:Asterisk
-->

Just change the 'conf_path' on top according to your installation if it is not correct...
Rename the page 'asterisk.sh' and put it in /www/cgi-bin/webif.

(Last edited by drwho on 1 May 2006, 15:35)

VERY NICE! Thanks very much for posting this- works great for me.  I love the config file editor.

One thing that might be nice is just use 'show channels' instead of 'sip show channels'  to view all active channels- IAX, SIP, or whatever.

Thank's for your comment.

I have only a basic 'home' asterisk configuration, so I have writen preformated commands that were (for me) the most useable. But we can imagine something more complicated with diaplan digest, remote hangup line or transfer etc... Perhaps it's a good time to start a real project on the asterisk page for Openwrt.

Just let me know.

wow, real nice smile

People always bitched asterisk not being on dd-wrt. Most liked dd-wrt for the web interface. Wait till they see this script big_smile

I should probably start another thread, I am trying to get something like DISA working. Also dtmf inband without asterisk going all crazy. any of you folks have experience with it ?

And thanks for the script smile

- LS

Hello drwho,

I recently noticed your script and was curious, what kind of options it will provide to manage my local asterisk setup on my ASUS WL-500g Deluxe.

So, I copied the script, verified the path and set the file permissions according to the file permissions of other files in that directory, like 'firewall.sh' and 'lan.sh': -rwxr-xr-x.
Then I rebooted the router (perhaps this was not necessary) and accessed the web interface. In category "Status" now I see the following pages "Status", "Connections", "DHCP" and "Wireless" (in that order). "Connections" (item #2) is selected by default. When I try to click on "Status" (on the light blue bar, not the category), I see this URL in the browser's status bar: http://<ip address>/cgi-bin/webif/7. Clicking it results in a "404 Not Found" page.

Do you have an idea, what may have went wrong?

Now I will compare your script to the other ones that belong to category "Status". Perhaps, so I can get a hint, what makes the difference...

Regards,

slowjoe

Hello,

Status is not a correct name for the page. It should be named 'Asterisk' and be placed in 7th rank of all 'Status' pages accord to this:

<!--
##WEBIF:name:Status:7:Asterisk
-->

Be sure to have this in the footer of the script. If you allready have a page in 7th rank you can change it yourself to change the placement in the menu.

let me know.

Regards,

Drwho

Hello Drwho,

thanks for your quick reply!
Your script works well... I just made a mistake when converting the line end characters. On my Windows system, I converted CR + LF to CR. But it had to be LF only.  hmm

Regards,

slowjoe

(Last edited by slowjoe on 5 Jun 2006, 09:38)

I'm happy it's working now, I hope you'll find this script useable.

Regards,

Drwho.

Drwho:

Very good script.

Thank you.

Juan C.

(Last edited by jcgalvez on 8 Jun 2006, 19:13)

Yep, thanks you. Very nice interface, very pratical.

Hi,

I try to use this script in my ASUS WL-500G box. But it seem not working... The gui page is shown properly but it shows errors when i try to access any modules in gui.

The thing is i install asterisk in usb drive , not in root space...

But i've already change my conf_path from "/etc/asterisk" to "/usb/etc/asterisk" ...

Have i missed anything ???

Attojung

Hello,

Your Asterisk installation has not been made in a system directory pointed in the system path so the binary cannot be found if you don't specify the correct path in your command line (ie. in a telnet prompt)

You have 2 ways to solve that:

1st: Add the path of your Asterisk binary to the system.
2nd: Add the path of the asterisk binary in the script.

If you have any trouble doing one, let me know, i'll change the script...

Regards,

Drwho.

Thx veru much !!

I've already add some system path in /etc/profile

Here is the details about path in my /etc/profile

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usb/bin:/usb/sbin:/usb/usr/bin:/usb/usr/sbin
export LD_LIBRARY_PATH=/lib:/usr/lib:/usb/usr/lib:/usb/lib

But i still face the same error ...

Is this the thing you mention in solution 1 ?? (i'm not sure, i may get it worng)

It's working on my kid right now ..

Thx very much

I created the page, uploading to my wrt54g,
display is alright,
but even when asterisk is running
on the page  i get " unable to connect to asterisk "
how does the page display the infos ? does it use the manager.conf file ? where do you put the param to connect to asterisk ?

hope somebody can help me ..
thanks!
jl

The script does not connect directly for security reason, all is done with command line. To do that Asterisk must be running on your machine and be accessible with a command line.

For example:
asterisk -r -x 'show version'
Must return the compilation version number. The console output are just redirected to the web page and give the result.

Just verify your Asterisk is accessible via command line and give me the feedback.

Regards,

Drwho.

Where do I put this script to get it work?

Got this error message when I try to go to any subpages in asterisk gui
"/bin/sh: asterisk: not found"
I have installed asterisk on a sd card and change to conf_path="/mnt/sd/etc/asterisk"
what is wrong?

Check #12 and #13

attojung wrote:

It's working on my kid right now ..

Thx very much

please let us know how you did big_smile

You have to add the path of your asterisk binaries that are in SD card to the exported path of the system and reboot. Look at #14 (example with usb device).

(Last edited by drwho on 22 Oct 2006, 22:18)

drwho wrote:

You have to add the path of your asterisk binaries that are in SD card to the exported path of the system and reboot. Look at #14 (example with usb device).

Have already done this but it doesn´t work hmm

Can you paste here a copy of your exported path and a directory tree of your system ?

The discussion might have continued from here.