Rev 1138 | Rev 1199 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1138 | Rev 1143 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | namespace ViaThinkSoft\OIDplus; |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | // phpcs:disable PSR1.Files.SideEffects |
22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusPageAdminSystemConfig extends OIDplusPagePluginAdmin { |
26 | class OIDplusPageAdminSystemConfig extends OIDplusPagePluginAdmin { |
27 | 27 | ||
28 | /** |
28 | /** |
29 | * @param string $actionID |
29 | * @param string $actionID |
30 | * @param array $params |
30 | * @param array $params |
31 | * @return int[] |
31 | * @return array |
32 | * @throws OIDplusException |
32 | * @throws OIDplusException |
33 | */ |
33 | */ |
34 | public function action(string $actionID, array $params): array { |
34 | public function action(string $actionID, array $params): array { |
35 | if ($actionID == 'config_update') { |
35 | if ($actionID == 'config_update') { |
36 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
36 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
37 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
37 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
38 | } |
38 | } |
39 | 39 | ||
40 | _CheckParamExists($params, 'name'); |
40 | _CheckParamExists($params, 'name'); |
41 | _CheckParamExists($params, 'value'); |
41 | _CheckParamExists($params, 'value'); |
42 | 42 | ||
43 | $name = $params['name']; |
43 | $name = $params['name']; |
44 | $value = $params['value']; |
44 | $value = $params['value']; |
45 | 45 | ||
46 | $res = OIDplus::db()->query("select protected, visible from ###config where name = ?", array($name)); |
46 | $res = OIDplus::db()->query("select protected, visible from ###config where name = ?", array($name)); |
47 | if (!$res->any()) { |
47 | if (!$res->any()) { |
48 | throw new OIDplusException(_L('Setting does not exist')); |
48 | throw new OIDplusException(_L('Setting does not exist')); |
49 | } |
49 | } |
50 | $row = $res->fetch_array(); |
50 | $row = $res->fetch_array(); |
51 | if (($row['protected'] == 1) || ($row['visible'] == 0)) { |
51 | if (($row['protected'] == 1) || ($row['visible'] == 0)) { |
52 | throw new OIDplusException(_L("Setting %1 is read-only",$name)); |
52 | throw new OIDplusException(_L("Setting %1 is read-only",$name)); |
53 | } |
53 | } |
54 | 54 | ||
55 | OIDplus::config()->setValue($name, $value); |
55 | OIDplus::config()->setValue($name, $value); |
56 | OIDplus::logger()->log("[OK]A?", "Changed system config setting '$name' to '$value'"); |
56 | OIDplus::logger()->log("[OK]A?", "Changed system config setting '$name' to '$value'"); |
57 | 57 | ||
58 | return array("status" => 0); |
58 | return array("status" => 0); |
59 | } else { |
59 | } else { |
60 | return parent::action($actionID, $params); |
60 | return parent::action($actionID, $params); |
61 | } |
61 | } |
62 | } |
62 | } |
63 | 63 | ||
64 | /** |
64 | /** |
65 | * @param bool $html |
65 | * @param bool $html |
66 | * @return void |
66 | * @return void |
67 | */ |
67 | */ |
68 | public function init(bool $html=true) { |
68 | public function init(bool $html=true) { |
69 | // Nothing |
69 | // Nothing |
70 | } |
70 | } |
71 | 71 | ||
72 | /** |
72 | /** |
73 | * @param string $id |
73 | * @param string $id |
74 | * @param array $out |
74 | * @param array $out |
75 | * @param bool $handled |
75 | * @param bool $handled |
76 | * @return void |
76 | * @return void |
77 | * @throws OIDplusException |
77 | * @throws OIDplusException |
78 | */ |
78 | */ |
79 | public function gui(string $id, array &$out, bool &$handled) { |
79 | public function gui(string $id, array &$out, bool &$handled) { |
80 | if (explode('$',$id)[0] == 'oidplus:edit_config') { |
80 | if (explode('$',$id)[0] == 'oidplus:edit_config') { |
81 | $handled = true; |
81 | $handled = true; |
82 | $out['title'] = _L('System configuration'); |
82 | $out['title'] = _L('System configuration'); |
83 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
83 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
84 | 84 | ||
85 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
85 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
86 | $out['icon'] = 'img/error.png'; |
86 | $out['icon'] = 'img/error.png'; |
87 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
87 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
88 | return; |
88 | return; |
89 | } |
89 | } |
90 | 90 | ||
91 | $output = '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
91 | $output = '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
92 | $output .= '<table class="table table-bordered table-striped">'; |
92 | $output .= '<table class="table table-bordered table-striped">'; |
93 | $output .= '<thead>'; |
93 | $output .= '<thead>'; |
94 | $output .= ' <tr>'; |
94 | $output .= ' <tr>'; |
95 | $output .= ' <th>'._L('Setting').'</th>'; |
95 | $output .= ' <th>'._L('Setting').'</th>'; |
96 | $output .= ' <th>'._L('Description').'</th>'; |
96 | $output .= ' <th>'._L('Description').'</th>'; |
97 | $output .= ' <th>'._L('Value').'</th>'; |
97 | $output .= ' <th>'._L('Value').'</th>'; |
98 | $output .= ' <th>'._L('Update').'</th>'; |
98 | $output .= ' <th>'._L('Update').'</th>'; |
99 | $output .= ' </tr>'; |
99 | $output .= ' </tr>'; |
100 | $output .= '</thead>'; |
100 | $output .= '</thead>'; |
101 | $output .= '<tbody>'; |
101 | $output .= '<tbody>'; |
102 | 102 | ||
103 | OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select |
103 | OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select |
104 | 104 | ||
105 | $result = OIDplus::db()->query("select * from ###config where visible = ? order by name", array(true)); |
105 | $result = OIDplus::db()->query("select * from ###config where visible = ? order by name", array(true)); |
106 | while ($row = $result->fetch_object()) { |
106 | while ($row = $result->fetch_object()) { |
107 | $output .= '<tr>'; |
107 | $output .= '<tr>'; |
108 | $output .= ' <td>'.htmlentities($row->name).'</td>'; |
108 | $output .= ' <td>'.htmlentities($row->name).'</td>'; |
109 | $output .= ' <td>'.htmlentities($row->description).'</td>'; |
109 | $output .= ' <td>'.htmlentities($row->description).'</td>'; |
110 | if ($row->protected == 1) { |
110 | if ($row->protected == 1) { |
111 | $desc = $row->value; |
111 | $desc = $row->value; |
112 | if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...'; |
112 | if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...'; |
113 | $output .= ' <td style="word-break: break-all;">'.htmlentities($desc).'</td>'; |
113 | $output .= ' <td style="word-break: break-all;">'.htmlentities($desc).'</td>'; |
114 | $output .= ' <td> </td>'; |
114 | $output .= ' <td> </td>'; |
115 | } else { |
115 | } else { |
116 | $output .= ' <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>'; |
116 | $output .= ' <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>'; |
117 | $output .= ' <td><button type="button" name="config_update_'.$row->name.'" id="config_update_'.$row->name.'" class="btn btn-success btn-xs update" onclick="OIDplusPageAdminSystemConfig.crudActionConfigUpdate('.js_escape($row->name).')">'._L('Update').'</button></td>'; |
117 | $output .= ' <td><button type="button" name="config_update_'.$row->name.'" id="config_update_'.$row->name.'" class="btn btn-success btn-xs update" onclick="OIDplusPageAdminSystemConfig.crudActionConfigUpdate('.js_escape($row->name).')">'._L('Update').'</button></td>'; |
118 | } |
118 | } |
119 | $output .= '</tr>'; |
119 | $output .= '</tr>'; |
120 | } |
120 | } |
121 | 121 | ||
122 | $output .= '</tbody>'; |
122 | $output .= '</tbody>'; |
123 | $output .= '</table>'; |
123 | $output .= '</table>'; |
124 | $output .= '</div></div>'; |
124 | $output .= '</div></div>'; |
125 | 125 | ||
126 | $output .= '<br><p>'._L('See also').':</p>'; |
126 | $output .= '<br><p>'._L('See also').':</p>'; |
127 | $output .= '<ul>'; |
127 | $output .= '<ul>'; |
128 | $output .= '<li><a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Setup part 1: Create %1 (contains database settings, CAPTCHA, admin password and SSL enforcement)','userdata/baseconfig/config.inc.php').'</a></li>'; |
128 | $output .= '<li><a href="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/">'._L('Setup part 1: Create %1 (contains database settings, CAPTCHA, admin password and SSL enforcement)','userdata/baseconfig/config.inc.php').'</a></li>'; |
129 | $oobePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.50'); // OIDplusPageAdminOOBE |
129 | $oobePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.50'); // OIDplusPageAdminOOBE |
130 | if (!is_null($oobePlugin)) { |
130 | if (!is_null($oobePlugin)) { |
131 | $output .= '<li><a href="'.OIDplus::webpath($oobePlugin->getPluginDirectory(),OIDplus::PATH_RELATIVE).'oobe.php">'._L('Setup part 2: Basic settings (they are all available above, too)').'</a></li>'; |
131 | $output .= '<li><a href="'.OIDplus::webpath($oobePlugin->getPluginDirectory(),OIDplus::PATH_RELATIVE).'oobe.php">'._L('Setup part 2: Basic settings (they are all available above, too)').'</a></li>'; |
132 | } else { |
132 | } else { |
133 | $output .= '<li>'._L('Setup part 2 requires plugin %1 (the basic settings are all available above, too)','OIDplusPageAdminOOBE').'</a></li>'; |
133 | $output .= '<li>'._L('Setup part 2 requires plugin %1 (the basic settings are all available above, too)','OIDplusPageAdminOOBE').'</a></li>'; |
134 | } |
134 | } |
135 | $output .= '</ul>'; |
135 | $output .= '</ul>'; |
136 | 136 | ||
137 | $out['text'] = $output; |
137 | $out['text'] = $output; |
138 | } |
138 | } |
139 | } |
139 | } |
140 | 140 | ||
141 | /** |
141 | /** |
142 | * @param array $json |
142 | * @param array $json |
143 | * @param string|null $ra_email |
143 | * @param string|null $ra_email |
144 | * @param bool $nonjs |
144 | * @param bool $nonjs |
145 | * @param string $req_goto |
145 | * @param string $req_goto |
146 | * @return bool |
146 | * @return bool |
147 | * @throws OIDplusException |
147 | * @throws OIDplusException |
148 | */ |
148 | */ |
149 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
149 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
150 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
150 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
151 | 151 | ||
152 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
152 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
153 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
153 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
154 | } else { |
154 | } else { |
155 | $tree_icon = null; // default icon (folder) |
155 | $tree_icon = null; // default icon (folder) |
156 | } |
156 | } |
157 | 157 | ||
158 | $json[] = array( |
158 | $json[] = array( |
159 | 'id' => 'oidplus:edit_config', |
159 | 'id' => 'oidplus:edit_config', |
160 | 'icon' => $tree_icon, |
160 | 'icon' => $tree_icon, |
161 | 'text' => _L('System configuration') |
161 | 'text' => _L('System configuration') |
162 | ); |
162 | ); |
163 | 163 | ||
164 | return true; |
164 | return true; |
165 | } |
165 | } |
166 | 166 | ||
167 | /** |
167 | /** |
168 | * @param string $request |
168 | * @param string $request |
169 | * @return array|false |
169 | * @return array|false |
170 | */ |
170 | */ |
171 | public function tree_search(string $request) { |
171 | public function tree_search(string $request) { |
172 | return false; |
172 | return false; |
173 | } |
173 | } |
174 | } |
174 | } |
175 | 175 |