index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. if (cfr('PLPINGER')) {
  3. /**
  4. * Returns ICMP ping configuration form
  5. *
  6. * @return string
  7. */
  8. function wf_PlPingerOptionsForm() {
  9. //previous setting
  10. if (ubRouting::checkPost('packet')) {
  11. $currentpack = ubRouting::post('packet', 'int');
  12. } else {
  13. $currentpack = '';
  14. }
  15. if (ubRouting::checkPost('count')) {
  16. $getCount = ubRouting::post('count', 'int');
  17. if ($getCount <= 10000) {
  18. $currentcount = $getCount;
  19. } else {
  20. $currentcount = '';
  21. }
  22. } else {
  23. $currentcount = '';
  24. }
  25. $inputs = wf_TextInput('packet', __('Packet size'), $currentpack, false, 5);
  26. $inputs .= wf_TextInput('count', __('Count'), $currentcount, false, 5);
  27. $inputs .= wf_Submit(__('Save'));
  28. $result = wf_Form('', 'POST', $inputs, 'glamour');
  29. return ($result);
  30. }
  31. if (ubRouting::checkGet('username')) {
  32. $login = ubRouting::get('username');
  33. $config = $ubillingConfig->getBilling();
  34. $ping_path = $config['PING'];
  35. $sudo_path = $config['SUDO'];
  36. $userdata = zb_UserGetStargazerData($login);
  37. $user_ip = $userdata['IP'];
  38. $pingCount = 10;
  39. $pingSize = 64;
  40. $rttTmp = '';
  41. //setting ping parameters
  42. $addParams = '';
  43. if (ubRouting::checkGet('packsize')) {
  44. $pingSize = ubRouting::get('packsize', 'int');
  45. $addParams .= ' -s ' . $pingSize;
  46. }
  47. if (ubRouting::checkGet('packcount')) {
  48. $pingCount = ubRouting::get('packcount', 'int');
  49. $addParams .= ' -c ' . $pingCount;
  50. }
  51. //setting ajax background params
  52. $addAjax = '';
  53. if (ubRouting::checkPost('packet')) {
  54. $pingSize = ubRouting::post('packet', 'int');
  55. $addAjax .= "&packsize=" . $pingSize;
  56. $addParams .= ' -s ' . $pingSize;
  57. }
  58. if (ubRouting::checkPost('count')) {
  59. $pingCount = ubRouting::post('count', 'int');
  60. $addAjax .= "&packcount=" . $pingCount;
  61. $addParams .= ' -c ' . $pingCount;
  62. }
  63. if (ubRouting::checkGet('charts')) {
  64. $addAjax .= '&charts=true';
  65. }
  66. $command = $sudo_path . ' ' . $ping_path . ' -i 0.01 -c 10 ' . $addParams . ' ' . $user_ip;
  67. $ping_result = wf_AjaxLoader();
  68. if (!ubRouting::checkGet('charts')) {
  69. $ping_result .= wf_Link('?module=pl_pinger&charts=true&username=' . $login, wf_img_sized('skins/icon_stats.gif', '', '16') . ' ' . __('Graphs'), false, 'ubButton');
  70. } else {
  71. $ping_result .= wf_Link('?module=pl_pinger&username=' . $login, wf_img('skins/ping_icon.png') . ' ' . __('Normal'), false, 'ubButton');
  72. }
  73. $ping_result .= wf_AjaxLink('?module=pl_pinger&username=' . $login . '&ajax=true' . $addAjax, wf_img('skins/refresh.gif') . ' ' . __('Renew'), 'ajaxping', true, 'ubButton');
  74. $rawResult = shell_exec($command);
  75. //some charts
  76. if (ubRouting::checkGet('charts')) {
  77. /**
  78. * 心の声で散弾銃のように
  79. * 唄い続けた
  80. */
  81. if (!empty($rawResult)) {
  82. $pingLines = explodeRows($rawResult);
  83. $tmpArr = array();
  84. for ($packCount = 0; $packCount <= $pingCount; $packCount++) {
  85. $tmpArr[$packCount] = -1;
  86. }
  87. $succArray = array();
  88. $firstSec = -2;
  89. $secOffset = 0;
  90. $params[0] = array(__('Packets'), __('Time'));
  91. if (!empty($pingLines)) {
  92. foreach ($pingLines as $io => $eachLine) {
  93. //each packet result
  94. if (ispos($eachLine, 'ttl')) {
  95. $latency = explode('=', $eachLine);
  96. $seq = $latency[1];
  97. $seq = ubRouting::filters($seq, 'int');
  98. //start couting packets
  99. if ($firstSec == -2) {
  100. $firstSec = $seq;
  101. //Linux system?
  102. if ($firstSec == 1) {
  103. $secOffset = 1; //decrement value
  104. }
  105. }
  106. if (isset($latency[3])) {
  107. $latency = explode(' ', $latency[3]);
  108. $latency = $latency[0];
  109. $sequenceNorm = $seq - $secOffset;
  110. $succArray[$sequenceNorm] = $latency;
  111. }
  112. } else {
  113. //RTT here
  114. if (ispos($eachLine, 'min/avg/max')) {
  115. $rttTmp = explode('=', $eachLine);
  116. $rttTmp = 'RTT: ' . __('min/avg/max/dev') . ' ' . $rttTmp[1];
  117. }
  118. }
  119. }
  120. }
  121. }
  122. if (!empty($tmpArr)) {
  123. for ($packCount = 0; $packCount <= $pingCount - 1; $packCount++) {
  124. if (isset($succArray[$packCount])) {
  125. $params[] = array($packCount, $succArray[$packCount]);
  126. } else {
  127. $params[] = array($packCount, $tmpArr[$packCount]);
  128. }
  129. }
  130. }
  131. $chartsOptions = "
  132. 'focusTarget': 'category',
  133. 'hAxis': {
  134. 'color': 'none',
  135. 'baselineColor': 'none',
  136. },
  137. 'vAxis': {
  138. 'color': 'none',
  139. 'baselineColor': '#006d0f',
  140. },
  141. 'curveType': 'function',
  142. 'pointSize': 5,
  143. 'crosshair': {
  144. trigger: 'none'
  145. },";
  146. $messages = new UbillingMessageHelper();
  147. //overriding result output
  148. $pingParams = __('IP') . ': ' . $user_ip . ' ' . __('Packets count') . ': ' . $pingCount . ' ' . __('Packet size') . ': ' . $pingSize;
  149. $rawResult = $messages->getStyledMessage($pingParams, 'info');
  150. $rawResult .= wf_gchartsLineZeroIsBad($params, '', '100%', '300px', $chartsOptions);
  151. $lossPercent = (100 - zb_PercentValue($pingCount, sizeof($succArray)));
  152. if ($lossPercent > 0) {
  153. $noticeStyle = 'error';
  154. $summaryStyle = 'warning';
  155. } else {
  156. $noticeStyle = 'success';
  157. $summaryStyle = 'info';
  158. }
  159. //loss stats
  160. $rawResult .= $messages->getStyledMessage(__('Packets lost') . ': ' . $lossPercent . '%', $noticeStyle);
  161. $succCount = sizeof($succArray);
  162. $pingSummary = __('Packets received') . ': ' . $succCount . ' ' . __('Packets lost') . ': ' . ($pingCount - $succCount) . ' ' . $rttTmp;
  163. $rawResult .= $messages->getStyledMessage($pingSummary, $summaryStyle);
  164. }
  165. if (ubRouting::checkGet('ajax')) {
  166. die($rawResult);
  167. }
  168. $ping_result .= wf_tag('pre', false, '', 'id="ajaxping"') . $rawResult . wf_tag('pre', true);
  169. show_window(__('Settings'), wf_PlPingerOptionsForm());
  170. show_window(__('User pinger'), $ping_result);
  171. show_window('', web_UserControls($login));
  172. }
  173. } else {
  174. show_error(__('You cant control this module'));
  175. }