lms-cachimprt-inteligo w zalaczeniu
Wielu sie pewnie przyda. Jedyna dziwną rzeczą jaką zauważyłem to fakt że HASH w MD5 nie zawsze jest taki sam dla tych samych danych i to bardzo dziwne jest.
konfiguracja w lms.ini
[cashimport_inteligo] id='12345678' ;# login do inteligo pass='abcdef' ;# hasło account='111111111111' ;# nr konta -ostatnie 12 cyfr ;#wyciag_r='strftime "%Y", localtime(time-86400);# rok wyciągu ;#wyciag_m='strftime "%m", localtime(time-86400);# m-c wyciągu ;#wyciag_d='strftime "%d", localtime(time-86400);# d-n wyciągu ;trans_type='CREDIT' ;# 'history_dir='/var/lms/cashimport' ;# folder do zapisu kopi wyciągów
-- ReYu
#!/usr/bin/perl -Tw # # LMS version 1.8.1 Shyla _ moded by ReYu # # (C) 2001-2006 LMS Developers # # Please, see the doc/AUTHORS for more information about authors! # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License Version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # # $Id: lms-cashimport-Inteligo,v 1.1.2.2 2006/01/16 09:35:17 reyu Exp $
use strict; use DBI; use Config::IniFiles; use Getopt::Long; use HTTP::Cookies; use HTTP::Request::Common qw(POST GET); use Crypt::SSLeay; use LWP::UserAgent; use POSIX; use POSIX qw(mktime strftime); use HTML::TokeParser; use Time::Local; use vars qw($configfile $quiet $help $version); use Digest::MD5; use Text::Iconv;
my $_version = '1.8.1 Shyla moded by ReYu';
my %options = ( "--config-file|C=s" => $configfile, "--quiet|q" => $quiet, "--help|h" => $help, "--version|v" => $version, );
Getopt::Long::config("no_ignore_case"); GetOptions(%options);
if($help) { print STDERR <<EOF; lms-cashimport-inteligo, version $_version (C) 2001-2006 LMS Developers & ReYu
-C, --config-file=/etc/lms/lms.ini alternate config file (default: /etc/lms/lms.ini); -h, --help print this help and exit; -v, --version print version info and exit; -q, --quiet suppress any output, except errors;
EOF exit 0; }
if($version) { print STDERR <<EOF; lms-cashimport-inteligo, version $_version (C) 2001-2006 LMS Developers & ReYu
EOF exit 0; }
if(!$configfile) { $configfile = "/etc/lms/lms.ini"; }
if(!$quiet) { print STDOUT "lms-cashimport-inteligo, version $_version\n"; print STDOUT "(C) 2001-2006 LMS Developers & ReYu\n"; print STDOUT "Using file $configfile as config.\n"; }
if(! -r $configfile) { print STDERR "Fatal error: Unable to read configuration file $configfile, exiting.\n"; exit 1; }
my $ini = new Config::IniFiles -file => $configfile; print @Config::IniFiles::errors;
my $dbtype = $ini->val('database', 'type') || 'mysql'; my $dbhost = $ini->val('database', 'host') || 'localhost'; my $dbuser = $ini->val('database', 'user') || 'root'; my $dbpasswd = $ini->val('database', 'password') || ''; my $dbname = $ini->val('database', 'database') || 'lms';
my $login_i = $ini->val('cashimport_inteligo', 'id') || '12345678'; my $passwd_i = $ini->val('cashimport_inteligo', 'pass') || 'abcdef'; my $konto = $ini->val('cashimport_inteligo', 'account') || '111111111111'; my $time_y = $ini->val('cashimport_inteligo', 'wyciag_r') || strftime "%Y", localtime(time-86400); my $time_m = $ini->val('cashimport_inteligo', 'wyciag_m') || strftime "%m", localtime(time-86400); my $time_d = $ini->val('cashimport_inteligo', 'wyciag_d') || strftime "%d", localtime(time-86400); my $trans_type = $ini->val('cashimport_inteligo', 'trans_type') || 'CREDIT'; my $file_out_dir = $ini->val('cashimport_inteligo', 'history_dir') || '/var/lms/cashimport';
my $dbase;
if($dbtype eq "mysql") { $dbase = DBI->connect("DBI:mysql:database=$dbname;host=$dbhost","$dbuser","$dbpasswd", { RaiseError => 1 }); } elsif($dbtype eq "postgres") { $dbase = DBI->connect("DBI:Pg:dbname=$dbname;host=$dbhost","$dbuser","$dbpasswd", { RaiseError => 1 }); } else { print STDERR "Fatal error: unsupported database type: $dbtype, exiting.\n"; exit 1; }
# Definicja Agenta http my $sd =''; my $cookie_jar = HTTP::Cookies->new; my $ua = new LWP::UserAgent; $ua->timeout(30); $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4'); $ua->env_proxy();
# Wchodzimy na stronê my $get = new HTTP::Request(GET => 'https://secure.inteligo.com.pl/'); my $res = $ua->request($get); if ($res->content =~ /Przepraszamy/ ){ print "ERROR: System chwilowo niedostêpny", "\n"; exit 1; } if ($res->content =~ /Identyfikator/ ){ my $p = HTML::TokeParser->new($res->content); while ( my $token1 = $p->get_tag("input")){ if (my $ur = $token1->[1]{name} =~ /sd/){ my $url = $token1->[1]{name} || "-"; my $url2 = $token1->[1]{value} || "-"; $sd = $url2; } } } print "Logujemy do Serwisu ... \t"; my $post = POST 'https://secure.inteligo.com.pl/', [ sd => $sd, form_name => "login", btn_ok => "", menu => "", cif => $login_i, password => $passwd_i, btn_ok => "", ]; my $res1 = $ua->request($post); if ($res1->content =~ /Stan Twoich/ ){ print "Jestesmy zalogowani", "\n"; my $p = HTML::TokeParser->new($res1->content); while ( my $token1 = $p->get_tag("input")){ if (my $ur = $token1->[1]{name} eq "sd"){ my $url = $token1->[1]{name} || "-"; my $url2 = $token1->[1]{value} || "-"; $sd = $url2; } } } print "Przechodzimy do historii ...\t"; my $post1 = POST 'https://secure.inteligo.com.pl/web', [ sd => $sd, section => "mojerachunki", return_point => "1", form_name => "accounts", menu => "history", button => "", ]; $res = $ua->request($post1); if ($res->content =~ /Historia rachunku/ ){ print "Strona Historii Rachunku \n"; my $p1 = HTML::TokeParser->new($res->content); while ( my $token2 = $p1->get_tag("input")){ if (my $ur = $token2->[1]{name} eq "sd"){ my $url = $token2->[1]{name} || "-"; my $url2 = $token2->[1]{value} || "-"; $sd = $url2; } } } print "Zmieniamy filtr historii....\t"; my $post2 = POST 'https://secure.inteligo.com.pl/web', [ sd => $sd, section => "mojerachunki", return_point => "1", form_name => "history", menu => "", button => "filter", selected_acc => $konto, beg_date_y => $time_y, beg_date_m => $time_m, beg_date_d => $time_d, end_date_y => $time_y, end_date_m => $time_m, end_date_d => $time_d, sel_tx_filter_type => $trans_type, amount_min => '', amount_max => '', export_type => 'CSV', ]; $res = $ua->request($post2); if ($res->content =~ /Historia rachunku/ ){ print "Zmieniono filtr \n"; my $p1 = HTML::TokeParser->new($res->content); while (my $token2 = $p1->get_tag("input")){ if (my $ur = $token2->[1]{name} eq "sd"){ my $url = $token2->[1]{name} || "-"; my $url2 = $token2->[1]{value} || "-"; $sd = $url2; } } } print "Pobieramy plik historii....\t"; my $post3 = POST 'https://secure.inteligo.com.pl/web', [ sd => $sd, section => "mojerachunki", return_point => "1", form_name => "history", menu => "", button => "export_list", selected_acc => $konto, beg_date_y => $time_y, beg_date_m => $time_m, beg_date_d => $time_d, end_date_y => $time_y, end_date_m => $time_m, end_date_d => $time_d, sel_tx_filter_type => $trans_type, amount_min => "", amount_max => "", export_type => "CSV", ]; $res = $ua->request($post3); my $post4 = 'https://secure.inteligo.com.pl' . $res->header('Location'); $post4 =GET $post4; $res =$ua->request($post4); print "Pobrano plik\n"; my @dana = split("\n", $res->content); my $file_name = $file_out_dir."/". $konto ."_". time(); if ($file_out_dir){ open (DOUT,">$file_name"); print DOUT "Ilo¶æ pozycji". scalar(@dana) ."\n" }
for (my $x=1;$x<scalar(@dana);$x++){ my $line = $dana[$x]; $line =~ s/"//g; #" my $converter = Text::Iconv->new("ISO-8859-2", "UTF-8"); $line = $converter->convert($line);
my @linia = split(",",$line); my @da = split('-',$linia[2]);
$linia[2] = mktime(0,0,0,$da[2],$da[1]-1, $da[0]-1900); $linia[4] =~ s/[^0-9.]//g; $linia[9] = $linia[9] || ""; $linia[10] = $linia[10] || ""; $linia[11] = $linia[11] || ""; $linia[12] = $linia[12] || "";
if ($file_out_dir){ print DOUT $line ."\n"; } my $date = $linia[2]; my $customer = $linia[8]; my $description = $linia[9] ." ". $linia[10] ." ". $linia[11] ." ". $linia[12]; my $value = $linia[4]; my $customerid = '0'; if ($description =~ m/SALDO/i){ my $customerid_t = $description; $customerid_t =~ s/.+SALDO//gi; $customerid_t =~ s/[^0-9 ]//g; $customerid_t =~ s/^\s+//; $customerid_t =~ s/[ ].*//; $customerid_t =~ s/\s+$//; $customerid = $customerid_t; } if($customerid == '0'){ @da = split(" ", $linia[8]); my $sdbq = $dbase->prepare("SELECT id FROM customers WHERE UPPER(lastname)=UPPER('$da[0]') and UPPER(name)=UPPER('$da[1]')"); $sdbq->execute; my $id = '0'; if (my $row = $sdbq->fetchrow_hashref()){ $customerid = $row->{'id'}; }else { my $sdbq = $dbase->prepare("SELECT id FROM customers WHERE UPPER(lastname)=UPPER('$da[1]') and UPPER(name)=UPPER('$da[0]')"); $sdbq->execute; if (my $row = $sdbq->fetchrow_hashref()){ $customerid = $row->{'id'}; } } } my $dx = new Digest::MD5; my $hash = $dx->md5_hex($date.$value.$customer.$description); my $sdbq = $dbase->prepare("SELECT id FROM cashimport WHERE hash = '$hash'"); $sdbq->execute(); my $row = $sdbq->fetchrow_hashref(); if ($row->{'id'}) { print "ERROR: Hash exists, ignoring $customer $description", "\n"; } else { my $sdbq = $dbase->prepare("INSERT INTO cashimport ( Date , Value , Customer , Description , CustomerId , Hash ) VALUES ('$date', '$value', '$customer', '$description', '$customerid', '$hash');"); $sdbq->execute(); print $date ."|".$value."|".$customerid ."|". $customer."|".$description ."|". $hash ."\n"; } } close DOUT; exit 0; print "ERROR: Nieznany b³±d"; exit 1;
uczestnicy (1)
-
-=ReYu=-