TestModule.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules;
  3. use \Exception;
  4. use \MGModule\DNSManager2\mgLibs\custom\dns;
  5. use \MGModule\DNSManager2\mgLibs\custom\dns\exceptions;
  6. use \MGModule\DNSManager2\mgLibs\custom\dns\interfaces;
  7. class TestModule extends dns\SubmoduleAbstract implements interfaces\SubmoduleIPInterface, interfaces\SubmoduleRDNSInterface, interfaces\SubmoduleTTLInterface, interfaces\SubmoduleImportInterface {
  8. public $configFields = array(
  9. 'validator' =>array (
  10. 'friendlyName' => 'Validator Test',
  11. 'validators' => array(
  12. 'required' => 'required',
  13. )
  14. ),
  15. 'testConnection' =>array (
  16. 'friendlyName' => 'Test Connection',
  17. 'type' => 'select',
  18. 'options' => array(
  19. '0' => 'Error',
  20. '1' => 'Random',
  21. '2' => 'Success'
  22. )
  23. ),
  24. 'zoneExist' =>array (
  25. 'friendlyName' => 'Zone Exist',
  26. 'type' => 'select',
  27. 'options' => array(
  28. '0' => 'Error',
  29. '1' => 'Random',
  30. '2' => 'Success'
  31. )
  32. ),
  33. 'activateZone' =>array (
  34. 'friendlyName' => 'Create Zone',
  35. 'type' => 'select',
  36. 'options' => array(
  37. '0' => 'Error',
  38. '1' => 'Random',
  39. '2' => 'Success'
  40. )
  41. ),
  42. 'terminateZone' =>array (
  43. 'friendlyName' => 'Remove Zone',
  44. 'type' => 'select',
  45. 'options' => array(
  46. '0' => 'Error',
  47. '1' => 'Random',
  48. '2' => 'Success'
  49. )
  50. ),
  51. 'addRecord' =>array (
  52. 'friendlyName' => 'Add Record',
  53. 'type' => 'select',
  54. 'options' => array(
  55. '0' => 'Error',
  56. '1' => 'Random',
  57. '2' => 'Success'
  58. )
  59. ),
  60. 'editRecord' =>array (
  61. 'friendlyName' => 'Edit Record',
  62. 'type' => 'select',
  63. 'options' => array(
  64. '0' => 'Error',
  65. '1' => 'Random',
  66. '2' => 'Success'
  67. )
  68. ),
  69. 'deleteRecord' =>array (
  70. 'friendlyName' => 'Remove Record',
  71. 'type' => 'select',
  72. 'options' => array(
  73. '0' => 'Error',
  74. '1' => 'Random',
  75. '2' => 'Success'
  76. )
  77. ),
  78. 'updateRDNS' =>array (
  79. 'friendlyName' => 'Update rDNS Record',
  80. 'type' => 'select',
  81. 'options' => array(
  82. '0' => 'Error',
  83. '1' => 'Random',
  84. '2' => 'Success'
  85. )
  86. ),
  87. 'removeRDNS' =>array (
  88. 'friendlyName' => 'Remove rDNS Record',
  89. 'type' => 'select',
  90. 'options' => array(
  91. '0' => 'Error',
  92. '1' => 'Random',
  93. '2' => 'Success'
  94. )
  95. ),
  96. 'getZones' =>array (
  97. 'friendlyName' => 'Import/Migrate Zones',
  98. 'type' => 'select',
  99. 'options' => array(
  100. '0' => 'Error',
  101. '1' => 'Random',
  102. '2' => 'Success'
  103. )
  104. ),
  105. 'default_ip' =>array (
  106. 'friendlyName' => 'Default IP',
  107. ),
  108. );
  109. public $availableTypes = array('A', 'AAAA', 'ASFDB', 'CNAME', 'DNAME', 'DS', 'Def', 'HINFO', 'ISDN', 'LOC', 'MB', 'MD', 'MF', 'MG',
  110. 'MINFO', 'MR', 'MX', 'NAPTR', 'NS', 'PTR', 'RP', 'SOA', 'SRV', 'TXT', 'WKS', 'X25');
  111. private function ret($function) {
  112. if(!isset($this->config[$function]) || $this->config[$function] == '2') {
  113. return true;
  114. }
  115. if($this->config[$function] == '1' && (rand() % 2) == 0) {
  116. return true;
  117. }
  118. $code = $this->configFields['exception']?:dns\SubmoduleExceptionCodes::COMMAND_ERROR;
  119. throw new exceptions\DNSSubmoduleException('ERROR', $code);
  120. }
  121. public function testConnection() {
  122. $this->ret(__FUNCTION__);
  123. }
  124. public function getRecords($recordType = false) { //TODO: moznaby zapisac do sesji
  125. $this->ret(__FUNCTION__);
  126. $out = array();
  127. if(count($_SESSION['DNS_TestModuleRecords']) > 30) {
  128. unset($_SESSION['DNS_TestModuleRecords']);
  129. }
  130. if(!isset($_SESSION['DNS_TestModuleRecords'])) {
  131. $record = new dns\record\Record();
  132. $record->line = 1;
  133. $record->name = 'test';
  134. $record->ttl = '14400';
  135. $record->type = 'TXT';
  136. $record->createRDATAObject('TXT');
  137. $record->rdata->setFirstProperty('test');
  138. $out[1] = $record->toArray(FALSE);
  139. $_SESSION['DNS_TestModuleRecords'] = $out;
  140. } else {
  141. $out = $_SESSION['DNS_TestModuleRecords'];
  142. }
  143. foreach($out as &$record) {
  144. $record = dns\record\Record::tryToCreateFromArray($record);
  145. }
  146. return $out;
  147. }
  148. public function addRecord(dns\record\Record $record) {
  149. $this->ret(__FUNCTION__);
  150. $record->line = uniqid();
  151. $_SESSION['DNS_TestModuleRecords'][$record->line] = $record->toArray(FALSE);
  152. }
  153. public function editRecord(dns\record\Record $record) {
  154. $this->ret(__FUNCTION__);
  155. $_SESSION['DNS_TestModuleRecords'][$record->line] = $record->toArray(FALSE);
  156. }
  157. public function deleteRecord(dns\record\Record $record) {
  158. $this->ret(__FUNCTION__);
  159. unset($_SESSION['DNS_TestModuleRecords'][$record->line]);
  160. }
  161. public function zoneExists() {
  162. try {
  163. $this->ret(__FUNCTION__);
  164. } catch (Exception $e) {
  165. return false;
  166. }
  167. return true;
  168. }
  169. public function activateZone() {
  170. $this->ret(__FUNCTION__);
  171. }
  172. public function terminateZone() {
  173. $this->ret(__FUNCTION__);
  174. }
  175. public function getZones() {
  176. $this->ret(__FUNCTION__);
  177. return array(
  178. 'example.com' => '123.123.123.123',
  179. 'test.eu' => '',
  180. );
  181. }
  182. public function updateRDNS($ip, $ttl = false, $value = false) {
  183. $this->ret(__FUNCTION__);
  184. }
  185. public function removeRDNS($ip) {
  186. $this->ret(__FUNCTION__);
  187. }
  188. }