api.onudelete.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * PON ONU deletion class
  4. */
  5. class OnuDelete extends OnuBase {
  6. /**
  7. * Performs ONU deregistration
  8. *
  9. * @return bool
  10. *
  11. * @throws Exception
  12. */
  13. public function deleteOnu() {
  14. if (empty($this->snmpTemplateParsed)) {
  15. $this->displayMessage = __('SNMP template is not found or not exists');
  16. return (false);
  17. }
  18. if (empty($this->onuData)) {
  19. $this->displayMessage = __('ONU data is empty');
  20. return (false);
  21. }
  22. $macOnu = $this->onuData['mac'];
  23. $snmpData = $this->snmpTemplateParsed;
  24. if (isset($snmpData['onu']['CONTROLMODE'])) {
  25. $snmpControlMode = $snmpData['onu']['CONTROLMODE'];
  26. if ($snmpControlMode == 'VSOL_1600D' or $snmpControlMode == 'STELSFD11' or $snmpControlMode == 'STELSFD12') {
  27. $macIndexOID = $snmpData['signal']['MACINDEX'];
  28. $macValType = $snmpData['signal']['MACVALUE'];
  29. if ($snmpControlMode == 'VSOL_1600D') {
  30. $reloadPONIdx = $snmpData['onu']['DELETEPONINDEX'];
  31. $reloadONUIdx = $snmpData['onu']['DELETEONUINDEX'];
  32. }
  33. if ($snmpControlMode == 'STELSFD11' or $snmpControlMode == 'STELSFD12') {
  34. $reloadOperIdx = $snmpData['onu']['OPERATION'];
  35. $reloadOperNum = $snmpData['onu']['DELETE'];
  36. }
  37. $macIndexFull = $this->snmp->walk($this->oltData['ip'], $this->oltData['snmp'], $macIndexOID);
  38. if (!empty($macIndexFull)) {
  39. $macIndexFull = str_ireplace(array($macIndexOID, $macValType, '"'), ' ', $macIndexFull);
  40. $macIndexFull = explodeRows($macIndexFull);
  41. $reloadData = array();
  42. foreach ($macIndexFull as $eachRow) {
  43. $indexMAC = explode(' = ', $eachRow);
  44. if (!empty($indexMAC[1])) {
  45. if ($snmpControlMode == 'VSOL_1600D') {
  46. $tmpCleanMAC = trim($indexMAC[1]);
  47. }
  48. if ($snmpControlMode == 'STELSFD11' or $snmpControlMode == 'STELSFD12') {
  49. $tmpCleanMAC = strtolower(str_replace(' ', ':', trim($indexMAC[1])));
  50. }
  51. if ($macOnu == $tmpCleanMAC) {
  52. $tmpIdx = trim(substr($indexMAC[0], 1), '.');
  53. $ponIfaceIndex = substr($tmpIdx, 0, strpos($tmpIdx, '.', 1));
  54. $onuIndex = substr($tmpIdx, strpos($tmpIdx, '.', 1) + 1);
  55. if ($snmpControlMode == 'VSOL_1600D') {
  56. $reloadData[] = array('oid' => $reloadPONIdx, 'type' => 'i', 'value' => $ponIfaceIndex);
  57. $reloadData[] = array('oid' => $reloadONUIdx, 'type' => 'i', 'value' => $onuIndex);
  58. }
  59. if ($snmpControlMode == 'STELSFD11') {
  60. $onuIndex = ($onuIndex - 1) / 256;
  61. $reloadData[] = array('oid' => $reloadOperIdx . '.' . $ponIfaceIndex . '.' . $onuIndex, 'type' => 'i', 'value' => $reloadOperNum);
  62. }
  63. if ($snmpControlMode == 'STELSFD12') {
  64. $reloadData[] = array('oid' => $reloadOperIdx . '.5.2.1.4' . '.1' . $onuIndex, 'type' => 'i', 'value' => $reloadOperNum);
  65. }
  66. $this->snmp->set($this->oltData['ip'], $this->oltData['snmpwrite'], $reloadData);
  67. return (true);
  68. } else {
  69. $onuFound = false;
  70. }
  71. }
  72. }
  73. } else {
  74. $onuFound = false;
  75. }
  76. }
  77. } elseif ($this->checkBDCOMEssentialOpts()) {
  78. $vlanMode = ': ' . $snmpData['vlan']['VLANMODE'];
  79. $this->displayMessage = __('Function is not supported by this OLT') . $vlanMode;
  80. return (false);
  81. }
  82. if (!$onuFound) {
  83. $this->displayMessage = __('ONU not found');
  84. }
  85. return (false);
  86. }
  87. /**
  88. * Returns ONU delete button
  89. *
  90. * @return string
  91. */
  92. public function delForm() {
  93. $inputs = wf_SubmitClassed('true', 'vlanButton', 'DeleteOnu', __('Delete onu'));
  94. $inputs.= wf_tag('p', false, '', 'style="margin-left: 10px;"');
  95. $inputs.= __('IMPORTANT NOTE: before ONU deletion it must be set offline, like with reboot action');
  96. $inputs.= wf_tag('p', true);
  97. $form = wf_Form("", 'POST', $inputs);
  98. return($form);
  99. }
  100. }