Copy Link
Add to Bookmark
Report
Fish Head Gang 04-03
# _______ __ ____ ---------------------------------------------
# __/ ___|\ / \/ ___\......Issue: FHG4-03.TXT.................. |
# | ___| |_| |/ __ .....Author: Ruiner....................... |
# \/| | _ || \ \...Subject: Achillies Hacking Script..... |
# | _| | | | \_\ |..FHG Pak: 04 |
# \__/ \__/ \__/\_____/_____________________________________________|
#
#
#Ok, this is another thing I found on Achillies, this isn't my code
#but it could be if I thought up all this stuff :P anyways edit
#to fit your needs, this one is designed specifically for Achillies
#to find information about whatever, it's cool, I found it after a while
#of searching around, it was hidden, like the weapons the US military kept
#hidden from the KGB during the Cold War :P
#PS....cut my blathering out
#Ruiner
userdb.pl
# low level read/write/find user information
#
#
# The database is stored as Perl scripts that are loaded to set variables.
#
#provides 'userdb.pl';
require 'shlock.pl';
if($live)
{
# production
$basedir="/achilles/billing/accounts";
} else {
# testing
$basedir="$ENV{'HOME'}/achilles/billing/accounts";
}
sub mapuser {
local($user) = @_;
local($first,$dir);
$first=substr($user,0,1);
$dir="$basedir/$first/$user";
system("mkdir -p $dir") unless (-d "$dir");
$dir;
}
sub invoicefile {
local($user) = @_;
local($dir);
$dir=&mapuser($user);
return "$dir/invoices";
}
sub loaduser {
local($user) = @_;
local($dir,$fullname,$accounttype,$uid,$gid,$groups,$monthprice,$period,$startdate,$freehours,$hourcost,$diskprice,$otherprice);
local($billstartdate,$billenddate,$hourstodate,$diskquota);
if(defined($infofields{$user}))
{
# already loaded.
return;
}
$fullname="Some User";
$accounttype="personal";
$monthprice="25.00";
$period="1";
$freehours=50;
$hourcost="0.5";
$balance=0;
$dir = &mapuser($user);
if( -f "$dir/info.pl")
{
require "$dir/info.pl";
}
if( -f "dir/invoice.pl")
{
require "$dir/invoice.pl";
}
$infofields{$user} ="fullname accounttype uid gid groups homedir shell monthprice period startdate freehours hourcost freedisk diskcost othercost otherdesc gstnum pstnum";
$invfields{$user} ="billstartdate billenddate hourstodate diskquota balance";
$fullname{$user}=$fullname;
$accounttype{$user}=$accounttype;
$uid{$user}= $uid;
$gid{$user}= $gid;
$homedir{$user}= $homedir;
$shell{$user}= $shell;
$groups{$user}= $groups;
$monthprice{$user}=$monthprice;
$period{$user}= $period;
$startdate{$user}=$startdate;
$freehours{$user}=$freehours;
$freedisk{$user}= $freedisk;
$hourcost{$user} =$hourcost;
$diskcost{$user} =$diskcost;
$othercost{$user}=$othercost;
$otherdesc{$user}=$otherdesc;
$pstnum{$user} =$pstnum;
$billstartdate{$user}=$billstartdate;
$billenddate{$user} =$billenddate;
$hourstodate{$user} =$diskquota;
$balance{$user} =$balance;
}
sub saveuser_info {
local($user) = @_;
local(@fields,$dir);
$dir=&mapuser($user);
@fields=split(/ /,$infofields{$user});
print "saving fields: ".join(',',@fields)."\n";
open(INFO,">$dir/info.pl");
foreach $field (@fields) {
# insert mangling of strings
print INFO "\$$field=\'".eval("\$${field}{'$user'}")."\';\n";
}
print INFO "1;\n";
close(INFO);
}
sub saveuser_invoice {
local($user) = @_;
local(@fields,$dir);
$dir=&mapuser($user);
@fields=split(/ /,$invfields{$user});
open(INV,">$dir/invoice.pl");
foreach $field (@fields) {
# insert mangling of strings
print INV "\$$field=\'".eval("\$$field{'$user'}")."\';\n";
}
print INV "1;\n";
close(INV);
}
sub saveuser {
&saveuser_info(@_);
&saveuser_invoice(@_);
}
sub alloc_uid {
local($uid);
print "Getting lock on uid number file...";
&lopen(LASTUID,"<","$config'datadir/lastuid");
chop($uid=<LASTUID>);
$uid++;
&lreopen(LASTUID,">","$config'datadir/lastuid");
print LASTUID "$uid\n";
&lclose(LASTUID);
$uid;
}
sub create_login {
local($username)=@_;
local($passwd,$home,$char1);
if(!defined($uid) || $uid{$username} < 1000) {
# allocating user id
$uid{$username}=&alloc_uid;
}
if(!defined($homedir{$username}))
{
if($accounttype{$username} eq "uucp")
{
$home="/nodir";
}
# other account types.
else
{
$char1=substr($loginid,0,1);
$home="$config'useraccounts/$char1/$loginid";
}
}
$passwd="$username:*NONE*:$uid{$username}:$gid{$username}:$fullname{$username}:$homedir{$username}:$shell{$username}";
$ENV{'EDITOR'}="/usr/bin/ed";
$ENV{'VISUAL'}="/usr/bin/ed";
$edfile="/tmp/uid.$$";
open(EDFILE,">$edfile");
print EDFILE "\$a\n";
print EDFILE "$passwd\n";
print EDFILE ".\nw\nq\n";
close(EDFILE);
system("vipw <$edfile");
}
sub init_account {
local($username)=@_;
if($accounttype{$username} eq "uucp")
{
$home="/nodir";
}
# other account types.
else
{
$home=$homedir{$username};
print "\n\nMaking home directory\n";
system("mkdir -p $home");
print "Copying init files\n";
system("cd $config'datadir/defaults; tar cf - . | (cd $home; tar xvf -)");
print "Changing ownership\n";
system("chown -R $username.$gid{$username} $home");
print "Adding quota\n";
system("edquota -p new $username");
print "Results:\n";
system("ls -lRga $home");
}
}
#
#
#provides 'userusage.pl';
require 'userdb.pl';
sub loadtimes {
local($user,$year,$month)=@_;
if($live)
{
dbmopen(%sysusage,"/achilles/billing/abs/datafiles/sysusage",undef);
# $lastupdate=$sysusage{"last-update\0"};
# print "Last update was: $lastupdate\n";
$usageentry=$sysusage{"U:$user-$month/$year\0"};
# print "Usage: $usageentry\n";
dbmclose(%sysusage);
} else {
$usageentry="-1 8770 -1 1829 8523 -1 -1 -1 1153 -1 15263 1269 -1 4006 762 159 -1 -1 1755 186 5333 923 1478 568 -1 -1 -1 -1 -1 -1 -1 0";
}
return $usageentry;
}
sub diskusage {
local($user)=@_;
$totdisk=0;
open(QUOTA,"quota -v $user|");
$junk1=<QUOTA>;
$junk2=<QUOTA>;
while(<QUOTA>) {
($part,$du)=split;
$totdisk+=du;
}
return $totdisk;
}
sub billusermonth {
local($user,$year,$month)=@_;
local($invfile);
$usageentry=&loadtimes($user,$year,$month);
&loaduser($user);
$invfile=&invoicefile($user);
$monname=("none","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$month];
open(INVFILE,">>$invfile");
print INVFILE "Achilles Internet INVOICE for $monname $year\n";
print INVFILE "Account: $user\n";
print INVFILE "User: $fullname{$user}\n";
print INVFILE "Type: $accounttype{$user}\n";
print INVFILE "\n";
format INVTOP =
Day Time used
------------------
.
format INVOICE =
@<< @> @>>>>>>>
$monname,$day,$niceusage
.
select((select(INVFILE),$^="INVTOP",$~="INVOICE")[0]); #/
@days=split(/ /,$usageentry);
$day=1;
$totsec=0;
$mondays=("none",31,28,"Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$month];
foreach $usage (@days)
{
# print "processing day:$day\n";
if($usage > 0)
{
$totsec+=$usage;
$sec=$usage%60;
$min=int($usage/60)%60;
$hr =int($usage/3600);
$niceusage=sprintf("%02d:%02d:%02d",$hr,$min,$sec);
write(INVFILE);
}
$day++;
}
$hours=$totsec/3600;
printf INVFILE "\nTotal number of hours: %.2f\n",$hours;
print INVFILE "Number of free hours: $freehours{$user}\n";
format SUMTOP =
Summary of charges
Item price
---------------------------------------------
.
format SUMITEM =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>
$item,$niceprice
.
select((select(INVFILE),$^="SUMTOP",$~="SUMITEM")[0]); #/
print INVFILE "\n\n";
print INVFILE " Item price\n";
print INVFILE "---------------------------------------------\n";
$newbalance=0;
if($balance{$user} != 0)
{
$item="Previous balance";
$price=$balance{$user};
$niceprice=sprintf("%.2f",$price);
$newbalance+=price;
write INVFILE;
}
if($monthprice{$user} > 0)
{
$item="Monthly account fee (type=$accounttype{$user})";
$price=$monthprice{$user};
$niceprice=sprintf("%.2f",$price);
$newbalance+=$price;
write INVFILE;
}
$billedhours=$hours-$freehours{$user};
if($billedhours>0)
{
$item=sprintf("%03.2g extra hours @\$%02.2g/hour",$billedhours,$hourcost{$user});
$price=$billedhours*$hourcost{$user};
$niceprice=sprintf("%.2f",$price);
$newbalance+=$price;
write INVFILE;
}
$diskusage=&diskusage($user);
$billeddisk=$diskusage-$freedisk{$user};
if($billeddisk > 0)
{
$item=sprintf("%05.1g kilobytes of disk @\$%02.2g/kB",$billeddisk,$diskcost{$user});
$price=$billeddisk*$diskcost{$user};
$niceprice=sprintf("%.2f",$price);
$newbalance+=$price;
write INVFILE;
}
if($othercost{$user} > 0)
{
$item="Other services: $otherdesc{$user}";
$price=$othercost{$user};
$niceprice=sprintf("%.2f",$price);
$newbalance+=$price;
write INVFILE;
}
print INVFILE "---------------------------------------------\n";
$subtotal=$newbalance;
$item="SUBTOTAL";
$niceprice=sprintf("%.2f",$price);
$price=$newbalance;
write INVFILE;
print INVFILE "---------------------------------------------\n";
if(length($pstnum{$user}) > 0)
{
if($pstnum{$user} == "no")
{
$item="Out of provice sale";
} else {
$item="PST Exemption number: $pstnum{$user}";
}
$price=0;
$niceprice=sprintf("%.2f",$price);
write INVFILE;
} else {
$item="Provincial Sales Tax (8%)";
$price=$subtotal*0.08;
$niceprice=sprintf("%.2f",$price);
$newbalance+=$price;
write INVFILE;
}
$item="Goods and Services Tax (7%)";
$price=$subtotal*0.07;
$niceprice=sprintf("%.2f",$price);
$newbalance+=$price;
write INVFILE;
print INVFILE "---------------------------------------------\n";
$item="TOTAL";
$price=$newbalance;
$niceprice=sprintf("%.2f",$price);
write INVFILE;
$balance{$user}=$newbalance;
}
&loaduser("mcr");
&billusermonth("mcr","1995","11");
&saveuser("mcr");