#! /usr/bin/perl -w
use WWW::Curl::Easy;
sub writeBMCallback {
my ($data, $pointer) = @_;
${$pointer}=${$pointer}.$data;
return length($data);
}
sub headerBMCallback {
my($data, $pointer) = @_;
return length($data);
}
sub betamax_curl () {
my $body='';
my $curl = new WWW::Curl::Easy;
$curl->setopt(CURLOPT_HEADER, 1);
$curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7');
$curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
$curl->setopt(CURLOPT_FAILONERROR, 1);
$curl->setopt(CURLOPT_COOKIEJAR, $sCookie_File);
$curl->setopt(CURLOPT_COOKIEFILE, $sCookie_File);
$curl->setopt(CURLOPT_SSL_VERIFYPEER, 0);
$curl->setopt(CURLOPT_WRITEFUNCTION, \&writeBMCallback );
$curl->setopt(CURLOPT_HEADERFUNCTION, \&headerBMCallback );
$curl->setopt(CURLOPT_FILE, \$body);
if ($_[1] =~ 'POST') {
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_POSTFIELDS,"username=$_[2]&password=$_[3]");
}
$curl->setopt(CURLOPT_URL,$_[0]);
$curl->perform();
my $err = $curl->errbuf;
return $body;
}
$MYSITE=$ARGV[0]; #Seite, z.B. voipcheap.com, nonoh.net etc.
$MYUSER=$ARGV[1]; #Username
$MYPASS=$ARGV[2]; #Passwort
# hier gewünschten Pfad eintragen
my $BFILE = '/var/lib/asterisk/data/betamax';
# Check user data at Provider
$sCookie_File = "/tmp/bm.cookie";
$url='https://myaccount.'.$MYSITE.'/clx';
if ( $MYSITE eq 'nonoh.net' ) {
$url1='/contacts.php';
} else {
$url1='/index.php?part=menu&justloggedin=true';
}
&betamax_curl($url.'/','POST',$MYUSER,$MYPASS);
&betamax_curl($url.$url1,'GET');
my $content=&betamax_curl($url.$url1,'GET');
my $sHTML_File="/tmp/bm.html";
open(HTML, '>'.$sHTML_File);
print HTML $content;
close(HTML);
system("lynx /tmp/bm.html --dump --nolist --nomargins > /tmp/bm.txt") == 0 or die "Keine Verarbeitung moeglich";
unlink($sHTML_File);
my $sTXT_File="/tmp/bm.txt";
open(TXT, '<'.$sTXT_File);
open(BF, '>'.$BFILE);
my $afree=0;
my $acredit=0;
while (<TXT>) {
if (( $MYSITE ne 'nonoh.net' ) && ( $_ =~ m/Freedays/ )) {
$afree=1;
} elsif (( $MYSITE eq 'nonoh.net' ) && ( $_ =~ m/freedays/ )) {
$myfree=$_;
$myfree=~ s/[^0-9]//g;
if ( length($myfree) eq 0 ) { $myfree = 0; }
$afree=0;
last;
} elsif (( $MYSITE ne 'nonoh.net' ) && ( $_ =~ m/Remaining credit/ )) {
$acredit=1;
} elsif (( $MYSITE eq 'nonoh.net' ) && ( $_ =~ m/You have/ ) && ( $_ =~ m/credit/ )) {
$mymoney=$_;
$mymoney=~ s/[^0-9\.]//g;
$mymoney=~ s/\./\,/;
print(BF $mymoney."\n");
$acredit=0;
} elsif ($acredit eq 1) {
$mymoney=$_;
$mymoney=~ s/[^0-9\.]//g;
$mymoney=~ s/\./\,/;
print(BF $mymoney."\n");
$acredit=0;
} elsif ($afree eq 1) {
$myfree=$_;
$myfree=~ s/[^0-9]//g;
if ( length($myfree) eq 0 ) { $myfree = 0; }
$afree=0;
last;
}
}
close(TXT);
close(BF);
unlink($sTXT_File);
&betamax_curl($url.'/index.php?part=logoff','GET');
unlink($sCookie_File);