Subversion Repositories oidplus

Rev

Rev 321 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

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