api.onureboot.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * PON ONU rebooting class
  4. */
  5. class OnuReboot extends OnuBase {
  6. /**
  7. * Performs ONU reboot
  8. *
  9. * @return bool
  10. *
  11. * @throws Exception
  12. */
  13. public function rebootOnu() {
  14. $onuFound = true;
  15. if (empty($this->snmpTemplateParsed)) {
  16. $this->displayMessage = __('SNMP template is not found or not exists');
  17. return (false);
  18. }
  19. if (empty($this->onuData)) {
  20. $this->displayMessage = __('ONU data is empty');
  21. return (false);
  22. }
  23. $macOnu = $this->onuData['mac'];
  24. $snmpData = $this->snmpTemplateParsed;
  25. if (isset($snmpData['onu']['CONTROLMODE'])) {
  26. $snmpControlMode = $snmpData['onu']['CONTROLMODE'];
  27. if ($snmpControlMode == 'VSOL_1600D' or $snmpControlMode == 'STELSFD11' or $snmpControlMode == 'STELSFD12') {
  28. $macIndexOID = $snmpData['signal']['MACINDEX'];
  29. $macValType = $snmpData['signal']['MACVALUE'];
  30. if ($snmpControlMode == 'VSOL_1600D') {
  31. $reloadPONIdx = $snmpData['onu']['RELOADPONINDEX'];
  32. $reloadONUIdx = $snmpData['onu']['RELOADONUINDEX'];
  33. }
  34. if ($snmpControlMode == 'STELSFD11' or $snmpControlMode == 'STELSFD12') {
  35. $reloadOperIdx = $snmpData['onu']['OPERATION'];
  36. $reloadOperNum = $snmpData['onu']['RELOAD'];
  37. }
  38. $macIndexFull = $this->snmp->walk($this->oltData['ip'], $this->oltData['snmp'], $macIndexOID);
  39. if (!empty($macIndexFull)) {
  40. $macIndexFull = str_ireplace(array($macIndexOID, $macValType, '"'), ' ', $macIndexFull);
  41. $macIndexFull = explodeRows($macIndexFull);
  42. $reloadData = array();
  43. foreach ($macIndexFull as $eachRow) {
  44. $indexMAC = explode(' = ', $eachRow);
  45. if (!empty($indexMAC[1])) {
  46. if ($snmpControlMode == 'VSOL_1600D') {
  47. $tmpCleanMAC = trim($indexMAC[1]);
  48. }
  49. if ($snmpControlMode == 'STELSFD11' or $snmpControlMode == 'STELSFD12') {
  50. $tmpCleanMAC = strtolower(str_replace(' ', ':', trim($indexMAC[1])));
  51. }
  52. if ($macOnu == $tmpCleanMAC) {
  53. $tmpIdx = trim(substr($indexMAC[0], 1), '.');
  54. $ponIfaceIndex = substr($tmpIdx, 0, strpos($tmpIdx, '.', 1));
  55. $onuIndex = substr($tmpIdx, strpos($tmpIdx, '.', 1) + 1);
  56. if ($snmpControlMode == 'VSOL_1600D') {
  57. $reloadData[] = array('oid' => $reloadPONIdx, 'type' => 'i', 'value' => $ponIfaceIndex);
  58. $reloadData[] = array('oid' => $reloadONUIdx, 'type' => 'i', 'value' => $onuIndex);
  59. }
  60. if ($snmpControlMode == 'STELSFD11') {
  61. $onuIndex = ($onuIndex - 1) / 256;
  62. $reloadData[] = array('oid' => $reloadOperIdx . '.' . $ponIfaceIndex . '.' . $onuIndex, 'type' => 'i', 'value' => $reloadOperNum);
  63. }
  64. if ($snmpControlMode == 'STELSFD12') {
  65. $reloadData[] = array('oid' => $reloadOperIdx . '.1.1.17' . '.1' . $onuIndex, 'type' => 'i', 'value' => $reloadOperNum);
  66. }
  67. $this->snmp->set($this->oltData['ip'], $this->oltData['snmpwrite'], $reloadData);
  68. return (true);
  69. } else {
  70. $onuFound = false;
  71. }
  72. }
  73. }
  74. } else {
  75. $onuFound = false;
  76. }
  77. }
  78. } elseif ($this->checkBDCOMEssentialOpts()) {
  79. $decMacOnu = $this->macHexToDec($macOnu);
  80. if (empty($decMacOnu)) {
  81. $this->displayMessage = __('Wrong MAC format (should be XX:XX:XX:XX:XX:XX)');
  82. return (false);
  83. }
  84. if ($snmpData['vlan']['VLANMODE'] == 'BDCOM_B') {
  85. $ifIndexOid = $snmpData['onu']['IFINDEX'] . '.' . $decMacOnu;
  86. $ifIndexFull = snmp2_get($this->oltData['ip'], $this->oltData['snmp'], $ifIndexOid);
  87. $ifIndex = trim(str_replace(array($ifIndexOid, 'INTEGER:'), '', $ifIndexFull));
  88. if (!empty($ifIndex)) {
  89. $reloadData[] = array('oid' => $snmpData['onu']['RELOAD'] . '.' . $ifIndex, 'type' => 'i', 'value' => '0');
  90. $result = $this->snmp->set($this->oltData['ip'], $this->oltData['snmpwrite'], $reloadData);
  91. return (true);
  92. } else {
  93. $onuFound = false;
  94. }
  95. }
  96. if ($snmpData['vlan']['VLANMODE'] == 'BDCOM_C') {
  97. $allOnuOid = $snmpData['signal']['MACINDEX'];
  98. snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
  99. $allOnu = @snmp2_real_walk($this->oltData['ip'], $this->oltData['snmp'], $allOnuOid);
  100. $searchArray = array();
  101. if (!empty($allOnu)) {
  102. foreach ($allOnu as $eachIndex => $eachOnu) {
  103. $eachIndex = trim(str_replace($allOnuOid . '.', '', $eachIndex));
  104. $eachOnu = strtolower(trim(str_replace($snmpData['signal']['MACVALUE'], '', $eachOnu)));
  105. $eachOnuMacArray = explode(" ", $eachOnu);
  106. $eachOnuMac = implode(":", $eachOnuMacArray);
  107. $searchArray[$eachOnuMac] = $eachIndex;
  108. }
  109. if (!empty($searchArray) and isset($searchArray[$macOnu])) {
  110. $ifIndex = $searchArray[$macOnu];
  111. $reloadData[] = array('oid' => $snmpData['onu']['RELOAD'] . '.' . $ifIndex, 'type' => 'i', 'value' => '0');
  112. $result = $this->snmp->set($this->oltData['ip'], $this->oltData['snmpwrite'], $reloadData);
  113. return (true);
  114. } else {
  115. $onuFound = false;
  116. }
  117. } else {
  118. $onuFound = false;
  119. }
  120. }
  121. } else {
  122. $this->displayMessage = __('Essential SNMP options are missing in template');
  123. return (false);
  124. }
  125. if (!$onuFound) {
  126. $this->displayMessage = __('ONU not found');
  127. }
  128. return (false);
  129. }
  130. /**
  131. * Returns ONU reboot button
  132. *
  133. * @return string
  134. */
  135. public function rebootForm() {
  136. $Inputs = wf_SubmitClassed('true', 'vlanButton', 'RebootOnu', __('Reboot onu'));
  137. $Form = wf_Form("", 'POST', $Inputs);
  138. return($Form);
  139. }
  140. }