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