First of all, i'm not the original poster but with the same problem.
I'm trying to wrote a small script what does next things:
Logs into router over telnet (that part works).
Send command to the router and get the necessary date (also works).
When i need some extra features to configure in router then a press a certain button, subroutine associated with the button does what it supposed to do and the that's basically it.
What i'm trying to do is:
Add a Button to the page and this button calls first subroutine.
My first sub is sub telnet { logging into router only!};
When i press the button it should call
sub called &telnet();
and after successful login it should call another sub what i define and all that should be working on the same page. Without sub pages on my site.
Example part of the script that's working fine:
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
use Net::Telnet ();
use CGI qw (:standard);;
my $user = 'username';
my $pass = 'password';
my $host = "192.168.1.254";
$t = new Net::Telnet (Timeout => 1, Prompt => '/\$ $/i');
$t->open($host);
$t->waitfor('/: $/i');
$t->print($user);
$t->waitfor('/ : $/i');
$t->print($pass);
$t->waitfor('/>$/i');
@lines = $t->print ("system settime"); # it takes router uptime info
($output) = $t->waitfor('/=>$/i');
print "<pre>"; #for nice output
print $output;
$t->print("exit");
print "</pre>"; #for nice output
This is all in one script to show you working part.
I know how to make a sub but How to call it with the button.
How to call several sub one after one just cliking the button.
Second sub contains something like that:
@lines = $t->print ("turn off dhcp server"); #for example
($output) = $t->waitfor('/=>$/i'); #waits prompt
print $output;
"turn off dhcp server" - whatever command i will wrote there.
It's not a good idea to call all subroutines at once, one bye one. It's not necessary, could make something worse etc.
To make this "page" more compact i would like to call those subs in the script itself with a button.
Any hints, examples appreciated!
| [reply] [Watch: Dir/Any] [d/l] [select] |