/[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.7 by dpavlin, Wed May 31 13:57:49 2000 UTC
# Line 41  my $mail_login; Line 41  my $mail_login;
41  my @mail_to;            # array to main initial message to  my @mail_to;            # array to main initial message to
42  open(WHO,"who am i |") || die "who am i? $!";  open(WHO,"who am i |") || die "who am i? $!";
43  my $db_user=<WHO>;  my $db_user=<WHO>;
44    chomp $db_user;
45  $db_user=~s/\s.+$//g;  $db_user=~s/\s.+$//g;
46  close(WHO);  close(WHO);
47    
48  xdebug "koristim korinika $db_user\n";  xdebug "koristim korinika $db_user\n";
49    
50    open(HOSTNAME,"hostname |") || die "hostname: $!";
51    my $hostname=<HOSTNAME>;
52    chomp $hostname;
53    close(HOSTNAME);
54    
55    xdebug "koristim hostname $hostname\n";
56    
57  v "/etc/aliases\n";  v "/etc/aliases\n";
58  open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!";  open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!";
# Line 105  sub nuke_chars { Line 112  sub nuke_chars {
112  my $max_osoba_id=0;  my $max_osoba_id=0;
113    
114  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;
115  my $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr();  
116    my $sth = $dbh->prepare("select ko_id from unix2ko where login='$db_user' and host='$hostname'") || die $dbh->errstr();
117    $sth->execute() || die $sth->errstr();
118    my ($ko_id)=$sth->fetchrow_array;
119    
120    xdebug "upotrebljavam ID kontakt osobe: $ko_id\n";
121    
122    $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr();
123  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
124  my ($last_open)=$sth->fetchrow_array;  my ($last_open)=$sth->fetchrow_array;
125    
126  if (! defined($open_only_id)) {  if (! defined($open_only_id)) {
127          $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();
128  } else {  } else {
# Line 137  while (my ($osoba_id,$ime,$prezime,$sifr Line 152  while (my ($osoba_id,$ime,$prezime,$sifr
152          $ime=nuke_chars($ime);          $ime=nuke_chars($ime);
153          $prezime=nuke_chars($prezime);          $prezime=nuke_chars($prezime);
154    
155          my $prezime_za_login;          my ($prezime_za_login,$ime_za_login);
156    
157          if ($prezime =~ /-/) {          # dva prezimena prezime1-prezime2          if ($prezime =~ /[- ]/) {          # dva prezimena prezime1-prezime2
158                  ($prezime_za_login,undef) = split(/-/,$prezime,2);                  ($prezime_za_login,undef) = split(/[- ]/,$prezime,2);
159          } else {          } else {
160                  $prezime_za_login = $prezime;                  $prezime_za_login = $prezime;
161          }          }
162    
163            if ($ime =~ /[- ]/) {          # dva imena ime1-ime2
164                    ($ime_za_login,undef) = split(/[- ]/,$ime,2);
165            } else {
166                    $ime_za_login = $ime;
167            }
168    
169          my $add="";          my $add="";
170          my $login;          my $login;
171    
172          do {          do {
173                  $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;
174                  $login =~ tr [A-Z] [a-z];                  $login =~ tr [A-Z] [a-z];
175                  xdebug "$ime, $prezime   login: $login\n";                  xdebug "$ime, $prezime   login: $login\n";
176                  $add++;                  $add++;
# Line 160  while (my ($osoba_id,$ime,$prezime,$sifr Line 181  while (my ($osoba_id,$ime,$prezime,$sifr
181          $add="";          $add="";
182          do {          do {
183                  $email_alias="$ime.$prezime$add";                  $email_alias="$ime.$prezime$add";
184                    $email_alias =~ s/ /./g;        # space -> dot
185                  $email_alias =~ tr [A-Z] [a-z];                  $email_alias =~ tr [A-Z] [a-z];
186                  xdebug "\t$email_alias\n";                  xdebug "\t$email_alias\n";
187                  $add++;                  $add++;
# Line 196  while (my ($osoba_id,$ime,$prezime,$sifr Line 218  while (my ($osoba_id,$ime,$prezime,$sifr
218          $full_name=~s/ +:/:/g;          $full_name=~s/ +:/:/g;
219          $full_name=~s/ +/ /g;          $full_name=~s/ +/ /g;
220          $full_name=nuke_chars($full_name);          $full_name=nuke_chars($full_name);
221          if ($shell eq "t") {          if ($shell) {
222                  $shell="/usr/local/bin/bash";                  $shell="/usr/local/bin/bash";
223          } else {          } else {
224                  $shell="/usr/bin/false";                  $shell="/usr/bin/false";
# Line 230  while (my ($osoba_id,$ime,$prezime,$sifr Line 252  while (my ($osoba_id,$ime,$prezime,$sifr
252          system "mkdir -p $dir ; mkdir $dir/bin ; \          system "mkdir -p $dir ; mkdir $dir/bin ; \
253                  chown -R $uid:$group_id{$group} $dir ; chmod 755 $dir" if (! $debug);                  chown -R $uid:$group_id{$group} $dir ; chmod 755 $dir" if (! $debug);
254    
255          $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);
256    
257          $max_osoba_id = $osoba_id if ($max_osoba_id < $osoba_id) ;          $max_osoba_id = $osoba_id if ($max_osoba_id < $osoba_id) ;
258  }  }
# Line 240  $dbh->do("insert into last_open values ( Line 262  $dbh->do("insert into last_open values (
262  close(NPASSWD);  close(NPASSWD);
263  close(NALIAS);  close(NALIAS);
264    
265  undef $sth;  undef $sth,$sth2;
266  $dbh->disconnect;  $dbh->disconnect;
267    
268  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.7

  ViewVC Help
Powered by ViewVC 1.1.26