cvs-auth.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /* $Id: cvs-auth.inc,v 1.11 2006/07/11 06:47:53 sfox Exp $ */
  3. require_once('config.inc');
  4. function get_auth($name, $pass, $connect = null) {
  5. static $cvs_encode = array(
  6. 32, 120, 53, 35, 36, 109, 72, 108,
  7. 70, 64, 76, 67, 116, 74, 68, 87,
  8. 111, 52, 75, 119, 49, 34, 82, 81,
  9. 95, 65, 112, 86, 118, 110, 122, 105,
  10. 64, 57, 83, 43, 46, 102, 40, 89,
  11. 38, 103, 45, 50, 42, 123, 91, 35,
  12. 125, 55, 54, 66, 124, 126, 59, 47,
  13. 92, 71, 115, 91, 92, 93, 94, 56,
  14. 96, 121, 117, 104, 101, 100, 69, 73,
  15. 99, 63, 94, 93, 39, 37, 61, 48,
  16. 58, 113, 32, 90, 44, 98, 60, 51,
  17. 33, 97, 62, 123, 124, 125, 126, 127);
  18. $encoded = 'A';
  19. $l = strlen($pass);
  20. for ($i = 0; $i < $l; $i++) {
  21. $o = ord($pass{$i});
  22. if ($o >= 32 && $o <= 127) {
  23. $encoded .= chr($cvs_encode[$o - 32]);
  24. } else {
  25. $encoded .= $pass{$i};
  26. }
  27. }
  28. if (!$connect) {
  29. $encrypted = crypt($encoded);
  30. return $encrypted;
  31. }
  32. $cvs = fsockopen('cvs.php.net', 2401, $errno, $errstr);
  33. if (!$cvs)
  34. return false;
  35. $pkt = "BEGIN VERIFICATION REQUEST\n/repository\n$name\n$encoded\nEND VERIFICATION REQUEST\n";
  36. fwrite($cvs, $pkt);
  37. $response = fgets($cvs);
  38. fclose($cvs);
  39. return 0 == strncmp($response, 'I LOVE YOU', 10) ? true : false;
  40. }
  41. function verify_password($user, $pass, $ref) {
  42. if (strlen($user) > 0 && strlen($pass) > 0) {
  43. if (!isset($_COOKIE['PHP-GTK'])) {
  44. $auth = get_auth($user, $pass, true);
  45. if ($auth == true) {
  46. $encoded = get_auth($user, $pass);
  47. setcookie('PHP-GTK', base64_encode($user.':'.$encoded), time()+(3600*6), '/');
  48. file_put_contents(DB_DIR."/$user.txt", $encoded);
  49. }
  50. }
  51. }
  52. header("Location: $ref");
  53. }
  54. function get_user() {
  55. if (isset($_COOKIE['PHP-GTK'])) {
  56. list($user, $pass) = explode(':', base64_decode($_COOKIE['PHP-GTK']));
  57. $stored = file_get_contents(DB_DIR."/$user.txt");
  58. if ($pass == $stored) {
  59. return $user;
  60. }
  61. }
  62. return false;
  63. }
  64. ?>