/[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.1.1 by dpavlin, Wed Apr 12 08:19:17 2000 UTC revision 1.6 by dpavlin, Wed May 17 09:57:22 2000 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");  if (defined($ARGV[0]) && $ARGV[0] eq "-d") {
18            $debug++;
19            shift @ARGV;
20    }
21    my $open_only_id=shift @ARGV if (defined($ARGV[0]));
22    
23  warn "DEBUG -- me kreira ništa!" if ($debug);  warn "DEBUG -- me kreira ništa!" if ($debug);
24    
25  $|++;  $|++;
26    
 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);  
27    
28  #----  #----
29    
# Line 39  my %etc_aliases; Line 38  my %etc_aliases;
38  my $mail_alias;  my $mail_alias;
39  my $mail_login;  my $mail_login;
40    
41    my @mail_to;            # array to main initial message to
42    open(WHO,"who am i |") || die "who am i? $!";
43    my $db_user=<WHO>;
44    $db_user=~s/\s.+$//g;
45    close(WHO);
46    
47    xdebug "koristim korinika $db_user\n";
48    
49    
50  v "/etc/aliases\n";  v "/etc/aliases\n";
51  open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!";  open(ALIAS,"/etc/aliases") || die "Can't open /etc/aliases: $!";
52  open(NALIAS,">aliases.new") || die "Can't open aliases.new: $!";  open(NALIAS,">aliases.new") || die "Can't open aliases.new: $!";
# Line 100  my $dbh = DBI->connect("DBI:Pg:dbname=in Line 108  my $dbh = DBI->connect("DBI:Pg:dbname=in
108  my $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr();  my $sth = $dbh->prepare("select max(id) from last_open") || die $dbh->errstr();
109  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
110  my ($last_open)=$sth->fetchrow_array;  my ($last_open)=$sth->fetchrow_array;
111  $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id > $last_open") || die $dbh->errstr();  if (! defined($open_only_id)) {
112            $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id > $last_open") || die $dbh->errstr();
113    } else {
114            $sth = $dbh->prepare("select id,ime,prezime,sifra,objekt,kat,soba,shell from view_otvori_nove where id=$open_only_id") || die $dbh->errstr();
115    
116    }
117  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
118    
119    
120    my $sth2;
121    
122  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() ) {
123    
124            $sth2 = $dbh->prepare("select max(status_tip_id) from status where osoba_id = $osoba_id") || die $dbh->errstr();
125            $sth2->execute() || die $sth2->errstr();
126            my ($max_status) = $sth2->fetchrow_array();
127            xdebug "max status zahtjeva $osoba_id je $max_status\n";
128            next if ($max_status > 3);      # 3 .. otvoren
129    
130          next if ($ime eq "ime" || $prezime eq "prezime");          next if ($ime eq "ime" || $prezime eq "prezime");
131    
132          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 137  while (my ($osoba_id,$ime,$prezime,$sifr
137          $ime=nuke_chars($ime);          $ime=nuke_chars($ime);
138          $prezime=nuke_chars($prezime);          $prezime=nuke_chars($prezime);
139    
140          my $prezime_za_login;          my ($prezime_za_login,$ime_za_login);
141    
142          if ($prezime =~ /-/) {          # dva prezimena prezime1-prezime2          if ($prezime =~ /[- ]/) {          # dva prezimena prezime1-prezime2
143                  ($prezime_za_login,undef) = split(/-/,$prezime,2);                  ($prezime_za_login,undef) = split(/[- ]/,$prezime,2);
144          } else {          } else {
145                  $prezime_za_login = $prezime;                  $prezime_za_login = $prezime;
146          }          }
147    
148            if ($ime =~ /[- ]/) {          # dva imena ime1-ime2
149                    ($ime_za_login,undef) = split(/[- ]/,$ime,2);
150            } else {
151                    $ime_za_login = $ime;
152            }
153    
154          my $add="";          my $add="";
155          my $login;          my $login;
156    
157          do {          do {
158                   $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;
159                   xdebug "$ime, $prezime   login: $login\n";                  $login =~ tr [A-Z] [a-z];
160                   $add++;                  xdebug "$ime, $prezime   login: $login\n";
161                    $add++;
162          } while defined($etc_passwd{$login});          } while defined($etc_passwd{$login});
         $login =~ tr [A-Z] [a-z];  
163    
164          my $email_alias;          my $email_alias;
165    
166          $add="";          $add="";
167          do {          do {
168                  $email_alias="$ime.$prezime$add";                  $email_alias="$ime.$prezime$add";
169                    $email_alias =~ s/ /./g;        # space -> dot
170                  $email_alias =~ tr [A-Z] [a-z];                  $email_alias =~ tr [A-Z] [a-z];
171                  xdebug "\t$email_alias\n";                  xdebug "\t$email_alias\n";
172                  $add++;                  $add++;
# Line 146  while (my ($osoba_id,$ime,$prezime,$sifr Line 176  while (my ($osoba_id,$ime,$prezime,$sifr
176          my $group="users";          my $group="users";
177    
178          if (defined($etc_passwd{$login})) {          if (defined($etc_passwd{$login})) {
179                  xerror "preskocen: $ime $prezime (postoji isti login $login)\n";                  xerror "preskocen: $ime $prezime osoba_id=$osoba_id (postoji isti login $login)\n";
180                  $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);
181                  next;                  next;
182          }          }
# Line 173  while (my ($osoba_id,$ime,$prezime,$sifr Line 203  while (my ($osoba_id,$ime,$prezime,$sifr
203          $full_name=~s/ +:/:/g;          $full_name=~s/ +:/:/g;
204          $full_name=~s/ +/ /g;          $full_name=~s/ +/ /g;
205          $full_name=nuke_chars($full_name);          $full_name=nuke_chars($full_name);
206          if ($shell eq "t") {          if ($shell) {
207                  $shell="/usr/local/bin/bash";                  $shell="/usr/local/bin/bash";
208          } else {          } else {
209                  $shell="/usr/bin/false";                  $shell="/usr/bin/false";
# Line 188  while (my ($osoba_id,$ime,$prezime,$sifr Line 218  while (my ($osoba_id,$ime,$prezime,$sifr
218          $etc_passwd{$login}=$full_name;          $etc_passwd{$login}=$full_name;
219    
220          if (defined($etc_aliases{$email_alias})) {          if (defined($etc_aliases{$email_alias})) {
221                  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";
222                  print NALIAS "$email_alias:\t$login,$etc_aliases{$email_alias}\n";                  print NALIAS "$email_alias:\t$login,$etc_aliases{$email_alias}\n";
223          } else {          } else {
224                  print NALIAS "$email_alias:\t$login\n";                  print NALIAS "$email_alias:\t$login\n";
# Line 217  $dbh->do("insert into last_open values ( Line 247  $dbh->do("insert into last_open values (
247  close(NPASSWD);  close(NPASSWD);
248  close(NALIAS);  close(NALIAS);
249    
250  undef $sth;  undef $sth,$sth2;
251  $dbh->disconnect;  $dbh->disconnect;
252    
253  system "mv /etc/passwd passwd.orig" if (! $debug);  system "mv /etc/passwd passwd.orig" if (! $debug);

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.26