/[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.3 by dpavlin, Tue Apr 18 12:09:03 2000 UTC revision 1.9 by dpavlin, Fri Jan 26 07:44:36 2001 UTC
# Line 14  use strict; Line 14  use strict;
14    
15  my $debug=0;  my $debug=0;
16    
17    my $res_uids=60000;     # uids larger than this are for system use
18    
19  if (defined($ARGV[0]) && $ARGV[0] eq "-d") {  if (defined($ARGV[0]) && $ARGV[0] eq "-d") {
20          $debug++;          $debug++;
21          shift @ARGV;          shift @ARGV;
22  }  }
23  my $open_only_id=shift @ARGV if (defined($ARGV[0]));  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    
# Line 41  my $mail_login; Line 43  my $mail_login;
43  my @mail_to;            # array to main initial message to  my @mail_to;            # array to main initial message to
44  open(WHO,"who am i |") || die "who am i? $!";  open(WHO,"who am i |") || die "who am i? $!";
45  my $db_user=<WHO>;  my $db_user=<WHO>;
46    chomp $db_user;
47  $db_user=~s/\s.+$//g;  $db_user=~s/\s.+$//g;
48  close(WHO);  close(WHO);
49    
50  xdebug "koristim korinika $db_user\n";  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: $!";
# Line 65  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 105  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    
129  if (! defined($open_only_id)) {  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();          $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 {  } else {
# Line 137  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                  $login =~ tr [A-Z] [a-z];                  $login =~ tr [A-Z] [a-z];
178                  xdebug "$ime, $prezime   login: $login\n";                  xdebug "$ime, $prezime   login: $login\n";
179                  $add++;                  $add++;
# Line 160  while (my ($osoba_id,$ime,$prezime,$sifr Line 184  while (my ($osoba_id,$ime,$prezime,$sifr
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 186  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 196  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 204  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    
# Line 223  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 240  $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.3  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.26