-
Notifications
You must be signed in to change notification settings - Fork 20
/
namesilo.php
2966 lines (2579 loc) · 113 KB
/
namesilo.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use Blesta\Core\Util\Modules\Registrar;
/**
* Namesilo Module
*
* @package blesta
* @subpackage blesta.components.modules.namesilo
* @copyright Copyright (c) 2010, Phillips Data, Inc.
* @link http://www.blesta.com/ Blesta
* @copyright Copyright (c) 2015-2018, NETLINK IT SERVICES
* @link http://www.netlink.ie/ NETLINK
*/
class Namesilo extends Module implements Registrar
{
/**
* @var string Debug email address
*/
private static $debug_to = 'root@localhost';
/**
* @var array Namesilo response codes
*/
private static $codes;
/**
* @var array Pending statutes
*/
private static $pending = ['in_review', 'pending'];
/**
* @var string Default module view path
*/
private static $defaultModuleView;
/**
* Initializes the module
*/
public function __construct()
{
// Load config.json
$this->loadConfig(__DIR__ . DS . 'config.json');
// Load components required by this module
Loader::loadComponents($this, ['Input', 'Record']);
// Load the language required by this module
Language::loadLang('namesilo', null, __DIR__ . DS . 'language' . DS);
// Load configuration
Configure::load('namesilo', __DIR__ . DS . 'config' . DS);
// Get Namesilo response codes
self::$codes = Configure::get('Namesilo.status.codes');
// Set default module view
self::$defaultModuleView = 'components' . DS . 'modules' . DS . 'namesilo' . DS;
}
/**
* Attempts to validate service info. This is the top-level error checking method. Sets Input errors on failure.
*
* @param stdClass $package A stdClass object representing the selected package
* @param array $vars An array of user supplied info to satisfy the request
* @return bool True if the service validates, false otherwise. Sets Input errors when false.
*/
public function validateService($package, array $vars = null)
{
$rules = [];
// Transfers (EPP Code)
if (isset($vars['transfer']) && ($vars['transfer'] == '1' || $vars['transfer'] == true)) {
$rule = [
'auth' => [
'empty' => [
'rule' => ['isEmpty'],
'negate' => true,
'message' => Language::_('Namesilo.!error.epp.empty', true),
'post_format' => 'trim'
]
],
];
$rules = array_merge($rules, $rule);
}
// .us fields
if (isset($vars['usnc']) || isset($vars['usap'])) {
$rule = [
'usnc' => [
'empty' => [
'rule' => ['isEmpty'],
'negate' => true,
'message' => Language::_('Namesilo.!error.US.RegistrantNexus.empty', true),
'post_format' => 'trim',
'final' => true
],
'valid' => [
'rule' => ['array_key_exists', Configure::get('Namesilo.domain_fields.us')['usnc']['options']],
'message' => Language::_('Namesilo.!error.US.RegistrantNexus.invalid', true)
]
],
'usap' => [
'empty' => [
'rule' => ['isEmpty'],
'negate' => true,
'message' => Language::_('Namesilo.!error.US.RegistrantPurpose.empty', true),
'post_format' => 'trim',
'final' => true
],
'valid' => [
'rule' => ['array_key_exists', Configure::get('Namesilo.domain_fields.us')['usap']['options']],
'message' => Language::_('Namesilo.!error.US.RegistrantPurpose.invalid', true)
]
],
];
$rules = array_merge($rules, $rule);
}
// .ca fields
if (isset($vars['calf']) || isset($vars['cawd']) || isset($vars['caln'])) {
$rule = [
'calf' => [
'empty' => [
'rule' => ['isEmpty'],
'negate' => true,
'message' => Language::_('Namesilo.!error.CA.CIRALegalType.empty', true),
'post_format' => 'trim',
'final' => true
],
'valid' => [
'rule' => ['array_key_exists', Configure::get('Namesilo.domain_fields.ca')['calf']['options']],
'message' => Language::_('Namesilo.!error.CA.CIRALegalType.invalid', true)
],
'other' => [
'rule' => ['matches', '/^OTHER$/'],
'negate' => true,
'message' => Language::_('Namesilo.!error.CA.CIRALegalType.other', true)
]
],
'cawd' => [
'empty' => [
'rule' => ['isEmpty'],
'negate' => true,
'message' => Language::_('Namesilo.!error.CA.CIRAWhoisDisplay.empty', true),
'post_format' => 'trim',
'final' => true
],
'valid' => [
'rule' => ['array_key_exists', Configure::get('Namesilo.domain_fields.ca')['cawd']['options']],
'message' => Language::_('Namesilo.!error.CA.CIRAWhoisDisplay.invalid', true)
]
],
'caln' => [
'empty' => [
'rule' => ['isEmpty'],
'negate' => true,
'message' => Language::_('Namesilo.!error.CA.CIRALanguage.empty', true),
'post_format' => 'trim',
'final' => true
],
'valid' => [
'rule' => ['array_key_exists', Configure::get('Namesilo.domain_fields.ca')['caln']['options']],
'message' => Language::_('Namesilo.!error.CA.CIRALanguage.invalid', true)
]
],
];
$rules = array_merge($rules, $rule);
}
if (isset($rules) && count($rules) > 0) {
$this->Input->setRules($rules);
return $this->Input->validates($vars);
}
return true;
}
/**
* Adds the service to the remote server. Sets Input errors on failure,
* preventing the service from being added.
*
* @param stdClass $package A stdClass object representing the selected package
* @param array $vars An array of user supplied info to satisfy the request
* @param stdClass $parent_package A stdClass object representing the parent service's selected package
* (if the current service is an addon service)
* @param stdClass $parent_service A stdClass object representing the parent service of the service being added
* (if the current service is an addon service and parent service has already been provisioned)
* @param string $status The status of the service being added. These include:
*
* - active
* - canceled
* - pending
* - suspended
* @return array A numerically indexed array of meta fields to be stored for this service containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
* @see Module::getModule()
* @see Module::getModuleRow()
*/
public function addService(
$package,
array $vars = null,
$parent_package = null,
$parent_service = null,
$status = 'pending'
) {
$row = $this->getModuleRow($package->module_row);
$api = $this->getApi($row->meta->user, $row->meta->key, $row->meta->sandbox == 'true');
#
# TODO: Handle validation checks
# TODO: Fix nameservers
#
if (isset($vars['domain'])) {
$tld = $this->getTld($vars['domain'], $row);
$vars['domain'] = trim($vars['domain']);
}
$input_fields = array_merge(
Configure::get('Namesilo.domain_fields'),
(array) Configure::get('Namesilo.domain_fields' . $tld),
(array) Configure::get('Namesilo.nameserver_fields'),
(array) Configure::get('Namesilo.transfer_fields'),
['years' => true, 'transfer' => isset($vars['transfer']) ? $vars['transfer'] : 1 ]
);
// .ca and .us domains can't have traditional whois privacy
if ($tld == '.ca' || $tld == '.us') {
unset($input_fields['private']);
}
if (isset($vars['use_module']) && $vars['use_module'] == 'true') {
if ($package->meta->type == 'domain') {
$vars['years'] = 1;
foreach ($package->pricing as $pricing) {
if ($pricing->id == $vars['pricing_id']) {
$vars['years'] = $pricing->term;
break;
}
}
$whois_fields = Configure::get('Namesilo.whois_fields');
// Set all whois info from client ($vars['client_id'])
if (!isset($this->Clients)) {
Loader::loadModels($this, ['Clients']);
}
if (!isset($this->Contacts)) {
Loader::loadModels($this, ['Contacts']);
}
$client = $this->Clients->get($vars['client_id']);
if ($client) {
$contact_numbers = $this->Contacts->getNumbers($client->contact_id);
}
foreach ($whois_fields as $key => $value) {
$input_fields[$value['rp']] = true;
if (strpos($key, 'phone') !== false) {
$vars[$value['rp']] = $this->formatPhone(
isset($contact_numbers[0]) ? $contact_numbers[0]->number : null,
$client->country
);
} else {
$vars[$value['rp']] = (isset($value['lp']) && !empty($value['lp']))
? $client->{$value['lp']}
: 'NA';
}
}
$fields = array_intersect_key($vars, $input_fields);
if (!empty($row->meta->portfolio)) {
$fields['portfolio'] = $row->meta->portfolio;
}
if (!empty($row->meta->payment_id)) {
$fields['payment_id'] = $row->meta->payment_id;
}
// for .ca domains we need to create a special contact to use
if ($tld == '.ca') {
$domains = new NamesiloDomains($api);
$response = $domains->addContacts($vars);
$this->processResponse($api, $response);
if ($this->Input->errors()) {
return;
}
$fields['contact_id'] = $response->response()->contact_id;
}
// Handle transfer
if (isset($vars['auth']) && $vars['auth']) {
$transfer = new NamesiloDomainsTransfer($api);
$response = $transfer->create($fields);
$this->processResponse($api, $response);
if ($this->Input->errors()) {
if (isset($vars['contact_id'])) {
$domains->deleteContacts(['contact_id' => $vars['contact_id']]);
}
return;
}
} else {
// Handle registration
$domains = new NamesiloDomains($api);
$response = $domains->create($fields);
$this->processResponse($api, $response);
if ($this->Input->errors()) {
// if namesilo is running a promotion on registrations we have to work around their system if
// we are doing a multi-year registration
$error = 'Invalid number of years, or no years provided.';
if (reset($this->Input->errors()['errors']) === $error) {
// unset the errors since we are working around it
$this->Input->setErrors([]);
// set the registration length to 1 year and save the remainder for an extension
$total_years = $fields['years'];
$fields['years'] = 1;
$response = $domains->create($fields);
$this->processResponse($api, $response);
// now extend the remainder of the years
$fields['years'] = $total_years - 1;
$response = $domains->renew($fields);
$this->processResponse($api, $response);
}
if (isset($vars['contact_id'])) {
$domains->deleteContacts(['contact_id' => $vars['contact_id']]);
}
return;
}
}
}
}
$meta = [];
$fields = array_intersect_key($vars, $input_fields);
foreach ($fields as $key => $value) {
$meta[] = [
'key' => $key,
'value' => $value,
'encrypted' => 0
];
}
return $meta;
}
/**
* Edits the service on the remote server. Sets Input errors on failure,
* preventing the service from being edited.
*
* @param stdClass $package A stdClass object representing the current package
* @param stdClass $service A stdClass object representing the current service
* @param array $vars An array of user supplied info to satisfy the request
* @param stdClass $parent_package A stdClass object representing the parent service's selected package
* (if the current service is an addon service)
* @param stdClass $parent_service A stdClass object representing the parent service of the service being edited
* (if the current service is an addon service)
* @return array A numerically indexed array of meta fields to be stored for this service containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
* @see Module::getModule()
* @see Module::getModuleRow()
*/
public function editService($package, $service, array $vars = [], $parent_package = null, $parent_service = null)
{
$renew = isset($vars['renew']) ? (int) $vars['renew'] : 0;
if ($renew > 0 && $vars['use_module'] == 'true') {
$this->renewService($package, $service, $parent_package, $parent_service, $renew);
unset($vars['renew']);
}
return null; // All this handled by admin/client tabs instead
}
/**
* Cancels the service on the remote server. Sets Input errors on failure,
* preventing the service from being canceled.
*/
public function cancelService($package, $service, $parent_package = null, $parent_service = null)
{
$row = $this->getModuleRow($package->module_row);
$api = $this->getApi($row->meta->user, $row->meta->key, $row->meta->sandbox == 'true');
if ($package->meta->type == 'domain') {
$fields = $this->serviceFieldsToObject($service->fields);
$domains = new NamesiloDomains($api);
$response = $domains->setAutoRenewal($fields->{'domain'}, false);
$this->processResponse($api, $response);
if ($this->Input->errors()) {
return;
}
}
return;
}
/**
* Suspends the service on the remote server. Sets Input errors on failure,
* preventing the service from being suspended.
*/
public function suspendService($package, $service, $parent_package = null, $parent_service = null)
{
$row = $this->getModuleRow($package->module_row);
$api = $this->getApi($row->meta->user, $row->meta->key, $row->meta->sandbox == 'true');
if ($package->meta->type == 'domain') {
$fields = $this->serviceFieldsToObject($service->fields);
// Make sure auto renew is off
$domains = new NamesiloDomains($api);
$response = $domains->setAutoRenewal($fields->{'domain'}, false);
$this->processResponse($api, $response);
if ($this->Input->errors()) {
return;
}
}
return;
}
/**
* Allows the module to perform an action when the service is ready to renew.
* Sets Input errors on failure, preventing the service from renewing.
*
* @param stdClass $package A stdClass object representing the current package
* @param stdClass $service A stdClass object representing the current service
* @param stdClass $parent_package A stdClass object representing the parent service's selected package
* (if the current service is an addon service)
* @param stdClass $parent_service A stdClass object representing the parent service of the service being renewed
* (if the current service is an addon service)
* @return mixed null to maintain the existing meta fields or a numerically indexed array of meta fields to be
* stored for this service containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
* @see Module::getModule()
* @see Module::getModuleRow()
*/
public function renewService($package, $service, $parent_package = null, $parent_service = null, $years = null)
{
$row = $this->getModuleRow($package->module_row);
$api = $this->getApi($row->meta->user, $row->meta->key, $row->meta->sandbox == 'true');
// Renew domain renewDomain?version=1&type=xml&key=12345&domain=namesilo.com&years=2
if ($package->meta->type == 'domain') {
$fields = $this->serviceFieldsToObject($service->fields);
$vars = [
'domain' => $fields->{'domain'},
'years' => 1
];
if (!$years) {
foreach ($package->pricing as $pricing) {
if ($pricing->id == $service->pricing_id) {
$vars['years'] = $pricing->term;
break;
}
}
} else {
$vars['years'] = $years;
}
$domains = new NamesiloDomains($api);
$response = $domains->renew($vars);
$this->processResponse($api, $response);
if ($this->Input->errors()) {
return;
}
}
return null;
}
/**
* Validates input data when attempting to add a package, returns the meta
* data to save when adding a package. Performs any action required to add
* the package on the remote server. Sets Input errors on failure,
* preventing the package from being added.
*
* @param array An array of key/value pairs used to add the package
* @return array A numerically indexed array of meta fields to be stored for this package containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
* @see Module::getModule()
* @see Module::getModuleRow()
*/
public function addPackage(array $vars = null)
{
$meta = [];
if (isset($vars['meta']) && is_array($vars['meta'])) {
// Return all package meta fields
foreach ($vars['meta'] as $key => $value) {
$meta[] = [
'key' => $key,
'value' => $value,
'encrypted' => 0
];
}
}
return $meta;
}
/**
* Validates input data when attempting to edit a package, returns the meta
* data to save when editing a package. Performs any action required to edit
* the package on the remote server. Sets Input errors on failure,
* preventing the package from being edited.
*
* @param stdClass $package A stdClass object representing the selected package
* @param array An array of key/value pairs used to edit the package
* @return array A numerically indexed array of meta fields to be stored for this package containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
* @see Module::getModule()
* @see Module::getModuleRow()
*/
public function editPackage($package, array $vars = null)
{
$meta = [];
if (isset($vars['meta']) && is_array($vars['meta'])) {
// Return all package meta fields
foreach ($vars['meta'] as $key => $value) {
$meta[] = [
'key' => $key,
'value' => $value,
'encrypted' => 0
];
}
}
return $meta;
}
/**
* Returns the rendered view of the manage module page
*
* @param mixed $module A stdClass object representing the module and its rows
* @param array $vars An array of post data submitted to or on the manage module page
* (used to repopulate fields after an error)
* @return string HTML content containing information to display when viewing the manager module page
*/
public function manageModule($module, array &$vars)
{
$action = isset($_GET['action']) ? $_GET['action'] : null;
// Load the required models
Loader::loadModels($this, ['Languages', 'Settings', 'Currencies', 'Packages']);
if ($action == 'manage_packages') {
// Load Namesilo packages
Loader::load(__DIR__ . DS . 'includes' . DS . 'namesilo_packages.php');
$this->NamesiloPackages = new NamesiloPackages();
$post = $vars;
$vars = [];
$this->view = new View('manage_packages', 'default');
$this->view->base_uri = $this->base_uri;
$this->view->setDefaultView(self::$defaultModuleView);
// Load the helpers required for this view
Loader::loadHelpers($this, ['Form', 'Html', 'Javascript', 'Widget', 'CurrencyFormat']);
// Fetch TLD prices
$tlds = $this->getPrices();
// Get all currencies
$currencies = $this->Form->collapseObjectArray(
$this->Currencies->getAll(Configure::get('Blesta.company_id')),
'code',
'code'
);
// Fetch module rows
$module_rows = $this->getRowsOptions();
// Fetch all available package groups
$package_groups = $this->Form->collapseObjectArray(
$this->Packages->getAllGroups(Configure::get('Blesta.company_id')),
'name',
'id'
);
// Fetch all installed languages
$languages = $this->Languages->getAll(Configure::get('Blesta.company_id'));
// Calculate maximum packages that can be saved at a time
$count_fields_per_currency = 5;
$count_fields_per_language = 7;
$count_settings_fields = 16;
$max_packages = round(
(
(ini_get('max_input_vars') - (count($languages) * $count_fields_per_language) - $count_settings_fields) /
((count($currencies) * $count_fields_per_currency) + 1)
),
0,
PHP_ROUND_HALF_DOWN
);
// Save packages
if (!empty($post)) {
$this->NamesiloPackages->process($post);
if (($errors = $this->NamesiloPackages->errors())) {
$this->setMessage('error', reset($errors));
} else {
$this->setMessage(
'success',
Language::_(
'Namesilo.!success.packages_saved',
true
)
);
}
}
// Fetch stored settings
$module_row = $this->getRow();
$settings = $this->NamesiloPackages->getSettings($module_row->id);
$post = array_merge($settings, $post);
// Set view
$this->view->set('tlds', $tlds);
$this->view->set('module_rows', $module_rows);
$this->view->set('languages', $languages);
$this->view->set('currencies', $currencies);
$this->view->set('package_groups', $package_groups);
$this->view->set('max_packages', $max_packages);
$this->view->set('vars', !empty($post) ? (object)$post : (object)$settings);
$this->view->set('messages', $this->getMessages());
$this->view->set('package_name_tags', $this->getPackageNameTags());
return $this->view->fetch();
} elseif ($action == 'tld_rows') {
// Load Namesilo packages
Loader::load(__DIR__ . DS . 'includes' . DS . 'namesilo_packages.php');
$this->NamesiloPackages = new NamesiloPackages();
// Fetch stored packages vars, if available
$module_row = $this->getRow();
$settings = $this->NamesiloPackages->getSettings($module_row->id);
$this->view = new View('tld_rows', 'default');
$this->view->base_uri = $this->base_uri;
$this->view->setDefaultView(self::$defaultModuleView);
// Load the helpers required for this view
Loader::loadHelpers($this, ['Form', 'Html', 'CurrencyFormat']);
// Fetch TLD prices
$tlds = $this->getPrices();
$tld = array_key_exists('.' . $_GET['tld'], $tlds) ? '.' . $_GET['tld'] : null;
// Get all currencies
$currencies = $this->Form->collapseObjectArray(
$this->Currencies->getAll(Configure::get('Blesta.company_id')),
'code',
'code'
);
// Set view
$this->view->set('tld', $tld);
$this->view->set('pricing', $tlds[$tld]);
$this->view->set('currencies', $currencies);
$this->view->set('vars', !empty($vars) ? (object)$vars : (object)$settings);
$this->view->set('messages', $this->getMessages());
$this->view->set('package_name_tags', $this->getPackageNameTags());
echo $this->view->fetch();
exit;
} else {
// Load the view into this object, so helpers can be automatically added to the view
$this->view = new View('manage', 'default');
$this->view->base_uri = $this->base_uri;
$this->view->setDefaultView(self::$defaultModuleView);
// Load the helpers required for this view
Loader::loadHelpers($this, ['Form', 'Html', 'Widget']);
#
#
# TODO: add tab to check status of all transfers: check if possible with Namesilo...
# ref: NamesiloDomainsTransfer->getList()
#
#
$link_buttons = [];
foreach ($module->rows as $row) {
if (isset($row->meta->key)) {
$link_buttons = [
[
'name' => Language::_('Namesilo.manage.manage_packages', true),
'attributes' => [
'href' => [
'href' => $this->base_uri . 'settings/company/modules/manage/'
. $module->id . '?action=manage_packages'
]
]
],
[
'name' => Language::_('Namesilo.manage.sync_renew_dates', true),
'attributes' => [
'href' => [
'href' => $this->base_uri . 'settings/company/modules/addrow/'
. $module->id . '?action=sync_renew_dates'
]
]
],
[
'name' => Language::_('Namesilo.manage.audit_domains', true),
'attributes' => [
'href' => $this->base_uri . 'settings/company/modules/addrow/'
. $module->id . '?action=audit_domains'
]
]
];
break;
}
}
$this->view->set('module', $module);
$this->view->set('link_buttons', $link_buttons);
$this->view->set('module', $module);
return $this->view->fetch();
}
}
/**
* Returns the rendered view of the add module row page
*
* @param array $vars An array of post data submitted to or on the add module row page
* (used to repopulate fields after an error)
* @return string HTML content containing information to display when viewing the add module row page
*/
public function manageAddRow(array &$vars)
{
$action = isset($_GET['action']) ? $_GET['action'] : null;
// Load the view into this object, so helpers can be automatically added to the view
$this->view = new View((!empty($action) ? $action : 'add_row'), 'default');
$this->view->base_uri = $this->base_uri;
$this->view->setDefaultView(self::$defaultModuleView);
// Load the helpers and models required for this view
Loader::loadHelpers($this, ['Form', 'Html', 'Widget']);
Loader::loadModels($this, ['Services', 'ModuleManager', 'Clients', 'ClientGroups']);
if ($action == 'audit_domains') {
$vars = [];
$module_row = $this->getRow();
$api = $this->getApi(
$module_row->meta->user,
$module_row->meta->key,
$module_row->meta->sandbox == 'true',
null,
true
);
$domains = new NamesiloDomains($api);
if ($module_row->meta->portfolio) {
$vars['portfolio'] = $module_row->meta->portfolio;
}
$response = $domains->getList($vars)->response();
$domain_list = $this->Html->ifSet($response->domains->domain);
$vars['domains'] = [];
if (!empty($domain_list)) {
foreach ($domain_list as $domain) {
$record = $this->Record->select()
->from('services')
->leftJoin('service_fields', 'services.id', '=', 'service_fields.service_id', false)
->where('services.status', 'IN', ['active', 'suspended'])
->where('service_fields.value', '=', $domain)
->where('services.module_row_id', '=', $module_row->id)
->where('service_fields.key', '=', 'domain')
->numResults();
if (!$record) {
$vars['domains'][] = $domain;
}
}
}
// Set view
$this->view->set('vars', (object)$vars);
return $this->view->fetch();
} elseif ($action == 'sync_renew_dates') {
if (isset($vars['sync_services'])) {
$post['sync_services'] = $vars['sync_services'];
}
$module_row = $this->getRow();
$api = $this->getApi(
$module_row->meta->user,
$module_row->meta->key,
$module_row->meta->sandbox == 'true',
null,
true
);
$domains = new NamesiloDomains($api);
$services = $this->Record->select(['services.id', 'services.client_id'])
->from('services')
->where('module_row_id', '=', $module_row->id)
->where('status', '=', 'active')
->fetchAll();
$vars['changes'] = [];
foreach ($services as $service_id) {
$vars['changes'][] = $this->getRenewInfo($service_id->id, $domains);
}
// Set view
$this->view->set('vars', $vars);
return $this->view->fetch();
} else {
// Set unspecified checkboxes
if (!empty($vars)) {
if (empty($vars['sandbox'])) {
$vars['sandbox'] = 'false';
}
}
// Set view
$this->view->set('vars', (object)$vars);
return $this->view->fetch();
}
}
/**
* Returns the rendered view of the edit module row page
*
* @param stdClass $module_row The stdClass representation of the existing module row
* @param array $vars An array of post data submitted to or on the edit module row page
* (used to repopulate fields after an error)
* @return string HTML content containing information to display when viewing the edit module row page
*/
public function manageEditRow($module_row, array &$vars)
{
// Load the view into this object, so helpers can be automatically added to the view
$this->view = new View('edit_row', 'default');
$this->view->base_uri = $this->base_uri;
$this->view->setDefaultView(self::$defaultModuleView);
// Load the helpers required for this view
Loader::loadHelpers($this, ['Form', 'Html', 'Widget']);
if (empty($vars)) {
$vars = $module_row->meta;
} else {
// Set unspecified checkboxes
if (empty($vars['sandbox'])) {
$vars['sandbox'] = 'false';
}
}
$this->view->set('vars', (object)$vars);
return $this->view->fetch();
}
/**
* Adds the module row on the remote server. Sets Input errors on failure,
* preventing the row from being added.
*
* @param array $vars An array of module info to add
* @return array A numerically indexed array of meta fields for the module row containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
*/
public function addModuleRow(array &$vars)
{
if (isset($vars['sync_services'])) {
Loader::loadModels($this, ['ModuleManager', 'Services', 'Clients', 'ClientGroups']);
$module_row = $this->getRow();
foreach ($vars['sync_services'] as $service_id) {
$api = $this->getApi(
$module_row->meta->user,
$module_row->meta->key,
$module_row->meta->sandbox == 'true',
null,
true
);
$domains = new NamesiloDomains($api);
$info = $this->getRenewInfo($service_id, $domains);
$this->Services->edit($service_id, ['date_renews' => $info['date_after']], true);
}
$url = explode('?', $_SERVER['REQUEST_URI']);
header('Location:' . $url[0].'?action=sync_renew_dates&msg=success');
exit();
}
$meta_fields = ['user', 'key', 'sandbox', 'portfolio', 'payment_id', 'namesilo_module'];
$encrypted_fields = ['key'];
// Set unspecified checkboxes
if (empty($vars['sandbox'])) {
$vars['sandbox'] = 'false';
}
$this->Input->setRules($this->getRowRules($vars));
// Validate module row
if ($this->Input->validates($vars)) {
// Build the meta data for this row
$meta = [];
foreach ($vars as $key => $value) {
if (in_array($key, $meta_fields)) {
$meta[] = [
'key' => $key,
'value' => $value,
'encrypted' => in_array($key, $encrypted_fields) ? 1 : 0
];
}
}
return $meta;
}
}
/**
* Edits the module row on the remote server. Sets Input errors on failure,
* preventing the row from being updated.
*
* @param stdClass $module_row The stdClass representation of the existing module row
* @param array $vars An array of module info to update
* @return array A numerically indexed array of meta fields for the module row containing:
*
* - key The key for this meta field
* - value The value for this key
* - encrypted Whether or not this field should be encrypted (default 0, not encrypted)
*/
public function editModuleRow($module_row, array &$vars)
{
$meta_fields = ['user', 'key', 'sandbox', 'portfolio', 'payment_id', 'namesilo_module'];
$encrypted_fields = ['key'];
// Merge package settings on to the module row meta
$module_row_meta = array_merge((array)$module_row->meta, $vars);
// Set unspecified checkboxes
if (empty($meta['sandbox'])) {
$meta['sandbox'] = 'false';
}
$this->Input->setRules($this->getRowRules($vars));
// Validate module row
if ($this->Input->validates($vars)) {
// Build the meta data for this row
$meta = [];
foreach ($module_row_meta as $key => $value) {
if (in_array($key, $meta_fields) || array_key_exists($key, (array)$module_row->meta)) {
$meta[] = [
'key' => $key,
'value' => $value,
'encrypted' => in_array($key, $encrypted_fields) ? 1 : 0
];
}
}
#die(var_export( $meta, true ) );