#!/usr/bin/perl -w use XIBUtils qw(xib_dbconnect l); close(STDERR); open(STDERR,'>>/var/log/xib/auth-user-verify.log'); #exit; `arp -an|grep '($ENV{'untrusted_ip'})'`=~/at (..:..:..:..:..:..)/; $real_mac=$1; $login_data="username: $ENV{'username'}; password: $ENV{'password'}; ip: $ENV{'untrusted_ip'}; mac: $real_mac"; $ENV{'password'}=~s/^(.{,10}).*$/$1/; $dbh=xib_dbconnect; $h=$dbh->prepare("SELECT id,pass,ip,mac,banned FROM users WHERE name='$ENV{'username'}'"); $h->execute; unless(($id,$pass,$ip,$mac,$banned)=$h->fetchrow_array) { l "failed to get data for $login_data"; exit(1); } if($pass ne $ENV{'password'}) { l "failed password for $login_data"; exit(2); } if(defined($ip)&&$ip ne '') { if($ip ne $ENV{'untrusted_ip'}) { l "failed ip ($ip) for $login_data"; # goto st_ip; exit(3); } } else { st_ip: l "store ip for $login_data"; $h=$dbh->prepare("UPDATE users SET ip='$ENV{'untrusted_ip'}' WHERE id=$id"); $h->execute; } if(defined($mac)&&$mac ne '') { if($mac ne $real_mac) { l "failed mac ($mac) for $login_data"; # goto st_mac; exit(4); } } else { st_mac: l "store mac for $login_data"; $h=$dbh->prepare("UPDATE users SET mac='$real_mac' WHERE id=$id"); $h->execute; } if($banned=~/\x01/) { l "banned $login_data"; exit(5); } #l "connected ok $login_data"; |