#!/usr/bin/perl -U # 程式:線上帳號管理程式 # 版次:1.62 # 修改日期:2001/7/18 # 程式設計:李忠憲 (hp2013@ms8.hinet.net) # 頁面美工:黃自強 (dd@mail.ysps.tp.edu.tw) # 特別感謝半點心工作坊林朝敏(prolin@sy3es.tnc.edu.tw)提供密碼檢查javascript程式 # 使用本程式必須遵守以下版權規定: # 本程式遵守GPL 開放原始碼之精神,但僅授權教育用途或您個人使用 # 此檔頭為本程式版權的一部份,請勿將此檔頭移除 # program: WAM(Web-Base Accounts Manager) # author: Shane Lee(hp2013@ms8.hinet.net) # UI design: John Hwang(dd@mail.ysps.tp.edu.tw) # special thanx prolin(prolin@sy3es.tnc.edu.tw) suport the passwd-checking javascript # This Software is Open Source, but for personal use only. # This title is a part of License. You can NOT remove it. # use FCGI; use strict; no strict 'vars'; $config = "./wam.conf"; $gconfig = "./group.conf"; $share_conf = "./share.conf"; $cgi_url = "/wam.cgi"; $cnt_url = "/count_demo.cgi"; $account = "./account.lst"; $quota_temp = "./quota.tmp"; $tmp_index = "./index.tmp"; $tmp_album = "./message.tmp"; $tmp_passwd = "./passwd.tmp"; $tmp_shadow = "./shadow.tmp"; $tmp_group = "./group.tmp"; $tmp_gshadow = "./gshadow.tmp"; $cnt_config = '.counter_conf'; $cnt_data = '.counter_data'; $cnt_dir = "/digits"; $cnt_base = "/usr/libexec/wam/digits"; $lang_base = "/usr/libexec/wam/lang"; $gb_config = '.guestbook_conf'; $gb_data = '.message_data'; $gb_reply = '.reply_data'; $gb_subscribe = '.subscribe_data'; $mailtmp = ".wam"; @referers = ('jls.idv.tw','61.64.116.164'); @special = ('shutdown','halt','operator','gdm','ftpadm','mysql','sync','samba','ftp','sendmail','adm','bin','console','daemon','dip','disk','floppy','ftp','games','gopher','kmem','lp','mail','man','mem' ,'wam','dd','nogroup','cdwriters','wnn','xgrp','root','news','nobody','popusers','postgres','pppusers','slipusers','slocate','sys','tty','utmp','uucp','wheel','xfs','ctools','ntools'); ############################################################################## $zip_test = `whereis zip`; $zip_exist = 0; $zip_exist = 1 if ($zip_test =~ /^zip: .+/); $itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; $base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; $HOST=`/bin/hostname`; $HOST=~ s/\n//g; push (@INC, '/usr/libexec/wam/neomail/etc', '/usr/libexec/wam/neomail' , '.'); use MD5; use IO::Socket; use Quota; require "neomail.conf"; require "demime.pl"; require "maildb.pl"; require "pop3mail.pl"; require "neomail.pl"; sub to64 { my ($v, $n) = @_; my $ret = ''; while (--$n >= 0) { $ret .= substr($itoa64, $v & 0x3f, 1); $v >>= 6; } $ret; } sub rnd64 { my $ret = ''; my $n = 8, $i; while (--$n >= 0) { $i = rand; if ($CONFIG{'passwd_range'} eq 'num') { $ret .= substr($itoa64, int($i*10)+2, 1); } elsif ($CONFIG{'passwd_range'} eq 'lcase') { $ret .= substr($itoa64, int($i*26)+38, 1); } elsif ($CONFIG{'passwd_range'} eq 'ucase') { $ret .= substr($itoa64, int($i*26)+12, 1); } elsif ($CONFIG{'passwd_range'} eq 'allcase') { $ret .= substr($itoa64, int($i*52)+12, 1); } elsif ($CONFIG{'passwd_range'} eq 'num-lcase') { my $j = int($i*36); if ($j > 9) { $ret .= substr($itoa64, $j+28, 1); } else { $ret .= substr($itoa64, $j+2, 1); } } elsif ($CONFIG{'passwd_range'} eq 'num-ucase') { $ret .= substr($itoa64, int($i*36)+2, 1); } elsif ($CONFIG{'passwd_range'} eq 'all') { $ret .= substr($itoa64, int($i*64), 1); } } $ret; } sub urldecode { my($str) = @_; $str =~ s/\%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $str; } sub urlencode { my($str) = @_; $str =~ s/([\W_ -])/'%'.unpack("H2",$1)/eg; $str; } sub b64decode { my($str) = @_; my($res); $str =~ tr|A-Za-z0-9+=/||cd; $str =~ s/=+$//; $str =~ tr|A-Za-z0-9+/| -_|; while ($str =~ /(.{1,60})/gs) { my $len = chr(32 + length($1)*3/4); $res .= unpack("u", $len . $1 ); } $res; } sub b64encode { my($str) = @_; my($res, $tail, $pre, $byte, $n, $tail); while ($str =~ /(.{3})/gs) { $tail = $'; $pre = unpack("B32",$1); while ($pre =~ /(.{6})/gs) { $byte = substr($base64,ord(pack("B8",'00'.$1)),1); $res .= $byte; } } $n = length($tail); $pre = unpack("B32",$tail); for($i=0;$i<=$n;$i++) { $pre =~ /(.{6})/gs; $byte = substr($base64,ord(pack("B8",'00'.$1)),1); $res .= $byte; } $res."=" x int(3 - $n); } sub qpdecode { my($str) = @_; my(@temp, $res, $line); @temp = split(/\n/,$str); foreach $line (@temp) { $flag = (substr($line, length($line)-1,1) eq '=')?1:0; $line =~ s/=([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($flag eq 1) { $res .= substr($line,0,length($line)-1); chop $res; } else { $res .= $line."\n"; } } $res; } sub qpencode { my($str) = @_; my(@temp, $res, $line, $st); @temp = split(/\n/,$str); foreach $line (@temp) { $line =~ s/([\W_ -])/'='.unpack("H2",$1)/eg; while (length($line)>74) { $st = index($line,'=',68); $st = 70 if ($st>=70); $res .= substr($line,0,$st)."=0A=\n"; $line = substr($line,$st); } $res .= $line."\n"; } $res; } sub apache_md5_crypt { my $Magic = '$apr1$'; unix_md5_crypt(@_); } sub unix_md5_crypt { my($pw, $salt) = @_; my $passwd; my $Magic = '$1$'; $salt =~ s/^\Q$Magic//; $salt =~ s/^(.*)\$.*$/$1/; $salt = substr($salt, 0, 8); $ctx = new MD5; $ctx->add($pw); $ctx->add($Magic); $ctx->add($salt); my ($final) = new MD5; $final->add($pw); $final->add($salt); $final->add($pw); $final = $final->digest; for ($pl = length($pw); $pl > 0; $pl -= 16) { $ctx->add(substr($final, 0, $pl > 16 ? 16 : $pl)); } for ($i = length($pw); $i; $i >>= 1) { if ($i & 1) { $ctx->add(pack("C", 0)); } else { $ctx->add(substr($pw, 0, 1)); } } $final = $ctx->digest; for ($i = 0; $i < 1000; $i++) { $ctx1 = new MD5; if ($i & 1) { $ctx1->add($pw); } else { $ctx1->add(substr($final, 0, 16)); } if ($i % 3) { $ctx1->add($salt); } if ($i % 7) { $ctx1->add($pw); } if ($i & 1) { $ctx1->add(substr($final, 0, 16)); } else { $ctx1->add($pw); } $final = $ctx1->digest; } $passwd = ''; $passwd .= to64(int(unpack("C", (substr($final, 0, 1))) << 16) | int(unpack("C", (substr($final, 6, 1))) << 8) | int(unpack("C", (substr($final, 12, 1)))), 4); $passwd .= to64(int(unpack("C", (substr($final, 1, 1))) << 16) | int(unpack("C", (substr($final, 7, 1))) << 8) | int(unpack("C", (substr($final, 13, 1)))), 4); $passwd .= to64(int(unpack("C", (substr($final, 2, 1))) << 16) | int(unpack("C", (substr($final, 8, 1))) << 8) | int(unpack("C", (substr($final, 14, 1)))), 4); $passwd .= to64(int(unpack("C", (substr($final, 3, 1))) << 16) | int(unpack("C", (substr($final, 9, 1))) << 8) | int(unpack("C", (substr($final, 15, 1)))), 4); $passwd .= to64(int(unpack("C", (substr($final, 4, 1))) << 16) | int(unpack("C", (substr($final, 10, 1))) << 8) | int(unpack("C", (substr($final, 5, 1)))), 4); $passwd .= to64(int(unpack("C", substr($final, 11, 1))), 2); $final = ''; $Magic . $salt . '$' . $passwd; } sub check_referer { my $check_referer = 0; my (@addrs); $check_referer = 1 if ($ENV{'QUERY_STRING'} eq '' || $ENV{'CONTENT_LENGTH'} == 0); if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) { $check_referer = 1; last; } } $check_referer = 1 if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$HOST|i); @addrs = `ifconfig | grep 'inet addr:'`; foreach $addr (@addrs) { $addr =~ /inet addr:([\w.]*)/; if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$1|i) { $check_referer = 1; last; } } } else { $check_referer = 1; } if ($check_referer ne 1) { &head("$SYSMSG{'title_system_info'}"); print "
$SYSMSG{'err_disk_failue'} \n"; print $msg; print '
'; print " ![]() |