Browse Source

Web config editor: board configs

pull/40/head
Michael Foster 11 years ago
parent
commit
424de7561d
  1. 50
      inc/mod/pages.php
  2. 1
      mod.php
  3. 22
      templates/mod/config-editor-php.html
  4. 23
      templates/mod/config-editor.html

50
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 = "<?php\n\n// This file does not exist yet. You are creating it.";
}
$instance_config = str_replace("\n", '&#010;', utf8tohtml($instance_config));
mod_page(_('Config editor'), 'mod/config-editor-php.html', array('php' => $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 = "<?php\n\n$config_append";
if (!@file_put_contents($config_file, $config_append, FILE_APPEND)) {
$config_append = htmlentities($config_append);
if ($config['minify_html'])
@ -2039,8 +2053,8 @@ function mod_config() {
$page['title'] = 'Cannot write to file!';
$page['config'] = $config;
$page['body'] = '
<p style="text-align:center">Tinyboard could not write to <strong>inc/instance-config.php</strong> with the ammended configuration, probably due to a permissions error.</p>
<p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>inc/instance-config.php</strong>:</p>
<p style="text-align:center">Tinyboard could not write to <strong>' . $config_file . '</strong> with the ammended configuration, probably due to a permissions error.</p>
<p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>' . $config_file . '</strong>:</p>
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
';
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() {

1
mod.php

@ -79,6 +79,7 @@ $pages = array(
'/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme
'/config' => 'config', // config editor
'/config/(\%b)' => 'config', // config editor
// these pages aren't listed in the dashboard without $config['debug']
'/debug/antispam' => 'debug_antispam',

22
templates/mod/config-editor-php.html

@ -1,10 +1,27 @@
<div style="max-width:800px;margin:auto">
<p>
Any changes you make here will simply be appended to <code>{{ file }}</code>. If you wish to make the most of Tinyboard's customizability, you can instead edit the file directly. This page is intended for making quick changes and for those who don't have a basic understanding of PHP code.
</p>
{% if boards|count %}
<ul>
{% if board %}
<li><a href="?/config">Edit site-wide config</a></li>
{% endif %}
{% for _board in boards if _board.uri != board %}
<li>
<a href="?/config/{{ _board.uri }}">Edit config for {{ config.board_abbreviation|sprintf(_board.uri) }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if readonly %}
<p style="text-align:center;max-width:800px;margin:20px auto">Tinyboard does not have the required permissions to edit <strong>inc/instance-config.php</strong>. To make changes, you will need to change the file's permissions first or manually edit the code.</p>
<p>Tinyboard does not have the required permissions to edit <code>{{ file }}</code>. To make changes, you will need to change the file's permissions first or manually edit the code.</p>
{% endif %}
{% if not readonly %}<form method="post" action="">{% endif %}
<textarea name="code" id="code" style="display:block; margin:auto;width:100%;max-width:800px;height:500px{% if readonly %};background:#eee" readonly{% else %}"{% endif %}>
<textarea name="code" id="code" style="margin:auto;width:100%;height:500px{% if readonly %};background:#eee" readonly{% else %}"{% endif %}>
{{ php }}
</textarea>
@ -12,6 +29,7 @@
<li><input name="save" type="submit" value="{% trans 'Save changes' %}"{% if readonly %} disabled{% endif %}></li>
</ul>
{% if not readonly %}</form>{% endif %}
</div>
<script type="text/javascript">
var observe;

23
templates/mod/config-editor.html

@ -1,10 +1,25 @@
<p>
Any changes you make here will simply be appended to <code>{{ file }}</code>. If you wish to make the most of Tinyboard's customizability, you can instead edit the file directly. This page is intended for making quick changes and for those who don't have a basic understanding of PHP code.
</p>
{% if boards|count %}
<ul>
{% if board %}
<li><a href="?/config">Edit site-wide config</a></li>
{% endif %}
{% for _board in boards if _board.uri != board %}
<li>
<a href="?/config/{{ _board.uri }}">Edit config for {{ config.board_abbreviation|sprintf(_board.uri) }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
<form method="post" action="">
<table class="mod config-editor">
<tr>
<th class="minimal">Name</th>
<th>Value</th>
<th class="minimal">Type</th>
<th>Description</th>
<th class="minimal">{% trans 'Name' %}</th>
<th>{% trans 'Value' %}</th>
<th class="minimal">{% trans 'Type' %}</th>
<th>{% trans 'Description' %}</th>
</tr>
{% for var in conf if var.type != 'array' %}
{% if var.name|count == 1 %}

Loading…
Cancel
Save