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