| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules;
- use \Exception;
- use \MGModule\DNSManager2\mgLibs\custom\dns;
- use \MGModule\DNSManager2\mgLibs\custom\dns\exceptions;
- use \MGModule\DNSManager2\mgLibs\custom\dns\interfaces;
- class TestModule extends dns\SubmoduleAbstract implements interfaces\SubmoduleIPInterface, interfaces\SubmoduleRDNSInterface, interfaces\SubmoduleTTLInterface, interfaces\SubmoduleImportInterface {
- public $configFields = array(
- 'validator' =>array (
- 'friendlyName' => 'Validator Test',
- 'validators' => array(
- 'required' => 'required',
- )
- ),
- 'testConnection' =>array (
- 'friendlyName' => 'Test Connection',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'zoneExist' =>array (
- 'friendlyName' => 'Zone Exist',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'activateZone' =>array (
- 'friendlyName' => 'Create Zone',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'terminateZone' =>array (
- 'friendlyName' => 'Remove Zone',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'addRecord' =>array (
- 'friendlyName' => 'Add Record',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'editRecord' =>array (
- 'friendlyName' => 'Edit Record',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'deleteRecord' =>array (
- 'friendlyName' => 'Remove Record',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'updateRDNS' =>array (
- 'friendlyName' => 'Update rDNS Record',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'removeRDNS' =>array (
- 'friendlyName' => 'Remove rDNS Record',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'getZones' =>array (
- 'friendlyName' => 'Import/Migrate Zones',
- 'type' => 'select',
- 'options' => array(
- '0' => 'Error',
- '1' => 'Random',
- '2' => 'Success'
- )
- ),
- 'default_ip' =>array (
- 'friendlyName' => 'Default IP',
- ),
- );
-
- public $availableTypes = array('A', 'AAAA', 'ASFDB', 'CNAME', 'DNAME', 'DS', 'Def', 'HINFO', 'ISDN', 'LOC', 'MB', 'MD', 'MF', 'MG',
- 'MINFO', 'MR', 'MX', 'NAPTR', 'NS', 'PTR', 'RP', 'SOA', 'SRV', 'TXT', 'WKS', 'X25');
-
- private function ret($function) {
- if(!isset($this->config[$function]) || $this->config[$function] == '2') {
- return true;
- }
-
- if($this->config[$function] == '1' && (rand() % 2) == 0) {
- return true;
- }
-
- $code = $this->configFields['exception']?:dns\SubmoduleExceptionCodes::COMMAND_ERROR;
- throw new exceptions\DNSSubmoduleException('ERROR', $code);
- }
-
- public function testConnection() {
- $this->ret(__FUNCTION__);
- }
-
- public function getRecords($recordType = false) { //TODO: moznaby zapisac do sesji
- $this->ret(__FUNCTION__);
-
- $out = array();
- if(count($_SESSION['DNS_TestModuleRecords']) > 30) {
- unset($_SESSION['DNS_TestModuleRecords']);
- }
-
- if(!isset($_SESSION['DNS_TestModuleRecords'])) {
- $record = new dns\record\Record();
- $record->line = 1;
- $record->name = 'test';
- $record->ttl = '14400';
- $record->type = 'TXT';
- $record->createRDATAObject('TXT');
- $record->rdata->setFirstProperty('test');
- $out[1] = $record->toArray(FALSE);
- $_SESSION['DNS_TestModuleRecords'] = $out;
- } else {
- $out = $_SESSION['DNS_TestModuleRecords'];
- }
-
- foreach($out as &$record) {
- $record = dns\record\Record::tryToCreateFromArray($record);
- }
-
- return $out;
- }
-
- public function addRecord(dns\record\Record $record) {
- $this->ret(__FUNCTION__);
- $record->line = uniqid();
- $_SESSION['DNS_TestModuleRecords'][$record->line] = $record->toArray(FALSE);
- }
-
- public function editRecord(dns\record\Record $record) {
- $this->ret(__FUNCTION__);
- $_SESSION['DNS_TestModuleRecords'][$record->line] = $record->toArray(FALSE);
- }
-
- public function deleteRecord(dns\record\Record $record) {
- $this->ret(__FUNCTION__);
- unset($_SESSION['DNS_TestModuleRecords'][$record->line]);
- }
-
- public function zoneExists() {
- try {
- $this->ret(__FUNCTION__);
- } catch (Exception $e) {
- return false;
- }
- return true;
- }
-
- public function activateZone() {
- $this->ret(__FUNCTION__);
- }
-
- public function terminateZone() {
- $this->ret(__FUNCTION__);
- }
-
- public function getZones() {
- $this->ret(__FUNCTION__);
-
- return array(
- 'example.com' => '123.123.123.123',
- 'test.eu' => '',
- );
- }
-
- public function updateRDNS($ip, $ttl = false, $value = false) {
- $this->ret(__FUNCTION__);
- }
-
- public function removeRDNS($ip) {
- $this->ret(__FUNCTION__);
- }
- }
|