1 | 2 | simandl | <?php |
2 | | | |
3 | | | namespace FreenetRouter\Models\System; |
4 | | | |
5 | | | use FreenetRouter\Libraries\ConfigEntryManagers\AdminEmailManager; |
6 | | | use FreenetRouter\Libraries\ConfigEntryManagers\DomainManager; |
7 | | | use FreenetRouter\Libraries\ConfigEntryManagers\HostnameManager; |
8 | | | use FreenetRouter\Libraries\ConfigEntryManagers\InternalIPv4PoolManager; |
9 | | | use FreenetRouter\Libraries\ConfigEntryManagers\MailServerManager; |
10 | | | use FreenetRouter\Libraries\ConfigEntryManagers\PrimaryDnsManager; |
11 | | | use FreenetRouter\Libraries\ConfigEntryManagers\SecondaryDnsManager; |
12 | | | use FreenetRouter\Libraries\ConfigEntryManagers\WritableManager; |
13 | | | use FreenetRouter\Libraries\ServiceManagers\AccountingServiceManager; |
14 | | | use FreenetRouter\Libraries\ServiceManagers\DHCPServerManager; |
15 | | | use FreenetRouter\Libraries\ServiceManagers\SSHServerManager; |
16 | | | use FreenetRouter\Libraries\ServiceManagers\WebServerManager; |
17 | | | use Phem\Core\Collection; |
18 | | | use Phem\Core\Object; |
19 | | | |
20 | | | /** |
21 | | | * @author Jakub PetrĹžĂlka <kubapet@lbcfree.net> |
22 | | | */ |
23 | | | class System extends Object |
24 | | | { |
25 | | | private static $instance; |
26 | | | |
27 | | | private $overview; |
28 | | | private $services; |
29 | | | private $writeEnabled; |
30 | | | private $activeIPs; |
31 | | | private $totalThroughput; |
32 | | | |
33 | | | /** |
34 | | | * @return System |
35 | | | */ |
36 | | | public static function getInstance() |
37 | | | { |
38 | | | if (self::$instance === null) |
39 | | | { |
40 | | | self::$instance = new self(); |
41 | | | } |
42 | | | return self::$instance; |
43 | | | } |
44 | | | |
45 | | | private function __construct() |
46 | | | { |
47 | | | $this->populateServices(); |
48 | | | $this->populateOverviewEntries(); |
49 | | | } |
50 | | | |
51 | | | private function populateServices() |
52 | | | { |
53 | | | $this->services = new Collection(); |
54 | | | $this->services->add( |
55 | | | new Service("APACHE", "web server", new WebServerManager())); |
56 | | | $this->services->add( |
57 | | | new Service("DHCP", "dhcp server", new DHCPServerManager())); |
58 | | | $this->services->add( |
59 | | | new Service("FIREWALL", "firewall", new WebServerManager())); |
60 | | | $this->services->add( |
61 | | | new Service("MACGUARD", "macguard", new WebServerManager())); |
62 | | | $this->services->add( |
63 | | | new Service("ACCOUNT", "tvorba grafĹŻ", new AccountingServiceManager())); |
64 | | | $this->services->add( |
65 | | | new Service("QUAGGA", "quagga", new WebServerManager())); |
66 | | | $this->services->add( |
67 | | | new Service("SNMP", "snmp", new WebServerManager())); |
68 | | | $this->services->add( |
69 | | | new Service("SSH", "ssh server", new SSHServerManager())); |
70 | | | } |
71 | | | |
72 | | | private function populateOverviewEntries() |
73 | | | { |
74 | | | $this->overview = new Collection(); |
75 | | | $this->overview->add(new ConfigEntry("HOSTNAME", |
76 | | | "nĂĄzev routeru", new HostnameManager())); |
77 | | | $this->overview->add(new ConfigEntry("PRIMARY_DNS", |
78 | | | "primĂĄrnĂ dns server", new PrimaryDnsManager())); |
79 | | | $this->overview->add(new ConfigEntry("SECONDARY_DNS", |
80 | | | "sekundĂĄrnĂ dns server", new SecondaryDnsManager())); |
81 | | | $this->overview->add(new ConfigEntry("DOMAIN", |
82 | | | "domĂŠna", new DomainManager())); |
83 | | | $this->overview->add(new ConfigEntry("INTERNAL_IP", |
84 | | | "vnitĹnĂ rozsahy sĂtÄ", new InternalIPv4PoolManager())); |
85 | | | $this->overview->add(new ConfigEntry("ADMIN_EMAIL", |
86 | | | "email sprĂĄvce", new AdminEmailManager())); |
87 | | | $this->overview->add(new ConfigEntry("MAIL_SERVER", |
88 | | | "mail server", new MailServerManager())); |
89 | | | } |
90 | | | |
91 | | | public function getOverview() |
92 | | | { |
93 | | | return $this->overview; |
94 | | | } |
95 | | | |
96 | | | public function getServices() |
97 | | | { |
98 | | | return $this->services; |
99 | | | } |
100 | | | |
101 | | | public function getWriteEnabled() |
102 | | | { |
103 | | | if ($this->writeEnabled === null) |
104 | | | { |
105 | | | $this->writeEnabled = (new WritableManager())->getValue(); |
106 | | | } |
107 | | | return $this->writeEnabled; |
108 | | | } |
109 | | | |
110 | | | public function getActiveIPs() |
111 | | | { |
112 | | | return $this->activeIPs; |
113 | | | } |
114 | | | |
115 | | | public function getTotalThroughput() |
116 | | | { |
117 | | | return $this->totalThroughput; |
118 | | | } |
119 | | | |
120 | | | public function setOverview($overview) |
121 | | | { |
122 | | | $this->overview = $overview; |
123 | | | } |
124 | | | |
125 | | | public function setServices($services) |
126 | | | { |
127 | | | $this->services = $services; |
128 | | | } |
129 | | | |
130 | | | public function setWriteEnabled($writeEnabled) |
131 | | | { |
132 | | | $wm = new WritableManager(); |
133 | | | $wm->setValue($writeEnabled); |
134 | | | $this->writeEnabled = $wm->getValue(); |
135 | | | } |
136 | | | |
137 | | | public function setActiveIPs($activeIPs) |
138 | | | { |
139 | | | $this->activeIPs = $activeIPs; |
140 | | | } |
141 | | | |
142 | | | public function setTotalThroughput($totalThroughput) |
143 | | | { |
144 | | | $this->totalThroughput = $totalThroughput; |
145 | | | } |
146 | | | |
147 | | | } |