configuration.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. namespace MGModule\DNSManager2;
  3. use MGModule\DNSManager2 as main;
  4. use MGModule\DNSManager2\mgLibs\custom\manager\DefaultNotifications;
  5. use MGModule\DNSManager2\helpers\upgrades\M2M10P0;
  6. /**
  7. * Module Configuration
  8. *
  9. * @author Michal Czech <michael@modulesgarden.com>
  10. */
  11. class configuration extends main\mgLibs\process\abstractConfiguration{
  12. //todo
  13. public $debug = false;
  14. public $systemName = 'DNSManager2';
  15. public $name = 'DNS Manager';
  16. public $description = 'DNS Manager For WHMCS is a fully featured addon module that allows your customers to manage DNS zones. It supports plenty of submodules and is extremely flexible!<br>For more info please visit our <a href="http://www.docs.modulesgarden.com/DNS_Manager_For_WHMCS" target="_blank" style="color: #4169E1;">Wiki</a>.';
  17. public $clientareaName = 'DNS Manager';
  18. public $encryptHash = 'uUc1Y8cWxDOAzlq11lBwelqzo6PGMTA0dbHaKQ109psefoJgIFMOgmReKCZbpCYpDSnrtfjmCIUyplaBJaUh40auDALprOHtj1g92ZRBS6S94IbZWaeZRYkG1f81h6qLMYEOr016RurCnmodFCWdMkTqrlVBvH249gzXPduKQVXpN9hooComaRPY5jZD6s8GdfR5E_BNP3v8Ui8RrdqMPST_8quMW48LhHY88xCvSWwDNjkC2tCAaK67Id2NjzIdoNTHUMISRg81nHX8ZGcbP74mxixo_ASd8YoWnDCAs8yiT4t0PwKRO_y3C1kDo69Nxz1YYt4tY1VzOD_DFBulAA5NCJLfogroo';
  19. public $version = '2.13.0';
  20. public $author = '<a href="http://www.modulesgarden.com" target="_blank">ModulesGarden</a>';
  21. public $tablePrefix = 'dns_manager2_';
  22. public $modelRegister = array(
  23. 'models\custom\globalsetting\GlobalSetting',
  24. 'models\custom\log\Log',
  25. 'models\custom\notification\Notification',
  26. 'models\custom\package\Package',
  27. 'models\custom\package\item\PackageItem',
  28. 'models\custom\package\server\PackageServer',
  29. 'models\custom\package\set\PackageSet',
  30. 'models\custom\package\setting\PackageSetting',
  31. 'models\custom\package\registrar\PackageRegistrar',
  32. 'models\custom\server\Server',
  33. 'models\custom\server\setting\ServerSetting',
  34. 'models\custom\server\nameserver\ServerNameserver',
  35. 'models\custom\set\Set',
  36. 'models\custom\set\record\SetRecord',
  37. 'models\custom\zone\Zone',
  38. 'models\custom\task\Task',
  39. 'models\custom\task\result\TaskResult',
  40. 'models\custom\reverse\Reverse',
  41. 'models\custom\status\Status',
  42. 'models\custom\clientfiles\ClientFiles',
  43. );
  44. public function __construct() {
  45. $file = dirname(__FILE__).DIRECTORY_SEPARATOR.'moduleVersion.php';
  46. if(file_exists($file)) {
  47. include $file;
  48. $this->version = $moduleVersion;
  49. //$this->description .= '<br/>For more info visit our Wiki: <a href="'.$moduleWikiUrl.'">'.$moduleWikiUrl.'</a>';
  50. } else {
  51. $this->description = '<span class="label terminated">THIS IS DEVELOPMENT VERSION !!!!!!!!!!</span><br/>'.$this->description;
  52. }
  53. if(isset($_GET['_debug'])) {
  54. $_SESSION['MG_DNSManager_debug'] = false;
  55. if($_GET['_debug'] == 'turnon') {
  56. $_SESSION['MG_DNSManager_debug'] = true;
  57. }
  58. }
  59. if(isset($_SESSION['MG_DNSManager_debug']) && $_SESSION['MG_DNSManager_debug'] == true) {
  60. error_reporting(E_ERROR);
  61. ini_set('display_errors', 'On');
  62. $this->debug = true;
  63. }
  64. }
  65. function getAddonMenu(){
  66. return array(
  67. 'dashboard' => array
  68. (
  69. 'icon' => 'glyphicon glyphicon-home'
  70. ),
  71. 'zones' => array
  72. (
  73. 'icon' => 'glyphicon glyphicon-globe'
  74. ),
  75. 'settings' => array
  76. (
  77. 'icon' => 'glyphicon glyphicon-cog',
  78. 'submenu' => array(
  79. 'global' => array(
  80. 'icon' => 'fa fa-cogs'
  81. ),
  82. 'servers' => array
  83. (
  84. 'icon' => ' glyphicon glyphicon-tasks'
  85. ),
  86. 'packages' => array(
  87. 'icon' => 'fa fa-cube'
  88. ),
  89. 'sets' => array(
  90. 'icon' => ' glyphicon glyphicon-list'
  91. ),
  92. 'blocked' => array(
  93. 'icon' => ' glyphicon glyphicon-remove'
  94. ),
  95. 'logs' => array(
  96. 'icon' => 'glyphicon glyphicon-calendar',
  97. ),
  98. )
  99. ),
  100. 'tools' => array
  101. (
  102. 'icon' => 'glyphicon glyphicon-wrench',
  103. 'submenu' => array(
  104. 'cron' => array(
  105. 'icon' => 'glyphicon glyphicon-time'
  106. ),
  107. 'migration' => array(
  108. 'icon' => 'glyphicon glyphicon-share-alt'
  109. ),
  110. 'import' => array(
  111. 'icon' => 'glyphicon glyphicon-download-alt'
  112. ),
  113. 'backups' => array(
  114. 'icon' => 'glyphicon glyphicon-folder-open'
  115. ),
  116. 'tasks' => array(
  117. 'icon' => 'fa fa-calendar'
  118. ),
  119. )
  120. ),
  121. );
  122. }
  123. function getServerMenu(){
  124. mgLibs\MySQL\query::query("
  125. UPDATE dns_manager2_globalsetting
  126. SET key = ?,
  127. cron_cleaner_no_active_domains = ?
  128. ", [M2M10P0::cronCleanerServiceValueToUpdate(), M2M10P0::cronCleanerDomainValueToUpdate()]);
  129. return array(
  130. 'configuration' => array(
  131. 'icon' => 'glyphicon glyphicon-cog'
  132. )
  133. );
  134. }
  135. /**
  136. * Return names of WHMCS product config fields
  137. * required if you want to use default WHMCS product configuration
  138. * max 20 fields
  139. *
  140. * if you want to use own product configuration use example
  141. * /models/customWHMCS/product to define own configuration model
  142. *
  143. * @return type
  144. */
  145. public function getServerWHMCSConfig() {
  146. return array(
  147. 'text_name'
  148. ,'text_name2'
  149. ,'checkbox_name'
  150. ,'onoff'
  151. ,'pass'
  152. ,'some_option'
  153. ,'some_option2'
  154. ,'radio_field'
  155. );
  156. }
  157. public function getAddonWHMCSConfig(){
  158. return array();
  159. }
  160. /**
  161. * Run When Module Install
  162. *
  163. * @author Michal Czech <michael@modulesgarden.com>
  164. */
  165. function activate(){
  166. $constructor = new mgLibs\models\tableContructor(__NAMESPACE__,$this->tablePrefix);
  167. $constructor->createDBModels($this->modelRegister);
  168. DefaultNotifications::createDefaultTemplates();
  169. $collationDetails = main\mgLibs\custom\helpers\CollationHelper::getCollation('dns_manager2_zone');
  170. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_zone` CHANGE `name` `name` VARCHAR(128) CHARACTER SET {$collationDetails['charset']} COLLATE {$collationDetails['charset']}_bin;");
  171. return true;
  172. }
  173. function deactivate(){ //TODO: zakomentować
  174. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_packageitem`');
  175. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_packageserver`');
  176. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_packageset`');
  177. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_packagesetting`');
  178. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_package`');
  179. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_reverse`');
  180. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_servernameserver`');
  181. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_serversetting`');
  182. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_zone`');
  183. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_server`');
  184. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_setrecord`');
  185. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_set`');
  186. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_taskresult`');
  187. // mgLibs\MySQL\query::query('DROP TABLE `dns_manager2_task`');
  188. return array(
  189. 'status'=>'success'
  190. );
  191. }
  192. public function upgrade($version)
  193. {
  194. $version = explode('-', $version)[0];
  195. $constructor = new mgLibs\models\tableContructor(__NAMESPACE__,$this->tablePrefix);
  196. $constructor->createDBModels($this->modelRegister);
  197. DefaultNotifications::createDefaultTemplates();
  198. if(version_compare($version, '2.0.1') == 0) {
  199. //TODO: czy tu nie czeba czego dodać?
  200. }
  201. if(version_compare($version, '2.0.2', '<=')) {
  202. DefaultNotifications::removeDefaultTemplates();
  203. DefaultNotifications::createDefaultTemplates();
  204. }
  205. if(version_compare($version, '2.0.3', '<=')) {
  206. DefaultNotifications::updateDefaultAdminTemplates();
  207. }
  208. if(version_compare($version, '2.2.0', '<=')) {
  209. mgLibs\MySQL\query::query("
  210. UPDATE dns_manager2_reverse, dns_manager2_zone
  211. SET dns_manager2_reverse.clientid = dns_manager2_zone.clientid
  212. WHERE dns_manager2_reverse.serverid = dns_manager2_zone.serverid
  213. AND dns_manager2_reverse.from = dns_manager2_zone.name");
  214. }
  215. if(version_compare($version, '2.5.0', '<'))
  216. {
  217. $constructor = new mgLibs\models\tableContructor(__NAMESPACE__,$this->tablePrefix);
  218. $constructor->createDBModels(array('models\custom\package\registrar\PackageRegistrar'));
  219. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_log` MODIFY `value` varchar(256) ");
  220. }
  221. if(version_compare($version, '2.8.0', '<'))
  222. {
  223. $constructor = new mgLibs\models\tableContructor(__NAMESPACE__,$this->tablePrefix);
  224. $constructor->createDBModels(array('models\custom\status\Status'));
  225. mgLibs\MySQL\query::query("
  226. UPDATE dns_manager2_packageitem , tbldomainpricing
  227. SET dns_manager2_packageitem.relid = tbldomainpricing.id
  228. WHERE dns_manager2_packageitem.relid = tbldomainpricing.extension
  229. AND dns_manager2_packageitem.type = 1");
  230. }
  231. if(version_compare($version, '2.10.0', '<'))
  232. {
  233. mgLibs\MySQL\query::query("
  234. UPDATE dns_manager2_globalsetting
  235. SET value = ?
  236. WHERE `key` = 'cron_cleaner_no_active_service'
  237. ", [M2M10P0::cronCleanerServiceValueToUpdate()]);
  238. mgLibs\MySQL\query::query("
  239. UPDATE dns_manager2_globalsetting
  240. SET value = ?
  241. WHERE `key` = 'cron_cleaner_no_active_domains'
  242. ", [M2M10P0::cronCleanerDomainValueToUpdate()]);
  243. mgLibs\MySQL\query::query("
  244. ALTER TABLE `dns_manager2_notification` CHANGE `value` `value` TEXT
  245. ");
  246. $constructor = new mgLibs\models\tableContructor(__NAMESPACE__,$this->tablePrefix);
  247. $constructor->createDBModels(array('models\custom\clientfiles\ClientFiles'));
  248. }
  249. if( version_compare($version, '2.10.0', '<') )
  250. {
  251. $ownedZones = main\models\custom\globalsetting\Repository::factory()->byKey('owned_domains_only');
  252. $ownedZonesSettings = $ownedZones->one();
  253. $setting = ( $ownedZonesSettings->value === 'on')
  254. ? main\mgLibs\custom\helpers\ZoneSettings::ALLOW_ONLY_DOMAINS_FROM_DOMAINS_AND_PRODUCT_ITEMS
  255. : main\mgLibs\custom\helpers\ZoneSettings::ALLOW_CUSTOM_DOMAINS;
  256. $toInsert = ['domainItemOptions', 'productItemOptions', 'addonItemOptions', 'otherItemOptions'];
  257. $columnsThatExist = array_column(main\mgLibs\MySQL\query::query('
  258. SELECT `key`
  259. FROM `dns_manager2_globalsetting`
  260. WHERE `key` IN (?,?,?,?)
  261. ', $toInsert)->fetchAll(), 'key');
  262. $toInsert = array_diff($toInsert, $columnsThatExist);
  263. if( count($toInsert) )
  264. {
  265. $sql = 'INSERT INTO `dns_manager2_globalsetting` (`key`, `value`) VALUES ';
  266. foreach( $toInsert as $value )
  267. {
  268. $sql .= "('{$value}','{$setting}'), ";
  269. }
  270. $sql = rtrim($sql, ' ,');
  271. main\mgLibs\MySQL\query::query($sql);
  272. }
  273. $ownedZones->delete();
  274. }
  275. if(version_compare($version, '2.11.0', '<'))
  276. {
  277. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_log` CHANGE `value` `value` TEXT;");
  278. }
  279. if ( version_compare($version, '2.12.0', '<') )
  280. {
  281. if ( !main\mgLibs\MySQL\query::query("SHOW COLUMNS FROM dns_manager2_zone LIKE 'is_locked'")->fetchAll() )
  282. {
  283. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_zone` ADD `is_locked` BOOLEAN NOT NULL DEFAULT FALSE;");
  284. }
  285. }
  286. mgLibs\MySQL\query::query("UPDATE dns_manager2_zone SET name = LOWER(name); ");
  287. if(version_compare($version, '2.12.0', '<='))
  288. {
  289. $collationDetails = main\mgLibs\custom\helpers\CollationHelper::getCollation('dns_manager2_zone');
  290. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_zone` CHANGE `name` `name` VARCHAR(128) CHARACTER SET {$collationDetails['charset']} COLLATE {$collationDetails['charset']}_bin;");
  291. }
  292. if(version_compare($version, '2.14.3', '<='))
  293. {
  294. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_task` ADD INDEX( `parentid`);");
  295. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_task` ADD INDEX( `repeats`);");
  296. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_task` ADD INDEX( `clientid`);");
  297. mgLibs\MySQL\query::query("ALTER TABLE `dns_manager2_task` CHANGE `parentid` `parentid` INT(32) NULL DEFAULT NULL, CHANGE `repeats` `repeats` INT(32) NULL DEFAULT NULL, CHANGE `clientid` `clientid` INT(32) NULL DEFAULT NULL;");
  298. }
  299. }
  300. }