Rev 1116 | Rev 1143 | Go to most recent revision | 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 string $actionID |
||
30 | * @param array $params |
||
31 | * @return int[] |
||
32 | * @throws OIDplusException |
||
33 | */ |
||
34 | public function action(string $actionID, array $params): array { |
||
635 | daniel-mar | 35 | if ($actionID == 'config_update') { |
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'))); |
||
38 | } |
||
39 | |||
40 | _CheckParamExists($params, 'name'); |
||
41 | _CheckParamExists($params, 'value'); |
||
42 | |||
43 | $name = $params['name']; |
||
44 | $value = $params['value']; |
||
45 | |||
46 | $res = OIDplus::db()->query("select protected, visible from ###config where name = ?", array($name)); |
||
790 | daniel-mar | 47 | if (!$res->any()) { |
635 | daniel-mar | 48 | throw new OIDplusException(_L('Setting does not exist')); |
49 | } |
||
50 | $row = $res->fetch_array(); |
||
51 | if (($row['protected'] == 1) || ($row['visible'] == 0)) { |
||
52 | throw new OIDplusException(_L("Setting %1 is read-only",$name)); |
||
53 | } |
||
54 | |||
55 | OIDplus::config()->setValue($name, $value); |
||
56 | OIDplus::logger()->log("[OK]A?", "Changed system config setting '$name' to '$value'"); |
||
57 | |||
58 | return array("status" => 0); |
||
59 | } else { |
||
1116 | daniel-mar | 60 | return parent::action($actionID, $params); |
635 | daniel-mar | 61 | } |
62 | } |
||
63 | |||
1116 | daniel-mar | 64 | /** |
65 | * @param bool $html |
||
66 | * @return void |
||
67 | */ |
||
68 | public function init(bool $html=true) { |
||
635 | daniel-mar | 69 | // Nothing |
70 | } |
||
71 | |||
1116 | daniel-mar | 72 | /** |
73 | * @param string $id |
||
74 | * @param array $out |
||
75 | * @param bool $handled |
||
76 | * @return void |
||
77 | * @throws OIDplusException |
||
78 | */ |
||
79 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 80 | if (explode('$',$id)[0] == 'oidplus:edit_config') { |
81 | $handled = true; |
||
82 | $out['title'] = _L('System configuration'); |
||
801 | daniel-mar | 83 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
635 | daniel-mar | 84 | |
85 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
800 | daniel-mar | 86 | $out['icon'] = 'img/error.png'; |
635 | daniel-mar | 87 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
88 | return; |
||
89 | } |
||
90 | |||
1116 | daniel-mar | 91 | $output = '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
635 | daniel-mar | 92 | $output .= '<table class="table table-bordered table-striped">'; |
1138 | daniel-mar | 93 | $output .= '<thead>'; |
635 | daniel-mar | 94 | $output .= ' <tr>'; |
95 | $output .= ' <th>'._L('Setting').'</th>'; |
||
96 | $output .= ' <th>'._L('Description').'</th>'; |
||
97 | $output .= ' <th>'._L('Value').'</th>'; |
||
98 | $output .= ' <th>'._L('Update').'</th>'; |
||
99 | $output .= ' </tr>'; |
||
1138 | daniel-mar | 100 | $output .= '</thead>'; |
101 | $output .= '<tbody>'; |
||
635 | daniel-mar | 102 | |
103 | OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select |
||
104 | |||
105 | $result = OIDplus::db()->query("select * from ###config where visible = ? order by name", array(true)); |
||
106 | while ($row = $result->fetch_object()) { |
||
107 | $output .= '<tr>'; |
||
108 | $output .= ' <td>'.htmlentities($row->name).'</td>'; |
||
109 | $output .= ' <td>'.htmlentities($row->description).'</td>'; |
||
110 | if ($row->protected == 1) { |
||
111 | $desc = $row->value; |
||
112 | if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...'; |
||
113 | $output .= ' <td style="word-break: break-all;">'.htmlentities($desc).'</td>'; |
||
114 | $output .= ' <td> </td>'; |
||
115 | } else { |
||
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>'; |
||
118 | } |
||
119 | $output .= '</tr>'; |
||
120 | } |
||
121 | |||
1138 | daniel-mar | 122 | $output .= '</tbody>'; |
635 | daniel-mar | 123 | $output .= '</table>'; |
124 | $output .= '</div></div>'; |
||
125 | |||
126 | $output .= '<br><p>'._L('See also').':</p>'; |
||
127 | $output .= '<ul>'; |
||
801 | daniel-mar | 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>'; |
635 | daniel-mar | 129 | $oobePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.50'); // OIDplusPageAdminOOBE |
130 | if (!is_null($oobePlugin)) { |
||
801 | daniel-mar | 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>'; |
635 | daniel-mar | 132 | } else { |
133 | $output .= '<li>'._L('Setup part 2 requires plugin %1 (the basic settings are all available above, too)','OIDplusPageAdminOOBE').'</a></li>'; |
||
134 | } |
||
135 | $output .= '</ul>'; |
||
136 | |||
137 | $out['text'] = $output; |
||
138 | } |
||
139 | } |
||
140 | |||
1116 | daniel-mar | 141 | /** |
142 | * @param array $json |
||
143 | * @param string|null $ra_email |
||
144 | * @param bool $nonjs |
||
145 | * @param string $req_goto |
||
146 | * @return bool |
||
147 | * @throws OIDplusException |
||
148 | */ |
||
149 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 150 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
151 | |||
800 | daniel-mar | 152 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 153 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 154 | } else { |
155 | $tree_icon = null; // default icon (folder) |
||
156 | } |
||
157 | |||
158 | $json[] = array( |
||
159 | 'id' => 'oidplus:edit_config', |
||
160 | 'icon' => $tree_icon, |
||
161 | 'text' => _L('System configuration') |
||
162 | ); |
||
163 | |||
164 | return true; |
||
165 | } |
||
166 | |||
1116 | daniel-mar | 167 | /** |
168 | * @param string $request |
||
169 | * @return array|false |
||
170 | */ |
||
171 | public function tree_search(string $request) { |
||
635 | daniel-mar | 172 | return false; |
173 | } |
||
707 | daniel-mar | 174 | } |