multigen.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // multigen attributes regeneration
  3. $remoteApiAction = ubRouting::get('action');
  4. if (($remoteApiAction == 'multigen') OR ( $remoteApiAction == 'multigentotal') OR ( $remoteApiAction == 'multigentraff') OR ( $remoteApiAction == 'multigenpod')) {
  5. if ($alterconf['MULTIGEN_ENABLED']) {
  6. $multigen = new MultiGen();
  7. if ($remoteApiAction == 'multigen') {
  8. //check for simultaneous process
  9. if (!$multigen->isMultigenRunning()) {
  10. //preventing further simultaneous runs
  11. $multigen->runPidStart();
  12. //automatic old data cleanup?
  13. if ($alterconf['MULTIGEN_AUTOCLEANUP_ENABLED']) {
  14. $cleanupTimes = $alterconf['MULTIGEN_AUTOCLEANUP_TIME'];
  15. if (!empty($cleanupTimes)) {
  16. $cleanupTimes = explode(',', $cleanupTimes);
  17. if (!empty($cleanupTimes)) {
  18. $cleanupTimes = array_flip($cleanupTimes);
  19. $nowTime = date("H:i");
  20. //Now its cleanup time!
  21. if (isset($cleanupTimes[$nowTime])) {
  22. //accounting and postdata cleanup
  23. $multigen->cleanupAccounting($alterconf['MULTIGEN_AUTOCLEANUP_ACCTDAYS'], $alterconf['MULTIGEN_AUTOCLEANUP_UNF']);
  24. //flushing all scenarios attributes
  25. $multigen->flushAllScenarios();
  26. print('OK: MULTIGEN_AUTOCLEANUP' . PHP_EOL);
  27. }
  28. }
  29. }
  30. }
  31. //regenerating attributes
  32. $multigen->generateNasAttributes();
  33. //releasing lock
  34. $multigen->runPidEnd();
  35. die('OK: MULTIGEN');
  36. } else {
  37. die('SKIP: MULTIGEN ALREADY RUNNING');
  38. }
  39. }
  40. //this callback left here just for legacy
  41. if ($remoteApiAction == 'multigentotal') {
  42. if (!$multigen->isMultigenRunning()) {
  43. $multigen->runPidStart();
  44. $multigen->flushAllScenarios();
  45. $multigen->generateNasAttributes();
  46. $multigen->runPidEnd();
  47. die('OK: MULTIGEN_TOTAL');
  48. } else {
  49. die('SKIP: MULTIGEN ALREADY RUNNING');
  50. }
  51. }
  52. //multigen accounting traffic processing
  53. if ($remoteApiAction == 'multigentraff') {
  54. $multigen->aggregateTraffic();
  55. die('OK: MULTIGEN_TRAFF');
  56. }
  57. if ($remoteApiAction == 'multigenpod') {
  58. $login = ubRouting::get('param');
  59. if (!empty($login)) {
  60. $userData = zb_UserGetAllData($login);
  61. $userData = $userData[$login];
  62. $newUserData = $userData;
  63. if ($alterconf['MULTIGEN_POD_ON_MAC_CHANGE']) {
  64. if ($alterconf['MULTIGEN_POD_ON_MAC_CHANGE'] == 2) {
  65. $multigen->podOnExternalEvent($login, $userData, $newUserData);
  66. $multigen->podOnExternalEvent($login, $newUserData);
  67. }
  68. if ($alterconf['MULTIGEN_POD_ON_MAC_CHANGE'] == 1) {
  69. $multigen->podOnExternalEvent($login, $newUserData);
  70. }
  71. die('OK: MULTIGENPOD');
  72. } else {
  73. die('ERROR: MULTIGEN_POD_ON_MAC_CHANGE DISABLED');
  74. }
  75. } else {
  76. die('ERROR: NO_LOGIN');
  77. }
  78. }
  79. } else {
  80. die('ERROR: MULTIGEN DISABLED');
  81. }
  82. }