1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-20 20:51:50 +01:00

Add file_unlink on page delete and prevent index overwrite

This commit is contained in:
8chan 2015-03-28 19:34:01 -07:00
parent fe6683ee5c
commit 076b64aba4

View File

@ -3353,14 +3353,18 @@ function delete_page_base($page = '', $board = false) {
if ($board !== FALSE && !openBoard($board))
error($config['error']['noboard']);
if ($board) {
$query = prepare('DELETE FROM ``pages`` WHERE `board` = :board AND `name` = :name');
$query->bindValue(':board', ($board ? $board : NULL));
} else {
$query = prepare('DELETE FROM ``pages`` WHERE `board` IS NULL AND `name` = :name');
if (preg_match('/^[a-z0-9]{1,255}$/', $page) && !preg_match('/^(index|catalog|index\+50)|(\d+)$/', $page)) {
if ($board) {
$query = prepare('DELETE FROM ``pages`` WHERE `board` = :board AND `name` = :name');
$query->bindValue(':board', ($board ? $board : NULL));
} else {
$query = prepare('DELETE FROM ``pages`` WHERE `board` IS NULL AND `name` = :name');
}
$query->bindValue(':name', $page);
$query->execute() or error(db_error($query));
@file_unlink(($board ? ($board . '/') : '') . $page . '.html');
}
$query->bindValue(':name', $page);
$query->execute() or error(db_error($query));
header('Location: ?/edit_pages' . ($board ? ('/' . $board) : ''), true, $config['redirect_http']);
}
@ -3475,6 +3479,9 @@ function mod_pages($board = false) {
if (!preg_match('/^[a-z0-9]{1,255}$/', $_POST['page']))
error(_('Page names must be < 255 chars and may only contain lowercase letters A-Z and digits 1-9.'));
if (preg_match('/^(index|catalog|index\+50)|(\d+)$/', $_POST['page']))
error(_('Nope.'));
foreach ($pages as $i => $p) {
if ($_POST['page'] === $p['name'])
error(_('Refusing to create a new page with the same name as an existing one.'));