1<?php
2/*
3	FusionPBX
4	Version: MPL 1.1
5
6	The contents of this file are subject to the Mozilla Public License Version
7	1.1 (the "License"); you may not use this file except in compliance with
8	the License. You may obtain a copy of the License at
9	http://www.mozilla.org/MPL/
10
11	Software distributed under the License is distributed on an "AS IS" basis,
12	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13	for the specific language governing rights and limitations under the
14	License.
15
16	The Original Code is FusionPBX
17
18	The Initial Developer of the Original Code is
19	Mark J Crane <markjcrane@fusionpbx.com>
20	Portions created by the Initial Developer are Copyright (C) 2008-2012
21	the Initial Developer. All Rights Reserved.
22
23	Contributor(s):
24	Mark J Crane <markjcrane@fusionpbx.com>
25*/
26include "root.php";
27require_once "resources/require.php";
28require_once "resources/check_auth.php";
29if (permission_exists('module_view')) {
30	//access granted
31}
32else {
33	echo "access denied";
34	exit;
35}
36
37//add multi-lingual support
38	$language = new text;
39	$text = $language->get();
40
41//get includes and the title
42	require_once "resources/header.php";
43	$document['title'] = $text['title-modules'];
44	require_once "resources/paging.php";
45
46//get the http values ans set as variables
47	$order_by = $_GET["order_by"];
48	$order = $_GET["order"];
49
50$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
51if (strlen($_GET["a"]) > 0) {
52	if ($_GET["a"] == "stop") {
53		$module_name = $_GET["m"];
54		if ($fp) {
55			$cmd = "api unload $module_name";
56			$response = trim(event_socket_request($fp, $cmd));
57			$msg = "<strong>".$text['label-unload_module'].":</strong> <pre>".$response."</pre>";
58		}
59	}
60	if ($_GET["a"] == "start") {
61		$module_name = $_GET["m"];
62		if ($fp) {
63			$cmd = "api load $module_name";
64			$response = trim(event_socket_request($fp, $cmd));
65			$msg = "<strong>".$text['label-load_module'].":</strong> <pre>".$response."</pre>";
66		}
67	}
68}
69
70$esl_alive = false;
71if($fp){
72	$esl_alive = true;
73	fclose($fp);
74}
75
76//Warning if FS not start
77	if(!$esl_alive){
78		$msg = "<div align='center'>".$text['error-event-socket']."<br /></div>";
79		echo "<div align='center'>\n";
80		echo "<table width='40%'>\n";
81		echo "<tr>\n";
82		echo "<th align='left'>".$text['label-message']."</th>\n";
83		echo "</tr>\n";
84		echo "<tr>\n";
85		echo "<td class='row_style1'><strong>$msg</strong></td>\n";
86		echo "</tr>\n";
87		echo "</table>\n";
88		echo "</div>\n";
89	}
90
91//use the module class to get the list of modules from the db and add any missing modules
92	$module = new modules;
93	$module->db = $db;
94	$module->dir = $_SESSION['switch']['mod']['dir'];
95	$module->get_modules();
96	$result = $module->modules;
97	$module_count = count($result);
98	$module->synch();
99	$module->xml();
100	$msg = $module->msg;
101
102//show the msg
103	if ($msg) {
104		echo "<div align='center'>\n";
105		echo "<table width='40%'>\n";
106		echo "<tr>\n";
107		echo "<th align='left'>".$text['label-message']."</th>\n";
108		echo "</tr>\n";
109		echo "<tr>\n";
110		echo "<td class='row_style1'>$msg</td>\n";
111		echo "</tr>\n";
112		echo "</table>\n";
113		echo "</div>\n";
114	}
115
116//show the content
117	echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr>\n";
118	echo "<td align='left' nowrap><b>".$text['header-modules']."</b></td>\n";
119	echo "</tr>\n";
120	echo "<tr>\n";
121	echo "<td align='left'>".$text['description-modules']."</td>\n";
122	echo "</tr>\n";
123	echo "</table>\n";
124
125	$c = 0;
126	$row_style["0"] = "row_style0";
127	$row_style["1"] = "row_style1";
128
129	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
130	$tmp_module_header = "\n";
131	$tmp_module_header .= "<tr>\n";
132	$tmp_module_header .= "<th>".$text['label-label']."</th>\n";
133	$tmp_module_header .= "<th>".$text['label-status']."</th>\n";
134	$tmp_module_header .= "<th>".$text['label-action']."</th>\n";
135	$tmp_module_header .= "<th>".$text['label-enabled']."</th>\n";
136	$tmp_module_header .= "<th>".$text['label-description']."</th>\n";
137	$tmp_module_header .= "<td class='list_control_icons'>";
138	$tmp_module_header .= "<a href='module_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
139	$tmp_module_header .= "</td>\n";
140	$tmp_module_header .= "<tr>\n";
141
142	if ($module_count > 0) {
143		$prev_module_category = '';
144		foreach($result as $row) {
145			if ($prev_module_category != $row["module_category"]) {
146				$c=0;
147				if (strlen($prev_module_category) > 0) {
148					echo "<tr>\n";
149					echo "<td colspan='6'>\n";
150					echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
151					echo "	<tr>\n";
152					echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
153					echo "		<td width='33.3%' align='center' nowrap>&nbsp;</td>\n";
154					echo "		<td width='33.3%' align='right'>\n";
155					if (permission_exists('module_add')) {
156						echo "			<a href='module_edit.php' alt='add'>$v_link_label_add</a>\n";
157					}
158					echo "		</td>\n";
159					echo "	</tr>\n";
160					echo "	</table>\n";
161					echo "</td>\n";
162					echo "</tr>\n";
163				}
164				echo "<tr><td colspan='4' align='left'>\n";
165				echo "	<br />\n";
166				echo "	<br />\n";
167				echo "	<b>".$row["module_category"]."</b>&nbsp;</td></tr>\n";
168				echo $tmp_module_header;
169			}
170
171			$tr_link = (permission_exists('module_edit')) ? "href='module_edit.php?id=".$row["module_uuid"]."'" : null;
172			echo "<tr ".$tr_link.">\n";
173			echo "   <td valign='top' class='".$row_style[$c]."'>";
174			if (permission_exists('module_edit')) {
175				echo "<a href='module_edit.php?id=".$row["module_uuid"]."'>".$row["module_label"]."</a>";
176			}
177			else {
178				echo $row["module_label"];
179			}
180			echo "	</td>\n";
181			if($esl_alive) {
182				if ($module->active($row["module_name"])) {
183					echo "   <td valign='top' class='".$row_style[$c]."'>".$text['label-running']."</td>\n";
184					echo "   <td valign='top' class='".$row_style[$c]."'><a href='modules.php?a=stop&m=".$row["module_name"]."' alt='".$text['label-stop']."'>".$text['label-stop']."</a></td>\n";
185				}
186				else {
187					if ($row['module_enabled']=="true") {
188						echo "   <td valign='top' class='".$row_style[$c]."'><b>".$text['label-stopped']."</b></td>\n";
189					}
190					else {
191						echo "   <td valign='top' class='".$row_style[$c]."'>".$text['label-stopped']." ".$notice."</td>\n";
192					}
193					echo "   <td valign='top' class='".$row_style[$c]."'><a href='modules.php?a=start&m=".$row["module_name"]."' alt='".$text['label-start']."'>".$text['label-start']."</a></td>\n";
194				}
195			}
196			else{
197				echo "   <td valign='top' class='".$row_style[$c]."'>".$text['label-unknown']."</td>\n";
198				echo "   <td valign='top' class='".$row_style[$c]."'>".$text['label-none']."</td>\n";
199			}
200			echo "   <td valign='top' class='".$row_style[$c]."'>";
201			if ($row["module_enabled"] == "true") {
202				echo $text['option-true'];
203			}
204			else if ($row["module_enabled"] == "false") {
205				echo $text['option-false'];
206			}
207			echo "</td>\n";
208			echo "	<td valign='top' class='row_stylebg'>".$row["module_description"]."&nbsp;</td>\n";
209			echo "   <td class='list_control_icons'>";
210			if (permission_exists('module_edit')) {
211				echo "<a href='module_edit.php?id=".$row["module_uuid"]."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
212			}
213			if (permission_exists('module_delete')) {
214				echo "<a href='module_delete.php?id=".$row["module_uuid"]."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
215			}
216			echo "</td>\n";
217			echo "</tr>\n";
218
219			$prev_module_category = $row["module_category"];
220			if ($c==0) { $c=1; } else { $c=0; }
221		} //end foreach
222		unset($sql, $modules, $row_count);
223	} //end if results
224
225	echo "<tr>\n";
226	echo "<td colspan='6'>\n";
227	echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
228	echo "	<tr>\n";
229	echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
230	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
231	echo "		<td class='list_control_icons'>";
232	if (permission_exists('module_add')) {
233		echo "<a href='module_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
234	}
235	echo "</td>\n";
236	echo "	</tr>\n";
237	echo "	</table>\n";
238	echo "</td>\n";
239	echo "</tr>\n";
240
241	echo "</table>";
242	echo "<br><br>";
243
244//show the footer
245	require_once "resources/footer.php";
246?>