WebCpxMonitor: Porovnání verzí

Z HKfree wiki
Skočit na navigaci Skočit na vyhledávání
 
m (přidání lang=perl)
 
Řádek 1: Řádek 1:
<perl>
+
<source lang="perl">
 
#!/usr/bin/perl
 
#!/usr/bin/perl
  
Řádek 75: Řádek 75:
 
     print "Error: Unknown format";
 
     print "Error: Unknown format";
 
}  
 
}  
</perl>
+
</source>

Aktuální verze z 5. 12. 2009, 19:12

#!/usr/bin/perl

#=============================================================
# Web Cpx Monitor
# Script to retrieve AP's WLAN statistics 
# from Compex NetPassage WPE54AG
# Author: pavkriz@hkfree.org
#
# Configuration:

my $ip  = '10.107.AA.BB';
my $psw = 'password';

#=============================================================

use LWP::UserAgent;
use strict;

# if this script is running from as CGI
# (one can also call this script e.g. from PHP
# or some other frameworks and include output
# in the "templated" pages)
my $runFromCGI = $ENV{SERVER_SOFTWARE};

my $ua = LWP::UserAgent->new;

# try login to compex
my $req = HTTP::Request->new(POST => "http://$ip/act_login");
$req->content_type('application/x-www-form-urlencoded');
$req->content('Bcmd=20&PSW='.$psw);

my $res = $ua->request($req);

# was http request/response sucessful?
if ( ! ($res->is_success)) {
    print "Error: ".$res->status_line;
    exit;
}

# page retrieved after login
my $afterLogin = $res->as_string;

# hadle common exceptions

if ($afterLogin =~ /WRONG PASSWORD/) {
    print "Error: Wrong password";
    exit;
}

if ($afterLogin =~ /the router is already being managed/) {
    print "Error: Unable to open session, the router is already being managed";
    exit;
}

# ask for "WLAN Station List" page (in AP mode)
my $req = HTTP::Request->new(GET => "http://$ip/staList.htm");
my $res = $ua->request($req);
# get the page content
my $staList = $res->as_string;

# print $staList;  # print content - debug only

# parse table containing stations
if ($staList =~ /(<table border="0" cellspacing="4" cellpadding="0" >.+?<\/table>)/s) {
	my $onlyList = $1;
	# remove links
	$onlyList =~ s/<a href=(.+?)>//g;
	$onlyList =~ s/<\/a>//g;
	# print table to output
	print "Content-type: text/html\n\n<html><body>" if ($runFromCGI);
	print $onlyList;
	print "</body></html>" if ($runFromCGI);
} else {
    print "Error: Unknown format";
}