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

Diff of /otvori_nove+db

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Wed Apr 12 08:19:17 2000 UTC revision 1.9 by dpavlin, Fri Jan 26 07:44:36 2001 UTC
# Line 8  Line 8 
8  # 2000-03-13 DbP podrska za novu support/last_open tablicu  # 2000-03-13 DbP podrska za novu support/last_open tablicu
9  # 2000-03-16 DbP cuva stare aliase iz /etc/aliases  # 2000-03-16 DbP cuva stare aliase iz /etc/aliases
10  # 2000-03-20 DbP skida razmake prije/poslje imena/prezimena  # 2000-03-20 DbP skida razmake prije/poslje imena/prezimena
11            
12  use DBI;  use DBI;
13  use strict;  use strict;
14    
15  my $debug=0;  my $debug=0;
16    
17  $debug++ if (defined($ARGV[0]) && $ARGV[0] eq "-d");  my $res_uids=60000;     # uids larger than this are for system use
18    
19    if (defined($ARGV[0]) && $ARGV[0] eq "-d") {
20            $debug++;
21            shift @ARGV;
22    }
23    my $open_only_id=shift @ARGV if (defined($ARGV[0]));
24    
25  warn "DEBUG -- me kreira ništa!" if ($debug);  warn "DEBUG -- ne kreira ništa!" if ($debug);
26    
27  $|++;  $|++;
28    
 my @mail_to;            # array to main initial message to  
 open(WHO,"who am i |") || die "who am i? $!";  
 my $db_user=<WHO>;  
 $db_user=~s/\s.+$//g;  
 close(WHO);  
