blib/lib/Uplug/Web/User.pm untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 115 CC 8 SCAR 19.7
CC
8
Cov
0%
RemoveUser
12.0
ReadUserInfo
12.0
SendFile
12.0
CRAP 7.2
1 # Copyright (C) 2004 Jörg Tiedemann <joerg@stp.ling.uu.se>
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  
17 package Uplug::Web::User;
18  
19 use strict;
20 use Exporter;
21 use lib '/home/staff/joerg/user_perl/lib/perl5/site_perl/5.6.1/';
22 use Mail::Mailer;
23 use Uplug::Web::Process::Stack;
24  
25 use vars qw(@ISA @EXPORT);
26  
27 @ISA = qw( Exporter);
28 @EXPORT = qw( ReadUserInfo );
29  
30 our $UplugAdmin = $ENV{UPLUGADMIN};
31 our $Uplug2Dir = $ENV{UPLUGDATA};
32 our $CorpusDir = $Uplug2Dir;
33 our $UserDataFile = $Uplug2Dir.'/.user';
34 our $PasswordFile = $Uplug2Dir.'/.htpasswd';
35  
36 # my $IniDir=$CorpusDir.'/ini';
37 # my $CorpusFile=$IniDir.'/uplugUserStreams';
38  
39  
40 ######################################################################
41  
42 sub SendUserPassword{
43 my $user=shift;
44 my %UserData=();
45 &ReadUserInfo(\%UserData,$user);
46  
47 if (not defined $UserData{$user}{Password}){
48 return "Cannot find user '$user'! Please register first!\n";
49 }
50 &SendMail($user,'UplugWeb password',
51 "UplugWeb account: $user\nUplugWeb password: $UserData{$user}{Password}");
52 return "Mail sent to $user!";
53 }
54  
55  
56 sub RemoveUser{
57 my $user=shift;
58 my %UserData=();
59 &ReadUserInfo(\%UserData,$user);
60 if (not -e "$CorpusDir/.recycled"){
61 `mkdir $CorpusDir/.recycled`;
62 `chmod 755 $CorpusDir/.recycled`;
63 `chmod g+s $CorpusDir/.recycled`;
64 }
65 if (-e "$CorpusDir/.recycled/$user"){
66 `rm -fr $CorpusDir/.recycled/$user`;
67 }
68 `mv $CorpusDir/$user $CorpusDir/.recycled/`;
69  
70 my $UserInfo=Uplug::Web::Process::Stack->new($UserDataFile);
71 $UserInfo->remove($user);
72  
73 &SendMail($user,'UplugWeb account',
74 'Your UplugWeb account has been removed!');
75 }
76  
77  
78 sub EditUser{
79 my $user=shift;
80 my %UserData=();
81 # &ReadUserInfo(\%UserData,$user);
82 return "edit $user (not implemented yet!)";
83 }
84  
85  
86 sub ReadUserInfo{
87 my $data=shift;
88 my $user=shift;
89 open F,"<$UserDataFile";
90 while (<F>){
91 chomp;
92 my ($u,$f)=split(/\:/);
93 $$data{$u}{info}=$f;
94 if (not -e $f){$$data{$u}{status}='removed';}
95 elsif ($user eq $u){
96 open U, '<:encoding(utf8)',$f;
97 # open U,"<$f";
98 while (<U>){
99 chomp;
100 my ($k,$v)=split(/\:/);
101 # if ($k eq 'Password'){$$data{$u}{$k}='******';}
102 # else{$$data{$u}{$k}=$v;}
103 $$data{$u}{$k}=$v;
104 }
105 close U;
106 }
107 }
108 close F;
109 }
110  
111  
112 sub SendMail{
113  
114 my ($to,$subject,$message)=@_;
115  
116 my $mailer=Mail::Mailer->new("sendmail");
117 $mailer->open({From => $UplugAdmin,
118 To => $to,
119 Subject => $subject});
120 print $mailer $message;
121 $mailer->close();
122 }
123  
124  
125 sub SendFile{
126  
127 my ($to,$subject,$file)=@_;
128  
129 if (not -e $file){return 0;}
130  
131 my $mailer=Mail::Mailer->new("sendmail");
132 $mailer->open({From => $UplugAdmin,
133 To => $to,
134 Subject => $subject});
135  
136 if ($file=~/\.gz$/){open F,"gzip -cd $file |";}
137 else{open F,"<$file";}
138 binmode (F);
139 while (<F>){print $mailer $_;}
140 $mailer->close();
141 }
142