An unfinished system to manage all your paper documentation in an easy way.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

il y a 5 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/perl
  2. use strict;
  3. use lib '/opt/autodoc/lib';
  4. use Autodoc;
  5. use warnings;
  6. my $conf = load_conf('/opt/autodoc/etc/autodoc.json');
  7. my $dbh = sqlconnect($conf->{sql});
  8. while(1) {
  9. print "User management\n";
  10. print "(l)ist, (a)dd, (d)elete, (q)uit\n";
  11. print "? ";
  12. my $m = input('^[ladq]$');
  13. if ( !defined $m ) {
  14. print "ERROR: Invalid input\n";
  15. }
  16. elsif ( $m eq 'l' ) {
  17. foreach my $user ( list_users() ) {
  18. print "User: $user\n";
  19. }
  20. }
  21. elsif ( $m eq 'a' ) {
  22. my ($user, $pass);
  23. while(!defined $user) {
  24. print "Username: ";
  25. $user = input('^[0-9a-zA-Z-]+$');
  26. print "Invalid username\n" if !defined $user;
  27. }
  28. while(!defined $pass) {
  29. print "Password: ";
  30. $pass = input('^[0-9a-zA-Z-]+$');
  31. print "Invalid password\n" if !defined $pass;
  32. }
  33. create_user($user,$pass);
  34. }
  35. elsif ( $m eq 'd' ) {
  36. print "Username to delete: ";
  37. my $user = input('^[0-9a-zA-Z-]+$');
  38. delete_user($user);
  39. }
  40. elsif ( $m eq 'q' ) {
  41. print "Bye\n";
  42. exit;
  43. }
  44. }
  45. sub create_user {
  46. my($user,$pass) = @_;
  47. my $crypt;
  48. open(X,"htpasswd -nbB '$user' '$pass' |");
  49. while(<X>) {
  50. chomp;
  51. (undef, $crypt)=split(/:/) if /:/;
  52. }
  53. close(X);
  54. if ( defined $crypt ) {
  55. sqlquery($dbh, "INSERT INTO users SET username = ?, passwd = ?", $user, $crypt);
  56. }
  57. }
  58. sub delete_user {
  59. my($user) = @_;
  60. sqlquery($dbh, "DELETE FROM users WHERE username = ?", $user);
  61. }
  62. sub list_users {
  63. my @users;
  64. my $q = sqlquery($dbh, "SELECT username FROM users ORDER BY username");
  65. while(my ($user) = $q->fetchrow_array()) { push @users, $user; }
  66. return @users;
  67. }
  68. sub input {
  69. my($re) = @_;
  70. my $str = <STDIN>; chomp $str;
  71. return $str if $str =~ /$re/;
  72. return undef;
  73. }