#!/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{'msg_acl_warn'}
"; exit 0; } } sub check_acl { my $check_acl = $CONFIG{'acltype'}; my @acls = split(/;/,$CONFIG{'acls'}); my $userip; if (defined $ENV{'HTTP_X_FORWARDED_FOR'} && $ENV{'HTTP_X_FORWARDED_FOR'} !~ /^10\./ && $ENV{'HTTP_X_FORWARDED_FOR'} !~ /^172\.[1-2][6-9]\./ && $ENV{'HTTP_X_FORWARDED_FOR'} !~ /^192\.168\./ && $ENV{'HTTP_X_FORWARDED_FOR'} !~ /^127\.0\./ ) { $userip=(split(/,/,$ENV{HTTP_X_FORWARDED_FOR}))[0]; } else { $userip=$ENV{REMOTE_ADDR}; } if ($userip) { foreach $acl (@acls) { if ($userip =~ /$acl/) { $check_acl = 1 - $CONFIG{'acltype'}; last; } } } else { $check_acl = $CONFIG{'acltype'}; } if ($check_acl eq 1) { &head("$SYSMSG{'title_system_info'}"); print "
$SYSMSG{'msg_acl_warn'}
"; exit 0; } } sub check_special { my($testname)= @_; my $ret = 0; foreach $epo (@special) { if ($testname eq $epo) { $ret = 1; last; } } $ret; } sub get_form_data { my(@parts, @pairs, $buffer, $pair, $name, $value, $bound, $getfilename, $fname, $filename, $tmp1, $tmp2, $temp, @cookies); if($ENV{'REQUEST_METHOD'} =~ /get/i) { @pairs=split(/&/,$ENV{'QUERY_STRING'}); } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs=split(/&/,$buffer); } %DATA = (); foreach $pair (@pairs) { ($name,$value) = split(/\=/,$pair); $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ s/~!/ ~!/g; $name =~ s/\+/ /g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $value =~ s/\+/ /g; if ($DATA{$name} ne '') { $DATA{$name} .= ",$value"; } else { $DATA{$name} = $value; } } if (!defined($DATA{'step'}) && $buffer ne '') { $buffer =~ /^(.+)\r\n/; $bound = $1; @parts = split(/$bound/,$buffer); for($i=1;$i<@parts;$i++) { next if ($parts[$i] =~ /^--.*/); $parts[$i] =~ s///g; $value = $parts[$i]; @temp = split(/Content-Type.+\r\n\r\n/,$parts[$i]); $content_type = $value; $content_type =~ /Content-Type\: (.*)\r\n\r\n/; $content_type = $1; $content_type = 'application/octet-stream' if ($content_type eq ''); $value =~ s/Content-Disposition.+\r\n//g; $value =~ s/Content-Type.+\r\n\r\n//g; $value =~ s/^\r\n//g; $value =~ s/^\r//g; $value =~ s/^\n//g; $value =~ s/\r\n$//; my($tmp1,$tmp2) = split(/\; filename=/,$temp[0]); $tmp1 =~ /Content-Disposition\: form-data\; name=\"(.*)\"(.*)/; $name = $1; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ s/~!/ ~!/g; $name =~ s/\+/ /g; $tmp2 =~ /\"(.*)\"(.*)/; $getfilename = $1; if($getfilename =~ /[\\\/\:]/) { $fname = $getfilename; #first ignore stuff before last backslash for Windows machines @a=split(/\\/,$fname); $totalT = @a; --$totalT; $fname=$a[$totalT]; @a=split(/\//,$fname); #then ignore stuff before last forwardslash for Unix machines $totalT = @a; --$totalT; $fname=$a[$totalT]; @a=split(/\:/,$fname); #then ignore stuff before last ":" for Macs? $totalT = @a; --$totalT; $fname=$a[$totalT]; @a=split(/\"/,$fname); #now we've got the real filename $filename = $a[0]; } else { $filename = $getfilename; } if ($name eq 'attachment' && $DATA{'step'} eq 'mail' && $value ne '') { &check_password; ($musr,$pwd,$uid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); $UIDNUM{$menu_id} = $musr; @attlist = @{&getattlist()}; if ( ($attlimit) && ( ( $savedattsize + (-s $name) ) > ($attlimit * 1048576) ) ) { neomailerror ("$lang_err{'att_overlimit'} $attlimit MB!"); } $value = encode_base64($value); $savedattsize += length($value); my $attnum = scalar(@attlist) || 0; $myfile = $neomaildir.getpwuid($menu_id)."-att$attnum"; open (ATTFILE, ">$myfile"); print ATTFILE "Content-Type: ", $content_type,";\n"; print ATTFILE "\tname=\"$filename\"\nContent-Transfer-Encoding: base64\n\n"; print ATTFILE "$value"; close ATTFILE; system("chown -f $menu_id:$menu_gid $myfile"); system("chmod 0700 $myfile"); } elsif ($name =~ /digits_(.{1})/ && $value ne '') { $digit = $1.".gif"; $mydir = "$cnt_base/$DATA{'folder'}"; system("mkdir -p $mydir"); open(REAL,"> $mydir/$digit") || &err_disk("$SYSMSG{'err_cannot_save_upload_file'} $mydir/$digit
"); binmode REAL; print REAL $value; close(REAL); } elsif ($name eq 'upload_file' && $value ne '') { if ($DATA{'step'} eq 'doupload') { open(REAL,"> $account") || &err_disk("$SYSMSG{'err_cannot_save_upload_file'} $account
"); print REAL $value; close(REAL); } elsif ($DATA{'step'} eq 'doupgrade' && $DATA{'mode'} eq 'upload') { system("mkdir -p /usr/libexec/wam/patch"); $myfile = "/usr/libexec/wam/patch/$filename"; system("rm -rf $myfile") if (-e $myfile); open(REAL,"> $myfile") || &err_disk("$SYSMSG{'err_cannot_save_upload_file'} $myfile
"); binmode REAL; print REAL $value; close(REAL); &patch($myfile); } elsif ($DATA{'step'} eq 'sharemgr') { if ($DATA{'folder'} eq '/') { $myfile = "$DATA{'folder'}$filename"; } else { $myfile = "$DATA{'folder'}/$filename"; } &check_password; open(REAL,"> $myfile") || &err_disk("$SYSMSG{'err_cannot_save_upload_file'} $myfile
"); binmode REAL; print REAL $value; close(REAL); system("chown -Rf $menu_id:$menu_gid $myfile"); system("chmod 0700 $myfile"); } elsif ($DATA{'step'} eq 'filesmgr') { if ($DATA{'folder'} eq '/') { $myfile = "$DATA{'folder'}$filename"; } else { $myfile = "$DATA{'folder'}/$filename"; } &check_password; $)=$menu_gid; $>=$menu_id; open(REAL,"> $myfile") || &err_disk("$SYSMSG{'err_cannot_save_upload_file'} $myfile
"); binmode REAL; print REAL $value; close(REAL); $)=0; $>=0; if ($filename =~ /(.+).zip/ && $zip_exist && $DATA{'unzip'}) { system("unzip -uoqq $myfile -d $DATA{'folder'} > /dev/null"); @zip_list = split(/\n/,`unzip -l $myfile`); foreach $item (@zip_list) { if ($item =~ /\d+ .+ \d\d:\d\d (.+)/) { if ($DATA{'folder'} eq '/') { system("chown -Rf $menu_id:$menu_gid /$1"); } else { system("chown -Rf $menu_id:$menu_gid $DATA{'folder'}/$1"); } } } unlink($myfile); # } elsif ($filename =~ /(.+).tar.gz/ && $DATA{'unzip'}) { # system("cd $DATA{'folder'}"); # system("tar -xzvf $myfile > /dev/null"); # unlink($myfile); } } } elsif ($DATA{$name} ne '') { $DATA{$name} .= ",$value"; } else { $DATA{$name} = $value; } } } } sub empty_cookie { print "Set-Cookie: uid=\n"; print "Set-Cookie: pid=\n"; } sub check_password { my($name, $value, $usr, $pwd); if ($DATA{'user'} ne '' && $DATA{'password'} ne '') { $usr = $DATA{'user'}; $menu_id = getpwnam($usr); $menu_gid = (getpwnam($usr))[3]; if (unix_md5_crypt($DATA{'password'},$PASS{$usr}) eq $PASS{$usr}) { print "Set-Cookie: uid=$menu_id\n"; print "Set-Cookie: pid=".urlencode($PASS{$usr})."\n"; $DATA{'flag'} = 'passed'; $DATA{'step'}='menu' if ($DATA{'step'} eq '' || $DATA{'step'} eq 'relogon'); } else { &err_account; } } else { @cookies = split(/; /,$ENV{'HTTP_COOKIE'}); foreach $cookie (@cookies) { ($name, $value) = split(/=/,$cookie); $menu_id = $value if ($name eq "uid"); $pwd = urldecode($value) if ($name eq "pid"); } $usr = getpwuid($menu_id); $menu_gid = (getpwuid($menu_id))[3]; $DATA{'flag'}='deny' if ($pwd ne $PASS{$usr}); } } sub err_disk { my($msg) = @_; &head("$SYSMSG{'title_system_info'}"); print "

$SYSMSG{'err_disk_failue'}

\n"; print $msg; print ''; print '
'; print "
$SYSMSG{'backto_prev_page'}
"; print '
'; print ""; exit 0; } sub err_account { &head("$SYSMSG{'title_system_info'}"); print "

$SYSMSG{'err_check_account'}

\n"; print "$SYSMSG{'msg_please_check'}"; print ''; print '
'; print "
$SYSMSG{'backto_prev_page'}
"; print '
'; print ""; exit 0; } sub get_lang_list { opendir (DIR, "$lang_base") || &err_disk("磁碟錯誤,語言套件目錄無法讀取。disk error! can't open language defined
"); @LANGS=readdir(DIR); close(DIR); } sub get_lang { my($line, @lines); $CONFIG{'lang'}='Big-5' if ($CONFIG{'lang'} eq ''); open (LANG, "$lang_base/$CONFIG{'lang'}") || &err_disk("磁碟錯誤,語言套件目錄無法讀取。disk error! can't open language defined
"); while ($line = ) { my($name, $value) = split(/:::/, $line); $value =~ s/\n//g; $SYSMSG{$name} = $value; } close(LANG); } sub read_conf { return if (!(-e $config)); open (CFG, "< $config") || &err_disk("$SYSMSG{'err_cannot_open_config'}
"); while ($line = ) { my($name, $value) = split(/:/, $line); $value =~ s/\n//g; $CONFIG{$name} = $value; } close(CFG); } sub read_gconf { return if (!(-e $gconfig)); open (GCFG, "< $gconfig") || &err_disk("$SYSMSG{'err_cannot_open_gconfig'}
"); while ($line = ) { my($name, $value) = split(/:/, $line); $value =~ s/\n//g; $GCONF{$name} = $value; } close(GCFG); } sub write_gconf { my($grp, $home); open(GCFG, "> $gconfig") || &err_disk("$SYSMSG{'err_cannot_open_gconfig'}
"); foreach $grp (keys %GCONF) { $home = $GCONF{$grp}; print GCFG "$grp:$home\n" if ($grp ne '' && $home ne ''); } close(GCFG); } sub read_share { return if (!(-e $share_conf)); open (SCFG, "< $share_conf") || &err_disk("$SYSMSG{'err_cannot_open_share'}
"); while ($line = ) { my($name, $desc, $value1, $value2, $value3, $value4, $value5, $grp) = split(/:/, $line); $grp =~ s/\n//g; $SHARE{$name} = $grp; $SDESC{$name} = $desc; $SPERM_DN{$name} = $value1; $SPERM_UP{$name} = $value2; $SPERM_DIR{$name} = $value3; $SPERM_EDIT{$name} = $value4; $SPERM_DEL{$name} = $value5; } close(SCFG); } sub write_share { open (SCFG, "> $share_conf") || &err_disk("$SYSMSG{'err_cannot_open_share'}
"); foreach $name (keys %SHARE) { $str = join ':', $name, $SDESC{$name}, $SPERM_DN{$name}, $SPERM_UP{$name}, $SPERM_DIR{$name}, $SPERM_EDIT{$name}, $SPERM_DEL{$name}, $SHARE{$name}."\n"; print SCFG $str; } close(SCFG); } sub read_shells { open (SHD, "< $CONFIG{'shells'}") || &err_disk("$SYSMSG{'err_cannot_open_shell'}
"); @SHLS=; close(SHD); } sub read_group { open (GRP, "< $CONFIG{'group'}") || &err_disk("$SYSMSG{'err_cannot_open_group'}
"); while ($line = ) { my($gname, $ignore, $gid, $users) = split(/:/, $line); if ($gid ne '') { $GIDS{$gid} ++; $GNAME{$gname} ++; $GNMID{$gname} = $gid; $GIDNM{$gid} = $gname; $GIG{$gname} = $ignore; $GUSRS{$gname} = $users; } } close(GRP); } sub write_group { my($gid, $grp, $gig, $gu, $gstr); open(TMPG, "> $tmp_group") || &err_disk("$SYSMSG{'err_cannot_open_temp'}
"); foreach $grp (keys %GNAME) { $gid = $GNMID{$grp}; $gig = $GIG{$grp}; $gu = $GUSRS{$grp}; $gstr = join ':', $grp, $gig, $gid, $gu; print TMPG "$gstr"; } close(TMPG); open(TMPG, "< $tmp_group") || &err_disk("$SYSMSG{'err_cannot_open_temp'}
"); open (GRP, "> $CONFIG{'group'}") || &err_disk("$SYSMSG{'err_cannot_open_group'}
"); flock GRP, $LOCK_EX; print GRP ; flock GRP, $LOCK_UN; close(GRP); close(TMPG); unlink($tmp_group); } sub read_passwd { open (PWD, "< $CONFIG{'passwd'}") || &err_disk("$SYSMSG{'err_cannot_open_passwd'}
"); while ($line = ) { my($uname, $ignore, $uid, $gid, $gecos, $home, $shell) = split(/:/, $line); if ($uid ne '') { $UIDS{$uid} ++; $UNAME{$uname} ++; $UNMID{$uname} = $uid; $UIDNM{$uid} = $uname; $UGID{$uid} = $gid; $GECOS{$uid} = $gecos; $HOME{$uid} = $home; $SHELL{$uid} = $shell; } } close(PWD); } sub write_passwd { my($uid, $n, $gn, $g, $gec, $h, $pstr, $sh); open(TMPP, "> $tmp_passwd") || &err_disk("$SYSMSG{'err_cannot_open_temp'}
"); foreach $uid (sort keys %UIDS) { $n = $UIDNM{$uid}; $g = $UGID{$uid}; $gec = $GECOS{$uid}; $h = $HOME{$uid}; $sh = $SHELL{$uid}; $pstr = join ':', $n, "x", $uid, $g, $gec, $h, $sh; print TMPP "$pstr"; } close(TMPP); open(TMPP, "< $tmp_passwd") || &err_disk("$SYSMSG{'err_cannot_open_temp'}
"); open (PWD, "> $CONFIG{'passwd'}") || &err_disk("$SYSMSG{'err_cannot_open_passwd'}
"); flock PWD, $LOCK_EX; print PWD ; flock PWD, $LOCK_UN; close(PWD); close(TMPP); unlink($tmp_passwd); } sub read_shadow { open (SHD, "< $CONFIG{'shadow'}") || &err_disk("$SYSMSG{'err_cannot_open_shadow'}
"); while ($line = ) { my($uname, $pwd, $sday, $smin, $smax, $swarn, $sinact, $sexp, $sflag) = split(/:/, $line); if ($uname ne '') { $PASS{$uname} = $pwd; $SDAY{$uname} = $sday; $SMIN{$uname} = $smin; $SMAX{$uname} = $smax; $SWARN{$uname} = $swarn; $SINACT{$uname} = $sinact; $SEXP{$uname} = $sexp; $SFLAG{$uname} = $sflag; } } close(SHD); } sub write_shadow { my($uid, $usr, $mi, $ma, $w, $d, $p, $i, $e, $w, $f, $sstr); open(TMPS, "> $tmp_shadow") || &err_disk("$SYSMSG{'err_cannot_open_temp'}
"); foreach $uid (sort keys %UIDS) { $usr = $UIDNM{$uid}; $p = $PASS{$usr}; $p = unix_md5_crypt($usr,&rnd64) if ($p eq ""); $d = $SDAY{$usr}; $d = $today if ($d eq ""); $mi = $SMIN{$usr}; $mi = $CONFIG{'min'} if ($mi eq ""); $ma = $SMAX{$usr}; $ma = $CONFIG{'max'} if ($ma eq ""); $w = $SWARN{$usr}; $w = $CONFIG{'pwarn'} if ($w eq ""); $i = $SINACT{$usr}; $i = $CONFIG{'inact'} if ($i eq ""); $e = $SEXP{$usr}; if ($e eq "") { $e = $today + $CONFIG{'expire'}; $e = -1 if ($CONFIG{'expire'} < 30); } $f = $SFLAG{$usr}; $f = $CONFIG{'flag'}."\n" if ($f eq ""); $sstr = join ':', $usr, $p, $d, $mi, $ma, $w, $i, $e, $f; print TMPS "$sstr"; } close(TMPS); open(TMPS, "< $tmp_shadow") || &err_disk("$SYSMSG{'err_cannot_open_temp'}
"); open (SHD, "> $CONFIG{'shadow'}") || &err_disk("$SYSMSG{'err_cannot_open_shadow'}
"); flock SHD, $LOCK_EX; print SHD ; flock SHD, $LOCK_UN; close(SHD); close(TMPS); unlink($tmp_shadow); } sub check_group { my($grp, $f1) = @_; my($warning, $f2); $f2 = defined($GNAME{$grp}); if ($f1 eq '1' && $f2) { print "
$grp $SYSMSG{'err_group_exist'}

"; $warning ++; } if ($f1 eq '0' && !$f2) { print "
$grp $SYSMSG{'err_group_not_exist'}

"; $warning ++; } if ($warning != 0) { if ($f1 eq '1') { print "
"; &foot(''); exit; } sub read_cnt_conf { my($conf) = @_; %CNTCONF = (); if (-e $conf) { open (CFG, "< $conf") || &err_disk("$SYSMSG{'err_cannot_open_counter_config'}
"); while ($line = ) { my($name, $value) = split(/:/, $line); $value =~ s/\n//g; $CNTCONF{$name} = $value; } close(CFG); } else { $CNTCONF{'start'} = 0; $CNTCONF{'check_ip'} = 'yes'; $CNTCONF{'add'} = 1; $CNTCONF{'digits'} = 5; $CNTCONF{'style'} = '01'; open (CFG, "> $conf") || &err_disk("$SYSMSG{'err_cannot_open_counter_config'}
"); foreach $name (keys %CNTCONF) { print CFG "$name:$CNTCONF{$name}\n"; } close(CFG); } } sub read_cnt_data { my($data) = @_; %COUNT = (); %LASTIP = (); if (-e $data) { open (SCFG, "< $data") || &err_disk("$SYSMSG{'err_cannot_open_counter_data'}
"); while ($line = ) { my($urlname, $counter, $lastip) = split(/:/, $line); $lastip =~ s/\n//g; $COUNT{$urlname} = $counter; $LASTIP{$urlname} = $lastip; } close(SCFG); } } sub write_cnt_data { my($data) = @_; open (SCFG, "> $data") || &err_disk("$SYSMSG{'err_cannot_open_counter_data'}
"); flock(SCFG,2); foreach $name (keys %COUNT) { $str = join ':', $name, $COUNT{$name}, $LASTIP{$name}."\n"; print SCFG $str; } flock(SCFG,8); close(SCFG); } sub read_gb_conf { my($conf) = @_; %GBCONF = (); if (-e $conf) { open (SCFG, "< $conf") || &err_disk("$SYSMSG{'err_cannot_open_gbook_config'}
"); while ($line = ) { my($name, $value) = split(/:/, $line); $value =~ s/\n//g; $GBCONF{$name} = $value; } close(SCFG); } else { $GBCONF{'title'} = getpwuid($menu_id)."$SYSMSG{'gbook_owned'}"; $GBCONF{'many'} = 5; $GBCONF{'page_jump'} = 'yes'; $GBCONF{'sort'} = 'by_date'; open (SCFG, "> $conf") || &err_disk("$SYSMSG{'err_cannot_open_gbook_config'}
"); foreach $name (keys %GBCONF) { print SCFG "$name:$GBCONF{$name}\n"; } close(SCFG); } } sub read_gb_data { my($data) = @_; %GBPARN = (); %GBDATE = (); %GBAUTH = (); %GBMAIL = (); %GBTITLE = (); %MESSAGES = (); %MODE = (); if (-e $data) { open (DATA, "< $data") || &err_disk("$SYSMSG{'err_cannot_open_gbook_message'}
"); while ($line = ) { my($cnt,$parn,$gdate,$auth,$mail,$mtitle,$mlink,$mod) = split(/:::/, $line); if (length($mod) eq 0) { $mlink =~ s/\n//g; $GBIP{$cnt} = '0.0.0.0'; $GBDATE{$cnt} = $parn; $GBAUTH{$cnt} = $gdate; $GBMAIL{$cnt} = $auth; $GBTITLE{$cnt} = $mail; $MESSAGES{$cnt} = $mtitle; $MODE{$cnt} = $mlink; } else { $mod =~ s/\n//g; $GBIP{$cnt} = $parn; $GBDATE{$cnt} = $gdate; $GBAUTH{$cnt} = $auth; $GBMAIL{$cnt} = $mail; $GBTITLE{$cnt} = $mtitle; $MESSAGES{$cnt} = $mlink; $MODE{$cnt} = $mod; } } close(DATA); } } sub read_gb_reply { my($data) = @_; %REPARN = (); %REDATE = (); %REAUTH = (); %REMAIL = (); %RETITLE = (); %REPLYS = (); %REIP = (); if (-e $data) { open (DATA, "< $data") || &err_disk("$SYSMSG{'err_cannot_open_gbook_message'}
"); while ($line = ) { my($cnt,$parn,$gdate,$auth,$mail,$mtitle,$mlink,$ip) = split(/:::/, $line); $ip =~ s/\n//g; $REPARN{$cnt} = $parn; $REDATE{$cnt} = $gdate; $REAUTH{$cnt} = $auth; $REMAIL{$cnt} = $mail; $RETITLE{$cnt} = $mtitle; $REPLYS{$cnt} = $mlink; $REIP{$cnt} = $ip; } close(DATA); } } sub write_gb_data { my($data) = @_; open (DATA, "> $data") || &err_disk("$SYSMSG{'err_cannot_open_gbook_message'}
"); foreach $cnt (keys %GBDATE) { $str = join ':::',$cnt,$GBIP{$cnt},$GBDATE{$cnt},$GBAUTH{$cnt},$GBMAIL{$cnt},$GBTITLE{$cnt},$MESSAGES{$cnt},$MODE{$cnt}."\n"; print DATA $str; } close(DATA); } sub write_gb_reply { my($data) = @_; open (DATA, "> $data") || &err_disk("$SYSMSG{'err_cannot_open_gbook_message'}
"); foreach $cnt (keys %REDATE) { $str = join ':::',$cnt,$REPARN{$cnt},$REDATE{$cnt},$REAUTH{$cnt},$REMAIL{$cnt},$RETITLE{$cnt},$REPLYS{$cnt},$REIP{$cnt}."\n"; print DATA $str; } close(DATA); } sub read_gb_subscribe { my($data) = @_; if (-e $data) { open (DATA, "< $data") || &err_disk("$SYSMSG{'err_cannot_open_gbook_subscribe'}
"); my $i = 0; while ($line = ) { $line =~ s/\n//g; $SUBSCRIBE{$i}=$line; $i ++; } close(DATA); } } sub write_gb_subscribe { my($data) = @_; open (DATA, "> $data") || &err_disk("$SYSMSG{'err_cannot_open_gbook_subscribe'}
"); foreach $line (sort values %SUBSCRIBE) { print DATA "$line\n"; } close(DATA); } sub mail2me { my($subject, $body) = @_; open(MAIL,"|$CONFIG{'mailprog'} -t") || &err_disk("$SYSMSG{'err_cannot_open'}$CONFIG{'mailprog'}$SYSMSG{'program'}.
"); print MAIL "To: $UIDNM{$menu_id}\@$HOST\n"; print MAIL "From: $SYSMSG{'wam'}(wam\@$HOST)\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$SYSMSG{'from_wam'}\n"; print MAIL "-" x 75 . "\n\n"; $body =~ s/
/\r\n/g; print MAIL "$body\n\n"; print MAIL "-" x 75 . "\n\n"; close (MAIL); } sub set_aliases { my($aliase,$maillist) = @_; open(ALIAS,"$CONFIG{'mailaliases'}") || &err_disk("$SYSMSG{'err_cannot_open_aliases'}$CONFIG{'mailaliases'}.
"); @lines=; close (ALIAS); system("mv $CONFIG{'mailaliases'} $CONFIG{'mailaliases'}.org"); open(ALIAS,">$CONFIG{'mailaliases'}") || &err_disk("$SYSMSG{'err_cannot_open_aliases'}$CONFIG{'mailaliases'}.
"); foreach $line (@lines) { print ALIAS $line if ($line !~ /^$aliase: /); } print ALIAS "$aliase: \":include:$maillist\"\n"; close (ALIAS); } sub unset_aliases { my($aliase) = @_; open(ALIAS,"$CONFIG{'mailaliases'}") || &err_disk("$SYSMSG{'err_cannot_open_aliases'}$CONFIG{'mailaliases'}.
"); @lines=; close (ALIAS); system("mv $CONFIG{'mailaliases'} $CONFIG{'mailaliases'}.org"); open(ALIAS,">$CONFIG{'mailaliases'}") || &err_disk("$SYSMSG{'err_cannot_open_aliases'}$CONFIG{'mailaliases'}.
"); foreach $line (@lines) { print ALIAS $line if ($line !~ /^$aliase: /); } close (ALIAS); } sub gb_submailer { my($from, $usr, $subject, $body) = @_; ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); $from = $SYSMSG{'gbook_miss_from'} if ($from eq ""); open(MAIL,"|$CONFIG{'mailprog'} -t") || &err_disk("$SYSMSG{'err_cannot_open'} $CONFIG{'mailprog'} $SYSMSG{'program'}
"); print MAIL "To: gbook-$musr\@$HOST\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$usr $SYSMSG{'gbook_post_on'}$GBCONF{'title'}$SYSMSG{'gbook_above'}\n\n"; print MAIL "$SYSMSG{'gbook_click_here'} $GBCONF{'title'} http://$HOST:$PORT/gbook.cgi?user=$user \n"; print MAIL "-" x 75 . "\n\n"; $body =~ s/
/\r\n/g; print MAIL "$body\n\n"; print MAIL "-" x 75 . "\n\n"; close (MAIL); } sub get_wam_version { open(VERSION, "version") || return 0; chop($myver = ); close(VERSION); $myver; } sub patch { my($myfile) = @_; if ($myfile =~ /(.+).zip/ && $zip_exist) { system("unzip -d /root -uoqq $myfile > /dev/null"); } elsif ($myfile =~ /(.+).tar.gz/) { system("cd /root"); system("tar -xzvf $myfile > /dev/null"); } system("cp -R /root/wam/* /usr/libexec/wam"); system("chmod 0755 /usr/libexec/wam/*.cgi"); system("chmod 0755 /usr/libexec/wam/patch.sh"); system("chmod 0755 /usr/libexec/wam/patch.cgi"); system("chmod 0755 /usr/libexec/wam/install"); system("rm -rf /root/wam"); `/usr/libexec/wam/patch.sh` if (-f "/usr/libexec/wam/patch.sh"); `perl /usr/libexec/wam/patch.cgi` if (-f "/usr/libexec/wam/patch.cgi"); } sub err_socket { my($msg) = @_; &head($SYSMSG{'title_system_info'}); print "

$SYSMSG{'err_group_exist'}

\n"; print "$SYSMSG{'err_cannot_continue_becouse'} $warning $SYSMSG{'err_group_exist'}
"; print '
    '; print "
  • $SYSMSG{'msg_delete_group_first'}"; print "
  • $SYSMSG{'msg_check_upload_group'}"; print '
'; } else { print "

$SYSMSG{'err_group_not_exist'}

\n"; print "$SYSMSG{'err_cannot_continue_becouse'} $warning $SYSMSG{'err_group_not_exist'}
"; print '
    '; print "
  • $SYSMSG{'msg_add_group_first'}"; print "
  • $SYSMSG{'msg_check_upload_group'}"; print '
'; } print '
'; print '
回上一頁
'; print '
'; print ""; exit 1; } } sub check_user { my($usr, $f1) = @_; my($warning, $f2); $f2 = defined($UNAME{$usr}); if ($f1 eq '1' && $f2) { print "
$usr $SYSMSG{'err_username_exist'}

"; $warning ++; } if ($f1 eq '0' && !$f2) { print "
$usr $SYSMSG{'err_username_not_exist'}

"; $warning ++; } if ($warning != 0) { if ($f1 eq '1') { print "

$SYSMSG{'err_username_exist'}

\n"; print "$SYSMSG{'err_cannot_continue_becouse'}$warning$SYSMSG{'err_username_exist'}
"; print '
    '; print "
  • $SYSMSG{'msg_delete_user_first'}"; print "
  • $SYSMSG{'msg_check_upload_username'}"; print '
'; } else { print "

$SYSMSG{'err_username_not_exist'}

\n"; print "$SYSMSG{'err_cannot_continue_becouse'}$warning$SYSMSG{'err_username_not_exist'}
"; print '
    '; print "
  • $SYSMSG{'msg_add_user_first'}"; print "
  • $SYSMSG{'msg_check_upload_username'}"; print '
'; } print '
'; print '
回上一頁
'; print '
'; print ""; exit 1; } } sub get_uid { my $i; for ($i=600;$i<65535;$i++) { last if (!defined($UIDS{$i})); } $i; } sub get_gid { my $i; for ($i=600;$i<65535;$i++) { last if (!defined($GIDS{$i})); } $i; } sub addone { my($usr, $grp, $pwd, $sub_grp) = @_; my($lvl, @lvls, $home, $gn); $gn = $grp; $home = $CONFIG{'base_dir'}; $home = "$CONFIG{'base_dir'}/$grp" if ($CONFIG{'home_nest'} eq 'yes'); &add_grp($grp,$home) if (!defined($GNAME{$grp})); if ($sub_grp ne '') { @lvls = split(/\//,$sub_grp); foreach $lvl (@lvls) { $home .= "/$lvl"; &add_grp($lvl,$home) if (!defined($GNAME{$lvl})); $gn = $lvl; } } &check_user($usr,'1'); $uid = &get_uid; $g = $GNMID{$gn}; $h = $GCONF{$gn}; $h = $CONFIG{'base_dir'} if ($CONFIG{'home_nest'} ne 'yes' || $h eq ''); $UIDS{$uid} ++; $UNAME{$usr} ++; $UNMID{$usr} = $uid; $UIDNM{$uid} = $usr; $UGID{$uid} = $g; $GECOS{$uid} = ''; $HOME{$uid} = "$h/$usr"; $SHELL{$uid} = $CONFIG{'shell'}."\n"; $PASS{$usr} = unix_md5_crypt($pwd,&rnd64); $SDAY{$usr} = $today; $SMIN{$usr} = $CONFIG{'min'}; $SMAX{$usr} = $CONFIG{'max'}; $SWARN{$usr} = $CONFIG{'pwarn'}; $SINACT{$usr} = $CONFIG{'inact'}; $exp = $today + $CONFIG{'expire'}; $exp = -1 if ($CONFIG{'expire'} < 30); $SEXP{$usr} = $exp; $SFLAG{$usr} = $CONFIG{'flag'}."\n"; $sreqn{$uid} = $usr; $sreqg{$uid} = $gn; $sreqp{$uid} = $pwd; $sreqt{$uid} = join ':', $usr, "x", $uid, $g, "", $HOME{$uid}, $SHELL{$uid}; $sreqs{$uid} = join ':', $usr, $PASS{$usr}, $SDAY{$usr}, $SMIN{$usr}, $SMAX{$usr}, $SWARN{$usr}, $SINACT{$usr}, $SEXP{$usr}, $SFLAG{$usr}; } sub read_request { open (REQ, "< $account") || &err_disk("$account $sysmsg{'err_cannot_open'}.
"); while ($line = ) { local($uname, $gname, $pwd) = split(/ /, $line); $pwd =~ s/[\n|\r]//g; &addone($uname, $gname, $pwd, '') if ($uname ne '' && $gname ne '' && $pwd ne ''); } close(REQ); } sub autoadd { my($grp, $pre, $st, $ed, $z, $gst, $ged, $cst, $ced) = @_; my($u1, $u2, $u3, $i, $j, $k, $l1, $l2, $l3, $g, $p, $n, $d); $l1 = length($ed); $l2 = length($ged); $l3 = length($ced); if ($CONFIG{'nest'} eq 1) { for ($i=int($st); $i<=int($ed); $i++) { $u1 = ''; for (1..$l1-length($i)){$u1 .= '0';} $n = $pre.(($z eq 'yes')?$u1:'').$i; $p = (($CONFIG{'passwd_form'} eq 'username')?$n:(($CONFIG{'passwd_form'} eq 'random')?&rnd64:"passwd")); &addone($n, $grp, $p, ''); } } elsif ($CONFIG{'nest'} eq 2) { for ($j=int($gst); $j<=int($ged); $j++) { for ($i=int($st); $i<=int($ed); $i++) { $u1 = ''; for (1..$l1-length($i)){$u1 .= '0';} $u2 = ''; for (1..$l2-length($j)){$u2 .= '0';} $n = $pre.(($z eq 'yes')?$u2:'').$j.(($z eq 'yes')?$u1:'').$i; $p = (($CONFIG{'passwd_form'} eq 'username')?$n:(($CONFIG{'passwd_form'} eq 'random')?&rnd64:"passwd")); $g = $pre.(($z eq 'yes')?$u2:'').$j; &addone($n, $pre, $p, $g); } } } elsif ($CONFIG{'nest'} eq 3) { for ($j=int($gst); $j<=int($ged); $j++) { for ($k=int($cst); $k<=int($ced); $k++) { for ($i=int($st); $i<=int($ed); $i++) { $u1 = ''; for (1..$l1-length($i)){$u1 .= '0';} $u2 = ''; for (1..$l2-length($j)){$u2 .= '0';} $u3 = ''; for (1..$l3-length($k)){$u3 .= '0';} $n = $pre.(($z eq 'yes')?$u2:'').$j.(($z eq 'yes')?$u3:'').$k.(($z eq 'yes')?$u1:'').$i; $p = (($CONFIG{'passwd_form'} eq 'username')?$n:(($CONFIG{'passwd_form'} eq 'random')?&rnd64:"passwd")); $d = $pre.(($z eq 'yes')?$u2:'').$j; $g = $pre.(($z eq 'yes')?$u2:'').$j.(($z eq 'yes')?$u3:'').$k; &addone($n, $pre, $p, "$d/$g"); } } } } } sub add_wam { my($usr) = @_; &check_group('wam','0'); &check_user($usr,'0'); if ($GUSRS{'wam'} eq "\n") { $GUSRS{'wam'} =~ s/\n//g; $GUSRS{'wam'} .= "$usr\n"; } else { $GUSRS{'wam'} =~ s/\n//g; $GUSRS{'wam'} .= ",$usr\n"; } } sub del_wam { my($usr) = @_; &check_group('wam','0'); if ($GUSRS{'wam'} ne "\n" && $usr ne "") { $GUSRS{'wam'} =~ s/,$usr//g; $GUSRS{'wam'} =~ s/$usr,//g; } } sub add_grp { my($grp,$home) = @_; my($gid); $home = '/home' if ($home eq ''); &check_group($grp,'1'); $gid = &get_gid; $GIDS{$gid} ++; $GNAME{$grp} ++; $GNMID{$grp} = $gid; $GIDNM{$gid} = $grp; $GIG{$grp} = ""; $GUSRS{$grp} = "\n"; $GCONF{$grp} = $home; } sub del_grp { my($grp) = @_; my($gid); &check_group($grp,'0'); $gid = $GNMID{$grp}; if (int($gid)>0) { delete $GIDS{$gid}; delete $GNAME{$grp}; delete $GCONF{$grp}; delete $GNMID{$grp}; delete $GIDNM{$gid}; delete $GIG{$grp}; delete $GUSRS{$grp}; } splice @GIDS; splice @GNAME; } sub delone { my($uid, $usr) = @_; my($line, @lines); print "
$SYSMSG{'del_user_now'} $usr ,uid: $uid ....

"; delete $UIDS{$uid}; delete $UNAME{$usr}; delete $UNMID{$usr}; delete $UIDNM{$uid}; delete $UGID{$uid}; delete $GECOS{$uid}; system("rm -rf $HOME{$uid}") if (-e "$HOME{$uid}" && -d _); system("rm -rf $mailspooldir/$usr") if (-e "$mailspooldir/$usr" && -d _); delete $HOME{$uid}; delete $SHELL{$uid}; delete $PASS{$usr}; delete $SDAY{$usr}; delete $SMIN{$usr}; delete $SMAX{$usr}; delete $SWARN{$usr}; delete $SINACT{$usr}; delete $SEXP{$usr}; delete $SFLAG{$usr}; open(SMB, "$CONFIG{'smbpasswd'}"); @lines = ; close(SMB); open(SMB, ">$CONFIG{'smbpasswd'}"); foreach $line (@lines) { print SMB $line if ($line !~ /^$usr:$uid:.+$/); } close(SMB); splice @UIDS; splice @UNAME; splice @PASS; } sub delete_pw { my($u, $g, $w) = @_; my($uid, $n, $mygrp, $usr, $d); if ($u eq '999') { $g = ''; $w = ''; foreach $uid (keys %UIDS) { $usr = $UIDNM{$uid}; &delone($uid,$usr) if (int($uid)>1000); } } elsif ($u ne '') { $g = ''; $w = ''; $uid = $UNMID{$u}; &delone($uid,$u); } if ($g ne '') { $w = ''; $mygrp = $GNMID{$g}; return if (int($mygrp)<500); foreach $uid (keys %UIDS) { $usr = $UIDNM{$uid}; &delone($uid,$usr) if ($UGID{$uid} eq $mygrp); } if ($CONFIG{'home_nest'} eq 'yes') { $d = $GCONF{$g}; system("rmdir $d") if ($d ne '' && -e "$d" && -d _); } &del_grp($g); } if ($w ne '') { foreach $usr (sort keys %UNAME) { $uid = $UNMID{$usr}; &delone($uid,$usr) if ($usr =~ /$w/); } foreach $mygrp (sort keys %GNAME) { if ($mygrp =~ /$w/) { if ($CONFIG{'home_nest'} eq 'yes') { $d = $GCONF{$mygrp}; system("rmdir $d") if ($d ne '' && -e "$d" && -d _); } &del_grp($mygrp); } } } &write_gconf; &write_group; } sub reset_pw { my($u, $g, $w, $pf) = @_; my($uid, $usr, $p); if ($u eq '999') { $g = ''; $w = ''; foreach $uid (keys %UIDS) { push (@CHGPW, $UIDNM{$uid}) if (int($uid)>1000); } } elsif ($u ne '') { $g = ''; $w = ''; &check_user($u,'0'); push (@CHGPW, $u); } if ($g ne '') { $w = ''; return if (int($GNMID{$g})<500); &check_group($g,'0'); foreach $uid (keys %UIDS) { push (@CHGPW, $UIDNM{$uid}) if ($UGID{$uid} eq $GNMID{$g}); } } if ($w ne '') { foreach $usr (keys %UNAME) { push (@CHGPW, $usr) if ($usr =~ /$w/); } } foreach $usr (@CHGPW) { if ($pf eq 'username') { $PASS{$usr} = unix_md5_crypt($usr,$PASS{$usr}); &smb_passwd($usr,$usr) if ($CONFIG{'sync_smb'} eq 'yes'); } elsif ($pf eq 'random') { $p = &rnd64; $UPASS{$usr} = $p; $PASS{$usr} = unix_md5_crypt($p,$PASS{$usr}); &smb_passwd($usr,$p) if ($CONFIG{'sync_smb'} eq 'yes'); } elsif ($pf eq 'single') { $PASS{$usr} = unix_md5_crypt('passwd',$PASS{$usr}); &smb_passwd($usr,'passwd') if ($CONFIG{'sync_smb'} eq 'yes'); } } } sub chg_passwd { my($p1, $p2) = @_; my $usr = getpwuid($menu_id); if ($p1 eq $p2) { $PASS{$usr} = unix_md5_crypt($p1,$PASS{$usr}); &smb_passwd($usr,$p1) if ($CONFIG{'sync_smb'} eq 'yes'); print "Set-Cookie: $menu_id&$PASS{$usr}\n"; } else { print "

$SYSMSG{'err_bad_passwd'}

\n"; print "$SYSMSG{'err_cannot_continue_change_passwd'}.
"; print '
    '; print "
  • $SYSMSG{'msg_passwd_must_same'}"; print '
'; print '
'; print "
$SYSMSG{'backto_prev_page'}
"; print '
'; print ""; exit 1; } } sub smb_passwd { my($usr, $pwd) = @_; system("(echo $pwd;echo $pwd)|$CONFIG{'smbprog'} -s -a $usr > /dev/null"); } sub sync_alluser { my($usr, $uid); foreach $uid (keys %UIDS) { next if ($uid ne 0 && int($uid)<500); $usr = $UIDNM{$uid}; system("$CONFIG{'smbprog'} -a $usr -n"); } } sub make_index { open(IDX, "> $tmp_index") || &err_disk("$SYSMSG{'err_cannot_open_homepage_sample'}.
"); print IDX "\n"; print IDX "\n"; print IDX "\n"; print IDX "\n"; print IDX "USER$SYSMSG{'msg_homepage'}\n"; print IDX "\n"; print IDX "

\n"; print IDX "$SYSMSG{'welcome_to'}USER$SYSMSG{'msg_homepage'} \n"; print IDX "


\n"; print IDX "
\n"; print IDX "\n"; print IDX "$SYSMSG{'msg_you_are'} $SYSMSG{'msg_visited'}\n"; print IDX "

$SYSMSG{'msg_my_gbook'} | "; print IDX "$SYSMSG{'msg_my_album'}
\n"; print IDX "


\n"; print IDX "$SYSMSG{'msg_hi'} \n"; print IDX "

\n"; print IDX "$SYSMSG{'msg_my_email'}:USER\@HOSTNAME

\n"; print IDX "

$SYSMSG{'msg_admin'}


\n"; close(IDX); } sub make_passwd { my($uid, $n, $gn, $g, $d, $p, $pstr, $sstr, $l, $h, @lvls, $lvl, $line, $exp); open(TMPP, "> $tmp_passwd") || &err_disk("$SYSMSG{'err_cannot_open_temp'}.
"); open(TMPS, "> $tmp_shadow") || &err_disk("$SYSMSG{'err_cannot_open_temp'}.
"); &write_group; &write_gconf; print "
$SYSMSG{'autoadd_add_these'}
"; foreach $uid (sort keys %sreqn) { print $UIDNM{$uid}."
"; print TMPP "$sreqt{$uid}"; print TMPS "$sreqs{$uid}"; } close(TMPP); close(TMPS); open(TMPP, "< $tmp_passwd") || &err_disk("$SYSMSG{'err_cannot_open_temp'}.
"); open (PWD, ">> $CONFIG{'passwd'}") || &err_disk("$SYSMSG{'err_cannot_open_passwd'}.
"); flock PWD, $LOCK_EX; print PWD ; flock PWD, $LOCK_UN; close(PWD); close(TMPP); open(TMPS, "< $tmp_shadow") || &err_disk("$SYSMSG{'err_cannot_open_temp'}.
"); open (SHD, ">> $CONFIG{'shadow'}") || &err_disk("$SYSMSG{'err_cannot_open_shadow'}.
"); flock SHD, $LOCK_EX; print SHD ; flock SHD, $LOCK_UN; close(SHD); close(TMPS); unlink($tmp_passwd); unlink($tmp_shadow); foreach $uid (sort keys %sreqn) { system("mkdir -p -m 711 $HOME{$uid}"); if ($CONFIG{'add_homepage'} eq 'yes') { system("mkdir -p -m 777 $HOME{$uid}/$CONFIG{'home_dir'}/album"); system("mkdir -p -m 755 $HOME{$uid}/$CONFIG{'home_dir'}/cgi-bin"); system("mkdir -p -m 755 $HOME{$uid}/$CONFIG{'home_dir'}/cgi"); if (-e $tmp_index) { open(IDX, "< $tmp_index"); my @buffer = ; close(IDX); foreach $line (@buffer) { $line =~ s/USER/$UIDNM{$uid}/g; $line =~ s/HOSTNAME/$HOST/g; $line =~ s/PORT/$ENV{'SERVER_PORT'}/g; } open(IDX, "> $HOME{$uid}/$CONFIG{'home_dir'}/index.html"); print IDX @buffer; close(IDX); } if (-e $tmp_album) { open(IDX, "< $tmp_album"); my @buffer = ; close(IDX); foreach $line (@buffer) { $line =~ s/USER/$UIDNM{$uid}/g; } open(IDX, "> $HOME{$uid}/$CONFIG{'home_dir'}/album/message.htm"); print IDX @buffer; close(IDX); } } system("cp -f $CONFIG{'skel_dir'}/local.cshrc $HOME{$uid}/.cshrc") if (-e "$CONFIG{'skel_dir'}/local.cshrc"); system("cp -f $CONFIG{'skel_dir'}/local.login $HOME{$uid}/.login") if (-e "$CONFIG{'skel_dir'}/local.login"); system("cp -f $CONFIG{'skel_dir'}/local.profile $HOME{$uid}/.profile") if (-e "$CONFIG{'skel_dir'}/local.profile"); system("chown -R $uid:$UGID{$uid} $HOME{$uid}"); system ("edquota -p $CONFIG{'quota_user'} $UIDNM{$uid}") if ($CONFIG{'quota_user'} ne ''); &smb_passwd($UIDNM{$uid},$sreqp{$uid}) if ($CONFIG{'sync_smb'} eq 'yes'); } print "
\n"; %sreqn = (); %sreqg = (); %sreqp = (); %sreqt = (); %sreqs = (); } sub get_date { my($mytime) = @_; my($date); $mytime = time if ($mytime eq ''); my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mytime); if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($mon < 10) { $mon = "0$mon"; } if ($mday < 10) { $mday = "$mday"; } my $mm = ($mon + 1); $year -= 11; $date = "$year/$mm/$mday $hour\:$min\:$sec"; chop($date) if ($date =~ /\n$/); $date; } sub myoct { my($num) = @_; my($perm1, $perm2, $perm3, $perm4); $perm1 = $num % 8; $num = int($num/8); $perm2 = $num % 8; $num = int($num/8); $perm3 = $num % 8; $perm4 = int($num/8); $perm = "$perm4$perm3$perm2$perm1"; $perm; } sub err_perm { my($msg) = @_; &head("$SYSMSG{'title_system_info'}"); print "

$SYSMSG{'err_perm_set'}

\n"; print $msg; print '
    '; print "
  • $SYSMSG{'msg_please_check_perm'}"; print "
  • $SYSMSG{'msg_contact_administrator'}"; print '
'; print '
'; print "
$SYSMSG{'backto_prev_page'}
"; print '
'; print ""; exit 0; } sub check_perm { my($target,$flag) = @_; my $true = 0; my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($target); my($perm) = &myoct($mode & 07777); if ($menu_id eq $uid) { $perm = substr($perm,1,1); } elsif ($menu_gid eq $gid) { $perm = substr($perm,2,1); } else { $perm = substr($perm,3,1); } if ($flag eq 0) { if ($menu_id eq $uid) { $true = 1; } else { $true = 0; } } else { $true = $perm & $flag; } $true = 1 if ($admin eq '1'); $true; } sub quota_filesys { my(@p); %DEVFS = (); %FSDEV = (); open(MTAB, "/etc/mtab"); while() { s/\n//g; s/#.*$//g; next if (!/\S/); @p = split(/\s+/, $_); if ($p[2] =~ /ext/ && $p[3] =~ /usrquota/) { $DEVFS{$p[0]} = $p[1]; $FSDEV{$p[1]} = $p[0]; } } close(MTAB); } sub user_quota { my($uid) = @_; my($null,$dev, $bc, $bs, $bh, $fc, $fs, $fh); %filesys = (); %usrquota = (); @response = `quota $UIDNM{$uid} -v`; my $n=0; foreach $line (@response) { $n++; next if ($n <= 2); ($null,$dev,$bc,$bs,$bh,$fc,$fs,$fh) = split(/\s+/,$line); $filesys{$DEVFS{$dev}} = $dev; $usrquota{$dev,'ublocks'} = int($bc); $usrquota{$dev,'sblocks'} = int($bs); $usrquota{$dev,'hblocks'} = int($bh); $usrquota{$dev,'ufiles'} = int($fc); $usrquota{$dev,'sfiles'} = int($fs); $usrquota{$dev,'hfiles'} = int($fh); } } sub edit_one_quota { my($u, $d, $sb, $hb, $sf, $hf) = @_; my(@devs, @sbs, @hbs, @sfs, @hfs, $i,$flag); @devs = split(/,/,$d); @sbs = split(/,/,$sb); @hbs = split(/,/,$hb); @sfs = split(/,/,$sf); @hfs = split(/,/,$hf); $flag = 0; $flag = 1 if (-f '/usr/sbin/setquota'); $i = 0; foreach $dev (@devs) { if ($flag eq 0) { Quota::setqlim($dev, $u, ($sbs[$i],$hbs[$i],$sfs[$i],$hfs[$i]),1); } else { system("/usr/sbin/setquota -u $u $sbs[$i] $hbs[$i] $sfs[$i] $hfs[$i] $dev"); } $i ++; } } sub edit_user_quota { my($u, $g, $w, $first, $temp_user); my($dev, @devs, $sblocks_def, $hblocks_def, $sfiles_def, $hfiles_def, $uid, $mygrp, $usr); $u = $DATA{'user'}; $g = $DATA{'grp'}; $w = $DATA{'word'}; @devs = split(/,/,$DATA{'device'}); foreach $dev (@devs) { $sblocks_def = $sblocks_def ne "" ? "$sblocks_def,$DATA{$dev.'_sb'}" : "$DATA{$dev.'_sb'}"; $hblocks_def = $hblocks_def ne "" ? "$hblocks_def,$DATA{$dev.'_hb'}" : "$DATA{$dev.'_hb'}"; $sfiles_def = $sfiles_def ne "" ? "$sfiles_def,0" : '0'; $hfiles_def = $hfiles_def ne "" ? "$hfiles_def,0" : '0'; } if ($u eq '999') { $g = ''; $w = ''; $first = '0'; foreach $uid (keys %UIDS) { if (int($uid)>1000) { if ($first eq '0') { &edit_one_quota($uid,$DATA{'device'},$sblocks_def,$hblocks_def,$sfiles_def,$hfiles_def); $temp_user = $UIDNM{$uid}; $first = '1'; } else { system("edquota -p $temp_user $UIDNM{$uid}"); } } } } elsif ($u ne '') { $g = ''; $w = ''; &edit_one_quota($UNMID{$u},$DATA{'device'},$sblocks_def,$hblocks_def,$sfiles_def,$hfiles_def); } if ($g ne '') { $w = ''; $mygrp = $GNMID{$g}; return if (int($mygrp)<500); $first = '0'; foreach $uid (keys %UIDS) { if ($UGID{$uid} eq $mygrp) { if ($first eq '0') { &edit_one_quota($uid,$DATA{'device'},$sblocks_def,$hblocks_def,$sfiles_def,$hfiles_def); $temp_user = $UIDNM{$uid}; $first = '1'; } else { system("edquota -p $temp_user $UIDNM{$uid}"); } } } } if ($w ne '') { $first = '0'; foreach $usr (sort keys %UNAME) { if ($usr =~ /$w/) { if ($first eq '0') { &edit_one_quota($UNMID{$usr},$DATA{'device'},$sblocks_def,$hblocks_def,$sfiles_def,$hfiles_def); $temp_user = $usr; $first = '1'; } else { system("edquota -p $temp_user $usr"); } } } } } sub free_space { my($mydir) = @_; my($out, @rv, $dev, $u, $h); if ($admin eq '0') { &user_quota($menu_id); foreach $f (sort keys %filesys) { $dev=$filesys{$f} if ($mydir =~ /^$f/); } if ($dev) { $u = $usrquota{$dev,'ublocks'}; $h = $usrquota{$dev,'hblocks'}; push(@rv, ($h."K", $u."K", $h-$u."K", (int($u*10000/$h)/100)."%")) if ($h >= $u && $h>0 && $u>0); } } if (!defined $rv[0]) { $out = `df $mydir`; $out =~ /Mounted on\n\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/; push(@rv, (int($1/1024)."M", int($2/1024)."M", int($3/1024)."M", $4."%")); } @rv; } $share_flag = 0; sub get_dir { my($mydir) = @_; my($line, @lines); $mydir = '' if ($admin eq '0' && $mydir !~ /^$home(.+)/ ); if ($mydir eq '') { $mydir = $home; $mydir = '/' if ($admin eq '1'); } opendir (DIR, "$mydir") || &err_disk("$mydir $SYSMSG{'err_cannot_open_dir'}
"); @lines=readdir(DIR); close(DIR); %FOLDS = (); %FILES = (); $filemgr_rows = -2; foreach $line (sort @lines) { if ($line !~ /^\.(\w+)/ || $admin eq '1') { if (-d "$mydir/$line") { $FOLDS{$line} ++; if ($SHARE{"$mydir/$line"} ne '') { $TYPE{$line} = $SYSMSG{'share'}; } else { $TYPE{$line} = $SYSMSG{'dir'}; } $IMAGE{$line} = '1folder.gif'; $filemgr_rows ++; } elsif (-f _) { $FILES{$line} ++; if ($line =~ /.[G|g][I|i][F|f]$/) { $IMAGE{$line} = 'image.gif'; $TYPE{$line} = 'GIF'; } elsif ($line =~ /.[J|j][P|p][E|e]?[G|g]$/) { $IMAGE{$line} = 'image.gif'; $TYPE{$line} = 'JPG'; } elsif ($line =~ /.[P|p][N|n][G|g]$/) { $IMAGE{$line} = 'image.gif'; $TYPE{$line} = 'PNG'; } elsif ($line =~ /.[B|b][M|m][P|p]$/) { $IMAGE{$line} = 'image.gif'; $TYPE{$line} = 'BMP'; } elsif ($line =~ /.[H|h][T|t][M|m][L|l]?$/) { $IMAGE{$line} = 'html.gif'; $TYPE{$line} = 'HTM'; } elsif ($line =~ /.[T|t][X|x][T|t]$/) { $IMAGE{$line} = 'text.gif'; $TYPE{$line} = 'TXT'; } elsif ($line =~ /.[E|e][X|x][E|e]$/) { $IMAGE{$line} = 'exe.gif'; $TYPE{$line} = 'EXE'; } elsif ($line =~ /.[Z|z][I|i][P|p]$/) { $IMAGE{$line} = 'zip.gif'; $TYPE{$line} = 'ZIP'; } elsif ($line =~ /.[G|g][Z|z]$/) { $IMAGE{$line} = 'zip.gif'; $TYPE{$line} = 'GZ'; } elsif ($line =~ /.[W|w][A|a][V|v]$/) { $IMAGE{$line} = 'wav.gif'; $TYPE{$line} = 'WAV'; } elsif ($line =~ /.[M|m][P|p][G|g]$/) { $IMAGE{$line} = 'mpg.gif'; $TYPE{$line} = 'MPG'; } elsif ($line =~ /.[M|m][P|p][E|e][G|g]$/) { $IMAGE{$line} = 'mpg.gif'; $TYPE{$line} = 'MPG'; } elsif ($line =~ /.[A|a][U|u]$/) { $IMAGE{$line} = 'wav.gif'; $TYPE{$line} = 'AU'; } elsif ($line =~ /.[M|m][I|i][D|d][I|i]?$/) { $IMAGE{$line} = 'wav.gif'; $TYPE{$line} = 'MID'; } elsif ($line =~ /.[D|d][O|o][C|c|T|t]$/) { $IMAGE{$line} = 'doc.gif'; $TYPE{$line} = 'DOC'; } elsif ($line =~ /.[X|x][L|l].?$/) { $IMAGE{$line} = 'xls.gif'; $TYPE{$line} = 'XLS'; } elsif ($line =~ /.[M|m][D|d][B|b|A|a|W|w]?$/) { $IMAGE{$line} = 'mdb.gif'; $TYPE{$line} = 'MDB'; } else { $IMAGE{$line} = '1file.gif'; $TYPE{$line} = $SYSMSG{'file'}; } $filemgr_rows ++; } } ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$mydir/$line"); $PERM{$line} = &myoct($mode & 07777); $OWNER{$line} = $uid; $GOWNER{$line} = $gid; $FSIZE{$line} = $size; $FTIME{$line} = $mtime; $MODIFY{$line} = &get_date($mtime); } $mydir; } sub by_perm { $PERM{$a} <=> $PERM{$b}; } sub by_gowner { $GOWNER{$a} cmp $GOWNER{$b}; } sub by_owner { $OWNER{$a} cmp $OWNER{$b}; } sub by_type { $TYPE{$a} cmp $TYPE{$b}; } sub by_size { $FSIZE{$a} <=> $FSIZE{$b}; } sub by_time { $FTIME{$a} <=> $FTIME{$b}; } sub get_share { my($mydir) = @_; my($line, $olddir,$check_ok); $share_flag = 1; $filemgr_rows = 0; $check_ok = 0; %FOLDS = (); %FILES = (); my($mgrp) = getgrgid($menu_gid); if ($mydir eq '' || $mydir eq '/') { foreach $line (keys %SHARE) { next if ($admin eq '0' && $SHARE{$line} !~ /$mgrp/); $FOLDS{$line} ++; $TYPE{$line} = $SYSMSG{'dir'}; $IMAGE{$line} = '1folder.gif'; $filemgr_rows ++; } $DATA{'share'} = ''; } else { foreach $line (keys %SHARE) { next if ($admin eq '0' && $SHARE{$line} !~ /$mgrp/); $FOLDS{$line} ++; $TYPE{$line} = $SYSMSG{'dir'}; $IMAGE{$line} = '1folder.gif'; $filemgr_rows ++; $check_ok = 1 if ($mydir =~ /^$line.*/); } if ($check_ok eq 1) { $olddir = &get_dir($mydir); } else { $DATA{'share'} = ''; $olddir = "/"; } } $olddir; } sub chg_dir { my($olddir,$newdir) = @_; my($temp) = $olddir; if ($newdir eq '/') { $olddir = $home; $olddir = '/' if ($admin eq '1'); } elsif ($newdir eq '..') { if ($share_flag eq 1) { if ($olddir eq $DATA{'share'}) { $DATA{'share'} = ''; $olddir = '/'; } else { my(@temp) = split(/\//, $olddir); pop(@temp); $olddir = join('/',@temp); } } elsif ($admin eq '1' || $olddir ne $home) { my(@temp) = split(/\//, $olddir); pop(@temp); $olddir = join('/',@temp); } } elsif ($newdir =~ /^\/.*/ && $admin eq '1') { $olddir = "/$newdir"; } else { $newdir =~ s/\.\.\///g; if ($olddir eq '/') { $olddir .= "$newdir"; } else { $olddir .= "/$newdir"; } } if ($share_flag eq 0) { &err_perm("$SYSMSG{'err_cannot_read'} $olddir $SYSMSG{'err_folder_priv'}$SYSMSG{'err_so_cannot_chdir'}
") if ($olddir ne '/' && &check_perm($olddir,4) eq 0); } $DATA{'share'} = $olddir if ($SHARE{$olddir} ne ''); $olddir; } sub make_dir { my($olddir,$newdir) = @_; $olddir if ($newdir eq ''); if ($share_flag eq 0) { &err_perm("$SYSMSG{'err_cannot_write'} $olddir $SYSMSG{'err_folder_priv'}$SYSMSG{'err_so_cannot_mkdir'}
") if (&check_perm($olddir,2) eq 0); } else { &err_perm("$SYSMSG{'share_folder'}$olddir$SYSMSG{'err_so_cannot_mkdir'}
") if ($SPERM_DIR{$DATA{'share'}} ne 'yes'); } if ($newdir =~ /(.*)\/(.+)/) { if ($olddir eq '/') { $olddir .= "$2"; } else { $olddir .= "/$2"; } } else { if ($olddir eq '/') { $olddir .= $newdir; } else { $olddir .= "/$newdir"; } } system("mkdir -p $olddir"); $olddir; } sub del_dir { my($olddir,$items) = @_; my $warning = 0; $olddir if ($items eq ''); @files = split(/,/,$items); if ($share_flag eq 1 && $SPERM_DEL{$DATA{'share'}} ne 'yes') { &err_perm("$SYSMSG{'share_folder'}$olddir$SYSMSG{'err_so_cannot_delete'}
"); } else { $olddir .= '/' if ($olddir ne '/'); foreach $f (@files) { if (&check_perm("$olddir$f",0) eq 0) { $warning ++; } else { system("rm -rf $olddir$f/* : rmdir $olddir$f"); } } &err_perm("
$warning $SYSMSG{'filemgr_cannot_del'}

") if ($warning > 0); } } sub chg_perm { my($perm,$olddir,$items) = @_; my $warning=0; $olddir if ($perm eq '' || $items eq ''); @files = split(/,/,$items); $olddir .= '/' if ($olddir ne '/'); foreach $f (@files) { if (&check_perm("$olddir$f",0) eq 0) { $warning ++; } else { system("chmod $perm $olddir$f"); } } &err_perm("
$warning $SYSMSG{'filemgr_cannot_priv'}

") if ($warning > 0); } sub chg_owner { my($owner,$olddir,$items) = @_; my $warning=0; $olddir if ($owner eq '' || $items eq ''); @files = split(/,/,$items); $olddir .= '/' if ($olddir ne '/'); foreach $f (@files) { if (&check_perm("$olddir$f",0) eq 0) { $warning ++; } else { system("chown $owner $olddir$f"); } } &err_perm("
$warning $SYSMSG{'filemgr_cannot_chown'}

") if ($warning > 0); } sub down_load { my($dnfile) = @_; my $fsize = (stat($dnfile))[7]; open(REAL,"< $dnfile") || &err_disk("$SYSMSG{'err_cannot_open_download_file'} $dnfile
"); binmode REAL; print "Content-length: $fsize\n"; print "Content-type: application/octet-stream\n\n"; while(read(REAL, $buf, 1024)) { print $buf; } close(REAL); } sub edit_file { my($dnfile) = @_; &head("$SYSMSG{'title_edit_file'} $dnfile"); print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print ""; print "
"; print ""; print "
\n"; &foot('f'); exit; } sub show_file { my($olddir,$dnfile) = @_; my $flag = 0; my($buf, $mydir); $olddir if ($dnfile eq ''); $mydir = $olddir; $mydir .= '/' if ($mydir ne '/'); &err_perm("$SYSMSG{'err_cannot_read'} $mydir$dnfile $SYSMSG{'err_file_priv'}$SYSMSG{'err_so_cannot_download'}
") if (&check_perm("$mydir$dnfile",4) eq 0 && $share_flag eq 0); if (-T "$mydir$dnfile") { if ($share_flag eq 1) { &err_perm("$SYSMSG{'share_folder'} $olddir$SYSMSG{'err_so_cannot_view'}
") if ($SPERM_EDIT{$DATA{'share'}} ne 'yes' && &check_perm("$mydir$dnfile",4) eq 0); } elsif (&check_perm("$mydir$dnfile",2) eq 0) { $flag = 1; } if ($flag eq 1) { print "Content-type: text/plain\n\n" ; open(REAL,"< $mydir$dnfile") || &err_disk("$SYSMSG{'err_cannot_open_download_file'}$mydir$dnfile
"); while(read(REAL, $buf, 1024)) { print $buf; } close(REAL); } else { &edit_file("$mydir$dnfile"); } } elsif (-B _) { &err_perm("$SYSMSG{'share_folder'} $olddir$SYSMSG{'err_so_cannot_download'}
") if ($share_flag eq 1 && $SPERM_DN{$DATA{'share'}} ne 'yes'); &down_load("$mydir$dnfile"); } exit; } sub share { my($olddir,$share) = @_; my(@files, $file, $mydir, $i); $olddir if ($share eq ''); $mydir = $olddir; $mydir .= '/' if ($mydir ne '/'); @files = split(/,/,$share); $mydir = '' if ($files[0] =~ /^\/(.*)/); &head($SYSMSG{'title_sharemgr'}); print "
\n"; print "\n"; } } $file = $files[0]; print "\n"; print "\n"; my $i = 1; &read_group; foreach $gid (sort keys %GIDS) { $grp = $GIDNM{$gid}; next if (int($gid)<500); next if (&check_special($grp) eq 1); print "" if (($i % 5) eq 0); $i ++; if ($SHARE{"$mydir$file"} =~ /$grp/) { print "\n"; } else { print "\n"; } } print "
$SYSMSG{'share_config_these'}\n"; print "\n"; print "\n"; print "\n"; foreach $file (@files) { if (-d "$mydir$file") { print "
$SYSMSG{'share_dir'}$mydir$file $SYSMSG{'share_share_name'}
$SYSMSG{'share_to_what'}\n"; print "
$SYSMSG{'pattern_match'}
$SYSMSG{'everygrp'}
$grp$grp
$SYSMSG{'share_make_group'}
" if ($i<=0); print "
$SYSMSG{'share_grant'}\n"; if ($SPERM_DN{"$mydir$file"} eq 'yes') { print "
$SYSMSG{'share_download'}\n"; } else { print "
$SYSMSG{'share_download'}\n"; } if ($SPERM_UP{"$mydir$file"} eq 'yes') { print "$SYSMSG{'share_upload'}\n"; } else { print "$SYSMSG{'share_upload'}\n"; } if ($SPERM_DIR{"$mydir$file"} eq 'yes') { print "$SYSMSG{'share_mkdir'}\n"; } else { print "$SYSMSG{'share_mkdir'}\n"; } if ($SPERM_EDIT{"$mydir$file"} eq 'yes') { print "$SYSMSG{'share_delete'}\n"; } else { print "$SYSMSG{'share_edit'}\n"; } if ($SPERM_DEL{"$mydir$file"} eq 'yes') { print "$SYSMSG{'share_delete'}
\n"; } else { print "
$SYSMSG{'share_delete'}
\n"; } if ($i <= 0) { print "$SYSMSG{'cancel'}\n"; print "
"; &foot('s'); exit; } sub del_share { my($items) = @_; $olddir if ($items eq ''); @files = split(/,/,$items); if ($admin eq '1') { foreach $f (@files) { delete $SHARE{$f}; } $DATA{'share'} = ''; &write_share; } &head($SYSMSG{'title_sharemgr'}); print "
$SYSMSG{'share_cancel_completed'}"; &foot('s'); exit; } sub many_download { my($olddir,$items) = @_; my($buf, $mydir, $tmpfolder, $dnfile); $olddir if ($items eq ''); $tmpfolder = time; $mydir = $olddir; $mydir .= '/' if ($olddir ne '/'); @files = split(/,/,$items); &err_perm("$SYSMSG{'share_folder'} $olddir$SYSMSG{'err_so_cannot_download'}
") if ($share_flag eq 1 && $SPERM_DN{$DATA{'share'}} ne 'yes'); system("mkdir -p /tmp/$menu_id/temp/$tmpfolder"); foreach $f (@files) { system("cp -Rf $mydir$f /tmp/$menu_id/temp/$tmpfolder > /dev/null") if (&check_perm("$mydir$f",4) ne 0 || $share_flag eq 1); } if ($zip_exist) { system("zip -rq /tmp/$menu_id/$tmpfolder /tmp/$menu_id/temp/$tmpfolder > /dev/null"); $dnfile = "/tmp/$menu_id/$tmpfolder\.zip"; } else { system("tar -zcf /tmp/$menu_id/$tmpfolder\.tar\.gz /tmp/$menu_id/temp/$tmpfolder > /dev/null"); $dnfile = "/tmp/$menu_id/$tmpfolder\.tar\.gz"; } &down_load($dnfile); $)=0; $>=0; system("rm -Rf /tmp/$menu_id"); if ($admin ne '1') { $) = $menu_gid; $> = $menu_id; } exit; } sub ren_dir { my($newname,$olddir,$items) = @_; $olddir if ($olddor eq '' || $newname eq '' || $items eq ''); @files = split(/,/,$items); $f = $files[0]; $olddir .= '/' if ($olddir ne '/'); if ($share_flag eq 0) { &err_perm("$SYSMSG{'err_cannot_change'} $olddir$f $SYSMSG{'err_name_priv'}
") if (&check_perm("$olddir$f",2) eq 0); } else { &err_perm("$SYSMSG{'share_folder'} $olddir $SYSMSG{'err_so_cannot_modify'}
") if ($SPERM_UP{$DATA{'share'}} ne 'yes'); } system("mv $olddir$f $olddir$newname"); } sub move_dir { my($dest,$olddir,$items) = @_; $olddir if ($dest eq '' || $items eq ''); @files = split(/,/,$items); $f = $files[0]; $olddir .= '/' if ($olddir ne '/'); if ($admin eq '0') { if (substr($dest,0,1) eq '/') { $dest = substr($dest,1); $dest = "$olddir$dest" ; } else { $dest = "$olddir$dest" ; } } else { $dest = "$olddir$dest" if (substr($dest,0,1) ne '/'); } if (-e "$dest") { &err_perm("$SYSMSG{'err_cannot_move_to_others'}
") if (&check_perm("$dest",2) eq 0); } else { &err_perm("$SYSMSG{'err_cannot_move_to_others'}
") if (&check_perm("$olddir",2) eq 0); } &err_perm("$SYSMSG{'err_cannot_move_from_others'}
") if (&check_perm("$olddir$f",0) eq 0); system("mv $olddir$f $dest"); system("chown $menu_id:$menu_gid $dest/$f"); } sub copy_dir { my($dest,$olddir,$items) = @_; $olddir if ($dest eq '' || $items eq ''); @files = split(/,/,$items); $f = $files[0]; $olddir .= '/' if ($olddir ne '/'); if ($admin eq '0') { if (substr($dest,0,1) eq '/') { $dest = substr($dest,1); $dest = "$olddir$dest" ; } else { $dest = "$olddir$dest" ; } } else { $dest = "$olddir$dest" if (substr($dest,0,1) ne '/'); } if (-e "$dest") { &err_perm("$SYSMSG{'err_cannot_copy_to_others'}
") if (&check_perm("$dest",2) eq 0); } else { &err_perm("$SYSMSG{'err_cannot_copy_to_others'}
") if (&check_perm("$olddir",2) eq 0); } &err_perm("$SYSMSG{'err_cannot_copy_from_others'}
") if (&check_perm("$olddir$f",0) eq 0); system("cp -Rf $olddir$f $dest"); system("chown $menu_id:$menu_gid $dest/$f"); } sub get_digits { opendir (DIR, "$cnt_base") || &err_disk("$SYSMSG{'err_cannot_open_counter_dir'}
"); @STYLES=readdir(DIR); close(DIR); } sub new_digits { &head($SYSMSG{'title_add_counter'}); print "
$SYSMSG{'counter_minihelp'}\n"; print "
\n"; print "\n"; print "$SYSMSG{'counter_lib_name'}
\n"; for ($z=0;$z<=9;++$z) { print "$SYSMSG{'counter_digit'}$z:
\n"; } print "\n"; print "

$SYSMSG{'err_cannot_open_socket'}

\n"; print $msg; print $SYSMSG{'msg_please_check'}; print '
    '; print "
  • $SYSMSG{'err_miss_host_or_port'}"; print "
  • $SYSMSG{'err_request_time_out'}"; print "
  • $SYSMSG{'err_file_too_large'}"; print '
'; print '
'; print ' 回上一頁'; print '
'; print ""; exit 0; } sub open_socket { my($httphost,$serverport,$type) = @_; eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm 5; $remote_sock=new IO::Socket::INET( Proto=>$type, PeerAddr=>$httphost, PeerPort=>$serverport,); alarm 0; }; &err_socket($SYSMSG{'err_connect_break'}) if ($@); &err_socket($SYSMSG{'err_connect_failue'}) if (!$remote_sock); $remote_sock->autoflush(1); $remote_sock; } sub http_download { my($httphost,$serverport,$pageurl,$dnfile) = @_; my($line, %header,$buf); if ($CONFIG{'http_proxy'} ne '' && $CONFIG{'proxy_port'} ne '') { # going through proxy $remote_sock = &open_socket($CONFIG{'http_proxy'},$CONFIG{'proxy_port'},'tcp'); } else { # can connect directly $remote_sock = &open_socket($httphost,$serverport,'tcp'); } print $remote_sock "GET http://$httphost:$serverport/$pageurl HTTP/1.0\r\n"; print $remote_sock "\r\n"; # read headers alarm(60); ($line = <$remote_sock>) =~ s/\r|\n//g; &err_socket($SYSMSG{'err_cannot_download_file'}) if ($line !~ /\/1\..\s+200\s+/); while(<$remote_sock> =~ /^(\S+):\s+(.*)$/) { $header{lc($1)} = $2; } alarm(0); # read data open(PFILE, "> $dnfile") || &err_disk("$SYSMSG{'err_cannot_save_upgrade'}
"); while(read($remote_sock, $buf, 1024) > 0) { print PFILE $buf; } close(PFILE); close($remote_sock); } sub head { my($title) = @_; print "Content-type: text/html\n\n"; print "\n"; print ''."\n"; print "$title\n"; print "
$title Ver. $myver [ "; if ($admin eq '1') { print "$SYSMSG{'root_help'} ]
"; } else { print "$SYSMSG{'help'} ]"; } } sub foot { my($flag) = @_; print "
\n"; print "$SYSMSG{'backto_prev_page'} 】\n"; print "
"; } #*********************************************************************************** # MAIN #*********************************************************************************** &get_wam_version; &read_conf; &get_lang; &check_acl; &read_shadow; &read_passwd; &read_shells; &read_gconf; &read_group; &read_share; "a_filesys; while (FCGI::accept()>=0) { $| = 1; $today = int(time / 86400); &check_referer; &get_form_data; &check_password; if ($DATA{'flag'} eq 'deny' || $DATA{'step'} eq '' || $DATA{'step'} eq 'relogon') { &empty_cookie; &head($SYSMSG{'logon'}); print '
'."\n"; print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'loginname'}:\n"; print "\n"; print "$SYSMSG{'loginpasswd'}:\n"; print "\n"; print "\n"; print "\n"; print "
\n"; exit; } $admin='0'; foreach $acc (split(/,/,$GUSRS{'wam'})) { $admin='1' if ($acc =~ /^$UIDNM{$menu_id}$/); } $> = 0; $) = 0; if ($DATA{'step'} eq 'menu' && $menu_id ne '') { print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "WAM $myver\n"; print "\n"; print "\n"; print "\n"; print "\n"; } elsif ($DATA{'step'} eq 'show_left') { print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "WAM $myver\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ($admin eq '1') { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } else { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "
WAM $myver
$SYSMSG{'help'}
$SYSMSG{'submenu_system'}
$SYSMSG{'set_config'}
$SYSMSG{'set_wam_manager'}
$SYSMSG{'file_manager'}
$SYSMSG{'share_folder'}
$SYSMSG{'quota_setup'}
$SYSMSG{'submenu_account'}
$SYSMSG{'group_add'}
$SYSMSG{'account_add_one'}
$SYSMSG{'del_group_account'}
$SYSMSG{'autoadd_account'}
$SYSMSG{'add_account_from_file'}
$SYSMSG{'reset_passwd'}
$SYSMSG{'change_passwd'}
$SYSMSG{'view_struct'}
$SYSMSG{'check_account'}
$SYSMSG{'trace_account'}
$SYSMSG{'submenu_homepage'}
$SYSMSG{'counter_img'}
$SYSMSG{'set_counter'}
$SYSMSG{'view_counter'}
$SYSMSG{'set_gbook'}
$SYSMSG{'manage_gbook'}
$SYSMSG{'submenu_mail'}
$SYSMSG{'mail_manager'}
$SYSMSG{'online_upgrade'}
$SYSMSG{'online_upgrade'}
$SYSMSG{'logout'}
$SYSMSG{'logout'}
$SYSMSG{'help'}
$SYSMSG{'file_manager'}
$SYSMSG{'share_folder'}
$SYSMSG{'change_passwd'}
$SYSMSG{'set_counter'}
$SYSMSG{'view_counter'}
$SYSMSG{'set_gbook'}
$SYSMSG{'manage_gbook'}
$SYSMSG{'mail_manager'}
$SYSMSG{'logout'}
$SYSMSG{'logout'}
\n"; } elsif ($DATA{'step'} eq 'show_right') { &head($SYSMSG{'logon'}); print "
\n"; print "
\n"; } elsif ($DATA{'step'} eq 'config' && $admin eq '1') { &head($SYSMSG{'title_setup'}); &get_lang_list; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ($CONFIG{'acltype'} eq 1) { print "\n"; } else { print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $CONFIG{'shells'} = '/etc/shells' if ($CONFIG{'shells'} eq ''); print "\n"; print "\n"; $CONFIG{'group'} = '/etc/group' if ($CONFIG{'group'} eq ''); print "\n"; print "\n"; $CONFIG{'gshadow'} = '/etc/gshadow' if ($CONFIG{'gshadow'} eq ''); print "\n"; print "\n"; $CONFIG{'passwd'} = '/etc/passwd' if ($CONFIG{'passwd'} eq ''); print "\n"; print "\n"; $CONFIG{'shadow'} = '/etc/shadow' if ($CONFIG{'shadow'} eq ''); print "\n"; print "\n"; $CONFIG{'mailprog'} = '/usr/bin/sendmail' if ($CONFIG{'mailprog'} eq ''); print "\n"; print "\n"; $CONFIG{'mailaliases'} = '/etc/aliases' if ($CONFIG{'mailaliases'} eq ''); print "\n"; print "\n"; $CONFIG{'smbprog'} = '/usr/bin/smbpasswd' if ($CONFIG{'smbprog'} eq ''); print "\n"; print "\n"; $CONFIG{'smbpasswd'} = '/etc/smbpasswd' if ($CONFIG{'smbpasswd'} eq ''); print "\n"; print ""; if ($CONFIG{'sync_smb'} eq 'yes') { print "\n"; } else { print "\n"; } print ""; if ($CONFIG{'codepage_smb'} eq 'yes') { print "\n"; } else { print "\n"; } print ""; if ($CONFIG{'home_nest'} eq 'yes') { print "\n"; } else { print "\n"; } print ""; if ($CONFIG{'add_homepage'} eq 'yes') { print "\n"; } else { print "\n"; } print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print ""; if (int($CONFIG{'passwd_rule'})%2) { print "\n"; } else { print "\n"; } if (int($CONFIG{'passwd_rule'})%4 >= 2) { print "\n"; } else { print "\n"; } if (int($CONFIG{'passwd_rule'})%8 >= 4) { print "\n"; } else { print "\n"; } if (int($CONFIG{'passwd_rule'}) >= 8) { print "\n"; } else { print "\n"; } print "\n"; $CONFIG{'base_dir'} = '/home' if ($CONFIG{'base_dir'} eq ''); print "\n"; print "\n"; $CONFIG{'skel_dir'} = '/etc/skel' if ($CONFIG{'skel_dir'} eq ''); print "\n"; print "\n"; $CONFIG{'shell'} = '/bin/bash' if ($CONFIG{'shell'} eq ''); print "\n"; print "\n"; $CONFIG{'home_dir'} = 'public_html' if ($CONFIG{'home_dir'} eq ''); print "\n"; &make_index if (!(-e "$tmp_index")); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print ">\n"; print "\n"; print "
$SYSMSG{'config_language'}
$SYSMSG{'config_aclcontrol'}$SYSMSG{'config_allow_ip'} $SYSMSG{'config_deny_ip'}$SYSMSG{'config_allow_ip'} $SYSMSG{'config_deny_ip'}
$SYSMSG{'config_acl_rule'}
$SYSMSG{'config_upgrade_proxy'}$SYSMSG{'config_proxy_hostname'}:\n"; print "$SYSMSG{'config_proxy_port'}:
$SYSMSG{'config_shell_dir'}
$SYSMSG{'config_group_file'}
$SYSMSG{'config_group_shadow'}
$SYSMSG{'config_passwd_file'}
$SYSMSG{'config_shadow_file'}
$SYSMSG{'config_mail_prog'}
$SYSMSG{'config_mail_aliase'}
$SYSMSG{'config_samba_prog'}
$SYSMSG{'config_samba_passwd_file'}
$SYSMSG{'config_samba_passwd_sync'}
$SYSMSG{'config_samba_use_codepage'}
$SYSMSG{'config_account_nest'}
$SYSMSG{'config_account_auto_homepage'}
$SYSMSG{'config_account_nest_level'}
$SYSMSG{'config_account_auto_passwd_style'}
$SYSMSG{'config_account_auto_passwd_range'}
$SYSMSG{'config_account_passwd_change_rule'}$SYSMSG{'config_account_passwd_limit_428'}$SYSMSG{'config_account_passwd_limit_428'}
$SYSMSG{'config_account_passwd_limit_no&letter'}
$SYSMSG{'config_account_passwd_limit_no&letter'}
$SYSMSG{'config_account_passwd_limit_diffrent'}
$SYSMSG{'config_account_passwd_limit_diffrent'}
$SYSMSG{'config_account_passwd_limit_keyboard'}
$SYSMSG{'config_account_passwd_limit_keyboard'}
$SYSMSG{'config_user_home_dir'}
$SYSMSG{'config_user_skel'}
$SYSMSG{'config_user_shell'}
$SYSMSG{'config_user_homepage_dir'}
$SYSMSG{'config_edit_user_homepage_sample'}
$SYSMSG{'config_days_to_change'}
$SYSMSG{'config_days_to_force_change'}
$SYSMSG{'config_days_to_hint'}
$SYSMSG{'config_days_to_inact'}
$SYSMSG{'config_days_to_expire'}
$SYSMSG{'config_account_flag_status'}
$SYSMSG{'config_account_quota_sample'}
"; &foot(''); } elsif ($DATA{'step'} eq 'doconfig' && $admin eq '1') { my $myrule = 0; $myrule = $myrule + 1 if ($DATA{'passwd_rule1'} eq 'yes'); $myrule = $myrule + 2 if ($DATA{'passwd_rule2'} eq 'yes'); $myrule = $myrule + 4 if ($DATA{'passwd_rule3'} eq 'yes'); $myrule = $myrule + 8 if ($DATA{'passwd_rule4'} eq 'yes'); open (CFG, "> $config") || die "$SYSMSG{'err_cannot_open_passwd'}
"; print CFG "http_proxy:".$DATA{'http_proxy'}."\n"; print CFG "proxy_port:".$DATA{'proxy_port'}."\n"; print CFG "lang:".$DATA{'lang'}."\n"; print CFG "shells:".$DATA{'shells'}."\n"; print CFG "group:".$DATA{'group'}."\n"; print CFG "gshadow:".$DATA{'gshadow'}."\n"; print CFG "passwd:".$DATA{'passwd'}."\n"; print CFG "shadow:".$DATA{'shadow'}."\n"; print CFG "mailprog:".$DATA{'mailprog'}."\n"; print CFG "mailaliases:".$DATA{'mailaliases'}."\n"; print CFG "smbprog:".$DATA{'smbprog'}."\n"; print CFG "smbpasswd:".$DATA{'smbpasswd'}."\n"; print CFG "sync_smb:".$DATA{'sync_smb'}."\n"; print CFG "codepage_smb:".$DATA{'codepage_smb'}."\n"; print CFG "home_nest:".$DATA{'home_nest'}."\n"; print CFG "nest:".$DATA{'nest'}."\n"; print CFG "add_homepage:".$DATA{'add_homepage'}."\n"; print CFG "passwd_form:".$DATA{'passwd_form'}."\n"; print CFG "passwd_range:".$DATA{'passwd_range'}."\n"; print CFG "passwd_rule:".$myrule."\n"; print CFG "base_dir:".$DATA{'base_dir'}."\n"; print CFG "home_dir:".$DATA{'home_dir'}."\n"; print CFG "skel_dir:".$DATA{'skel_dir'}."\n"; print CFG "shell:".$DATA{'shell'}."\n"; print CFG "min:".$DATA{'min'}."\n"; print CFG "max:".$DATA{'max'}."\n"; print CFG "pwarn:".$DATA{'pwarn'}."\n"; print CFG "inact:".$DATA{'inact'}."\n"; print CFG "expire:".$DATA{'expire'}."\n"; print CFG "flag:".$DATA{'flag'}."\n"; print CFG "quota_user:".$DATA{'quota_user'}."\n"; print CFG "acltype:".$DATA{'acltype'}."\n"; print CFG "acls:".$DATA{'acls'}."\n"; close(CFG); system("echo '' > $DATA{'smbpasswd'}") if not (-e "$DATA{'smbpasswd'}"); &head($SYSMSG{'title_setup'}); print "
$SYSMSG{'config_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'upgrade' && $admin eq '1') { &head($SYSMSG{'title_upgrade'}); print "
"; print "\n"; print "
\n"; print "\n"; print ""; print ""; print ""; print ""; print ""; print "
$SYSMSG{'online_upgrade_minihelp'}
$SYSMSG{'online_upgrade_choose'}
$SYSMSG{'online_upgrade_choose_1'}
$SYSMSG{'online_upgrade_choose_2'}
$SYSMSG{'online_upgrade_choose_3'}

"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'doupgrade' && $admin eq '1') { if ($DATA{'mode'} eq 'local') { &patch($DATA{'file'}); } elsif ($DATA{'mode'} eq 'http') { $type = 'tar.gz'; $type = 'zip' if ($zip_exist); &http_download('webmail.ysps.tp.edu.tw','12000',"logon.cgi?type=$type&ver=$myver&host=$HOST",'/usr/libexec/wam/patch/upgrade.wam'); open(PATCH, "/usr/libexec/wam/patch/upgrade.wam") || &err_disk($SYSMSG{'err_cannot_open_upgrade'}."
"); chop($myfile=); close(PATCH); if ($myfile =~ /^wam-(.+)-upgrade\.(.*)$/) { &http_download('webmail.ysps.tp.edu.tw','12000',"/patch/$myfile","/usr/libexec/wam/patch/$myfile"); &patch("/usr/libexec/wam/patch/$myfile"); } } &get_wam_version; &head($SYSMSG{'title_upgrade'}); if ($myfile =~ /^wam-(.+)-upgrade\.(.*)$/) { print "
$SYSMSG{'online_upgrade_completed'} $myver !!!
\n"; } else { print "
$myfile
\n"; } &foot(''); } elsif ($DATA{'step'} eq 'setadmin' && $admin eq '1') { &head($SYSMSG{'title_manager'}); print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'wam_manager_add'}\n"; print "
\n"; print '

'."\n"; print "
\n"; print "\n"; print "\n"; print "" if (($i % 5) eq 0); $i ++; print "
$SYSMSG{'wam_manager_now'}\n"; my $i = 0; my @name = split(/,/, $GUSRS{'wam'}); foreach $usr (sort @name) { print "
$usr\n"; } print '
',"\n"; &foot(''); } elsif ($DATA{'step'} eq 'add_wam' && $admin eq '1') { &head($SYSMSG{'title_manager'}); &add_wam($DATA{'user'}); &write_group; print "
$SYSMSG{'wam_manager_add_completed'} $DATA{'user'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'del_wam' && $admin eq '1') { &head($SYSMSG{'title_manager'}); print "
$SYSMSG{'wam_manager_del_action'}
\n"; foreach $usr (keys %DATA) { if ($DATA{$usr} eq "ON") { &del_wam($usr); print "$usr
\n"; } } &write_group; print "$SYSMSG{'wam_manager_del_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'addgrp' && $admin eq '1') { &head($SYSMSG{'title_addgrp'}); print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'groupname'}"; print "
$SYSMSG{'group_home_dir'}" if ($CONFIG{'home_nest'} eq 'yes'); print "
\n"; print "

"; print "\n"; print "" if (($i % 8) eq 0); $i ++; print "
$SYSMSG{'group_now'}\n"; my $i = 0; foreach $gname (sort keys %GNAME) { print "
$gname\n"; } print "
"; &foot(''); } elsif ($DATA{'step'} eq 'doaddgrp' && $admin eq '1') { &head($SYSMSG{'title_addgrp'}); $DATA{'home'} .= "/$DATA{'grp'}" if ($CONFIG{'home_nest'} eq 'yes' && $DATA{'home'} eq $CONFIG{'base_dir'}); &add_grp($DATA{'grp'},$DATA{'home'}); &write_group; &write_gconf; print "
$SYSMSG{'group_add_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'addone' && $admin eq '1') { &head($SYSMSG{'title_addoneuser'}); print "\n"; print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'username'}\n"; print "\n"; print "
$SYSMSG{'password'}\n"; print "\n"; print "
$SYSMSG{'account_add_group'}\n"; print "\n"; print "
$SYSMSG{'account_add_to_manager'}\n"; print ""; print "
\n"; print "
"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'doaddone' && $admin eq '1') { &head($SYSMSG{'title_addoneuser'}); &addone($DATA{'user'}, $DATA{'grp'}, $DATA{'pwd'}, ''); &add_wam($DATA{'user'}) if ($DATA{'admin'} eq "ON"); &write_group; &make_passwd; &foot(''); } elsif ($DATA{'step'} eq 'upload' && $admin eq '1') { &head($SYSMSG{'title_manuadd'}); print "\n"; print '
'."\n"; print "\n"; print "\n"; print "
$SYSMSG{'manuadd_minihelp'}
\n"; print "$SYSMSG{'manuadd_minihelp_1'}
\n"; print "$SYSMSG{'manuadd_minihelp_2'}
\n"; print "$SYSMSG{'manuadd_minihelp_3'}
\n"; print "$SYSMSG{'manuadd_minihelp_4'}
\n"; print "
$SYSMSG{'manuadd_uploadfile'}"; print "\n"; print "
\n"; print "
"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'doupload' && $admin eq '1') { &head($SYSMSG{'title_manuadd'}); &read_request; &make_passwd; &foot(''); } elsif ($DATA{'step'} eq 'autoadd' && $admin eq '1') { &head($SYSMSG{'title_autoadd'}); if ($CONFIG{'nest'} eq 1) { print "\n"; } elsif ($CONFIG{'nest'} eq 2) { print "\n"; } elsif ($CONFIG{'nest'} eq 3) { print "\n"; } print "
\n"; print "\n"; print "\n"; if ($CONFIG{'nest'} eq 1) { &read_group; print "\n"; print "
$SYSMSG{'groupname'}
$SYSMSG{'group_hint'}\n"; print "

"; print "\n"; } print "
$SYSMSG{'autoadd_pre'}\n"; print "\n"; if ($CONFIG{'nest'} eq 2) { print "
$SYSMSG{'autoadd_level_2'}\n"; print "$SYSMSG{'autoadd_from'} $SYSMSG{'autoadd_to'} $SYSMSG{'autoadd_class'}\n"; } if ($CONFIG{'nest'} eq 3) { print "
$SYSMSG{'autoadd_level_2'}\n"; print "$SYSMSG{'autoadd_from'} $SYSMSG{'autoadd_to'} $SYSMSG{'autoadd_grade'}\n"; print "
$SYSMSG{'autoadd_level_3'}\n"; print "$SYSMSG{'autoadd_from'} $SYSMSG{'autoadd_to'} $SYSMSG{'autoadd_class'}\n"; } print "
$SYSMSG{'autoadd_level_4'}\n"; print "$SYSMSG{'autoadd_from'} $SYSMSG{'autoadd_to'} $SYSMSG{'autoadd_num'}\n"; print "
$SYSMSG{'autoadd_addzero'}"; print "

$SYSMSG{'autoadd_hint_2'}\n" if ($CONFIG{'nest'} eq 1); print "
$SYSMSG{'autoadd_hint_3'}\n" if ($CONFIG{'nest'} eq 2); print "
$SYSMSG{'autoadd_hint_4'}\n" if ($CONFIG{'nest'} eq 3); print "
\n"; print "
"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'doauto' && $admin eq '1') { &head($SYSMSG{'title_autoadd'}); &autoadd($DATA{'grp'},$DATA{'pre_name'},$DATA{'num1'},$DATA{'num2'},$DATA{'addzero'},$DATA{'grade_num1'},$DATA{'grade_num2'},$DATA{'class_num1'},$DATA{'class_num2'}); &make_passwd; if ($CONFIG{'passwd_form'} eq 'random') { print "\n"; print "\n"; my $i = 0; foreach $uid (sort keys %sreqn) { print "" if (($i % 3) eq 0); $i ++; print "
$SYSMSG{'username'}$SYSMSG{'password'}$SYSMSG{'username'}$SYSMSG{'password'}$SYSMSG{'username'}$SYSMSG{'password'}
$sreqn{$uid}$sreqp{$uid}\n"; } } print "
"; &foot(''); } elsif ($DATA{'step'} eq 'resetpw' && $admin eq '1') { &head($SYSMSG{'title_resetpw'}); print "\n"; print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'username'}\n"; print "\n"; print "
$SYSMSG{'groupname'}
$SYSMSG{'group_hint'}
\n"; print "
\n"; print "
$SYSMSG{'pattern_search'}\n"; print "\n"; print "
$SYSMSG{'reset_passwd_setto'}\n"; print "\n"; print "
\n"; print "
"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'checkreset' && $admin eq '1') { &head($SYSMSG{'title_resetpw'}); if ($DATA{'user'} ne '') { &reset_pw($DATA{'user'},'','',$DATA{'passwd_form'}); &write_shadow; print "
$SYSMSG{'reset_passwd_completed'}\n"; if ($DATA{'passwd_form'} eq 'random') { print "
$SYSMSG{'reset_passwd_list'}\n"; print "\n"; print "\n"; foreach $usr (@CHGPW) { print "\n"; } } print '
$SYSMSG{'username'}$SYSMSG{'password'}
$usr$UPASS{$usr}
'; } elsif ($DATA{'grp'} ne '') { print "
$SYSMSG{'reset_passwd_grp_question'} $DATA{'grp'}\n"; print "

$SYSMSG{'reset_passwd_reset_these'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "" if (($i % 5) eq 0); $i ++; print "\n"; } print "\n"; print "
$SYSMSG{'group_member'}\n"; my $i = 0; $mygrp = $GNMID{$DATA{'grp'}}; foreach $uid (sort keys %UIDS) { next if ($UGID{$uid} ne $mygrp); print "
$UIDNM{$uid}
"; } else { print "
$SYSMSG{'reset_passwd_search_question'} $DATA{'word'}\n"; print "

$SYSMSG{'reset_passwd_reset_these'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "" if (($i % 5) eq 0); $i ++; print "\n"; } print "\n"; print "
$SYSMSG{'user_search_result'}\n"; my $i = 0; foreach $usr (sort keys %UNAME) { next if ($usr !~ /$DATA{'word'}/); print "
$usr
"; } &foot(''); } elsif ($DATA{'step'} eq 'doreset' && $admin eq '1') { &head($SYSMSG{'title_resetpw'}); &reset_pw($DATA{'user'},$DATA{'grp'},$DATA{'word'},$DATA{'passwd_form'}); &write_shadow; print "
$SYSMSG{'reset_passwd_completed'}\n"; if ($DATA{'passwd_form'} eq 'random') { print "
$SYSMSG{'reset_passwd_list'}\n"; print "\n"; print "\n"; my $i = 0; foreach $usr (sort @CHGPW) { print "" if (($i % 3) eq 0); $i ++; print "
$SYSMSG{'username'}$SYSMSG{'password'}$SYSMSG{'username'}$SYSMSG{'password'}$SYSMSG{'username'}$SYSMSG{'password'}
$usr$UPASS{$usr}\n"; } } print '
'; &foot(''); } elsif ($DATA{'step'} eq 'chgpw' && $menu_id ne '') { &head($SYSMSG{'title_chgpw'}); print "\n"; print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'change_passwd_new'}\n"; print "\n"; print "
$SYSMSG{'change_passwd_again'}\n"; print "\n"; print "
\n"; print "
"; print "\n"; print "\n"; print "
$SYSMSG{'change_passwd_minihelp'}

    "; print "
  1. $SYSMSG{'change_passwd_rule_1'}
  2. \n"; print "
  3. $SYSMSG{'change_passwd_rule_2'}
  4. \n" if (int($CONFIG{'passwd_rule'})%2); print "
  5. $SYSMSG{'change_passwd_rule_3'}
  6. \n" if (int($CONFIG{'passwd_rule'})%4 >= 2); print "
  7. $SYSMSG{'change_passwd_rule_4'}
  8. \n" if (int($CONFIG{'passwd_rule'})%8 >= 4); print "
  9. $SYSMSG{'change_passwd_rule_5'}
  10. " if (int($CONFIG{'passwd_rule'}) >= 8); print "
\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'dochgpw' && $menu_id ne '') { &chg_passwd($DATA{'pwd'},$DATA{'pwd2'}); &write_shadow; &head($SYSMSG{'title_chgpw'}); print "
$SYSMSG{'change_passwd_completed'}
"; &foot(''); } elsif ($DATA{'step'} eq 'delete' && $admin eq '1') { &head($SYSMSG{'title_delacc'}); print "\n"; print "
\n"; print "\n"; print "
\n"; print "
$SYSMSG{'username'}\n"; print "\n"; print "
$SYSMSG{'groupname'}
$SYSMSG{'group_hint'}\n"; print "
\n"; print "
$SYSMSG{'pattern_search'}\n"; print "\n"; print "
  $SYSMSG{'del_user_cancel'}\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'checkdel' && $admin eq '1') { &head($SYSMSG{'title_delacc'}); if ($DATA{'user'} ne '') { &delete_pw($DATA{'user'},'',''); &write_passwd; &write_shadow; print "
$SYSMSG{'del_user_completed'}
\n"; } elsif ($DATA{'grp'} ne '') { print "

$SYSMSG{'del_user_grp_question'} $DATA{'grp'}

\n"; print "

$SYSMSG{'del_user_del_these'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "" if (($i % 5) eq 0); $i ++; print "\n"; } print "\n"; print "
$SYSMSG{'group_member'}\n"; my $i = 0; $mygrp = $GNMID{$DATA{'grp'}}; foreach $uid (sort keys %UIDS) { next if ($UGID{$uid} ne $mygrp); print "
$UIDNM{$uid}
  $SYSMSG{'del_user_cancel'}
"; } else { print "
$SYSMSG{'del_user_search_question'} $DATA{'word'}\n"; print "

$SYSMSG{'del_user_del_these'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "" if (($i % 5) eq 0); $i ++; print "\n"; } print "" if (($i % 5) eq 0); $i ++; print "\n"; } print "\n"; print "
$SYSMSG{'user_search_result'}\n"; my $i = 0; foreach $usr (sort keys %UNAME) { next if ($usr !~ /$DATA{'word'}/); print "
$usr
$SYSMSG{'group_search_result'}\n"; my $i = 0; foreach $grp (sort keys %GNAME) { next if ($grp !~ /$DATA{'word'}/); print "
$grp
  $SYSMSG{'del_user_cancel'}
"; } &foot(''); } elsif ($DATA{'step'} eq 'dodelete' && $admin eq '1') { &head($SYSMSG{'title_delacc'}); &delete_pw($DATA{'user'},$DATA{'grp'},$DATA{'word'}); &write_passwd; &write_shadow; print "
$SYSMSG{'del_user_cmpleted'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'check' && $menu_id ne '') { &head($SYSMSG{'title_checkacc'}); print "
\n"; print "
$SYSMSG{'check_account_group'}\n"; print "
";
	print "\n";
	system("grpck");
	print @_;
	print "
$SYSMSG{'check_account_username'}\n"; print "
";
	system("pwck");
	print @_;
	print "
"; print "
\n"; &foot(''); } elsif ($DATA{'step'} eq 'struct' && $admin eq '1') { &head($SYSMSG{'title_viewstruct'}); print "
\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'groupname'}
$SYSMSG{'group_hint'}\n"; print "
\n"; print "
"; if ($DATA{'grp'} ne '') { print "
\n"; print "
";
		print `tree -d $GCONF{$DATA{'grp'}}`;
		print "
"; print "
\n"; } &foot(''); } elsif ($DATA{'step'} eq 'trace' && $admin eq '1') { &head($SYSMSG{'title_trace'}); print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'username'}\n"; print "\n"; print "
\n"; print "

"; if ($DATA{'user'} ne '') { $uid = $UNMID{$DATA{'user'}}; if (-e "$HOME{$uid}/.bash_history") { open (HIS, "< $HOME{$uid}/.bash_history") || &err_disk("$SYSMSG{'err_cannot_open_history'}
"); @line = ; close(HIS); } elsif (-e "$HOME{$uid}/.history") { open (HIS, "< $HOME{$uid}/.history") || &err_disk("$SYSMSG{'err_cannot_open_history'}
"); @line = ; close(HIS); } else { @line = ("$SYSMSG{'trace_account_notfound'} $DATA{'user'}"); } print "
\n"; print "
";
		print @line;
		print "
"; print "
\n"; } &foot(''); } elsif ($DATA{'step'} eq 'edquota' && $admin eq '1') { &head($SYSMSG{'title_userquota'}); print "\n"; print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'username'}\n"; print "\n"; print "
$SYSMSG{'groupname'}
\n"; print "
\n"; print "
$SYSMSG{'pattern_search'}\n"; print "\n"; print "
  $SYSMSG{'cancel'}\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'chkquota' && $admin eq '1') { &head($SYSMSG{'title_userquota'}); if ($DATA{'user'} ne '') { print "
$DATA{'user'} $SYSMSG{'quota_status'}
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'dir'}$SYSMSG{'partition'}$SYSMSG{'used'}$SYSMSG{'quota_hard_limit'}$SYSMSG{'quota_soft_limit'}\n"; &user_quota($UNMID{$DATA{'user'}}); foreach $f (sort keys %filesys) { $dev = $filesys{$f}; print "\n"; print "
$f$dev$usrquota{$dev,'ublocks'}\n"; } print "
\n"; print "
\n"; } elsif ($DATA{'grp'} ne '') { print "

$SYSMSG{'quota_group_member_checkout'}

\n"; print "
$DATA{'user'} $SYSMSG{'quota_group_change'}
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'dir'}$SYSMSG{'partition'}$SYSMSG{'quota_hard_limit'}$SYSMSG{'quota_soft_limit'}\n"; foreach $dev (sort keys %DEVFS) { $f = $DEVFS{$dev}; print "\n"; print "
$f$dev\n"; } print "
\n"; print "
\n"; } else { print "

$SYSMSG{'quota_search_result_checkout'}

\n"; print "
$SYSMSG{'quota_user_change'}
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'dir'}$SYSMSG{'partition'}$SYSMSG{'quota_hard_limit'}$SYSMSG{'quota_soft_limit'}\n"; foreach $dev (sort keys %DEVFS) { $f = $DEVFS{$dev}; print "\n"; print "
$f$dev\n"; } print "
\n"; print "
\n"; } &foot(''); } elsif ($DATA{'step'} eq 'listquota' && $admin eq '1') { &head($SYSMSG{'title_viewquota'}); if ($DATA{'grp'} ne '') { print "

$DATA{'grp'}$SYSMSG{'quota_group_member_list'}

\n"; print "

$SYSMSG{'quota_set_these'}

\n"; print "\n"; print "
$SYSMSG{'user'}$SYSMSG{'dir'}$SYSMSG{'partition'}$SYSMSG{'used'}$SYSMSG{'quota_hard_limit'}$SYSMSG{'quota_soft_limit'}\n"; my $mini = 0; my $maxi = 0; my $number_count = 0; my $nextpage = 0; my $mygrp = $GNMID{$DATA{'grp'}}; @show_quota = (); foreach $uid (sort keys %UIDS) { next if ($UGID{$uid} ne $mygrp); $usr = $UIDNM{$uid}; push(@show_quota,$usr); $maxi ++; } $number_count = $maxi; $DATA{'page'} = 1 if (!$DATA{'page'}); my $prevpage = int($DATA{'page'})-1; $mini = $prevpage * 20; if ($maxi>int($DATA{'page'})*20) { $maxi = int($DATA{'page'})*20; $nextpage = int($DATA{'page'})+1; } for ($i=$mini;$i<$maxi;$i++) { $usr = $show_quota[$i]; &user_quota($UNMID{$usr}); foreach $f (sort keys %filesys) { $dev = $filesys{$f}; print "
$usr$f$dev$usrquota{$dev,'ublocks'}$usrquota{$dev,'hblocks'}$usrquota{$dev,'sblocks'}\n"; } } print "
\n"; print " $SYSMSG{'prev_page'} " if ($prevpage>0); my $page_count = ($number_count % 20)>0 ? int($number_count/20)+1 : int($number_count/20); print "$SYSMSG{'page_no'} $DATA{'page'}/$page_count $SYSMSG{'total'} $number_count $SYSMSG{'records'}"; print " $SYSMSG{'next_page'} " if ($nextpage>0); print "
\n"; } else { print "

$SYSMSG{'quota_search_result_list'}

\n"; print "

$SYSMSG{'quota_set_these'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'user'}$SYSMSG{'dir'}$SYSMSG{'partition'}$SYSMSG{'used'}$SYSMSG{'quota_hard_limit'}$SYSMSG{'quota_soft_limit'}\n"; my $mini = 0; my $maxi = 0; my $nextpage = 0; @show_quota = (); foreach $usr (sort keys %UNAME) { next if ($usr !~ /$DATA{'word'}/); push(@show_quota,$usr); $maxi ++; } $DATA{'page'} = 1 if (!$DATA{'page'}); my $prevpage = int($DATA{'page'})-1; $mini = $prevpage * 20; if ($maxi>int($DATA{'page'})*20) { $maxi = int($DATA{'page'})*20; $nextpage = int($DATA{'page'})+1; } for ($i=$mini;$i<$maxi;$i++) { $usr = $show_quota[$i]; &user_quota($UNMID{$usr}); foreach $f (sort keys %filesys) { $dev = $filesys{$f}; print "
$usr$f$dev$usrquota{$dev,'ublocks'}$usrquota{$dev,'hblocks'}$usrquota{$dev,'sblocks'}\n"; } } print "
\n"; print " $SYSMSG{'prev_page'} " if ($prevpage>0); print " $SYSMSG{'next_page'} " if ($nextpage>0); print "
\n"; } &foot(''); } elsif ($DATA{'step'} eq 'doquota' && $admin eq '1') { &head($SYSMSG{'title_userquota'}); &edit_user_quota; print "
$SYSMSG{'quota_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'mail' && $menu_id ne '') { my $gid=getgrnam('mail'); umask(0002); if ( ($logfile ne 'no') && (! -f $logfile) ) { open (LOGFILE,">>$logfile") or neomailerror("$lang_err{'couldnt_open'} $logfile!"); close(LOGFILE); chmod(0660,$logfile); chown(0,$gid,$logfile); } %prefs = %{&readprefs}; %style = %{&readstyle}; $lang = $prefs{'language'} || $defaultlanguage; ($lang =~ /^(..)$/) && ($lang = $1); require "lang/$lang"; $lang_charset ||= 'iso-8859-1'; $numberofheaders = $prefs{'numberofmessages'} || $numberofheaders; if ($DATA{"firstmessage"}) { $firstmessage = $DATA{"firstmessage"}; } else { $firstmessage = 1; } if ($DATA{"sort"}) { $sort = $DATA{"sort"}; } else { $sort = $prefs{"sort"} || 'date'; } if ($DATA{"keyword"}) { $keyword = $DATA{"keyword"}; $escapedkeyword=&urlencode($keyword); } else { $keyword = $escapedkeyword = ''; } $hitquota = 0; if ( $homedirfolders eq 'yes') { $folderdir = "$HOME{$menu_id}/$homedirfolderdirname"; } else { $folderdir = "$userprefsdir/$UIDNM{$menu_id}"; } $isvalid = 0; @validfolders = @{&getfolders()}; if ($DATA{"folder"}) { $folder = $DATA{"folder"}; foreach $checkfolder (@validfolders) { if ($folder eq $checkfolder) { $isvalid = 1; last; } } ($folder = 'INBOX') unless ( $isvalid ); } else { $folder = "INBOX"; } $printfolder = $lang_folders{$folder} || $folder || ''; $escapedfolder = &urlencode($folder); # $escapedfolder = $folder; # once we print the header, we don't want to do it again if there's an error $headerprinted = 0; $total_size = 0; $savedattsize; # last html read within a message, # used to check if an attachment is linked by this html $decodedhtml=""; $action = $DATA{"action"}; if ($action =~ /^(\w+)$/) { $action = $1; if ($action eq "displayheaders") { displayheaders(); } elsif ($action eq "readmessage") { readmessage(); } elsif ($action eq "emptytrash") { emptytrash(); } elsif ($action eq "viewattachment") { viewattachment(); } elsif ($action eq "composemessage") { composemessage(); } elsif ($action eq "sendmessage") { sendmessage(); } elsif ($action eq "movemessage") { movemessage(); } elsif ($action eq "retrpop3s") { retrpop3s(); } elsif ($action eq "retrpop3") { retrpop3(); } elsif ($action eq "setprefs") { setprefs(); } elsif ($action eq "saveprefs") { saveprefs(); } elsif ($action eq "editfolders") { editfolders(); } elsif ($action eq "addfolder") { addfolder(); } elsif ($action eq "deletefolder") { deletefolder(); } elsif ($action eq "addressbook") { addressbook(); } elsif ($action eq "editaddresses") { editaddresses(); } elsif ($action eq "addaddress") { modaddress("add"); } elsif ($action eq "deleteaddress") { modaddress("delete"); } elsif ($action eq "importabook") { importabook(); } elsif ($action eq "editpop3") { editpop3(); } elsif ($action eq "addpop3") { modpop3("add"); } elsif ($action eq "deletepop3") { modpop3("delete"); } elsif ($action eq "editfilter") { editfilter(); } elsif ($action eq "addfilter") { modfilter("add"); } elsif ($action eq "deletefilter") { modfilter("delete"); } else { neomailerror("Action $lang_err{'has_illegal_chars'}"); } } else { writelog("login - $UIDNM{$menu_id}"); if ( -d "$userprefsdir$UIDNM{$menu_id}" ) { displayheaders(); } else { firsttimeuser(); } } } elsif ($DATA{'step'} eq 'filesmgr' && $menu_id ne '') { if ($admin ne '1') { $) = $menu_gid; $> = $menu_id; } $share_flag = 0; ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); my $ext = 'tar.gz'; $ext = 'zip' if ($zip_exist); $DATA{'folder'} = &get_dir($DATA{'folder'}); $DATA{'folder'} = &chg_dir($DATA{'folder'},$DATA{'chfolder'}) if ($DATA{'action'} eq 'chdir'); &make_dir($DATA{'folder'},$DATA{'newfolder'}) if ($DATA{'action'} eq 'mkdir'); &del_dir($DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'delete'); &chg_perm($DATA{'newperm'},$DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'chmod'); &chg_owner($DATA{'newowner'},$DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'chown'); &ren_dir($DATA{'newname'},$DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'rename'); &move_dir($DATA{'movefolder'},$DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'move'); ©_dir($DATA{'copypath'},$DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'copy'); &show_file($DATA{'folder'},$DATA{'dnfile'}) if ($DATA{'action'} eq 'showfile'); &many_download($DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'many_download'); &share($DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'share'); $DATA{'folder'} = &get_dir($DATA{'folder'}); @free = &free_space($DATA{'folder'}); my $used = int((substr($free[3],0,-1)) * 0.6); &head($SYSMSG{'title_filesmgr'}); $tmpdnfile = time; print "
"; print "\n"; print "\n"; print "\n"; print ""; print ""; $fusr = getpwuid($OWNER{'..'}); $fgrp = getgrgid($GOWNER{'..'}); print ""; print ""; print ""; print "\n"; $folder_cnt++; foreach $file (@myfolds) { $myfile = $file; if ($CONFIG{'codepage_smb'} eq 'yes') { $myfile =~ s/\:/\=/g; $myfile = &qpdecode($myfile); } next if ($file eq '.' || $file eq '..'); print ""; print ""; print ""; print ""; $fusr = getpwuid($OWNER{$file}); $fgrp = getgrgid($GOWNER{$file}); print ""; print ""; print ""; print "\n"; $folder_cnt++; } foreach $file (@myfiles) { $myfile = $file; if ($CONFIG{'codepage_smb'} eq 'yes') { $myfile =~ s/\:/\=/g; $myfile = &qpdecode($myfile); } print ""; print ""; print ""; print ""; $fusr = getpwuid($OWNER{$file}); $fgrp = getgrgid($GOWNER{$file}); print ""; print ""; print ""; print "\n"; } print "\n" if ($filemgr_rows le 0); for (1..18 - $filemgr_rows) { print "\n"; } print "\n"; print "
$SYSMSG{'sign_left'}$SYSMSG{'filemgr_current_dir'} $DATA{'folder'} $SYSMSG{'sign_right'}    $SYSMSG{'sign_left'}$SYSMSG{'filemgr_goto_sharemgr'}$SYSMSG{'sign_right'}
\n"; print "
$SYSMSG{'filemgr_total_quota'}$free[0] $SYSMSG{'filemgr_total_quota_used'}$free[1] $SYSMSG{'filemgr_total_quota_left'}$free[2] $SYSMSG{'filemgr_total_quota_use'}$free[3]
\n"; if ($DATA{'sort'} eq 'name' || $DATA{'sort'} eq '') { print "$SYSMSG{'filemgr_file_name'}\n"; } else { print "$SYSMSG{'filemgr_file_name'}\n"; } if ($DATA{'sort'} eq 'type') { print "$SYSMSG{'filemgr_file_type'}\n"; } else { print "$SYSMSG{'filemgr_file_type'}\n"; } if ($DATA{'sort'} eq 'perm') { print "$SYSMSG{'filemgr_file_priv'}\n"; } else { print "$SYSMSG{'filemgr_file_priv'}\n"; } if ($DATA{'sort'} eq 'owner') { print "$SYSMSG{'filemgr_file_owner'}\n"; } else { print "$SYSMSG{'filemgr_file_owner'}\n"; } if ($DATA{'sort'} eq 'gowner') { print "$SYSMSG{'filemgr_file_owner_group'}\n"; } else { print "$SYSMSG{'filemgr_file_owner_group'}\n"; } if ($DATA{'sort'} eq 'size') { print "$SYSMSG{'filemgr_file_size'}\n"; } else { print "$SYSMSG{'filemgr_file_size'}\n"; } if ($DATA{'sort'} eq 'time') { print "$SYSMSG{'filemgr_file_date'}\n"; } else { print "$SYSMSG{'filemgr_file_date'}\n"; } print "$SYSMSG{'filemgr_pannel'}
《$SYSMSG{'filemgr_gohome'}》"; print ""; print "\n"; print "$SYSMSG{'upload'}$SYSMSG{'files'}\n"; print ""; print "
"; print "\n"; print "\n"; print "\n"; print "

$SYSMSG{'filemgr_pannel_minihelp'}

"; print "

\n"; print "

\n"; print "

\n"; print "

\n"; print "

\n"; print "

\n"; print "

\n"; print "

\n"; print "

\n"; print "

\n" if ($admin eq '1'); if ( $DATA{'sort'} eq 'name' || $DATA{'sort'} eq '') { @myfolds = sort keys %FOLDS; @myfiles = sort keys %FILES; } elsif ( $DATA{'sort'} eq 'name_rev' ) { @myfolds = reverse(sort keys %FOLDS); @myfiles = reverse(sort keys %FILES); } elsif ( $DATA{'sort'} eq 'time') { @myfolds = sort by_time keys %FOLDS; @myfiles = sort by_time keys %FILES; } elsif ( $DATA{'sort'} eq 'time_rev' ) { @myfolds = reverse(sort by_time keys %FOLDS); @myfiles = reverse(sort by_time keys %FILES); } elsif ( $DATA{'sort'} eq 'type' ) { @myfolds = sort by_time keys %FOLDS; @myfiles = sort by_time keys %FILES; } elsif ( $DATA{'sort'} eq 'type_rev' ) { @myfolds = reverse(sort by_time keys %FOLDS); @myfiles = reverse(sort by_time keys %FILES); } elsif ( $DATA{'sort'} eq 'perm' ) { @myfolds = sort by_perm keys %FOLDS; @myfiles = sort by_perm keys %FILES; } elsif ( $DATA{'sort'} eq 'perm_rev') { @myfolds = reverse(sort by_perm keys %FOLDS); @myfiles = reverse(sort by_perm keys %FILES); } elsif ( $DATA{'sort'} eq 'owner' ) { @myfolds = sort by_owner keys %FOLDS; @myfiles = sort by_owner keys %FILES; } elsif ( $DATA{'sort'} eq 'owner_rev') { @myfolds = reverse(sort by_owner keys %FOLDS); @myfiles = reverse(sort by_owner keys %FILES); } elsif ( $DATA{'sort'} eq 'gowner' ) { @myfolds = sort by_gowner keys %FOLDS; @myfiles = sort by_gowner keys %FILES; } elsif ( $DATA{'sort'} eq 'gowner_rev') { @myfolds = reverse(sort by_gowner keys %FOLDS); @myfiles = reverse(sort by_gowner keys %FILES); } elsif ( $DATA{'sort'} eq 'size' ) { @myfolds = sort by_size keys %FOLDS; @myfiles = sort by_size keys %FILES; } elsif ( $DATA{'sort'} eq 'size_rev') { @myfolds = reverse(sort by_size keys %FOLDS); @myfiles = reverse(sort by_size keys %FILES); } print "
$SYSMSG{'parrent'}"; print "$TYPE{'..'}$PERM{'..'}$fusr$fgrp$FSIZE{'..'}$MODIFY{'..'}
$myfile$TYPE{$file}$PERM{$file}$fusr$fgrp$FSIZE{$file}$MODIFY{$file}
$myfile$TYPE{$file}$PERM{$file}$fusr$fgrp$FSIZE{$file}$MODIFY{$file}
$SYSMSG{'err_file&dir_notfound'}
 
$SYSMSG{'filemgr_total_quota'}$free[0] $SYSMSG{'filemgr_total_quota_used'}$free[1] $SYSMSG{'filemgr_total_quota_left'}$free[2] $SYSMSG{'filemgr_total_quota_use'}$free[3]
\n"; &foot('f'); } elsif ($DATA{'step'} eq 'fupload' && $menu_id ne '') { &head($DATA{'title'}); print "

$SYSMSG{'filemgr_upload_where'} $DATA{'folder'} $SYSMSG{'folder'}"; print "

\n"; print "$SYSMSG{'filemgr_upload_unzip'}
\n" if ($zip_exist); if ($DATA{'act'} eq 'f') { print "\n"; } elsif ($DATA{'act'} eq 's') { print "\n"; print "\n"; } print "\n"; if ($DATA{'filemany'}) { for ($z=1;$z<=$DATA{'filemany'};++$z) { print "$SYSMSG{'file'}$z:
\n"; } --$z; } else { for ($z=1;$z<6;++$z) { print "$SYSMSG{'file'}$z:
\n"; } --$z; } print "\n"; print "
"; &foot($DATA{'act'}); } elsif ($DATA{'step'} eq 'edit_file' && $admin eq '1') { &edit_file($DATA{'dnfile'}); } elsif ($DATA{'step'} eq 'down_load' && $admin eq '1') { &down_load($DATA{'dnfile'}); } elsif ($DATA{'step'} eq 'dosave' && $menu_id ne '') { my($buf, @mydir, $edfile); $edfile = $DATA{'edfile'}; @mydir = split(/\//,$edfile); my $totalT = @mydir; --$totalT; my $fname=$mydir[$totalT]; $buf = $DATA{'textbody'}; $buf =~ s/\r//g; open(REAL,"> $edfile") || &err_disk("$SYSMSG{'filemgr_upload_cannot_open_editfile'}$edfile
"); print REAL $buf; close(REAL); if ($DATA{'action'} eq 'save') { print "Location: $cgi_url/$fname?step=edit_file&dnfile=$edfile\n\n"; } else { &head($SYSMSG{'title_savefile'}); print "
$SYSMSG{'filemgr_upload_completed'}"; &foot('f'); } } elsif ($DATA{'step'} eq 'sharemgr' && $menu_id ne '') { $DATA{'folder'} = &get_share($DATA{'folder'}); $DATA{'folder'} = &chg_dir($DATA{'folder'},$DATA{'chfolder'}) if ($DATA{'action'} eq 'chdir'); &make_dir($DATA{'folder'},$DATA{'newfolder'}) if ($DATA{'action'} eq 'mkdir'); &del_dir($DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'delete'); &ren_dir($DATA{'newname'},$DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'rename'); &show_file($DATA{'folder'},$DATA{'dnfile'}) if ($DATA{'action'} eq 'showfile'); &many_download($DATA{'folder'},$DATA{'sel'}) if ($DATA{'action'} eq 'many_download'); &del_share($DATA{'sel'}) if ($DATA{'action'} eq 'del_share'); &share('',$DATA{'sel'}) if ($DATA{'action'} eq 'share'); $DATA{'folder'} = &get_share($DATA{'folder'}); $tmpdnfile = time; &head($SYSMSG{'title_sharemgr'}); print "
\n"; print "\n"; print "\n"; } if ($DATA{'share'} eq '') { print ""; print ""; $fusr = getpwuid($OWNER{'..'}); $fgrp = getgrgid($GOWNER{'..'}); print ""; print ""; print ""; print "\n"; } if ( $DATA{'sort'} eq 'name' || $DATA{'sort'} eq '') { @myfolds = sort keys %FOLDS; @myfiles = sort keys %FILES; } elsif ( $DATA{'sort'} eq 'name_rev' ) { @myfolds = reverse(sort keys %FOLDS); @myfiles = reverse(sort keys %FILES); } elsif ( $DATA{'sort'} eq 'time') { @myfolds = sort by_time keys %FOLDS; @myfiles = sort by_time keys %FILES; } elsif ( $DATA{'sort'} eq 'time_rev' ) { @myfolds = reverse(sort by_time keys %FOLDS); @myfiles = reverse(sort by_time keys %FILES); } elsif ( $DATA{'sort'} eq 'type' ) { @myfolds = sort by_time keys %FOLDS; @myfiles = sort by_time keys %FILES; } elsif ( $DATA{'sort'} eq 'type_rev' ) { @myfolds = reverse(sort by_time keys %FOLDS); @myfiles = reverse(sort by_time keys %FILES); } elsif ( $DATA{'sort'} eq 'perm' ) { @myfolds = sort by_perm keys %FOLDS; @myfiles = sort by_perm keys %FILES; } elsif ( $DATA{'sort'} eq 'perm_rev') { @myfolds = reverse(sort by_perm keys %FOLDS); @myfiles = reverse(sort by_perm keys %FILES); } elsif ( $DATA{'sort'} eq 'owner' ) { @myfolds = sort by_owner keys %FOLDS; @myfiles = sort by_owner keys %FILES; } elsif ( $DATA{'sort'} eq 'owner_rev') { @myfolds = reverse(sort by_owner keys %FOLDS); @myfiles = reverse(sort by_owner keys %FILES); } elsif ( $DATA{'sort'} eq 'gowner' ) { @myfolds = sort by_gowner keys %FOLDS; @myfiles = sort by_gowner keys %FILES; } elsif ( $DATA{'sort'} eq 'gowner_rev') { @myfolds = reverse(sort by_gowner keys %FOLDS); @myfiles = reverse(sort by_gowner keys %FILES); } elsif ( $DATA{'sort'} eq 'size' ) { @myfolds = sort by_size keys %FOLDS; @myfiles = sort by_size keys %FILES; } elsif ( $DATA{'sort'} eq 'size_rev') { @myfolds = reverse(sort by_size keys %FOLDS); @myfiles = reverse(sort by_size keys %FILES); } foreach $file (@myfolds) { $myfile = $file; if ($CONFIG{'codepage_smb'} eq 'yes') { $myfile =~ s/\:/\=/g; $myfile = &qpdecode($myfile); } next if ($file eq '.' || $file eq '..'); if ($DATA{'share'} eq '') { $sfile = substr($file,1); print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; } else { print ""; print ""; print ""; print ""; $fusr = getpwuid($OWNER{$file}); $fgrp = getgrgid($GOWNER{$file}); print ""; print ""; print ""; print "\n"; } $folder_cnt++; } foreach $file (@myfiles) { $myfile = $file; if ($CONFIG{'codepage_smb'} eq 'yes') { $myfile =~ s/\:/\=/g; $myfile = &qpdecode($myfile); } print ""; print ""; print ""; print ""; $fusr = getpwuid($OWNER{$file}); $fgrp = getgrgid($GOWNER{$file}); print ""; print ""; print ""; print "\n"; } print "\n" if ($filemgr_rows le 0); for (1..6 - $filemgr_rows) { print "\n"; } print "
$SYSMSG{'sign_left'}$SYSMSG{'share_current_dir'} $DATA{'folder'} $SYSMSG{'sign_right'}\n"; if ($SPERM_UP{$DATA{'share'}} eq 'yes') { print "
\n"; print "$SYSMSG{'upload'}$SYSMSG{'files'}\n"; print " $SYSMSG{'share_backto_filemgr'}
"; } else { print "
$SYSMSG{'share_readonly'} $SYSMSG{'share_backto_filemgr'}
$SYSMSG{'share_name'}$SYSMSG{'share_download'}$SYSMSG{'share_upload'}$SYSMSG{'share_mkdir'}$SYSMSG{'share_edit'}$SYSMSG{'share_delete'}"; print "$SYSMSG{'share_realpath'}"; } else { print "
\n"; if ($DATA{'sort'} eq 'name' || $DATA{'sort'} eq '') { print "$SYSMSG{'filemgr_file_name'}\n"; } else { print "$SYSMSG{'filemgr_file_name'}\n"; } if ($DATA{'sort'} eq 'type') { print "$SYSMSG{'filemgr_file_type'}\n"; } else { print "$SYSMSG{'filemgr_file_type'}\n"; } if ($DATA{'sort'} eq 'perm') { print "$SYSMSG{'filemgr_file_priv'}\n"; } else { print "$SYSMSG{'filemgr_file_priv'}\n"; } if ($DATA{'sort'} eq 'owner') { print "$SYSMSG{'filemgr_file_owner'}\n"; } else { print "$SYSMSG{'filemgr_file_owner'}\n"; } if ($DATA{'sort'} eq 'gowner') { print "$SYSMSG{'filemgr_file_owner_group'}\n"; } else { print "$SYSMSG{'filemgr_file_owner_group'}\n"; } if ($DATA{'sort'} eq 'size') { print "$SYSMSG{'filemgr_file_size'}\n"; } else { print "$SYSMSG{'filemgr_file_size'}\n"; } if ($DATA{'sort'} eq 'time') { print "$SYSMSG{'filemgr_file_date'}\n"; } else { print "$SYSMSG{'filemgr_file_date'}\n"; } } print "
"; print "\n"; print "\n"; print "\n"; print "\n"; print "

$SYSMSG{'share_pannel_minihelp'}

"; if ($DATA{'share'} eq '') { print "

" if ($admin eq '1'); print "

" if ($admin eq '1'); print "
"; } else { print "

"; print "

"; print "

"; print "

"; } $folder_cnt = 0; if ($DATA{'share'}) { print "
$SYSMSG{'parrent'}"; print "$TYPE{'..'}$PERM{'..'}$fusr$fgrp$FSIZE{'..'}$MODIFY{'..'}
$SDESC{$file}".(($SPERM_DN{$file} eq 'yes') ? "ˇ" : 'ㄨ')."".(($SPERM_UP{$file} eq 'yes') ? "ˇ" : 'ㄨ')."".(($SPERM_DIR{$file} eq 'yes') ? "ˇ" : 'ㄨ')."".(($SPERM_EDIT{$file} eq 'yes') ? "ˇ" : 'ㄨ')."".(($SPERM_DEL{$file} eq 'yes') ? "ˇ" : 'ㄨ')."$myfile
$myfile$TYPE{$file}$PERM{$file}$fusr$fgrp$FSIZE{$file}$MODIFY{$file}
$myfile$TYPE{$file}$PERM{$file}$fusr$fgrp$FSIZE{$file}$MODIFY{$file}
$SYSMSG{'err_file&dir_notfound'}
\n"; &foot('s'); } elsif ($DATA{'step'} eq 'doshare' && $admin eq '1') { if ($DATA{'folder'} eq '') { $mydir = ''; } else{ $mydir = $DATA{'folder'}; $mydir .= '/' if ($mydir ne '/'); } if ($DATA{'grp'} =~ /999/) { $DATA{'grp'} = 'root'; foreach $gid (sort keys %GIDS) { $grp = $GIDNM{$gid}; next if (int($gid)<500); next if (&check_special($grp) eq 1); $DATA{'grp'} .= ','.$grp; } } @items = split(/,/,$DATA{'items'}); foreach $item (@items) { $SHARE{"$mydir$item"} = $DATA{'grp'}; $SDESC{"$mydir$item"} = $DATA{"share-$item"}; $SDESC{"$mydir$item"} = "$mydir$item" if ($SDESC{"$mydir$item"} eq ''); $SPERM_DN{"$mydir$item"} = $DATA{'dn'}; $SPERM_UP{"$mydir$item"} = $DATA{'up'}; $SPERM_DIR{"$mydir$item"} = $DATA{'dir'}; $SPERM_EDIT{"$mydir$item"} = $DATA{'edit'}; $SPERM_DEL{"$mydir$item"} = $DATA{'del'}; } &write_share; &head($SYSMSG{'title_sharemgr'}); print "
$SYSMSG{'share_completed'}"; &foot('s'); } elsif ($DATA{'step'} eq 'imgmgr' && $admin eq '1') { &new_digits if ($DATA{'action'} eq 'new_digits'); &del_dir($cnt_base,$DATA{'style'}) if ($DATA{'action'} eq 'delete'); &get_digits; &head($SYSMSG{'title_digitsmgr'}); print "
\n"; print "\n"; print "\n"; print "\n"; print "
"; $digits_rows = $#STYLES - 4; print "
$SYSMSG{'counter_choose'}$SYSMSG{'counter_img_lib'}$SYSMSG{'counter_name'}\n"; foreach $file (sort @STYLES) { next if (!(-d "$cnt_base/$file")); next if ($file eq '.' || $file eq '..'); print "
"; print ""; print "$file"; } print "
"; &foot(''); } elsif ($DATA{'step'} eq 'set_count' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_cnt_conf("$home/$cnt_config"); &get_digits; &head($SYSMSG{'title_setcnt'}); print "
\n"; print "\n"; print "\n"; print "
\n"; foreach $file (sort @STYLES) { next if (!(-d "$cnt_base/$file")); next if ($file eq '.' || $file eq '..'); if ($CNTCONF{'style'} eq $file) { print "
$SYSMSG{'set_counter_start'}\n"; print "\n"; print "
$SYSMSG{'set_counter_incream'}\n"; print "\n"; print "
$SYSMSG{'set_counter_digits'}\n"; print "\n"; print "
$SYSMSG{'set_counter_check_ip'}\n"; if ($CNTCONF{'check_ip'} eq 'yes') { print "\n"; } else { print "\n"; } print "
$SYSMSG{'set_counter_style'}
"; } else { print "
"; } print ""; } print "
\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'cnt_conf' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); $CNTCONF{'start'} = $DATA{'start'}; $CNTCONF{'check_ip'} = $DATA{'check_ip'}; $CNTCONF{'add'} = $DATA{'add'}; $CNTCONF{'digits'} = $DATA{'digits'}; $CNTCONF{'style'} = $DATA{'style'}; open (CFG, "> $home/$cnt_config") || &err_disk("$SYSMSG{'err_cannot_open_counter_config'}
"); flock(CFG,2); foreach $name (keys %CNTCONF) { print CFG "$name:$CNTCONF{$name}\n"; } flock(CFG,8); close(CFG); &head($SYSMSG{'title_setcnt'}); print "
$SYSMSG{'cset_counter_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'view_count' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_cnt_data("$home/$cnt_data"); &head($SYSMSG{'title_viewcnt'}); print "
\n"; print "
$SYSMSG{'view_counter_pagename'}$SYSMSG{'view_counter_total'}$SYSMSG{'view_counter_last_ip'}\n"; foreach $cnt (keys %COUNT) { print "
$SYSMSG{'view_counter_delete'}$cnt$COUNT{$cnt}$LASTIP{$cnt}\n"; } print "
"; print "
\n"; print "\n"; print "
$SYSMSG{'view_counter_hint'}
"; print "

\n"; if ($menu_id eq 0) { print "
$SYSMSG{'view_counter_jumpto_rootpage'}
\n"; } else { print "
$SYSMSG{'view_counter_jumpto_homepage'}
\n"; } &foot(''); } elsif ($DATA{'step'} eq 'del_count' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_cnt_conf("$home/$cnt_config"); &read_cnt_data("$home/$cnt_data"); $cnt = $DATA{'cnt'}; delete $COUNT{$cnt}; &write_cnt_data("$home/$cnt_data"); &head($SYSMSG{'title_delcnt'}); print "
$SYSMSG{'view_counter_page'} $cnt $SYSMSG{'view_counter_delete_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'reset_cnt' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_cnt_conf("$home/$cnt_config"); &read_cnt_data("$home/$cnt_data"); foreach $cnt (keys %COUNT) { $COUNT{$cnt} = $CNTCONF{'start'}; } &write_cnt_data("$home/$cnt_data"); &head($SYSMSG{'title_resetcnt'}); print "
$SYSMSG{'view_counter_reset_all_become'}$CNTCONF{'start'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'set_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_conf("$home/$gb_config"); &head($SYSMSG{'title_setgb'}); print "
\n"; print "\n"; print "\n"; print "
$SYSMSG{'set_gbook_title'}\n"; print "\n"; print "
$SYSMSG{'set_gbook_per_page'}\n"; print "$SYSMSG{'set_gbook_msg_no'}\n"; print "
$SYSMSG{'set_gbook_page_yes'}\n"; if ($GBCONF{'page_jump'} eq 'no') { print "$SYSMSG{'set_gbook_page_no'}\n"; } else { print "$SYSMSG{'set_gbook_page_no'}\n"; } print "
$SYSMSG{'set_gbook_sort_mode'}\n"; if ($GBCONF{'sort'} eq 'by_name') { print "$SYSMSG{'set_gbook_sort_by_name'}\n"; } else { print "$SYSMSG{'set_gbook_sort_by_name'}\n"; } if ($GBCONF{'sort'} eq 'by_date') { print "$SYSMSG{'set_gbook_sort_by_date'}\n"; } else { print "$SYSMSG{'set_gbook_sort_by_date'}\n"; } print "
$SYSMSG{'set_gbook_mailto_owner'}\n"; if ($GBCONF{'email'} eq 'yes') { print "$SYSMSG{'set_gbook_mailto_owner_yes'}\n"; } else { print "$SYSMSG{'set_gbook_mailto_owner_yes'}\n"; } print "
$SYSMSG{'set_gbook_subscribe_mode'}\n"; if ($GBCONF{'subscribe'} eq 'yes') { print "$SYSMSG{'set_gbook_subscribe_mode_yes'}\n"; } else { print "$SYSMSG{'set_gbook_subscribe_mode_yes'}\n"; } print "
\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'gb_conf' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); $GBCONF{'title'} = $DATA{'title'}; $GBCONF{'many'} = $DATA{'many'}; $GBCONF{'page_jump'} = $DATA{'page_jump'}; $GBCONF{'email'} = $DATA{'email'}; $GBCONF{'subscribe'} = $DATA{'subscribe'}; $GBCONF{'sort'} = $DATA{'sort'}; open (CFG, "> $home/$gb_config") || &err_disk("$SYSMSG{'err_cannot_open_gbook_config'}
"); flock(CFG,2); foreach $name (keys %GBCONF) { print CFG "$name:$GBCONF{$name}\n"; } flock(CFG,8); close(CFG); if ($GBCONF{'subscribe'} eq 'yes') { &set_aliases('gbook-'.$musr,"$home/$gb_subscribe"); } else { &unset_aliases('gbook-'.$musr); } system("$CONFIG{'mailprog'} -bi"); &head($SYSMSG{'title_setgb'}); print "
$SYSMSG{'set_gbook_completed'}
\n"; &foot(''); } elsif ($DATA{'step'} eq 'edit_gb' && $menu_id ne '') { my @GB = (); ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_conf("$home/$gb_config"); &read_gb_data("$home/$gb_data"); &read_gb_reply("$home/$gb_reply"); &head($SYSMSG{'title_gbmgr'}); sub byredate { $REDATE{$a} <=> $REDATE{$b}; } sub bydate { $GBDATE{$b} <=> $GBDATE{$a}; } sub byname { $GBAUTH{$a} cmp $GBAUTH{$b}; } print "

$SYSMSG{'sign_left'}$SYSMSG{'gbook_manage'} $GBCONF{'title'}$SYSMSG{'sign_right'}

"; print "$SYSMSG{'gbook_user'}
" if ($GBCONF{'subscribe'} eq 'yes'); print "
\n"; @GB = sort byname keys %GBAUTH if ($GBCONF{'sort'} eq 'by_name'); @GB = sort bydate keys %GBDATE if ($GBCONF{'sort'} eq 'by_date'); @REPLY = sort byredate keys %REDATE; $DATA{'page'} = 1 if ($DATA{'page'} eq ''); $DATA{'startpage'} = 1 if ($DATA{'startpage'} eq ''); if ($GBCONF{'page_jump'} ne 'no') { if ($DATA{'page'} == 1) { $start = 0; $end = $GBCONF{'many'}-1; } else { $start = $GBCONF{'many'} * ($DATA{'page'}-1); $end = $start + $GBCONF{'many'} - 1; } } else { $start = 0; $end = $#GB; } $end = $#GB if ($end > $#GB); print "\n"; if ($end < 0) { print "

$SYSMSG{'gbook_no_msg'}

\n"; } else { print "
$SYSMSG{'gbook_del_all_msg'} \n"; print "

\n"; print "
$SYSMSG{'quick_jump'}"; if ($GBCONF{'page_jump'} ne 'no') { $num = $DATA{'startpage'}-10; print "$SYSMSG{'ten_up'}\n" if ($DATA{'startpage'} > 10); $num = $DATA{'page'}-1; print "$SYSMSG{'sign_up'}\n" if ($DATA{'page'} > 1); $pagecnt = $DATA{'startpage'}+9; $pagecnt = int($#GB/$GBCONF{'many'}+1) if (int($#GB/$GBCONF{'many'}+1) < $pagecnt); foreach ($DATA{'startpage'}..$pagecnt) { if ($DATA{'page'} == $_) { print "$_ "; } else { print "  $_ "; } } $num = $DATA{'page'}+1; print "$SYSMSG{'sign_down'}\n" if ($end < $#GB); $num = $DATA{'startpage'}+10; print "$SYSMSG{'ten_down'}\n" if ($DATA{'startpage'}+9 < int($#GB/$GBCONF{'many'}+1)); } print "

"; for ($start..$end) { $cnt = $GB[$_]; $mydate = &get_date($GBDATE{$cnt}); if ($GBMAIL{$cnt} eq "") { print "
$GBAUTH{$cnt}   $SYSMSG{'gbook_msg_date'}$mydate ($GBIP{$cnt}) \n"; print "$SYSMSG{'gbook_msg_reply'} \n"; print "$SYSMSG{'gbook_msg_edit'} \n"; print "$SYSMSG{'gbook_msg_del'} \n"; } else { print "
$GBAUTH{$cnt}   $SYSMSG{'gbook_msg_date'}$mydate ($GBIP{$cnt}) \n"; print "$SYSMSG{'gbook_msg_reply'} \n"; print "$SYSMSG{'gbook_msg_edit'} \n"; print " $SYSMSG{'gbook_msg_del'} \n"; } if ($MODE{$cnt} eq '1') { print "
\n"; print ""; } else { print "
$SYSMSG{'gbook_msg_subject'}$GBTITLE{$cnt}
$SYSMSG{'gbook_msg_content'}$MESSAGES{$cnt}
\n"; print ""; } print "
$SYSMSG{'gbook_msg_subject'}$GBTITLE{$cnt}
$SYSMSG{'gbook_msg_content'}$MESSAGES{$cnt}
\n"; for (0..$#REPLY) { $parn = $REPLY[$_]; if ($REPARN{$parn} eq $cnt) { $mydate = &get_date($REDATE{$parn}); if ($REMAIL{$cnt} eq "") { print "\n"; } else { print "\n"; } print "\n"; print ""; } } print "
$REAUTH{$parn}   $SYSMSG{'gbook_msg_date'}$mydate ($REIP{$parn}) $SYSMSG{'gbook_msg_del'}
$REAUTH{$parn} $SYSMSG{'gbook_msg_date'}$mydate ($REIP{$parn}) $SYSMSG{'gbook_msg_del'}
$SYSMSG{'gbook_msg_subject'}$RETITLE{$parn}
$SYSMSG{'gbook_msg_content'}$REPLYS{$parn}

\n"; } print "
$SYSMSG{'quick_jump'}"; if ($GBCONF{'page_jump'} ne 'no') { $num = $DATA{'startpage'}-10; print "$SYSMSG{'ten_up'}\n" if ($DATA{'startpage'} > 10); $num = $DATA{'page'}-1; print "$SYSMSG{'sign_up'}\n" if ($DATA{'page'} > 1); $pagecnt = $DATA{'startpage'}+9; $pagecnt = int($#GB/$GBCONF{'many'}+1) if (int($#GB/$GBCONF{'many'}+1) < $pagecnt); foreach ($DATA{'startpage'}..$pagecnt) { if ($DATA{'page'} == $_) { print "$_ "; } else { print "  $_ "; } } $num = $DATA{'page'}+1; print "$SYSMSG{'sign_down'}\n" if ($end < $#GB); $num = $DATA{'startpage'}+10; print "$SYSMSG{'ten_down'}\n" if ($DATA{'startpage'}+9 < int($#GB/$GBCONF{'many'}+1)); } print "

"; } print "
"; &foot(''); } elsif ($DATA{'step'} eq 'modify_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_data("$home/$gb_data"); &head($SYSMSG{'title_gbmgr'}); print "
$SYSMSG{'gbook_title_edit'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'gbook_input_name'}\n"; print "\n"; print "
$SYSMSG{'gbook_input_email'}\n"; print "\n"; print "
$SYSMSG{'gbook_input_mode'}\n"; if ($MODE{$DATA{'id'}} eq '1') { print "$SYSMSG{'gbook_mode_public'}\n"; print "$SYSMSG{'gbook_mode_private'}\n"; } else { print "$SYSMSG{'gbook_mode_public'}\n"; print "$SYSMSG{'gbook_mode_private'}\n"; } print "
$SYSMSG{'gbook_msg_subject'}:\n"; print "\n"; print "
$SYSMSG{'gbook_msg_content'}\n"; print "\n"; print "
\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'reply_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_data("$home/$gb_data"); &head($SYSMSG{'title_gbmgr'}); print "
$SYSMSG{'gbook_title_reply'}

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$SYSMSG{'gbook_msg_subject'}:\n"; print "\n"; print "
$SYSMSG{'gbook_msg_content'}\n"; my $body = $MESSAGES{$DATA{'id'}}; $body =~ s/
/\r\n>/g; print "
\n"; print "
\n"; print "
"; &foot(''); } elsif ($DATA{'step'} eq 'save_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_conf("$home/$gb_config"); if ($DATA{'parn'} eq '') { &read_gb_data("$home/$gb_data"); $cnt = $DATA{'id'}; $GBDATE{$cnt} = time; $GBAUTH{$cnt} = $DATA{'auth'}; $GBMAIL{$cnt} = $DATA{'email'}; $GBTITLE{$cnt} = $DATA{'subject'}; $DATA{'body'} =~ s/\r\n/
/g; $MESSAGES{$cnt} = $DATA{'body'}; $MODE{$cnt} = $DATA{'mode'}; &write_gb_data("$home/$gb_data"); } else { &read_gb_reply("$home/$gb_reply"); for ($cnt=1;$cnt<65535;$cnt++) { last if (!defined($REDATE{$cnt})); } $REIP{$cnt} = '0.0.0.0'; $REPARN{$cnt} = $DATA{'parn'}; $REDATE{$cnt} = time; $REAUTH{$cnt} = $DATA{'auth'}; $REMAIL{$cnt} = $DATA{'email'}; $RETITLE{$cnt} = $DATA{'subject'}; $DATA{'body'} =~ s/\r\n/
/g; $REPLYS{$cnt} = $DATA{'body'}; &write_gb_reply("$home/$gb_reply"); } &gb_submailer($DATA{'email'},$DATA{'auth'},$DATA{'subject'},$DATA{'body'}) if ($GBCONF{'subscribe'} eq 'yes'); print "Location: $cgi_url?step=edit_gb&page=$DATA{'page'}&startpage=$DATA{'startpage'}\n\n"; } elsif ($DATA{'step'} eq 'del_all_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); if ($DATA{'del_all'} eq 'yes') { open (DATA, "> $home/$gb_data"); close(DATA); open (DATA, "> $home/$gb_reply"); close(DATA); } print "Location: $cgi_url?step=edit_gb\n\n"; } elsif ($DATA{'step'} eq 'del_checked_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_data("$home/$gb_data"); &read_gb_reply("$home/$gb_reply"); @chkid=split(/,/,$DATA{'id'}); foreach $myid (@chkid) { delete $GBDATE{$myid}; foreach $cnt (keys %REDATE) { delete $REDATE{$cnt} if ($REPARN{$cnt} eq $myid); } } @chkid=split(/,/,$DATA{'reply'}); foreach $myid (@chkid) { next if (!defined($REDATE{$myid})); delete $REDATE{$myid}; } &write_gb_data("$home/$gb_data"); &write_gb_reply("$home/$gb_reply"); print "Location: $cgi_url?step=edit_gb&page=$DATA{'page'}&startpage=$DATA{'startpage'}\n\n"; } elsif ($DATA{'step'} eq 'del_gb' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_data("$home/$gb_data"); delete $GBDATE{$DATA{'id'}}; &write_gb_data("$home/$gb_data"); &read_gb_reply("$home/$gb_reply"); foreach $cnt (keys %REDATE) { delete $REDATE{$cnt} if ($REPARN{$cnt} eq $DATA{'id'}); } &write_gb_reply("$home/$gb_reply"); print "Location: $cgi_url?step=edit_gb&page=$DATA{'page'}&startpage=$DATA{'startpage'}\n\n"; } elsif ($DATA{'step'} eq 'del_reply' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_reply("$home/$gb_reply"); delete $REDATE{$DATA{'id'}}; &write_gb_reply("$home/$gb_reply"); print "Location: $cgi_url?step=edit_gb&page=$DATA{'page'}&startpage=$DATA{'startpage'}\n\n"; } elsif ($DATA{'step'} eq 'gb_subscribe' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); &read_gb_conf("$home/$gb_config"); &read_gb_subscribe("$home/$gb_subscribe"); &head($SYSMSG{'title_gbsubmgr'}); print "
$SYSMSG{'sign_left'}$GBCONF{'title'}$SYSMSG{'sign_right'}

\n"; print "
\n"; print "\n"; print "
"; if (defined $SUBSCRIBE{'0'}) { print "
\n"; print "\n"; print "\n"; print "\n"; } print "
$SYSMSG{'gbook_del_user'}\n"; print "$SYSMSG{'gbook_user_email'}\n"; foreach $cnt (sort values %SUBSCRIBE) { print "
\n"; print "$cnt
\n"; print "
"; } &foot(''); } elsif ($DATA{'step'} eq 'gb_addnew' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); if ($DATA{'email'} ne '') { &read_gb_subscribe("$home/$gb_subscribe"); $SUBSCRIBE{'new'} = $DATA{'email'}; &write_gb_subscribe("$home/$gb_subscribe"); } print "Location: $cgi_url?step=gb_subscribe\n\n"; } elsif ($DATA{'step'} eq 'gb_unsubscribe' && $menu_id ne '') { ($musr,$pwd,$muid,$mgid,$quo,$com,$gcos,$home,$shell) = getpwuid($menu_id); if ($DATA{'email'} ne '') { &read_gb_subscribe("$home/$gb_subscribe"); @email = split(/,/,$DATA{'email'}); foreach $line (@email) { foreach $i (keys %SUBSCRIBE) { delete $SUBSCRIBE{$i} if ($SUBSCRIBE{$i} eq $line); } } &write_gb_subscribe("$home/$gb_subscribe"); } print "Location: $cgi_url?step=gb_subscribe\n\n"; } }