29    
30  #----  #----
31    
# Line 39  my %etc_aliases; Line 40  my %etc_aliases;
40  my $mail_alias;  my $mail_alias;
41  my $mail_login;  my $mail_login;
42    
43    my @mail_to;            # array to main initial message to
44    open(WHO,"who am i |") || die "who am i? $!";
45    my $db_user=<WHO>;
46    chomp $db_user;
47    $db_user=~s/\s.+$//g;
48    close(WHO);
49    
50    xdebug "koristim korisnika $db_user\n";
51    
52    open(HOSTNAME,"hostname |") || die "hostname: $!";
53    my $hostname=<HOSTNAME>;
54    chomp $hostname;
55    close(HOSTNAME);
56    
57    xdebug "koristim hostname $hostname\n";
58    
59  v "/etc/aliases\n";  v "/etc/aliases\n";
60  open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!";  open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!";
61  open(NALIAS,">aliases.new") || die "Can't open aliases.new: $!";  open(NALIAS,">aliases.new") || die "Can't open aliases.new: $!";
# Line 57  while(<ALIAS>) { Line 74  while(<ALIAS>) {
74  close(ALIAS);  close(ALIAS);
75    
76  my %etc_passwd;  my %etc_passwd;
77  my $uid;        # current (or max) uid  my $max_uid = 0;        # maximum uid
78    
79  v "/etc/passwd\n";  v "/etc/passwd\n";
80  open(PASSWD,"/etc/passwd") || die "Can't open /etc/passwd !";  open(PASSWD,"/etc/passwd") || die "Can't open /etc/passwd !";
81  open(NPASSWD,">passwd.new") || die "Can't open passwd.new !";  open(NPASSWD,">passwd.new") || die "Can't open passwd.new !";
82  while(<PASSWD>) {  while(<PASSWD>) {
83          chop;          chop;
84          my ($login,$gid,$full_name,$dir,$shell);          my ($login,$uid,$gid,$full_name,$dir,$shell);
85          ($login,undef,$uid,$gid,$full_name,$dir,$shell) = split(/:/,$_,7);          ($login,undef,$uid,$gid,$full_name,$dir,$shell) = split(/:/,$_,7);
86          $etc_passwd{$login}=$full_name;          $etc_passwd{$login}=$full_name;
87          print NPASSWD "$_\n";          print NPASSWD "$_\n";
88  #       xdebug "$login:$full_name\n";  #       xdebug "$login:$full_name\n";
89            $max_uid = $uid if ($max_uid < $uid && $uid < $res_uids);
90  }  }
91  close(PASSWD);  close(PASSWD);
92    
# Line 97  sub nuke_chars { Line 115  sub nuke_chars {
115  my $max_osoba_id=0;  my $max_osoba_id=0;
116    
117  my $dbh = DBI->connect("DBI:Pg:dbname=informatika;host=support.pliva.hr;user=$db_user","","") || die $DBI::errstr;  my $dbh = DBI->connect("DBI:Pg:dbname=informatika;host=support.pliva.hr;user=$db_user","","") || die $DBI::errstr;
118  my $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr();  
119    my $sth = $dbh->prepare("select ko_id from unix2ko where login='$db_user' and host='$hostname'") || die $dbh->errstr();
120    $sth->execute() || die $sth->errstr();
121    my ($ko_id)=$sth->fetchrow_array;
122    
123    xdebug "upotrebljavam ID kontakt osobe: $ko_id\n";
124    
125    $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr();
126  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
127  my ($last_open)=$sth->fetchrow_array;  my ($last_open)=$sth->fetchrow_array;
128  $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id > $last_open") || die $dbh->errstr();  
129    if (! defined($open_only_id)) {
130            $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id > $last_open") || die $dbh->errstr();
131    } else {
132            $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id=$open_only_id") || die $dbh->errstr();
133    
134    }
135  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
136    
137    
138    my $sth2;
139    
140  while (my ($osoba_id,$ime,$prezime,$sifra,$objekt,$kat,$soba,$shell) = $sth->fetchrow_array() ) {  while (my ($osoba_id,$ime,$prezime,$sifra,$objekt,$kat,$soba,$shell) = $sth->fetchrow_array() ) {
141    
142            $sth2 = $dbh->prepare("select max(status_tip_id) from status where osoba_id = $osoba_id") || die $dbh->errstr();
143            $sth2->execute() || die $sth2->errstr();
144            my ($max_status) = $sth2->fetchrow_array();
145            xdebug "max status zahtjeva $osoba_id je $max_status\n";
146            next if ($max_status > 3);      # 3 .. otvoren
147    
148          next if ($ime eq "ime" || $prezime eq "prezime");          next if ($ime eq "ime" || $prezime eq "prezime");
149    
150          if (!defined($ime) || !defined($prezime) || $ime eq "" || $prezime eq "") {          if (!defined($ime) || !defined($prezime) || $ime eq "" || $prezime eq "") {
# Line 114  while (my ($osoba_id,$ime,$prezime,$sifr Line 155  while (my ($osoba_id,$ime,$prezime,$sifr
155          $ime=nuke_chars($ime);          $ime=nuke_chars($ime);
156          $prezime=nuke_chars($prezime);          $prezime=nuke_chars($prezime);
157    
158          my $prezime_za_login;          my ($prezime_za_login,$ime_za_login);
159    
160          if ($prezime =~ /-/) {          # dva prezimena prezime1-prezime2          if ($prezime =~ /[- ]/) {          # dva prezimena prezime1-prezime2
161                  ($prezime_za_login,undef) = split(/-/,$prezime,2);                  ($prezime_za_login,undef) = split(/[- ]/,$prezime,2);
162          } else {          } else {
163                  $prezime_za_login = $prezime;                  $prezime_za_login = $prezime;
164          }          }
165    
166            if ($ime =~ /[- ]/) {          # dva imena ime1-ime2
167                    ($ime_za_login,undef) = split(/[- ]/,$ime,2);
168            } else {
169                    $ime_za_login = $ime;
170            }
171    
172          my $add="";          my $add="";
173          my $login;          my $login;
174    
175          do {          do {
176                   $login=substr($ime,0,1).substr($prezime_za_login,0,7-length($add)).$add;                  $login=substr($ime_za_login,0,1).substr($prezime_za_login,0,7-length($add)).$add;
177                   xdebug "$ime, $prezime   login: $login\n";                  $login =~ tr [A-Z] [a-z];
178                   $add++;                  xdebug "$ime, $prezime   login: $login\n";
179                    $add++;
180          } while defined($etc_passwd{$login});          } while defined($etc_passwd{$login});
         $login =~ tr [A-Z] [a-z];  
181    
182          my $email_alias;          my $email_alias;
183    
184          $add="";          $add="";
185          do {          do {
186                  $email_alias="$ime.$prezime$add";                  $email_alias="$ime.$prezime$add";
187                    $email_alias =~ s/ /./g;        # space -> dot
188                  $email_alias =~ tr [A-Z] [a-z];                  $email_alias =~ tr [A-Z] [a-z];
189                  xdebug "\t$email_alias\n";                  xdebug "\t$email_alias\n";
190                  $add++;                  $add++;
# Line 146  while (my ($osoba_id,$ime,$prezime,$sifr Line 194  while (my ($osoba_id,$ime,$prezime,$sifr
194          my $group="users";          my $group="users";
195    
196          if (defined($etc_passwd{$login})) {          if (defined($etc_passwd{$login})) {
197                  xerror "preskocen: $ime $prezime (postoji isti login $login)\n";                  xerror "preskocen: $ime $prezime osoba_id=$osoba_id (postoji isti login $login)\n";
198                  $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($osoba_id,3,'now'::datetime,4)") if (! $debug);                  $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($osoba_id,3,'now'::datetime,4)") if (! $debug);
199                  next;                  next;
200          }          }
# Line 163  while (my ($osoba_id,$ime,$prezime,$sifr Line 211  while (my ($osoba_id,$ime,$prezime,$sifr
211          my $salt = $saltch[int(rand($#saltch))].$saltch[int(rand($#saltch))];          my $salt = $saltch[int(rand($#saltch))].$saltch[int(rand($#saltch))];
212          my $crypt_passwd = crypt($passwd,$salt);          my $crypt_passwd = crypt($passwd,$salt);
213    
214          $uid++;          $max_uid++;
215          my $loc="";          my $loc="";
216          $loc.=$objekt if (defined($objekt));          $loc.=$objekt if (defined($objekt));
217          $loc.=" $kat" if (defined($kat));          $loc.=" $kat" if (defined($kat));
# Line 173  while (my ($osoba_id,$ime,$prezime,$sifr Line 221  while (my ($osoba_id,$ime,$prezime,$sifr
221          $full_name=~s/ +:/:/g;          $full_name=~s/ +:/:/g;
222          $full_name=~s/ +/ /g;          $full_name=~s/ +/ /g;
223          $full_name=nuke_chars($full_name);          $full_name=nuke_chars($full_name);
224          if ($shell eq "t") {          if ($shell) {
225                  $shell="/usr/local/bin/bash";                  $shell="/usr/local/bin/bash";
226          } else {          } else {
227                  $shell="/usr/bin/false";                  $shell="/usr/bin/false";
# Line 181  while (my ($osoba_id,$ime,$prezime,$sifr Line 229  while (my ($osoba_id,$ime,$prezime,$sifr
229          my $dir="/usr/users/$login";          my $dir="/usr/users/$login";
230    
231          die "Nema grupe $group!" if (! defined($group_id{$group}));          die "Nema grupe $group!" if (! defined($group_id{$group}));
232          xdebug "$login:$passwd:$uid:$group_id{$group}:$full_name:$dir:$shell\n";          xdebug "$login:$passwd:$max_uid:$group_id{$group}:$full_name:$dir:$shell\n";
233    
234          print NPASSWD "$login:$crypt_passwd:$uid:$group_id{$group}:$full_name:$dir:$shell\n";          print NPASSWD "$login:$crypt_passwd:$max_uid:$group_id{$group}:$full_name:$dir:$shell\n";
235          $dbh->do("insert into racuni (osoba_id,login,passwd) values ($osoba_id,'$login','$passwd')") if (! $debug);          $dbh->do("insert into racuni (osoba_id,login,passwd) values ($osoba_id,'$login','$passwd')") if (! $debug);
236          $etc_passwd{$login}=$full_name;          $etc_passwd{$login}=$full_name;
237    
238          if (defined($etc_aliases{$email_alias})) {          if (defined($etc_aliases{$email_alias})) {
239                  xerror "upozorenje: $ime $prezime (postoji e-mail alias) -- $email_alias\n";                  xerror "upozorenje: $ime $prezime osoba_id=$osoba_id (postoji e-mail alias) -- $email_alias\n";
240                  print NALIAS "$email_alias:\t$login,$etc_aliases{$email_alias}\n";                  print NALIAS "$email_alias:\t$login,$etc_aliases{$email_alias}\n";
241          } else {          } else {
242                  print NALIAS "$email_alias:\t$login\n";                  print NALIAS "$email_alias:\t$login\n";
# Line 200  while (my ($osoba_id,$ime,$prezime,$sifr Line 248  while (my ($osoba_id,$ime,$prezime,$sifr
248  #---- C2 security  #---- C2 security
249  #       if (!$debug || 1) {  #       if (!$debug || 1) {
250  #               open(AUTH,">> $0.auth");  #               open(AUTH,">> $0.auth");
251  #               print AUTH "$login:u_name=$login:u_id#$uid:u_pwd=$crypt_passwd:u_succhg#",time,":u_lock\@:chkent:\n";  #               print AUTH "$login:u_name=$login:u_id#$max_uid:u_pwd=$crypt_passwd:u_succhg#",time,":u_lock\@:chkent:\n";
252  #               close(AUTH);  #               close(AUTH);
253  #       }  #       }
254    
255          system "mkdir -p $dir ; mkdir $dir/bin ; \          system "mkdir -p $dir ; mkdir $dir/bin ; \
256                  chown -R $uid:$group_id{$group} $dir ; chmod 755 $dir" if (! $debug);                  chown -R $max_uid:$group_id{$group} $dir ; chmod 755 $dir" if (! $debug);
257    
258          $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($osoba_id,3,'now'::datetime,3)") if (! $debug);          $dbh->do("insert into status (osoba_id,kontakt_osoba_id,datum,status_tip_id) values ($osoba_id,$ko_id,'now'::datetime,3)") if (! $debug);
259    
260          $max_osoba_id = $osoba_id if ($max_osoba_id < $osoba_id) ;          $max_osoba_id = $osoba_id if ($max_osoba_id < $osoba_id) ;
261  }  }
# Line 217  $dbh->do("insert into last_open values ( Line 265  $dbh->do("insert into last_open values (
265  close(NPASSWD);  close(NPASSWD);
266  close(NALIAS);  close(NALIAS);
267    
268    $sth->finish;
269  undef $sth;  undef $sth;
270    if (defined($sth2)) {
271            $sth2->finish;
272            undef $sth2;
273    }
274  $dbh->disconnect;  $dbh->disconnect;
275    
276  system "mv /etc/passwd passwd.orig" if (! $debug);  system "mv /etc/passwd passwd.orig" if (! $debug);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.26