Subversion Repositories oidplus

Rev

Rev 1267 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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