Web config editor: board configs
This commit is contained in:
parent
eb3fc990f5
commit
424de7561d
|
@ -1941,30 +1941,43 @@ function mod_report_dismiss($id, $all = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function mod_config() {
|
function mod_config($board_config = false) {
|
||||||
global $config, $mod;
|
global $config, $mod, $board;
|
||||||
|
|
||||||
if (!hasPermission($config['mod']['edit_config']))
|
if ($board_config && !openBoard($board_config))
|
||||||
|
error($config['error']['noboard']);
|
||||||
|
|
||||||
|
if (!hasPermission($config['mod']['edit_config'], $board_config))
|
||||||
error($config['error']['noaccess']);
|
error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
$config_file = $board_config ? $board['dir'] . 'config.php' : 'inc/instance-config.php';
|
||||||
|
|
||||||
if ($config['mod']['config_editor_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'])) {
|
if (!$readonly && isset($_POST['code'])) {
|
||||||
$code = $_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']);
|
header('Location: ?/config', true, $config['redirect_http']);
|
||||||
return;
|
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", '
', utf8tohtml($instance_config));
|
$instance_config = str_replace("\n", '
', 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
require_once 'inc/mod/config-editor.php';
|
require_once 'inc/mod/config-editor.php';
|
||||||
|
|
||||||
$conf = config_vars();
|
$conf = config_vars();
|
||||||
|
@ -2012,7 +2025,7 @@ function mod_config() {
|
||||||
|
|
||||||
|
|
||||||
$config_append .= ' = ';
|
$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(
|
$perm_array = array(
|
||||||
JANITOR => 'JANITOR',
|
JANITOR => 'JANITOR',
|
||||||
MOD => 'MOD',
|
MOD => 'MOD',
|
||||||
|
@ -2029,8 +2042,9 @@ function mod_config() {
|
||||||
|
|
||||||
if (!empty($config_append)) {
|
if (!empty($config_append)) {
|
||||||
$config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
|
$config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
|
||||||
|
if (!is_file($config_file))
|
||||||
if (!@file_put_contents('inc/instance-config.php', $config_append, FILE_APPEND)) {
|
$config_append = "<?php\n\n$config_append";
|
||||||
|
if (!@file_put_contents($config_file, $config_append, FILE_APPEND)) {
|
||||||
$config_append = htmlentities($config_append);
|
$config_append = htmlentities($config_append);
|
||||||
|
|
||||||
if ($config['minify_html'])
|
if ($config['minify_html'])
|
||||||
|
@ -2039,8 +2053,8 @@ function mod_config() {
|
||||||
$page['title'] = 'Cannot write to file!';
|
$page['title'] = 'Cannot write to file!';
|
||||||
$page['config'] = $config;
|
$page['config'] = $config;
|
||||||
$page['body'] = '
|
$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">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>inc/instance-config.php</strong>:</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>
|
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
|
||||||
';
|
';
|
||||||
echo Element('page.html', $page);
|
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;
|
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() {
|
function mod_themes_list() {
|
||||||
|
|
73
mod.php
73
mod.php
|
@ -21,64 +21,65 @@ if (get_magic_quotes_gpc()) {
|
||||||
$query = isset($_SERVER['QUERY_STRING']) ? urldecode($_SERVER['QUERY_STRING']) : '';
|
$query = isset($_SERVER['QUERY_STRING']) ? urldecode($_SERVER['QUERY_STRING']) : '';
|
||||||
|
|
||||||
$pages = array(
|
$pages = array(
|
||||||
'' => ':?/', // redirect to dashboard
|
'' => ':?/', // redirect to dashboard
|
||||||
'/' => 'dashboard', // dashboard
|
'/' => 'dashboard', // dashboard
|
||||||
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
|
'/confirm/(.+)' => 'confirm', // confirm action (if javascript didn't work)
|
||||||
'/logout' => 'logout', // logout
|
'/logout' => 'logout', // logout
|
||||||
|
|
||||||
'/users' => 'users', // manage users
|
'/users' => 'users', // manage users
|
||||||
'/users/(\d+)' => 'user', // edit user
|
'/users/(\d+)' => 'user', // edit user
|
||||||
'/users/(\d+)/(promote|demote)' => 'user_promote', // prmote/demote user
|
'/users/(\d+)/(promote|demote)' => 'user_promote', // prmote/demote user
|
||||||
'/users/new' => 'user_new', // create a new user
|
'/users/new' => 'user_new', // create a new user
|
||||||
'/new_PM/([^/]+)' => 'new_pm', // create a new pm
|
'/new_PM/([^/]+)' => 'new_pm', // create a new pm
|
||||||
'/PM/(\d+)(/reply)?' => 'pm', // read a pm
|
'/PM/(\d+)(/reply)?' => 'pm', // read a pm
|
||||||
'/inbox' => 'inbox', // pm inbox
|
'/inbox' => 'inbox', // pm inbox
|
||||||
|
|
||||||
'/noticeboard' => 'noticeboard', // view noticeboard
|
'/noticeboard' => 'noticeboard', // view noticeboard
|
||||||
'/noticeboard/(\d+)' => 'noticeboard', // view noticeboard
|
'/noticeboard/(\d+)' => 'noticeboard', // view noticeboard
|
||||||
'/noticeboard/delete/(\d+)' => 'noticeboard_delete',// delete from noticeboard
|
'/noticeboard/delete/(\d+)' => 'noticeboard_delete', // delete from noticeboard
|
||||||
'/log' => 'log', // modlog
|
'/log' => 'log', // modlog
|
||||||
'/log/(\d+)' => 'log', // modlog
|
'/log/(\d+)' => 'log', // modlog
|
||||||
'/log:([^/]+)' => 'user_log', // modlog
|
'/log:([^/]+)' => 'user_log', // modlog
|
||||||
'/log:([^/]+)/(\d+)' => 'user_log', // modlog
|
'/log:([^/]+)/(\d+)' => 'user_log', // modlog
|
||||||
'/news' => 'news', // view news
|
'/news' => 'news', // view news
|
||||||
'/news/(\d+)' => 'news', // view news
|
'/news/(\d+)' => 'news', // view news
|
||||||
'/news/delete/(\d+)' => 'news_delete', // delete from news
|
'/news/delete/(\d+)' => 'news_delete', // delete from news
|
||||||
|
|
||||||
'/edit/(\%b)' => 'edit_board', // edit board details
|
'/edit/(\%b)' => 'edit_board', // edit board details
|
||||||
'/new-board' => 'new_board', // create a new board
|
'/new-board' => 'new_board', // create a new board
|
||||||
|
|
||||||
'/rebuild' => 'rebuild', // rebuild static files
|
'/rebuild' => 'rebuild', // rebuild static files
|
||||||
'/reports' => 'reports', // report queue
|
'/reports' => 'reports', // report queue
|
||||||
'/reports/(\d+)/dismiss(all)?' => 'report_dismiss', // dismiss a report
|
'/reports/(\d+)/dismiss(all)?' => 'report_dismiss', // dismiss a report
|
||||||
|
|
||||||
'/IP/([\w.:]+)' => 'ip', // view ip address
|
'/IP/([\w.:]+)' => 'ip', // view ip address
|
||||||
'/IP/([\w.:]+)/remove_note/(\d+)' => 'ip_remove_note', // remove note from ip address
|
'/IP/([\w.:]+)/remove_note/(\d+)' => 'ip_remove_note', // remove note from ip address
|
||||||
'/bans' => 'bans', // ban list
|
'/bans' => 'bans', // ban list
|
||||||
'/bans/(\d+)' => 'bans', // ban list
|
'/bans/(\d+)' => 'bans', // ban list
|
||||||
|
|
||||||
'/search' => 'search_redirect', // search
|
'/search' => 'search_redirect', // search
|
||||||
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
|
'/search/(posts|IP_notes|bans|log)/(.+)/(\d+)' => 'search', // search
|
||||||
'/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
|
'/search/(posts|IP_notes|bans|log)/(.+)' => 'search', // search
|
||||||
|
|
||||||
// CSRF-protected moderator actions
|
// CSRF-protected moderator actions
|
||||||
'/ban' => 'secure_POST ban', // new ban
|
'/ban' => 'secure_POST ban', // new ban
|
||||||
'/(\%b)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster
|
'/(\%b)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster
|
||||||
'/(\%b)/move/(\d+)' => 'secure_POST move', // move thread
|
'/(\%b)/move/(\d+)' => 'secure_POST move', // move thread
|
||||||
'/(\%b)/edit(_raw)?/(\d+)' => 'secure_POST edit_post', // edit post
|
'/(\%b)/edit(_raw)?/(\d+)' => 'secure_POST edit_post', // edit post
|
||||||
'/(\%b)/delete/(\d+)' => 'secure delete', // delete post
|
'/(\%b)/delete/(\d+)' => 'secure delete', // delete post
|
||||||
'/(\%b)/deletefile/(\d+)' => 'secure deletefile', // delete file from post
|
'/(\%b)/deletefile/(\d+)' => 'secure deletefile', // delete file from post
|
||||||
'/(\%b)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
|
'/(\%b)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address
|
||||||
'/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
|
'/(\%b)/(un)?lock/(\d+)' => 'secure lock', // lock thread
|
||||||
'/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
|
'/(\%b)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread
|
||||||
'/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
|
'/(\%b)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread
|
||||||
|
|
||||||
'/themes' => 'themes_list', // manage themes
|
'/themes' => 'themes_list', // manage themes
|
||||||
'/themes/(\w+)' => 'theme_configure', // configure/reconfigure theme
|
'/themes/(\w+)' => 'theme_configure', // configure/reconfigure theme
|
||||||
'/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme
|
'/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme
|
||||||
'/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme
|
'/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme
|
||||||
|
|
||||||
'/config' => 'config', // config editor
|
'/config' => 'config', // config editor
|
||||||
|
'/config/(\%b)' => 'config', // config editor
|
||||||
|
|
||||||
// these pages aren't listed in the dashboard without $config['debug']
|
// these pages aren't listed in the dashboard without $config['debug']
|
||||||
'/debug/antispam' => 'debug_antispam',
|
'/debug/antispam' => 'debug_antispam',
|
||||||
|
|
|
@ -1,17 +1,35 @@
|
||||||
{% if readonly %}
|
<div style="max-width:800px;margin:auto">
|
||||||
<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>
|
||||||
{% endif %}
|
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 %}
|
||||||
{% if not readonly %}<form method="post" action="">{% endif %}
|
<ul>
|
||||||
<textarea name="code" id="code" style="display:block; margin:auto;width:100%;max-width:800px;height:500px{% if readonly %};background:#eee" readonly{% else %}"{% endif %}>
|
{% if board %}
|
||||||
{{ php }}
|
<li><a href="?/config">Edit site-wide config</a></li>
|
||||||
</textarea>
|
{% 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 %}
|
||||||
|
|
||||||
<ul style="padding:0;text-align:center;list-style:none">
|
{% if readonly %}
|
||||||
<li><input name="save" type="submit" value="{% trans 'Save changes' %}"{% if readonly %} disabled{% endif %}></li>
|
<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>
|
||||||
</ul>
|
{% endif %}
|
||||||
{% if not readonly %}</form>{% endif %}
|
|
||||||
|
|
||||||
|
{% if not readonly %}<form method="post" action="">{% endif %}
|
||||||
|
<textarea name="code" id="code" style="margin:auto;width:100%;height:500px{% if readonly %};background:#eee" readonly{% else %}"{% endif %}>
|
||||||
|
{{ php }}
|
||||||
|
</textarea>
|
||||||
|
|
||||||
|
<ul style="padding:0;text-align:center;list-style:none">
|
||||||
|
<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">
|
<script type="text/javascript">
|
||||||
var observe;
|
var observe;
|
||||||
|
|
|
@ -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="">
|
<form method="post" action="">
|
||||||
<table class="mod config-editor">
|
<table class="mod config-editor">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="minimal">Name</th>
|
<th class="minimal">{% trans 'Name' %}</th>
|
||||||
<th>Value</th>
|
<th>{% trans 'Value' %}</th>
|
||||||
<th class="minimal">Type</th>
|
<th class="minimal">{% trans 'Type' %}</th>
|
||||||
<th>Description</th>
|
<th>{% trans 'Description' %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for var in conf if var.type != 'array' %}
|
{% for var in conf if var.type != 'array' %}
|
||||||
{% if var.name|count == 1 %}
|
{% if var.name|count == 1 %}
|
||||||
|
|
Loading…
Reference in New Issue