script.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. function usic_usermod($arg)
  3. {
  4. $values = array();
  5. $result = 0;
  6. $command = "echo -e \"login=".$arg['login'];
  7. if (!is_null($arg['surname'])) $command .= "\\n name=".$arg['surname']." ".$arg['name']." ".$arg['middle_name'];
  8. if (!is_null($arg['password'])) $command .= "\\n password=".$arg['password'];
  9. if (!is_null($arg['entering_year'])) $command .= "\\n entry_year=".$arg['entering_year'];
  10. if (!is_null($arg['profession'])) $command .= "\\n profession=".$arg['profession'];
  11. if (!is_null($arg['status'])) $command .= "\\n class=".$arg['status'];
  12. if (!is_null($arg['reader_card'])) $command .= "\\n reader_card_number=".$arg['reader_card'];
  13. if (!is_null($arg['student_card'])) $command .= "\\n student_card_number=".$arg['student_card'];
  14. if (!is_null($arg['passport'])) $command .= "\\n passport_number=".$arg['passport'];
  15. $command .= "\\n\" | /opt/usic/bin/usic_usermod";
  16. echo $command;
  17. //return $command;
  18. exec($command, $values, $result);
  19. $return = processUserErrors($result);
  20. return $return;
  21. }
  22. function processUserErrors($error)
  23. {
  24. switch ($error)
  25. {
  26. case 0:
  27. case 32:
  28. case 33:
  29. case 34:
  30. case 35:
  31. case 36:
  32. case 11:
  33. case 15:
  34. case 21:
  35. case 22:
  36. case 23:
  37. case 31:
  38. return $userErrors[$error];
  39. default:
  40. return 'wtf';
  41. }
  42. }
  43. $userErrors = array ( 11 => 'bind with database failed',
  44. 15 => 'LDAP doesn\'t like you',
  45. 21 => 'your folder can\'t be created',
  46. 22 => 'your present haven\'t been received in a proper way',
  47. 23 => 'your folder can\'t be deleted',
  48. 31 => 'an internal error of the script',
  49. 32 => 'search can\'t find anything for you',
  50. 33 => 'you can\'t be duplicated, even if you want',
  51. 34 => 'your reader card already exists!',
  52. 35 => 'your student card already exists!',
  53. 36 => 'your passport already exists!',
  54. 0 => 'everything is ok' );
  55. $args = array(
  56. 'login' => 'naskrina', 'student_card' => 'КВ06968382' );
  57. echo usic_usermod($args);