1+ <?php
2+ /**
3+ * ICANN MoSAPI Registrar Monitor for FOSSBilling
4+ *
5+ * Written in 2026 by Taras Kondratyuk (https://namingo.org)
6+ * Based on example modules and inspired by existing modules of FOSSBilling
7+ * (https://www.fossbilling.org) and BoxBilling.
8+ *
9+ * @license Apache-2.0
10+ * @see https://www.apache.org/licenses/LICENSE-2.0
11+ */
12+
13+ namespace Box \Mod \Mosapimonitor \Controller ;
14+
15+ class Admin implements \FOSSBilling \InjectionAwareInterface
16+ {
17+ protected $ di ;
18+
19+ public function setDi (\Pimple \Container |null $ di ): void
20+ {
21+ $ this ->di = $ di ;
22+ }
23+
24+ public function getDi (): ?\Pimple \Container
25+ {
26+ return $ this ->di ;
27+ }
28+
29+ public function fetchNavigation (): array
30+ {
31+ return [
32+ 'subpages ' => [
33+ [
34+ 'location ' => 'extensions ' ,
35+ 'label ' => __trans ('MoSAPI Monitor ' ),
36+ 'index ' => 2000 ,
37+ 'uri ' => $ this ->di ['url ' ]->adminLink ('mosapimonitor ' ),
38+ 'class ' => '' ,
39+ ],
40+ ],
41+ ];
42+ }
43+
44+ public function register (\Box_App &$ app ): void
45+ {
46+ $ app ->get ('/mosapimonitor ' , 'get_index ' , [], static ::class);
47+ $ app ->post ('/mosapimonitor ' , 'get_index ' , [], static ::class);
48+ }
49+
50+ public function get_index (\Box_App $ app ): string
51+ {
52+ $ this ->checkAccess ();
53+
54+ $ service = $ this ->di ['mod_service ' ]('mosapimonitor ' );
55+ $ cfg = $ service ->getConfig ();
56+
57+ $ forceRefresh = (bool )$ this ->di ['request ' ]->get ('refresh ' , false );
58+
59+ $ data = null ;
60+ $ error = null ;
61+
62+ if ($ service ->isConfigured ($ cfg )) {
63+ try {
64+ $ data = $ service ->getData ($ cfg , $ forceRefresh );
65+ } catch (\Throwable $ e ) {
66+ $ error = $ e ->getMessage ();
67+ }
68+ }
69+
70+ return $ app ->render ('mod_mosapimonitor_index ' , [
71+ 'cfg ' => $ cfg ,
72+ 'configured ' => $ service ->isConfigured ($ cfg ),
73+ 'data ' => $ data ,
74+ 'error ' => $ error ,
75+ ]);
76+ }
77+
78+ public function post_index (\Box_App $ app ): void
79+ {
80+ $ this ->checkAccess ();
81+
82+ $ service = $ this ->di ['mod_service ' ]('mosapimonitor ' );
83+
84+ $ payload = [
85+ 'base_url ' => trim ((string )$ this ->di ['request ' ]->get ('base_url ' , '' )),
86+ 'username ' => trim ((string )$ this ->di ['request ' ]->get ('username ' , '' )),
87+ 'password ' => (string )$ this ->di ['request ' ]->get ('password ' , '' ),
88+ 'timeout ' => trim ((string )$ this ->di ['request ' ]->get ('timeout ' , '10 ' )),
89+ 'cache_ttl ' => trim ((string )$ this ->di ['request ' ]->get ('cache_ttl ' , '290 ' )),
90+ 'show_domains ' => $ this ->di ['request ' ]->get ('show_domains ' , null ) ? '1 ' : '0 ' ,
91+ 'source_ip ' => trim ((string )$ this ->di ['request ' ]->get ('source_ip ' , '' )),
92+ ];
93+
94+ $ service ->saveConfig ($ payload );
95+
96+ $ this ->di ['tools ' ]->redirect ('/mosapimonitor ' );
97+ }
98+
99+ private function checkAccess (): void
100+ {
101+ $ this ->di ['mod_service ' ]('Staff ' )->checkPermissionsAndThrowException ('mosapimonitor ' , 'access ' );
102+ }
103+
104+ }
0 commit comments