feat: add configuration for allowed image hosts

This commit is contained in:
Floorb 2023-05-23 12:31:11 -04:00
parent 1ec073081b
commit ac14a2628d
3 changed files with 219 additions and 186 deletions

View file

@ -9,6 +9,7 @@ return array (
'site_name' => 'PonePaste', 'site_name' => 'PonePaste',
'email' => '' 'email' => ''
), ),
'allowed_image_hosts' => array(),
'interface' => 'interface' =>
array ( array (
'language' => 'en', 'language' => 'en',
@ -19,16 +20,6 @@ return array (
'disable_guest' => false, 'disable_guest' => false,
'private' => false, 'private' => false,
), ),
'mail' =>
array (
'verification' => false,
'smtp_host' => '',
'smtp_port' => '',
'smtp_user' => '',
'socket' => '',
'auth' => '',
'protocol' => '',
),
'captcha' => 'captcha' =>
array ( array (
'enabled' => true, 'enabled' => true,

View file

@ -292,4 +292,4 @@ $script_bundles = [];
/* Security headers */ /* Security headers */
header('X-Frame-Options: SAMEORIGIN'); header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff'); header('X-Content-Type-Options: nosniff');
header("Content-Security-Policy: default-src 'self' data: 'unsafe-inline'"); header("Content-Security-Policy: default-src 'self' data: 'unsafe-inline'; img-src " . implode(' ', $site_info['allowed_image_hosts']));

View file

@ -23,8 +23,8 @@ function updateConfiguration(string $path, array $new_config) : void {
$current_config = require(CONFIG_FILE_PATH); $current_config = require(CONFIG_FILE_PATH);
$current_site_info = $current_config['site_info']; $current_site_info = $current_config['site_info'];
$current_allowed_image_hosts = $current_config['allowed_image_hosts'];
$current_permissions = $current_config['permissions']; $current_permissions = $current_config['permissions'];
$current_mail = $current_config['mail'];
$current_captcha = $current_config['captcha']; $current_captcha = $current_config['captcha'];
/* Update the configuration if necessary */ /* Update the configuration if necessary */
@ -48,6 +48,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$msg = '<div class="paste-alert alert3" style="text-align: center;"> $msg = '<div class="paste-alert alert3" style="text-align: center;">
Configuration saved. Configuration saved.
</div>'; </div>';
} elseif ($action === 'allowed_image_hosts') {
$new_allowed_image_hosts = array_filter($_POST['allowed_image_hosts'], function ($host) {
return !empty($host);
});
$current_config['allowed_image_hosts'] = $new_allowed_image_hosts;
$current_allowed_image_hosts = $new_allowed_image_hosts;
updateConfiguration(CONFIG_FILE_PATH, $current_config);
$msg = '<div class="paste-alert alert3" style="text-align: center;">
Allowed image hosts saved.
</div>';
} elseif ($action === 'permissions') { } elseif ($action === 'permissions') {
$new_permissions = [ $new_permissions = [
'disable_guest' => trim($_POST['disableguest']), 'disable_guest' => trim($_POST['disableguest']),
@ -89,6 +100,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<title>Paste - Configuration</title> <title>Paste - Configuration</title>
<link rel="shortcut icon" href="favicon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link href="css/paste.css" rel="stylesheet" type="text/css"/> <link href="css/paste.css" rel="stylesheet" type="text/css"/>
<style>
</style>
</head> </head>
<body> <body>
@ -103,7 +117,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<ul class="top-right"> <ul class="top-right">
<li class="dropdown link"> <li class="dropdown link">
<a href="#" data-toggle="dropdown" class="dropdown-toggle profilebox"><b>Admin</b><span <a href="#" data-toggle="dropdown" class="dropdown-toggle profilebox"><b>Admin</b><span
class="caret"></span></a> class="caret"></span></a>
<ul class="dropdown-menu dropdown-menu-list dropdown-menu-right"> <ul class="dropdown-menu dropdown-menu-list dropdown-menu-right">
<li><a href="admin.php">Settings</a></li> <li><a href="admin.php">Settings</a></li>
<li><a href="?logout">Logout</a></li> <li><a href="?logout">Logout</a></li>
@ -128,206 +142,234 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<div class="panel-body"> <div class="panel-body">
<?php if (isset($msg)) echo $msg; ?> <?php if (isset($msg)) echo $msg; ?>
<div role="tabpanel"> <div class="tabs">
<!-- Nav tabs --> <div class="tabs__content">
<ul class="nav nav-tabs nav-line" role="tablist" style="text-align: center;"> <h2>General Settings</h2>
<li role="presentation" class="active"><a href="#siteinfo" aria-controls="siteinfo" <form class="form-horizontal" method="POST"
role="tab" data-toggle="tab">Site Info</a> action="<?= $_SERVER['PHP_SELF']; ?>">
</li>
<li role="presentation"><a href="#permissions" aria-controls="permissions" role="tab"
data-toggle="tab">Permissions</a></li>
<li role="presentation"><a href="#captcha" aria-controls="captcha" role="tab"
data-toggle="tab">Captcha Settings</a></li>
</ul>
<!-- Tab panes --> <div class="form-group">
<div class="tab-content"> <label class="col-sm-2 control-label form-label" for="site_info_name">Site
<div role="tabpanel" class="tab-pane active" id="siteinfo"> Name</label>
<form class="form-horizontal" method="POST" <div class="col-sm-10">
action="<?= $_SERVER['PHP_SELF']; ?>"> <input type="text" class="form-control" name="site_info[site_name]"
id="site_info_name"
placeholder="The name of your site"
value="<?= pp_html_escape($current_site_info['site_name']); ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_title">Site
Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[title]"
id="site_info_title"
placeholder="Site title tag"
value="<?= pp_html_escape($current_site_info['title']); ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label form-label"
for="site_info_description">Site Description</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[description]"
id="site_info_description"
placeholder="Site description"
value="<?= pp_html_escape($current_site_info['description']); ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_keywords">Site
Keywords</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[keywords]"
id="site_info_keywords"
placeholder="Keywords (separated by a comma)"
value="<?= pp_html_escape($current_site_info['keywords']); ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_email">Admin
Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[email]"
placeholder="Email" id="site_info_email"
value="<?= pp_html_escape($current_site_info['email']); ?>">
</div>
</div>
<input type="hidden" name="action" value="site_info"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button>
</div>
</div>
</form>
</div>
<!-- Allowed Image Hosts -->
<h2>Allowed Image Hosts</h2>
<div class="tabs__content">
<form class="form-horizontal" method="POST"
action="<?= $_SERVER['PHP_SELF']; ?>">
<?php foreach ($current_allowed_image_hosts as $index => $host): ?>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_name">Site
Name</label> <label class="col-sm-2 control-label form-label">Allowed Image Host
#<?= $index ?></label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" name="site_info[site_name]" <input type="text" class="form-control" name="allowed_image_hosts[]"
id="site_info_name" placeholder="URL..."
placeholder="The name of your site" value="<?= pp_html_escape($host); ?>">
value="<?= pp_html_escape($current_site_info['site_name']); ?>">
</div> </div>
</div> </div>
<?php endforeach; ?>
<div class="form-group">
<label class="col-sm-2 control-label form-label">Add another?</label>
<div class="form-group"> <div class="col-sm-10">
<label class="col-sm-2 control-label form-label" for="site_info_title">Site <input type="text" class="form-control" name="allowed_image_hosts[]"
Title</label> placeholder="Add another...">
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[title]"
id="site_info_title"
placeholder="Site title tag"
value="<?= pp_html_escape($current_site_info['title']); ?>">
</div>
</div> </div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label form-label" <input type="hidden" name="action" value="allowed_image_hosts"/>
for="site_info_description">Site Description</label>
<div class="col-sm-10"> <div class="form-group">
<input type="text" class="form-control" name="site_info[description]" <div class="col-sm-offset-2 col-sm-10">
id="site_info_description" <button type="submit" class="btn btn-default">Save</button>
placeholder="Site description"
value="<?= pp_html_escape($current_site_info['description']); ?>">
</div>
</div> </div>
</div>
</form>
</div>
<div class="form-group"> <!-- CAPTCHA -->
<label class="col-sm-2 control-label form-label" for="site_info_keywords">Site <div class="tabs__content">
Keywords</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[keywords]"
id="site_info_keywords"
placeholder="Keywords (separated by a comma)"
value="<?= pp_html_escape($current_site_info['keywords']); ?>">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label form-label" for="site_info_email">Admin
Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="site_info[email]"
placeholder="Email" id="site_info_email"
value="<?= pp_html_escape($current_site_info['email']); ?>">
</div>
</div>
<input type="hidden" name="action" value="site_info"/> <h2>CAPTCHA</h2>
<form class="form-horizontal" method="POST"
action="<?= $_SERVER['PHP_SELF']; ?>">
<div class="form-group"> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button>
</div>
</div>
</form>
</div>
<!-- Permissions -->
<div role="tabpanel" class="tab-pane" id="permissions">
<form class="form-horizontal" method="POST"
action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="checkbox checkbox-primary">
<input <?php if ($site_disable_guests) echo 'checked="true"'; ?>
type="checkbox" name="disableguest" id="disableguest">
<label for="disableguest">
Only allow registered users to paste
</label>
</div>
<div class="checkbox checkbox-primary">
<input <?php if ($site_is_private) echo 'checked="true"'; ?>
type="checkbox" name="siteprivate" id="siteprivate">
<label for="siteprivate">
Make site private (no Recent Pastes or Archives)
</label>
</div>
<br/>
<input type="hidden" name="permissions" value="permissions"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button>
</div>
</div>
</form>
</div>
<!-- Captcha pane -->
<div role="tabpanel" class="tab-pane" id="captcha">
<form class="form-horizontal" method="POST"
action="<?= $_SERVER['PHP_SELF']; ?>">
<div class="checkbox checkbox-primary"> <div class="checkbox checkbox-primary">
<input <?php if ($current_captcha['enabled']) echo 'checked="true"'; ?> <input <?php if ($current_captcha['enabled']) echo 'checked="true"'; ?>
type="checkbox" type="checkbox"
name="captcha[enabked]" name="captcha[enabked]"
id="captcha_enabled"> id="captcha_enabled">
<label for="captcha_enabled">Enable Captcha</label> <label for="captcha_enabled">Enable Captcha</label>
</div> </div>
<br/> </div>
<div class="form-group row"> <div class="form-group">
<label for="captcha_mode" class="col-sm-1 col-form-label">Captcha <label class="col-sm-2 control-label form-label" for="captcha_mode">Captcha
Type</label> Type</label>
<select id="captcha_mode" class="selectpicker" name="captcha[mode]"> <select class="form-control col-sm-10" id="captcha_mode" class="" name="captcha[mode]">
<?php <?php
if ($current_captcha['mode'] == "Easy") { if ($current_captcha['mode'] == "Easy") {
echo '<option selected="">Easy</option>'; echo '<option selected="">Easy</option>';
} else { } else {
echo '<option>Easy</option>'; echo '<option>Easy</option>';
} }
if ($current_captcha['mode'] == "Normal") { if ($current_captcha['mode'] == "Normal") {
echo '<option selected="">Normal</option>'; echo '<option selected="">Normal</option>';
} else { } else {
echo '<option>Normal</option>'; echo '<option>Normal</option>';
} }
if ($current_captcha['mode'] == "Tough") { if ($current_captcha['mode'] == "Tough") {
echo '<option selected="">Tough</option>'; echo '<option selected="">Tough</option>';
} else { } else {
echo '<option>Tough</option>'; echo '<option>Tough</option>';
} }
?> ?>
</select> </select>
</div>
<hr/>
<div class="panel-title">
Internal Captcha Settings:
</div>
<div class="checkbox checkbox-primary">
<input <?php if ($current_captcha['multiple']) echo 'checked="checked"'; ?>
type="checkbox"
name="captcha[multiple]"
id="captcha_multiple">
<label for="captcha_multiple">Enable multiple backgrounds</label>
</div>
<br/>
<div class="form-group row">
<label for="captcha_allowed" class="col-sm-1 col-form-label">Captcha
Characters</label>
<div class="col-sm-10">
<input type="text" id="captcha_allowed" name="captcha[allowed]"
placeholder="Allowed Characters"
value="<?php echo $current_captcha['allowed']; ?>">
</div> </div>
</div>
<hr/> <div class="form-group row">
<div class="panel-title"> <label for="captcha_colour" class="col-sm-1 col-form-label">Captcha Text
Internal Captcha Settings: Colour</label>
</div> <div class="col-sm-10">
<div class="checkbox checkbox-primary"> <input type="text" id="captcha_colour" name="captcha[colour]"
<input <?php if ($current_captcha['multiple']) echo 'checked="checked"'; ?> placeholder="Captcha Text Colour"
type="checkbox" value="<?= $current_captcha['colour']; ?>">
name="captcha[multiple]"
id="captcha_multiple">
<label for="captcha_multiple">Enable multiple backgrounds</label>
</div>
<br/>
<div class="form-group row">
<label for="captcha_allowed" class="col-sm-1 col-form-label">Captcha
Characters</label>
<div class="col-sm-10">
<input type="text" id="captcha_allowed" name="captcha[allowed]"
placeholder="Allowed Characters"
value="<?php echo $current_captcha['allowed']; ?>">
</div>
</div> </div>
</div>
<div class="form-group row"> <hr/>
<label for="captcha_colour" class="col-sm-1 col-form-label">Captcha Text
Colour</label> <input type="hidden" name="cap" value="cap"/>
<div class="col-sm-10">
<input type="text" id="captcha_colour" name="captcha[colour]" <div class="form-group">
placeholder="Captcha Text Colour" <div class="col-sm-offset-2 col-sm-10">
value="<?= $current_captcha['colour']; ?>"> <button type="submit" class="btn btn-default">Save</button>
</div>
</div> </div>
</div>
<hr/> </form>
<input type="hidden" name="cap" value="cap"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button>
</div>
</div>
</form>
</div>
</div> </div>
<h2>Permissions</h2>
<form class="form-horizontal" method="POST"
action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="checkbox checkbox-primary">
<input <?php if ($site_disable_guests) echo 'checked="true"'; ?>
type="checkbox" name="disableguest" id="disableguest">
<label for="disableguest">
Only allow registered users to paste
</label>
</div>
<div class="form-group">
<div class="checkbox checkbox-primary">
<input <?php if ($site_is_private) echo 'checked="true"'; ?>
type="checkbox" name="siteprivate" id="siteprivate">
<label for="siteprivate">
Make site private (no Recent Pastes or Archives)
</label>
</div>
</div>
<input type="hidden" name="permissions" value="permissions"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button>
</div>
</div>
</form>
</div> </div>
</div> </div>
</div> </div>