/[useradm]/otvori_nove
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /otvori_nove

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Wed Apr 12 08:19:17 2000 UTC (19 years, 2 months ago) by dpavlin
Branch point for: MAIN, PLIVA
Initial revision

1 dpavlin 1.1 #!/usr/local/bin/perl -w
2    
3     # Dobrica Pavlinusic <dpavlin@pliva.hr>
4     # 2000-01-31 DbP prva verzija
5     # 2000-02-14 DbP mozda i radi?
6    
7     $debug=0;
8    
9     $debug++ if (defined($ARGV[0]) && $ARGV[0] eq "-d");
10    
11     warn "DEBUG -- me kreira ni¹ta!" if ($debug);
12    
13     $|++;
14    
15     #----
16    
17     open(ERR,"> error-log");
18    
19     print STDERR "/etc/aliases";
20     open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases";
21     open(NALIAS,">aliases.new") || die "Can't open aliases.new";
22     while(<ALIAS>) {
23     chop;
24     print NALIAS "$_\n";
25     next if (m!^#!);
26     if (m!\w+.\w+!) {
27     ($mail_alias,$mail_login) = split(/\s*:\s*/,$_,2);
28     $mail_alias =~ tr [A-Z] [a-z];
29     }
30     $etc_alias{$mail_alias}=$mail_login;
31     # print "$mail_alias: $mail_login\n" if ($debug);
32     print STDERR ".";
33     }
34     close(ALIAS);
35     print STDERR "\n";
36    
37     print STDERR "/etc/passwd";
38     open(PASSWD,"/etc/passwd") || die "Can't open /etc/passwd !";
39     open(NPASSWD,">passwd.new") || die "Can't open passwd.new !";
40     while(<PASSWD>) {
41     chop;
42     ($login,$foo,$id,$gid,$full_name,$dir,$shell) = split(/:/,$_,7);
43     $etc_passwd{$login}=$full_name;
44     # print "$login:$full_name\n" if ($debug);
45     print NPASSWD "$_\n";
46     print STDERR ".";
47     }
48     close(PASSWD);
49     print STDERR "\n";
50    
51     print STDERR "/etc/group";
52     open(GROUP,"/etc/group") || die "Can't open /etc/group !";
53     while(<GROUP>) {
54     ($group,$foo,$gid,$foo) = split (/:/,$_,4);
55     $group_id{$group}=$gid;
56     # print "$group:$gid\n" if ($debug);
57     print STDERR ".";
58     }
59     close(GROUP);
60     print STDERR "\n";
61    
62     sub nuke_chars {
63     my $foo=$_[0];
64     $foo =~ tr/¹ðè澩ÐÈÆ®/sdcczSDCCZ/; # nuke iso88592
65     $foo =~ tr/šðè枊ÐÈƎ/sdcczSDCCZ/; # nuke cp1250
66     return $foo;
67     }
68    
69     open(KORI,"zaotvaranje.txt") || die "Can't open data file: $!";
70     while(<KORI>) {
71     chomp;
72     next if (/^#/ || /^$/);
73     ($ime,$prezime,$tojzoj,$odjel,$lokacija,$objekt,$kat,$soba,$tip,
74     $z,$sifrarad,$login,$passwd,$grupa,$IPadresa,$IPime,$email_alias,
75     $brojzahtjeva,$datumzaprimanja,$kontakt,$datummreza,
76     $datumserver,$lupdate,$vrsta,$telefon,$gateway,$MT) =
77     split(/\t/,$_,27);
78    
79    
80     next if ($ime eq "ime" || $prezime eq "prezime");
81    
82     if (!defined($ime) || !defined($prezime) || $ime eq "" || $prezime eq "") {
83     print ERR "preskacem red '$_'\n";
84     next;
85     }
86    
87     $ime=nuke_chars($ime);
88     $prezime=nuke_chars($prezime);
89     $email_alias=nuke_chars($email_alias);
90    
91     if ($email_alias =~ / /) {
92     print ERR "email_alias $email_alias ima razmake!\n";
93     $email_alias =~ s/ //g;
94     }
95    
96    
97     $tojzoj=~ tr [A-Z] [a-z];
98     # @groups=("inzenjer","proizv","uprava","regpro","kadrovi",
99     # "odnosi","prehrana","sirovine","strateg","veterina",
100     # "kozmeti","farma","financ","zajednic");
101    
102     $group="users";
103     # foreach $gr (@groups) {
104     # if ($tojzoj =~ /$gr/) {
105     # $group="$gr";
106     # }
107     # }
108    
109     # $add="";
110     # do {
111     # $email_alias="$ime.$prezime$add";
112     # print " email: $email_alias\n" if ($debug);
113     # $add++;
114     # } while ($etc_alias{$email_alias} ne "");
115    
116     if (defined($etc_alias{$email_alias})) {
117     print STDERR "Korisnik: $ime $prezime veæ postoji!\n";
118     print ERR "preskocen: $ime $prezime (postoji e-mail alias)\n";
119     next;
120     }
121    
122     if (defined($etc_passwd{$login})) {
123     print STDERR "Korisnik: $ime $prezime veæ postoji ($login) !\n";
124     print ERR "preskocen: $ime $prezime (postoji isti login $login)\n";
125     next;
126     }
127    
128     push @novi_aliases,$email_alias;
129    
130     @foo = ( 'a'..'z','0'..'9','A'..'Z' );
131    
132     # for (1..8) { $passwd=$passwd.$foo[int(rand($#foo))] };
133     $salt = $foo[int(rand($#foo))].$foo[int(rand($#foo))];
134     $crypt_passwd = crypt($passwd,$salt);
135    
136     $id++;
137     $loc="";
138     $loc.=$objekat if (defined($objekat));
139     $loc.=" $kat" if (defined($kat));
140     $loc.=" $soba" if (defined($soba));
141     $full_name="$ime $prezime,$loc,$sifrarad";
142     $full_name=~s/, +/,/g;
143     $full_name=~s/ +:/:/g;
144     $full_name=nuke_chars($full_name);
145     $shell="/usr/bin/false";
146     $dir="/usr/users/$login";
147    
148     die "Nema grupe $group!" if (! defined($group_id{$group}));
149     print "$login:$passwd:$id:$group_id{$group}:$full_name:$dir:$shell\n" if ($debug);
150     print NPASSWD "$login:$crypt_passwd:$id:$group_id{$group}:$full_name:$dir:$shell\n";
151     print NALIAS "$email_alias: $login\n";
152    
153     #---- C2 security
154     # if (!$debug || 1) {
155     # open(AUTH,">> $0.auth");
156     # print AUTH "$login:u_name=$login:u_id#$id:u_pwd=$crypt_passwd:u_succhg#",time,":u_lock\@:chkent:\n";
157     # close(AUTH);
158     # }
159    
160     system "mkdir -p $dir ; mkdir $dir/bin ; \
161     chown -R $id:$group_id{$group} $dir ; chmod 755 $dir" if (! $debug);
162    
163     }
164    
165     close(NPASSWD);
166     close(NALIAS);
167    
168     system "mv /etc/passwd passwd.orig" if (! $debug);
169     system "cp passwd.new /etc/passwd" if (! $debug);
170     system "chmod 644 /etc/passwd" if (! $debug);
171     system "/usr/sbin/mkpasswd /etc/passwd" if (! $debug);
172     system "mv /etc/aliases aliases.orig" if (! $debug);
173     system "cp aliases.new /etc/aliases" if (! $debug);
174     system "chmod 644 /etc/aliases" if (! $debug);
175     system "/usr/sbin/newaliases" if (! $debug);
176     #system "/tcb/bin/edauth -s < $0.auth" if (! $debug);
177    
178     foreach $alias (@novi_aliases) {
179     system "/usr/lib/sendmail $alias < mail.txt" if (! $debug);
180     }

  ViewVC Help
Powered by ViewVC 1.1.26