upload.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. if (!isset($_POST['expire']) or !isset($_POST['id']) or !isset($_POST['key'])) {
  3. exit('No hack 1');
  4. }
  5. $config = yaml_parse_file('./config.yaml');
  6. include('./lib/functions.php');
  7. // # False = pas de checksum
  8. // var_dump(md5_file('files/checksum.db'));
  9. // var_dump(md5_file('checksum.db'));
  10. // require('lib/Checksum.php');
  11. // $checksum = new Checksum();
  12. // #var_dump($checksum->addFile("12121353-12", "toto.txt", "0000000001", 1681907411));
  13. // #var_dump($checksum->checkChecksum("0000000000"));
  14. // var_dump($checksum->checkChecksum("0000000001"));
  15. // var_dump($checksum->cleanExpire());
  16. // var_dump($checksum->checkChecksum("0000000000"));
  17. // #var_dump($checksum->deleteFile("12121353-12", 'toto.txt'));
  18. // #var_dump($checksum->checkChecksum("0000000000"));
  19. // exit();
  20. if (isset($_COOKIE['langue'])) {
  21. $locale = lang2locale($_COOKIE['langue']);
  22. $localeshort=locale2lang($locale);
  23. } else {
  24. $HTTP_ACCEPT_LANGUAGE=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
  25. //echo $HTTP_ACCEPT_LANGUAGE.'<br />';
  26. $lang_from_http_accept = explode(',', $HTTP_ACCEPT_LANGUAGE);
  27. //echo $lang_from_http_accept[0].'<br />';
  28. $locale = lang2locale($lang_from_http_accept[0]);
  29. if (substr($locale,0,2) != substr($lang_from_http_accept[0],0,2)) {
  30. //echo "Non trouvé, 2ème tentative";
  31. $lang_from_http_accept = explode('-', $lang_from_http_accept[0]);
  32. //echo $lang_from_http_accept[0].'<br />';
  33. $locale = lang2locale($lang_from_http_accept[0]);
  34. }
  35. //echo $locale.'<br />';
  36. $localeshort=locale2lang($locale);
  37. }
  38. // Définition de la langue :
  39. $results=putenv("LC_ALL=$locale.utf8");
  40. if (!$results) {
  41. exit ('putenv failed');
  42. }
  43. $results=putenv("LC_LANG=$locale.utf8");
  44. if (!$results) {
  45. exit ('putenv failed');
  46. }
  47. $results=putenv("LC_LANGUAGE=$locale.utf8");
  48. if (!$results) {
  49. exit ('putenv failed');
  50. }
  51. $results=setlocale(LC_ALL, "$locale.utf8");
  52. if (!$results) {
  53. exit ('setlocale failed: locale function is not available on this platform, or the given local does not exist in this environment');
  54. }
  55. bindtextdomain("messages", "./lang");
  56. textdomain("messages");
  57. $id=$_POST['id'];
  58. $uploadDir = $config['uploadDir'].'/'.$id;
  59. // Création du répertoire
  60. if (!is_dir($uploadDir)) {
  61. mkdir($uploadDir);
  62. } else {
  63. $fileAlreadyUploadSizeTotal=0;
  64. foreach (scandir($uploadDir) as $fileAlreadyUpload) {
  65. if (is_file($uploadDir.'/'.$fileAlreadyUpload)) {
  66. $fileAlreadyUploadSizeTotal=filesize($uploadDir.'/'.$fileAlreadyUpload)+$fileAlreadyUploadSizeTotal;
  67. }
  68. }
  69. }
  70. if (!is_file($uploadDir.'/.key-'.$_POST['key'].'.cfg')) {
  71. touch($uploadDir.'/.key-'.$_POST['key'].'.cfg');
  72. }
  73. if (isset($_POST['accessCheckbox']) && isset($_POST['access']) && preg_match('/^[0-9]+$/', $_POST['access'])) {
  74. if (!is_file($uploadDir.'/.access.cfg')) {
  75. file_put_contents($uploadDir.'/.access.cfg', $_POST['access']);
  76. }
  77. }
  78. if (isset($_POST['passwordCheckbox']) && isset($_POST['password'])) {
  79. file_put_contents("/tmp/pwd", $_POST['password']);
  80. if (!is_file($uploadDir.'/.password.cfg')) {
  81. file_put_contents($uploadDir.'/.password.cfg', password_hash($config['passwordUniqKey'].$_POST['password'], PASSWORD_DEFAULT));
  82. }
  83. }
  84. require('lib/UploadHandler.php');
  85. $upload_handler = new UploadHandler();