forked from dondominio/whmcs-addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdondominio.php
447 lines (375 loc) · 12.4 KB
/
dondominio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<?php
/**
* The DonDominio Manager Addon for WHMCS.
*
* WHMCS version 5.2.x / 5.3.x / 6.x / 7.x
* @link https://github.com/dondominio/whmcsaddon
* @package DonDominioWHMCSAddon
* @license CC BY-ND 3.0 <http://creativecommons.org/licenses/by-nd/3.0/>
*/
/**
* The DonDominio API Client for PHP
*/
if( !class_exists( 'DonDominioAPI' )){
require_once( "lib/sdk/DonDominioAPI.php" );
}
require_once( "dd_utils.php" );
require_once( "dd_domain_pricing.php" );
if( !defined( "WHMCS" )){
die( "This file cannot be accessed directly" );
}
/**
* Return configuration array for WHMCS.
* @return array
*/
function dondominio_config()
{
$configarray = array(
"name" => "DonDominio Manager",
"description" => "Advanced features from DonDominio.",
"version" => dd_getVersion(),
"author" => "DonDominio",
"language" => "english",
"fields" => array()
);
return $configarray;
}
/**
* Perform a query and check the result.
* @param string $sql query to send to the database
* @return array|boolean
*/
function dd_do_query( $sql )
{
$result = full_query( $sql );
if( !$result ){
return array(
'status' => 'error',
'description' => 'There was a problem activating the DonDominio Manager Addon. Please contact support.'
);
}
return true;
}
/**
* Activation hook for addon.
* Creates tables in database needed to work.
* @return array
*/
function dondominio_activate()
{
//Check if EUR is in currencies; if not, fail
$currency = full_query( "SELECT id FROM tblcurrencies WHERE code='EUR'" );
if( mysql_num_rows( $currency ) == 0 ){
return array(
'status' => 'error',
'description' => 'The DonDominio API works with Euros (EUR). Please, add this currency to your WHMCS configuration before enabling the Addon.'
);
}
//Creating mod_dondominio_pricing
if( is_array( $result = dd_do_query( "
CREATE TABLE IF NOT EXISTS `mod_dondominio_pricing`
(
`id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`tld` VARCHAR(64) NOT NULL,
`register_price` DECIMAL(10,2) NULL,
`transfer_price` DECIMAL(10,2) NULL,
`renew_price` DECIMAL(10,2) NULL,
`register_range` VARCHAR(128) NULL,
`transfer_range` VARCHAR(128) NULL,
`renew_range` VARCHAR(128) NULL,
`old_register_price` DECIMAL(10,2) NULL,
`old_transfer_price` DECIMAL(10,2) NULL,
`old_renew_price` DECIMAL(10,2) NULL,
`authcode_required` TINYINT(1) NULL,
`last_update` DATETIME NOT NULL
)
" ))){
return $result;
}
//Creating mod_dondominio_tld_settings
if( is_array( $result = dd_do_query( "
CREATE TABLE IF NOT EXISTS `mod_dondominio_tld_settings`
(
`id` INT(1) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`tld` VARCHAR(64) NOT NULL,
`ignore` TINYINT(1) NOT NULL,
`enabled` TINYINT(1) NOT NULL,
`register_increase` DECIMAL(10,2) NOT NULL DEFAULT 0,
`register_increase_type` VARCHAR(16) NOT NULL DEFAULT 'fixed',
`renew_increase` DECIMAL(10,2) NOT NULL DEFAULT 0,
`renew_increase_type` VARCHAR(16) NOT NULL DEFAULT 'fixed',
`transfer_increase` DECIMAL(10,2) NOT NULL DEFAULT 0,
`transfer_increase_type` VARCHAR(16) NOT NULL DEFAULT 'fixed',
UNIQUE INDEX `unique_tld` (`tld`)
)
" ))){
return $result;
}
//Creating mod_dondominio_settings
if( is_array( $result = dd_do_query( "
CREATE TABLE IF NOT EXISTS `mod_dondominio_settings`
(
`key` VARCHAR(32) NOT NULL PRIMARY KEY,
`value` VARCHAR(256) NULL
)
" ))){
return $result;
}
//Creating mod_dondominio_watchlist
if( is_array( $result = dd_do_query("
CREATE TABLE IF NOT EXISTS `mod_dondominio_watchlist`
(
`id` INT(1) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`tld` VARCHAR(64) NOT NULL
)
"))){
return $result;
}
//Default values
if( is_array( $result = dd_do_query( "
INSERT INTO `mod_dondominio_settings` (`key`, `value`) VALUES
('register_increase', '0.00'),
('transfer_increase', '0.00'),
('renew_increase', '0.00'),
('register_increase_type', 'fixed'),
('transfer_increase_type', 'fixed'),
('renew_increase_type', 'fixed'),
('notifications_enabled', '0'),
('notifications_email', ''),
('notifications_new_tlds', '0'),
('notifications_prices', '0'),
('api_username', ''),
('api_password', ''),
('watchlist_mode', 'disabled'),
('prices_autoupdate', '0')
" ))){
return $result;
}
return array(
'status' => 'success',
'description' => 'The DonDominio Manager Addon is now ready. Enjoy!'
);
}
/**
* Disable hook for addon.
* Deletes tables from the database.
* @return array
*/
function dondominio_deactivate()
{
//Removing mod_dondominio_pricing
if( is_array( $result = dd_do_query( "DROP TABLE IF EXISTS `mod_dondominio_pricing`" ))){
return $result;
}
//Removing mod_dd_settings
if( is_array( $result = dd_do_query( "DROP TABLE IF EXISTS `mod_dondominio_settings`" ))){
return $result;
}
//Removing mod_dd_settings
if( is_array( $result = dd_do_query( "DROP TABLE IF EXISTS `mod_dondominio_watchlist`" ))){
return $result;
}
return array( 'status' => 'success', 'description' => 'The DonDominio Manager Addon has been successfully disabled.' );
}
/**
* Upgrade function.
* Performs updates in the database.
* @param Array $vars Parameters passed by WHMCS
* @return bool
*/
function dondominio_upgrade( $vars )
{
$version = $vars['version'];
/*
* La versión 1.0 no tiene "authcode_required" en "mod_dondominio_pricing"
*/
if( $version < 1.1 ){
$query = "ALTER TABLE `mod_dondominio_pricing` ADD `authcode_required` TINYINT(1) NOT NULL";
$result = full_query( $query );
}
# Run SQL Updates for V1.1 to V1.2
if( $version < 1.2 ){
$query = "
CREATE TABLE IF NOT EXISTS `mod_dondominio_tld_settings`
(
`id` INT(1) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`tld` VARCHAR(64) NOT NULL,
`ignore` TINYINT(1) NOT NULL,
`enabled` TINYINT(1) NOT NULL,
`register_increase` DECIMAL(10,2) NOT NULL DEFAULT 0,
`register_increase_type` VARCHAR(16) NOT NULL DEFAULT 'fixed',
`renew_increase` DECIMAL(10,2) NOT NULL DEFAULT 0,
`renew_increase_type` VARCHAR(16) NOT NULL DEFAULT 'fixed',
`transfer_increase` DECIMAL(10,2) NOT NULL DEFAULT 0,
`transfer_increase_type` VARCHAR(16) NOT NULL DEFAULT 'fixed'
)
";
$result = full_query( $query );
$query = "CREATE UNIQUE INDEX `unique_tld` ON `mod_dondominio_tld_settings`(`tld`)";
$result = full_query( $query );
}
if( $version < 1.6 ){
$query = "ALTER TABLE `mod_dondominio_tld_settings` ADD `ignore` TINYINT(1) NOT NULL";
$result = full_query( $query );
}
return true;
}
/**
* Check the DonDominio Domain Management Addon version.
* @return Array|bool
*/
function dondominio_addon_version_check()
{
$localVersionInfo = file_get_contents( '../modules/addons/dondominio/version.json' );
$githubVersionInfo = file_get_contents( 'https://raw.githubusercontent.com/dondominio/whmcs-addon/master/version.json' );
// Have we retrieved anything?
if( empty( $localVersionInfo ) || empty( $githubVersionInfo )){
return false;
}
$localJson = json_decode( $localVersionInfo, true );
$githubJson = json_decode( $githubVersionInfo, true );
// Have we decoded the JSONs correctly?
if( !is_array( $localJson ) || !is_array( $githubJson )){
return false;
}
// Comparing the versions found on the JSONs
if( version_compare( $localJson['version'], $githubJson['version'] ) < 0 ){
return $githubJson;
}
return false;
}
/**
* Check the DonDominio Registrar Plugin version.
* @return Array|bool
*/
function dondominio_plugin_version_check()
{
if( !is_dir( '../modules/registrars/dondominio' )){
return false;
}
$localVersionInfo = @file_get_contents( '../modules/registrars/dondominio/version.json' );
$githubVersionInfo = @file_get_contents( 'https://raw.githubusercontent.com/dondominio/whmcs-plugin/master/version.json' );
// Have we retrieved anything?
if( empty( $localVersionInfo ) || empty( $githubVersionInfo )){
return false;
}
$localJson = json_decode( $localVersionInfo, true );
$githubJson = json_decode( $githubVersionInfo, true );
// Have we decoded the JSONs correctly?
if( !is_array( $localJson) || !is_array( $githubJson )){
return false;
}
// Comparing versions found on the JSONs
if( version_compare( $localJson['version'], $githubJson['version'] ) < 0 ){
return $githubJson;
}
return false;
}
function dondominio_version_check()
{
// Getting last time we checked versions
$last_check = dd_get( 'last_version_check' );
if( !empty( $last_check ) && time() - $last_check < 86400 ){
return false;
}
/*
* Checking DonDominio Domain Management Addon version.
*/
if( $version = dondominio_addon_version_check()){
echo "
<a href='https://github.com/dondominio/whmcs-addon'>
<div style='background-color: #F3F3C8; padding: 10px; border: 2px black solid; font-weight: 600;'>
<h1>New Addon version available</h1>
<p>A new version of the DonDominio Addon for WHMCS has been released. Regularly updating the plugin is recommended to get all the features
and avoid future incompatibilities with the DonDominio API.</p>
Click here to download <strong>version " . $version['version'] . " released on " . date( 'd/m/Y', strtotime( $version['releaseDate'] )) . "</strong></a>
</div>
</a>
";
}
/*
* Checking DonDominio Registrar Plugin version.
*/
if( $version = dondominio_plugin_version_check()){
echo "
<a href='https://github.com/dondominio/whmcs-plugin'>
<div style='background-color: #F3F3C8; padding: 10px; border: 2px black solid; font-weight: 600;'>
<h1>DonDominio Registrar Plugin for WHMCS updated</h1>
<p>A new version of the DonDominio Registrar Plugin for WHMCS has been released. Regularly updating the plugin is recommended to get all the features
and avoid future incompatibilities with the DonDominio API.</p>
<p>Click here to download <strong>version " . $version['version'] . " released on " . date( 'd/m/Y', strtotime( $version['releaseDate'] )) . "</strong></a></p>
</div>
</a>
";
}
dd_set( 'last_version_check', time());
}
/**
* Module loader for the DD Addon for WHMCS.
* @param array $vars Parameters from WHMCS
*/
function dondominio_output( $vars )
{
$modulelink = $vars['modulelink'];
$version = $vars['version'];
$LANG = $vars['_lang'];
if( !array_key_exists( 'action', $_REQUEST )){
$_REQUEST['action'] = 'tlds';
}
if( !array_key_exists( 'option', $_REQUEST )){
$_REQUEST['option'] = 'index';
}
/*
* We do not allow to go anywhere before entering API Username & Password.
*/
$username = trim( dd_get( 'api_username' ));
$password = trim( base64_decode( dd_get( 'api_password' )));
if( strlen( $username ) == 0 || strlen( $password ) == 0 ){
$_REQUEST['action'] = 'settings';
$_REQUEST['option'] = 'index';
}
/* * * */
$action = 'dondominio_mod_' . $_REQUEST['action'] . '_' . $_REQUEST['option'];
$path = dirname( __FILE__ ) . "/dondominio_mod_" . $_REQUEST['action'] . ".php";
if( !file_exists( $path )){
echo "<h3>Module not found: " . $_REQUEST['action'] . "</h3>";
return false;
}
require_once $path;
if( !is_callable( $action )){
echo "<h3>Action not found: " . $_REQUEST['action'] . '/' . $_REQUEST['option'] . "</h3>";
return false;
}
dondominio_version_check();
$action( $vars );
}
/**
* Build the sidebar for the addon.
* @param array $vars Parameters from WHMCS
* @return string
*/
function dondominio_sidebar( $vars )
{
$modulelink = $vars['modulelink'];
$version = $vars['version'];
$LANG = $vars['_lang'];
$sidebar = '
<span class="header">
<img src="https://www.dondominio.com/images/favicon_appletouch.png" class="absmiddle" width="16" height="16" /> DonDominio Manager
</span>
<ul class="menu">
<li><a href="' . $modulelink . '&action=tlds">' . $LANG['menu_tlds_update'] . '</a></li>
<li><a href="' . $modulelink . '&action=tlds_new">' . $LANG['menu_tlds_new'] . '</a></li>
<li><a href="' . $modulelink . '&action=domains">' . $LANG['menu_domains'] . '</a></li>
<li><a href="' . $modulelink . '&action=transfer">' . $LANG['menu_transfer'] . '</a></li>
<li><a href="' . $modulelink . '&action=import">' . $LANG['menu_import'] . '</a></li>
<li><a href="' . $modulelink . '&action=suggests">' . $LANG['menu_suggests'] . '</a></li>
<li><a href="' . $modulelink . '&action=whois">' . $LANG['menu_whois'] . '</a></li>
<li><a href="' . $modulelink . '&action=settings">' . $LANG['menu_settings'] . '</a></li>
<li class="divider"> </li>
<li><a href="https://docs.dondominio.com/" target="_api">' . $LANG['menu_help'] . '</a></li>
</ul>
';
return $sidebar;
}
?>