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