/gui/tools/webmail/plugins/html_mail/fckeditor/editor/filemanager/browser/mcpuk/connectors/php/Auth/Default.php

https://github.com/BenBE/ispCP · PHP · 86 lines · 42 code · 10 blank · 34 comment · 12 complexity · 48bb32c977e42e7e3c62da61dd125266 MD5 · raw file

  1. <?php
  2. /*
  3. * FCKeditor - The text editor for internet
  4. * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  5. *
  6. * Licensed under the terms of the GNU Lesser General Public License:
  7. * http://www.opensource.org/licenses/lgpl-license.php
  8. *
  9. * For further information visit:
  10. * http://www.fckeditor.net/
  11. *
  12. * "Support Open Source software. What about a donation today?"
  13. *
  14. * File Name: Default.php
  15. * Im not very clued up on authentication but even i can see that anyone
  16. * who can spoof an IP could perform a replay attack on this, but its
  17. * better than nothing.
  18. * There is a 1 hour time out on tokens to help this slightly.
  19. *
  20. * File Authors:
  21. * Grant French (grant@mcpuk.net)
  22. */
  23. class Auth {
  24. function authenticate($data,$fckphp_config) {
  25. //Hold relevant$fckphp_config vars locally
  26. $key=$fckphp_config['auth']['Handler']['SharedKey'];
  27. $fckphp_config['authSuccess']=false;
  28. //Decrypt the data passed to us
  29. $decData="";
  30. for ($i=0;$i<strlen($data)-1;$i+=2) $decData.=chr(hexdec($data[$i].$data[$i+1]));
  31. $decArray=explode("|^SEP^|",$decData);
  32. if (sizeof($decArray)==4) {
  33. //0 = Timestamp
  34. //1 = Client IP
  35. //2 = Username
  36. //3 = MD5
  37. if ($decArray[3]==md5($decArray[0]."|^SEP^|".$decArray[1]."|^SEP^|".$decArray[2].$key)) {
  38. if (time()-$decArray[0]<3600) { //Token valid for max of 1 hour
  39. if ($_SERVER['REMOTE_ADDR']==$decArray[1]) {
  40. //Set the file root to the users individual one
  41. $top=str_replace("//","/",$fckphp_config['basedir'].'/'.$fckphp_config['UserFilesPath']."/users");
  42. $fckphp_config['UserFilesPath']=$fckphp_config['UserFilesPath']."/users/".$decArray[2];
  43. $up=str_replace("//","/",$fckphp_config['basedir'].'/'.$fckphp_config['UserFilesPath']);
  44. if (!file_exists($top)) {
  45. mkdir($top,0777) or die("users folder in UserFilesPath does not exist and could not be created.");
  46. chmod($top,0777);
  47. }
  48. //Create folder if it doesnt exist
  49. if (!file_exists($up)) {
  50. mkdir($up,0777) or die("users/".$decArray[2]." folder in UserFilesPath does not exist and could not be created.");
  51. chmod($up,0777); //Just for good measure
  52. }
  53. //Create resource area subfolders if they dont exist
  54. foreach ($fckphp_config['ResourceTypes'] as $value) {
  55. if (!file_exists("$up/$value")) {
  56. mkdir("$up/$value",0777) or die("users/".$decArray[2]."/$value folder in UserFilesPath does not exist and could not be created.");
  57. chmod("$up/$value",0777); //Just for good measure
  58. }
  59. }
  60. $fckphp_config['authSuccess']=true;
  61. } else {
  62. //Not same client as auth token is for
  63. }
  64. } else {
  65. //Token more than an hour old
  66. }
  67. } else {
  68. //Data integrity failed
  69. }
  70. } else {
  71. //Not enough data (decryption failed?)
  72. }
  73. return $fckphp_config;
  74. }
  75. }
  76. ?>