home *** CD-ROM | disk | FTP | other *** search
/ ftp.ac-grenoble.fr / 2015.02.ftp.ac-grenoble.fr.tar / ftp.ac-grenoble.fr / pub / slis / updates_rsync / users_pop.cgi < prev    next >
Text File  |  2000-06-07  |  6KB  |  201 lines

  1. #!/usr/bin/perl 
  2.  
  3. # users_pop.cgi - Creation d'utilisateur
  4. # Version 1.4
  5.  
  6. # This script is part of the SLIS Project initiated by the CARMI-Internet
  7. # (AcadΘmie de Grenoble - France 38).
  8. # Ce script fait partie du projet SLIS dΘmarrΘ par le CARMI-Internet
  9. # (AcadΘmie de Grenoble - France 38).
  10. #
  11. # SLIS : Serveur de communications Linux pour l'Internet Scolaire.
  12. # Copyright (C) 1998 Bruno Bzeznik
  13. #
  14. #    This program is free software; you can redistribute it and/or modify
  15. #    it under the terms of the GNU General Public License as published by
  16. #    the Free Software Foundation; either version 2 of the License, or
  17. #    (at your option) any later version.
  18. #
  19. #    This program is distributed in the hope that it will be useful,
  20. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. #    GNU General Public License for more details.
  23. #    You should have received a copy of the GNU General Public License
  24. #    along with this program (For example ./COPYING);
  25. #    if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  26. #    Cambridge, MA 02139, USA.
  27. #
  28. # Please send all comments and bug reports by electronic mail to:
  29. #   Bruno Bzeznik <Bruno@ac-grenoble.fr>
  30. # or to <slis@ac-grenoble.fr>
  31. #
  32. # Envoyez vos suggestions et reports de bugs par e-mail α
  33. #   Bruno Bzeznik <Bruno@ac-grenoble.fr>
  34. # ou α <slis@ac-grenoble.fr>
  35. #
  36.  
  37. # Variables
  38. do '/home/hadmin/slis.conf.pl';
  39.  
  40. use CGI ; 
  41. $html = new CGI ;
  42. print $html->header ; 
  43.  
  44. # Lecture de l'entete standard HTML
  45. open (HEAD,"$ENTETE");
  46. print <HEAD> ;
  47. close HEAD ;
  48.  
  49. # Lecture des parametres administrateur
  50. open (PARAMS,"$BASE/params_admin.txt");
  51. @param= <PARAMS> ;
  52.  
  53. # Tests de validitΘ
  54. if ($param[2] eq "") {
  55.   print "<CENTER>";
  56.   print "Vous n'avez pas entré correctement les paramètres administrateur\n";
  57.   print "<A HREF=/cgi-bin/params_admin_form.cgi>VEUILLEZ LE FAIRE.</A>\n";
  58.   print "</CENTER></BODY></HTML>";
  59.   exit;
  60.   }
  61. if ($html->param('Prenom') eq "") {
  62.   print "<CENTER>";
  63.   print "Il faut au moins un NOM et un PRENOM<BR>\n";
  64.   print "<A HREF=/users_pop.html>RECOMMENCEZ.</A>\n";
  65.   print "</CENTER></BODY></HTML>";
  66.   exit;
  67.   }
  68. if ($html->param('Prenom') eq "") {
  69.   print "<CENTER>";
  70.   print "Il faut au moins un NOM et un PRENOM\n";
  71.   print "<A HREF=/users_pop.html>RECOMMENCEZ.</A>\n";
  72.   print "</CENTER></BODY></HTML>";
  73.   exit;
  74.   }
  75.  
  76. # Routine de generation de mots de passe
  77. # Utilisation:
  78. #    srand($$|time);
  79. #    $passwd = &pw_generate;
  80. sub pw_generate {
  81.         local(@passset, $rnd_passwd, $randum_num);   
  82.         local($randum_num);
  83.  
  84.         # Since 1 ~= l and 0 =~ O, don't generate passwords with them.   
  85.         # This will just confuse people using ugly fonts.
  86.         #
  87.         @passset = ('a'..'k', 'm'..'z', '2'..'9');
  88.         $rnd_passwd = "";
  89.         for ($i = 0; $i < 8; $i++) {
  90.                 $randum_num = int(rand($#passset + 1));
  91.                 $rnd_passwd .= @passset[$randum_num];
  92.         }
  93.         return $rnd_passwd;
  94. }
  95. # Generation du mot de passe et de la chaine cryptΘe.
  96. $passwd = &pw_generate;
  97. $salt= &pw_generate;
  98. $crypted_passwd= crypt($passwd, substr($salt, 0, 2));
  99.  
  100. open(USERS_POP,">>$QUEUE/users_pop");
  101.  
  102. # Generation d'un login
  103. $u1=$html->param('Prenom') ;
  104. $u2=$html->param('Nom') ;
  105.   $u1=~ s/Θ/e/g ;
  106.   $u2=~ s/Θ/e/g ;
  107.   $u1=~ s/Φ/e/g ;
  108.   $u2=~ s/Φ/e/g ;
  109.   $u1=~ s/α/a/g ;
  110.   $u2=~ s/α/a/g ;
  111.   $u1=~ s/δ/e/g ;
  112.   $u2=~ s/δ/e/g ;
  113.   $u1=~ s/Ω/e/g ;
  114.   $u2=~ s/Ω/e/g ;
  115.   $u1=~ s/∙/u/g ;
  116.   $u2=~ s/∙/u/g ;
  117.   $u1=~ s/⌠/o/g ;
  118.   $u2=~ s/⌠/o/g ;
  119.   $u1=~ s/÷/o/g ;
  120.   $u2=~ s/÷/o/g ;
  121.   $u1=~ s/τ/c/g ;
  122.   $u2=~ s/τ/c/g ;
  123. $login1=substr $u2,0,7;
  124. $login2=substr $u1,0,1;
  125. $login="$login1"."$login2";
  126. $login=~ y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ ;
  127.  
  128. # Au cas ou le login existe deja dans /etc/passwd ou dans le fichier en
  129. # cours.
  130. $already1=`cut -d: -f1 /etc/passwd | grep -x $login` ;
  131. $already2=`cut -d: -f1 $QUEUE/users_pop | grep -x $login` ;
  132. $already="$already1"."$already2" ;
  133. $c=0 ;
  134. $login1=substr $login,0,6;
  135. while ($already ne "") {
  136.   $c += 1 ;
  137.   $login="$login1"."$c";
  138.   $already1=`cut -d: -f1 /etc/passwd | grep -x $login` ;
  139.   $already2=`cut -d: -f1 $QUEUE/users_pop | grep -x $login` ;
  140.   $already="$already1"."$already2" ;
  141.   }
  142.  
  143. # Au cas ou l'alias existe deja dans /etc/aliases ou dans le fichier en
  144. # cours.
  145. $Prenom=$html->param('Prenom');
  146. $Nom=$html->param('Nom');
  147.   $Prenom=~ s/Θ/e/g ;
  148.   $Nom=~ s/Θ/e/g ;
  149.   $Prenom=~ s/Φ/e/g ;
  150.   $Nom=~ s/Φ/e/g ;
  151.   $Prenom=~ s/α/a/g ;
  152.   $Nom=~ s/α/a/g ;
  153.   $Prenom=~ s/δ/e/g ;
  154.   $Nom=~ s/δ/e/g ;
  155.   $Prenom=~ s/Ω/e/g ;
  156.   $Nom=~ s/Ω/e/g ;
  157.   $Prenom=~ s/∙/u/g ;
  158.   $Nom=~ s/∙/u/g ;
  159.   $Prenom=~ s/⌠/o/g ;
  160.   $Nom=~ s/⌠/o/g ;
  161.   $Prenom=~ s/÷/o/g ;
  162.   $Nom=~ s/÷/o/g ;
  163.   $Prenom=~ s/τ/c/g ;
  164.   $Nom=~ s/τ/c/g ;
  165. $already1=`cut -d: -f1 /etc/aliases | grep -x "$Prenom.$Nom"` ;
  166. $already2=`cut -d: -f5 $QUEUE/users_pop | grep -x "$Prenom.$Nom"` ;
  167. $already="$already1"."$already2" ;
  168. $c=0 ;
  169. $alias="$Prenom.$Nom";
  170. $alias1="$Prenom.$Nom";
  171. while ($already ne "") {
  172.   $c += 1 ;
  173.   $alias="$alias1"."$c";
  174.   $already1=`cut -d: -f1 /etc/aliases | grep -x $alias` ;
  175.   $already2=`cut -d: -f5 $QUEUE/users_pop | grep -x $alias` ;
  176.   $already="$already1"."$already2" ;
  177.   }
  178.  
  179. # Ecriture dans le fichier
  180. print USERS_POP $login,":";
  181. print USERS_POP $passwd,":";
  182. print USERS_POP $crypted_passwd,":";
  183. print USERS_POP $html->param('Prenom')," ";
  184. print USERS_POP $html->param('Nom'),",";
  185. print USERS_POP $html->param('Comm1'),",";
  186. print USERS_POP $html->param('Comm2'),":";
  187. print USERS_POP $alias,"\n";
  188.  
  189. # Ecriture du resultat
  190. print "<CENTER><H3><I>Les informations ont été enregistrées" ;
  191. print "\n</I></H3><P>Ce compte sera créé lors de la" ;
  192. print " prochaine validation.<P>\n" ;
  193. print "<B><A HREF=/users_pop.html>Créer un autre compte</A></B>\n" ;
  194.  
  195. # Lecture du pied de page standard
  196. open (FOOT,"$PIED");
  197. print <FOOT> ;
  198. close FOOT ;
  199.  
  200. close(PARAMS);
  201.