authority.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/blockedlog/ajax/authority.php
  20. * \ingroup blockedlog
  21. * \brief authority
  22. */
  23. // This script is called with a POST method.
  24. // Directory to scan (full path) is inside POST['dir'].
  25. if (!defined('NOTOKENRENEWAL')) {
  26. define('NOTOKENRENEWAL', 1); // Disables token renewal
  27. }
  28. if (!defined('NOREQUIREMENU')) {
  29. define('NOREQUIREMENU', '1');
  30. }
  31. if (!defined('NOREQUIREHTML')) {
  32. define('NOREQUIREHTML', '1');
  33. }
  34. $res = require '../../master.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/authority.class.php';
  37. $user = new User($db);
  38. $user->fetch(1); //TODO conf user authority
  39. /*
  40. * View
  41. */
  42. top_httphead();
  43. $auth = new BlockedLogAuthority($db);
  44. $signature = GETPOST('s');
  45. $newblock = GETPOST('b');
  46. $hash = GETPOST('h');
  47. if ($auth->fetch(0, $signature) <= 0) {
  48. $auth->signature = $signature;
  49. $auth->create($user);
  50. }
  51. if (!empty($hash)) {
  52. echo $auth->checkBlockchain($hash) ? 'hashisok' : 'hashisjunk';
  53. } elseif (!empty($newblock)) {
  54. if ($auth->checkBlock($newblock)) {
  55. $auth->addBlock($newblock);
  56. $auth->update($user);
  57. echo 'blockadded';
  58. } else {
  59. echo 'blockalreadyadded';
  60. }
  61. } else {
  62. echo 'idontunderstandwhatihavetodo';
  63. }