Reload plugin

How would I reload the plugin using a bash shell script?

Thanks!

jselleck,

I can’‘t think of an easy way to do so. Can you explain the use-case so we can understand what you’'re trying to do better?

Regards,

Matt

Hi jselleck,

do you want to do the same thing as one could do using the web admin interface?

You could use curl or wget to do this. I recently wrote a perl script to broadcast a message form the command line using the broadcast plugin.

LG

Hey,

I tried using curl but it fails becoz the auth page requiers javascript to be enabled.

Can you plz explain how you achieved this becoz even I am trying to do the same thing using curl or lynx. I need to reload the asterisk-im pluigin.

Or could you give me your perl script ?

Thanks,

Deepak

Hi,

you don’'t need to retrieve the login.jsp page, sending username+pass and then retrieving the cookie is fine.

I did post this script somewhere in this forum already … using the code tag it may have some problems with & so you may need to fix some lines where & is used.

LG

#!perl.exe
#my $version = ''v0.01'';
use strict;
use warnings;
use utf8;
use IO::Socket;
use IO::Handle; $|=1;
my $message = (defined($ARGV[0]))?"@ARGV":""; my ($buf, $buflen, $buf2); # adjust this
my $my_servername = "127.0.0.1";
my $my_adminport = "9090";
my $my_adminpath = ""; # ''Wifi/'' if you are using Tomcat and ''Wifi.war'', don''t forget the trailing ''/''
my $my_adminuser = "admin";
my $my_password = "test";
my $baseurl = "http://" . $my_servername . ":" . $my_adminport . "/" . $my_adminpath; my $loginpage = "login.jsp";
my $broadcastpage = "user-message.jsp";
my $TRGT_PROTO = ''tcp'';
my $HTTP_HEADER = "Host: " . $my_servername . ":" . $my_adminport . "\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n" .
"Connection: close\r\n" .
"Content-Type: text/html; charset=UTF-8\r\n\r\n";
my $cookie = ""; # login - POST and GET are possible, we will use POST
#printf("############# login #############\n");
$buf = "url=/" . $my_adminpath . $broadcastpage . "&";
$buf .= "login=true" . "&";
$buf .= "username=" . $my_adminuser . "&";
$buf .= "password=" . $my_password;
$buflen=length($buf);
$buf = "POST " . $baseurl . $loginpage . " HTTP/1.0\r\n" .
"Content-Length: " . $buflen . "\r\n" .
$HTTP_HEADER .
$buf;
&send();
&get_cookie(); #printf("############# sending broadcast #############\n");
$message =~ s/\%/\%25/g;
$message =~ s/\+/\%2b/g;
$message =~ s/\&/\%26/g; $buf = "tabs=true" . "&";
$buf .= "send=true" . "&";
$buf .= "message=" . $message;
$buflen=length($buf);
$buf = "POST " . $baseurl . $broadcastpage . " HTTP/1.0\r\n" .
"Content-Length: " . $buflen . "\r\n" .
$cookie . "\r\n" .
$HTTP_HEADER .
$buf;
&send(); #printf("############# success ? #############\n");
if ($buf2 =~ /$broadcastpage\?success=true/)
{
printf("OK\n");
} else
{
printf("Error\n");
exit(3);
};
exit(0); sub get_cookie()
{
if ($buf2 =~ /(Cookie\s*:\s[^;]*)/)
{
$cookie = $1;
} else
{
printf("Could not get Cookie / Login");
exit(1);
};
#printf("############# Cookie: %s\n", $cookie);
};
sub send()
{
#printf("############# Send: %s\n", $buf);
my $sock = new IO::Socket::INET->new(PeerAddr => $my_servername,
PeerPort => $my_adminport, Proto => $TRGT_PROTO);
if (!defined $sock)
{
printf("Could not create socket.\n");
exit(2);
};
$sock->send($buf);
$buf = "";
$buf2 = "";
while (<$sock>)
{
read($sock, $buf, 1000);
$buf2 .= $buf;
};
close ($sock);
#printf("############# Recv: %s\n", $buf2);
};

Thanks man ! Thanks for the tip and the script.

This is how I am doing it using curl: -

curl -D cookies.txt -d “username=admin&password=qwerty&login=true&url=%2Fplugin-admin.jsp%3Freloadplug in%3Dasterisk-im” “http://example.com:9090/login.jsp

curl -b cookies.txt “http://example.com:9090/plugin-admin.jsp?reloadplugin=asterisk-im

-Deepak