Subversion Repositories oidplus

Rev

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