Subversion Repositories oidplus

Rev

Rev 496 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
61 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
61 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPageAdminSystemConfig extends OIDplusPagePluginAdmin {
23
 
321 daniel-mar 24
        public function action($actionID, $params) {
25
                if ($actionID == 'config_update') {
61 daniel-mar 26
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
360 daniel-mar 27
                                throw new OIDplusException(_L('You need to log in as administrator.'));
61 daniel-mar 28
                        }
29
 
321 daniel-mar 30
                        $name = $params['name'];
31
                        $value = $params['value'];
139 daniel-mar 32
 
263 daniel-mar 33
                        $res = OIDplus::db()->query("select protected, visible from ###config where name = ?", array($name));
251 daniel-mar 34
                        if ($res->num_rows() == 0) {
360 daniel-mar 35
                                throw new OIDplusException(_L('Setting does not exist'));
251 daniel-mar 36
                        }
236 daniel-mar 37
                        $row = $res->fetch_array();
263 daniel-mar 38
                        if (($row['protected'] == 1) || ($row['visible'] == 0)) {
360 daniel-mar 39
                                throw new OIDplusException(_L("Setting %1 is read-only",$name));
64 daniel-mar 40
                        }
41
 
115 daniel-mar 42
                        OIDplus::config()->setValue($name, $value);
288 daniel-mar 43
                        OIDplus::logger()->log("[OK]A?", "Changed system config setting '$name' to '$value'");
115 daniel-mar 44
 
328 daniel-mar 45
                        return array("status" => 0);
321 daniel-mar 46
                } else {
360 daniel-mar 47
                        throw new OIDplusException(_L('Unknown action ID'));
61 daniel-mar 48
                }
49
        }
50
 
75 daniel-mar 51
        public function init($html=true) {
61 daniel-mar 52
                // Nothing
53
        }
54
 
55
        public function gui($id, &$out, &$handled) {
56
                if (explode('$',$id)[0] == 'oidplus:edit_config') {
57
                        $handled = true;
360 daniel-mar 58
                        $out['title'] = _L('System configuration');
241 daniel-mar 59
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
61 daniel-mar 60
 
61
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
62
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 63
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 64
                                return;
65
                        }
360 daniel-mar 66
 
281 daniel-mar 67
                        $output = '';
68
                        $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
69
                        $output .= '<table class="table table-bordered table-striped">';
70
                        $output .= '    <tr>';
360 daniel-mar 71
                        $output .= '         <th>'._L('Setting').'</th>';
72
                        $output .= '         <th>'._L('Description').'</th>';
73
                        $output .= '         <th>'._L('Value').'</th>';
74
                        $output .= '         <th>'._L('Update').'</th>';
281 daniel-mar 75
                        $output .= '    </tr>';
61 daniel-mar 76
 
281 daniel-mar 77
                        OIDplus::config(); // <-- make sure that the config table is loaded/filled correctly before we do a select
61 daniel-mar 78
 
281 daniel-mar 79
                        $result = OIDplus::db()->query("select * from ###config where visible = ? order by name", array(true));
80
                        while ($row = $result->fetch_object()) {
81
                                $output .= '<tr>';
82
                                $output .= '     <td>'.htmlentities($row->name).'</td>';
83
                                $output .= '     <td>'.htmlentities($row->description).'</td>';
84
                                if ($row->protected == 1) {
85
                                        $desc = $row->value;
86
                                        if (strlen($desc) > 100) $desc = substr($desc, 0, 100) . '...';
87
                                        $output .= '     <td style="word-break: break-all;">'.htmlentities($desc).'</td>';
88
                                        $output .= '     <td>&nbsp;</td>';
89
                                } else {
90
                                        $output .= '     <td><input type="text" id="config_'.$row->name.'" value="'.htmlentities($row->value).'"></td>';
360 daniel-mar 91
                                        $output .= '     <td><button type="button" name="config_update_'.$row->name.'" id="config_update_'.$row->name.'" class="btn btn-success btn-xs update" onclick="crudActionConfigUpdate('.js_escape($row->name).')">'._L('Update').'</button></td>';
61 daniel-mar 92
                                }
281 daniel-mar 93
                                $output .= '</tr>';
94
                        }
61 daniel-mar 95
 
281 daniel-mar 96
                        $output .= '</table>';
97
                        $output .= '</div></div>';
61 daniel-mar 98
 
360 daniel-mar 99
                        $output .= '<br><p>'._L('See also').':</p>';
281 daniel-mar 100
                        $output .= '<ul>';
496 daniel-mar 101
                        $output .= '<li><a href="'.OIDplus::webpath().'setup/">'._L('Setup part 1: Create %1 (contains database settings, ReCAPTCHA, admin password and SSL enforcement)','userdata/baseconfig/config.inc.php').'</a></li>';
380 daniel-mar 102
                        $oobePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.50'); // OIDplusPageAdminOOBE
103
                        if (!is_null($oobePlugin)) {
104
                                $output .= '<li><a href="'.OIDplus::webpath($oobePlugin->getPluginDirectory()).'oobe.php">'._L('Setup part 2: Basic settings (they are all available above, too)').'</a></li>';
281 daniel-mar 105
                        } else {
360 daniel-mar 106
                                $output .= '<li>'._L('Setup part 2 requires plugin %1 (the basic settings are all available above, too)','OIDplusPageAdminOOBE').'</a></li>';
61 daniel-mar 107
                        }
281 daniel-mar 108
                        $output .= '</ul>';
61 daniel-mar 109
 
281 daniel-mar 110
                        $out['text'] = $output;
61 daniel-mar 111
                }
112
        }
113
 
106 daniel-mar 114
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 115
                if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
360 daniel-mar 116
 
61 daniel-mar 117
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 118
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
61 daniel-mar 119
                } else {
120
                        $tree_icon = null; // default icon (folder)
121
                }
122
 
123
                $json[] = array(
124
                        'id' => 'oidplus:edit_config',
125
                        'icon' => $tree_icon,
360 daniel-mar 126
                        'text' => _L('System configuration')
61 daniel-mar 127
                );
104 daniel-mar 128
 
129
                return true;
61 daniel-mar 130
        }
108 daniel-mar 131
 
132
        public function tree_search($request) {
133
                return false;
134
        }
360 daniel-mar 135
}