From 424de7561dcd1476c64f42f86af2a42fa2c39814 Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Sat, 3 Aug 2013 06:26:17 -0400
Subject: Web config editor: board configs
---
inc/mod/pages.php | 50 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 15 deletions(-)
(limited to 'inc/mod/pages.php')
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 13520871..38bdac8b 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -1941,30 +1941,43 @@ function mod_report_dismiss($id, $all = false) {
}
-function mod_config() {
- global $config, $mod;
+function mod_config($board_config = false) {
+ global $config, $mod, $board;
+
+ if ($board_config && !openBoard($board_config))
+ error($config['error']['noboard']);
- if (!hasPermission($config['mod']['edit_config']))
+ if (!hasPermission($config['mod']['edit_config'], $board_config))
error($config['error']['noaccess']);
+ $config_file = $board_config ? $board['dir'] . 'config.php' : 'inc/instance-config.php';
+
if ($config['mod']['config_editor_php']) {
- $readonly = !is_writable('inc/instance-config.php');
+ $readonly = !(is_file($config_file) ? is_writable($config_file) : is_writable(dirname($config_file)));
if (!$readonly && isset($_POST['code'])) {
$code = $_POST['code'];
- file_put_contents('inc/instance-config.php', $code);
+ file_put_contents($config_file, $code);
header('Location: ?/config', true, $config['redirect_http']);
return;
}
- $instance_config = file_get_contents('inc/instance-config.php');
+ $instance_config = @file_get_contents($config_file);
+ if ($instance_config === false) {
+ $instance_config = " $instance_config, 'readonly' => $readonly));
+ mod_page(_('Config editor'), 'mod/config-editor-php.html', array(
+ 'php' => $instance_config,
+ 'readonly' => $readonly,
+ 'boards' => listBoards(),
+ 'board' => $board_config,
+ 'file' => $config_file
+ ));
return;
}
-
require_once 'inc/mod/config-editor.php';
$conf = config_vars();
@@ -2012,7 +2025,7 @@ function mod_config() {
$config_append .= ' = ';
- if ($var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) {
+ if (@$var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) {
$perm_array = array(
JANITOR => 'JANITOR',
MOD => 'MOD',
@@ -2029,8 +2042,9 @@ function mod_config() {
if (!empty($config_append)) {
$config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
-
- if (!@file_put_contents('inc/instance-config.php', $config_append, FILE_APPEND)) {
+ if (!is_file($config_file))
+ $config_append = "Tinyboard could not write to inc/instance-config.php with the ammended configuration, probably due to a permissions error.
- You may proceed with these changes manually by copying and pasting the following code to the end of inc/instance-config.php:
+ Tinyboard could not write to ' . $config_file . ' with the ammended configuration, probably due to a permissions error.
+ You may proceed with these changes manually by copying and pasting the following code to the end of ' . $config_file . ':
';
echo Element('page.html', $page);
@@ -2048,12 +2062,18 @@ function mod_config() {
}
}
- header('Location: ?/', true, $config['redirect_http']);
+ header('Location: ?/config', true, $config['redirect_http']);
exit;
}
- mod_page(_('Config editor'), 'mod/config-editor.html', array('conf' => $conf));
+ mod_page(_('Config editor') . ($board_config ? ': ' . sprintf($config['board_abbreviation'], $board_config) : ''),
+ 'mod/config-editor.html', array(
+ 'boards' => listBoards(),
+ 'board' => $board_config,
+ 'conf' => $conf,
+ 'file' => $config_file
+ ));
}
function mod_themes_list() {
--
cgit v1.3