index.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. if (cfr('ROOT')) {
  3. set_time_limit(0);
  4. $sgTemplate = 'StreamGen';
  5. $sgLogin = 'admin';
  6. $sgPassword = 'password';
  7. $sgNameMask = 'Pseudo Cam';
  8. $cameras = new Cameras();
  9. $sgHost = ubRouting::checkPost('sghost') ? ubRouting::post('sghost', 'mres') : '';
  10. $sgStartPort = ubRouting::checkPost('sgport') ? ubRouting::post('sgport', 'int') : 8554;
  11. $sgCount = ubRouting::checkPost('sgcount') ? ubRouting::post('sgcount', 'int') : 0;
  12. $sgModelId = 0;
  13. function sgGetModelId($sgTemplate = 'StreamGen') {
  14. $result = 0;
  15. $models = new Models();
  16. $allModels = $models->getAllModelData();
  17. if (!empty($allModels)) {
  18. foreach ($allModels as $io => $each) {
  19. if ($each['template'] == $sgTemplate) {
  20. $result = $each['id'];
  21. }
  22. }
  23. }
  24. return ($result);
  25. }
  26. function sgForm() {
  27. $result = '';
  28. $inputs = '';
  29. $inputs .= wf_TextInput('sghost', __('Host'), '', false, '15', 'ip');
  30. $inputs .= wf_TextInput('sgport', __('Start port'), '8554', false, 4, 'digits');
  31. $inputs .= wf_TextInput('sgcount', __('Count of streams'), ubRouting::post('sgcount'), false, '4', 'digits');
  32. $inputs .= wf_Submit(__('Generate'));
  33. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  34. $result .= wf_delimiter();
  35. $delUrl = '?module=streamgen&flushall=true';
  36. $result .= wf_ConfirmDialog($delUrl, web_delete_icon() . ' ' . __('Flush all cameras'), __('All streamgen cameras will be destroyed'), 'ubButton', '?module=streamgen', __('Destroy') . '?');
  37. return ($result);
  38. }
  39. if (ubRouting::checkGet('flushall')) {
  40. $sgModelId = sgGetModelId($sgTemplate);
  41. if ($sgModelId) {
  42. $delCount = 0;
  43. $allCameras = $cameras->getAllCamerasFullData();
  44. if (!empty($allCameras)) {
  45. foreach ($allCameras as $io => $each) {
  46. $cameraData = $each['CAMERA'];
  47. if ($cameraData['modelid'] == $sgModelId) {
  48. $cameras->deactivate($cameraData['id']);
  49. }
  50. }
  51. sleep(5);
  52. $cameras = new Cameras();
  53. $allCameras = $cameras->getAllCamerasFullData();
  54. foreach ($allCameras as $io => $each) {
  55. $cameraData = $each['CAMERA'];
  56. if ($cameraData['modelid'] == $sgModelId) {
  57. $delResult = $cameras->delete($cameraData['id']);
  58. $delCount++;
  59. if (empty($delResult)) {
  60. show_warning(__('Camera') . ' ' . $cameraData['comment'] . ' ' . __('Destroyed') . '!');
  61. } else {
  62. show_error(__('Camera') . ' ' . $cameraData['comment'] . ' ' . __('deletion failed') . '!');
  63. }
  64. }
  65. }
  66. if ($delCount == 0) {
  67. show_info(__('No registered pseudo cameras found'));
  68. }
  69. } else {
  70. show_error(__('No registered cameras found'));
  71. }
  72. } else {
  73. show_error(__('Any') . ' ' . $sgTemplate . ' ' . __('models found'));
  74. }
  75. show_window('', wf_BackLink('?module=streamgen'));
  76. } else {
  77. show_window(__('Generate test cameras'), sgForm());
  78. }
  79. if ($sgCount and $sgHost) {
  80. //gettin modelId
  81. $sgModelId = sgGetModelId($sgTemplate);
  82. //creating new one
  83. if (empty($sgModelId)) {
  84. $models = new Models();
  85. $models->create('SG Pseudo Cam', $sgTemplate);
  86. $sgModelId = sgGetModelId($sgTemplate);
  87. }
  88. if ($sgModelId) {
  89. for ($i = 0; $i < $sgCount; $i++) {
  90. $nextPort = $sgStartPort + $i;
  91. $isFree = $cameras->isCameraIpPortFree($sgHost, $nextPort);
  92. if ($isFree) {
  93. $camName = $sgNameMask . ' ' . ($i + 1);
  94. $regResult = $cameras->create($sgModelId, $sgHost, $sgLogin, $sgPassword, true, 0, $camName, $nextPort);
  95. if (empty($regResult)) {
  96. show_success($sgHost . ':' . $nextPort . ' ' . __('Registered'));
  97. } else {
  98. show_error($sgHost . ':' . $nextPort . ' ' . __('Registration failed'));
  99. }
  100. } else {
  101. show_info($sgHost . ':' . $nextPort . ' ' . __('Already registered'));
  102. }
  103. }
  104. } else {
  105. show_error(__('ModelId not detected'));
  106. }
  107. }
  108. } else {
  109. show_error(__('Access denied'));
  110. }