api.onudlp.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * PON Disable lan port on onu class
  4. */
  5. class OnuDlp extends OnuBase {
  6. /**
  7. * Performs Disable lan port on onu
  8. *
  9. * @return bool
  10. *
  11. * @throws Exception
  12. */
  13. public function dlpOnu() {
  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. } elseif ($this->checkBDCOMEssentialOpts()) {
  27. $decMacOnu = $this->macHexToDec($macOnu);
  28. if (empty($decMacOnu)) {
  29. $this->displayMessage = __('Wrong MAC format (should be XX:XX:XX:XX:XX:XX)');
  30. return (false);
  31. }
  32. if ($snmpData['vlan']['VLANMODE'] == 'BDCOM_C') {
  33. $allOnuOid = $snmpData['signal']['MACINDEX'];
  34. snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
  35. $allOnu = @snmp2_real_walk($this->oltData['ip'], $this->oltData['snmp'], $allOnuOid);
  36. $searchArray = array();
  37. if (!empty($allOnu)) {
  38. foreach ($allOnu as $eachIndex => $eachOnu) {
  39. $eachIndex = trim(str_replace($allOnuOid . '.', '', $eachIndex));
  40. $eachOnu = strtolower(trim(str_replace($snmpData['signal']['MACVALUE'], '', $eachOnu)));
  41. $eachOnuMacArray = explode(" ", $eachOnu);
  42. $eachOnuMac = implode(":", $eachOnuMacArray);
  43. $searchArray[$eachOnuMac] = $eachIndex;
  44. }
  45. if (!empty($searchArray) and isset($searchArray[$macOnu])) {
  46. $ifIndex = $searchArray[$macOnu];
  47. $reloadData[] = array('oid' => $snmpData['onu']['DLP'] . '.' . $ifIndex . '.1', 'type' => 'i', 'value' => '2');
  48. $result = $this->snmp->set($this->oltData['ip'], $this->oltData['snmpwrite'], $reloadData);
  49. return (true);
  50. } else {
  51. $onuFound = false;
  52. }
  53. } else {
  54. $onuFound = false;
  55. }
  56. }
  57. } else {
  58. $this->displayMessage = __('Essential SNMP options are missing in template');
  59. return (false);
  60. }
  61. if (!$onuFound) {
  62. $this->displayMessage = __('ONU not found');
  63. }
  64. return (false);
  65. }
  66. /**
  67. * Returns Disable lan port on onu button
  68. *
  69. * @return string
  70. */
  71. public function dlpForm() {
  72. $Inputs = wf_SubmitClassed('true', 'vlanButton', 'DlpOnu', __('Disable lan port on onu'));
  73. $Form = wf_Form("", 'POST', $Inputs);
  74. return($Form);
  75. }
  76. }