syncs.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. require_once "bootstrap.inc.php";
  3. gettopost();
  4. if (! auth()) {
  5. sync_error(__FILE__.':'.__LINE__, "Auth failed");
  6. die();
  7. }
  8. if (empty($_POST['sens']) || !is_string($sens=$_POST['sens']) || !in_array($_POST['sens'], ['pd', 'dp'])){
  9. sync_error(__FILE__.':'.__LINE__, "Bad param : sens : ".(empty($_POST['sens']) ?'empty' :json_encode($_POST['sens'])));
  10. die();
  11. }
  12. if (empty($_POST['list']) || !is_array($list=$_POST['list'])){
  13. sync_error(__FILE__.':'.__LINE__, "Bad param : list : ".(empty($_POST['list']) ?'empty' :json_encode($_POST['list'])));
  14. die();
  15. }
  16. foreach($list as $r) {
  17. if (empty($r['type']) || !is_string($type=$r['type'])){
  18. sync_error(__FILE__.':'.__LINE__, "Bad param : type : ".json_encode($r));
  19. break;
  20. }
  21. if (empty($r['action']) || !is_string($action=$r['action']) || !in_array($r['action'], ['create', 'osync', 'delete'])){
  22. sync_error(__FILE__.':'.__LINE__, "Bad param : action : ".json_encode($r));
  23. break;
  24. }
  25. if (empty($r['otype']) || !is_string($otype=$r['otype'])){
  26. sync_error(__FILE__.':'.__LINE__, "Bad param : otype : ".json_encode($r));
  27. break;
  28. }
  29. if (empty($r['oid']) || !is_numeric($oid=$r['oid'])){
  30. sync_error(__FILE__.':'.__LINE__, "Bad param : oid : ".json_encode($r));
  31. break;
  32. }
  33. sync::_action($type, $sens, $action, $otype, $oid);
  34. }