ikibooru/admin.html.l
2024-06-01 17:40:11 +03:00

157 lines
6.5 KiB
Plaintext

{%
-- ADMIN ONLY
if verified and verified.privs ~= 255 then verified = nil end
if verified then
local pohst = request:post()
if pohst and pohst.csrf and DB.csrfverify(verified.id, Escapes.urlunescape(tostring(pohst.csrf))) then
-- Basic settings
if pohst["sitename"] and not Escapes.urlunescape(pohst["sitename"]):match"^%s*$" then
BigGlobe.cfg.sitename = Escapes.urlspunescape(pohst["sitename"])
end
BigGlobe.cfg.enable18plus = pohst["enable18plus"] ~= nil
-- Tag categories
for i=1,BigGlobe.cfg.tc.n do
if pohst["tcn" .. i] then
BigGlobe.cfg.tc[i].name = Escapes.urlspunescape(pohst["tcn" .. i])
end
if pohst["tcc" .. i] then
BigGlobe.cfg.tc[i].col = tonumber(Escapes.urlunescape(pohst["tcc" .. i]):sub(2), 16) or 0
end
end
-- New tag
if pohst["ntn"] and tonumber(pohst["ntc"]) then
local cat = tonumber(pohst["ntc"])
if cat >= 1 and cat <= BigGlobe.cfg.tc.n then
DB.tagadd(Escapes.urlspunescape(pohst["ntn"]), cat, pohst["nta"] ~= nil)
end
end
-- Tag editing
if pohst["ettags"] and (#pohst["ettags"] > 0) then
local tagarr = {}
for tagstr in pohst["ettags"]:gmatch("%d+") do
table.insert(tagarr, tonumber(tagstr))
end
local newname = pohst["etname"] and Escapes.urlspunescape(pohst["etname"])
if newname and newname:match"^%s*$" then newname = nil end
local newcategory = tonumber(pohst["etcat"])
local newadultonly = pohst["eta"] ~= nil
local del = pohst["etdel"]
if del and del:match"^%s*$" then del = nil end
DB.updatetags(tagarr, newname, newcategory, newadultonly, del)
end
-- Mods
if pohst["mods"] then
local newmods = {}
for m in Escapes.urlspunescape(pohst["mods"]):gmatch"[^,]+" do
if not m:match("^%s*$") then
table.insert(newmods, m)
end
end
DB.setmodsviaemails(newmods)
end
-- Ruleset
if pohst["ruleset"] then
BigGlobe.cfg.ruleset = Escapes.urlspunescape(pohst["ruleset"])
end
-- X-Sendfile
if pohst["sendfilehdr"] then
BigGlobe.cfg.sendfile = Escapes.urlunescape(pohst["sendfilehdr"])
end
if pohst["sendfileprefix"] then
BigGlobe.cfg.sendfileprefix = Escapes.urlunescape(pohst["sendfileprefix"])
end
BigGlobe.sv()
end
else
response:statusCode(403)
end
%}
{% title = "Administrative Settings" %}
{% function content() %}
{% if verified then %}
<form method="POST" action="/admin" id="adminform">
<input type="hidden" name="csrf" value="{{ Escapes.htmlescape(DB.csrf(verified.id)) }}" />
<h1>{{ title }} <input type="submit" value="Submit" style="vertical-align:middle;" /></h1>
<div style="display:inline-block;width:60%;vertical-align:top;">
<h2>Basic Site Settings</h2>
<p style="margin-bottom:0;">Site Name</p>
<input type="text" name="sitename" autocomplete="off" value="{{ Escapes.htmlescape(BigGlobe.cfg.sitename) }}" style="display:block;margin-bottom:1em;" />
<input id="enable18plusparam" type="checkbox" name="enable18plus" {% if BigGlobe.cfg.enable18plus then %}checked {% end %}/>
<label for="enable18plusparam">Enable 18+</label>
<h2>New Tag</h2>
<p style="margin-bottom:0;">Set category ID</p>
<input type="number" name="ntc" min="1" max="{{ BigGlobe.cfg.tc.n }}" />
<p style="margin-bottom:0;">Set name</p>
<input type="text" name="ntn" autocomplete="off" />
<div style="margin-top:1em;"><input type="checkbox" name="nta" id="ntaparam" /><label for="ntaparam">18+</label></div>
<h2>Edit Tag</h2>
<div data-over18="1" style="position:relative;width:30%;" class="tagbox" data-formid="adminform" data-formparaminputid="ettagsparam">
<p>Tags to edit...</p>
<span style="position:relative;min-width:4px;left:0;" contenteditable></span>
</div>
<div class="autocomplete" style="visibility:hidden;width:30%;"></div>
<input type="hidden" id="ettagsparam" name="ettags" value="" />
<input type="number" name="etcat" min="1" max="{{ BigGlobe.cfg.tc.n }}" placeholder="Set category..." style="display:block;margin-bottom:1em;" />
<input type="text" name="etname" autocomplete="off" placeholder="Set name..." style="display:block;margin-bottom:1em;" />
<div style="margin-bottom:1em;"><input type="checkbox" name="eta" id="etaparam" /><label for="etaparam">18+</label></div>
<input type="checkbox" name="etdel" id="etdelbox" /><label for="etdelbox">Delete</label>
<h2>Moderators</h2>
<p>Enter a comma-separated list of e-mails that shall be granted moderator permissions.</p>
{% local mods = DB.getmoderators() %}
<textarea name="mods" style="width:80%;height:10em;">{% for _, m in pairs(mods) do %}{{ Escapes.htmlescape(m.email) }},{% end %}</textarea>
<h2>Ruleset</h2>
<p>The following HTML <strong>(!)</strong> will be displayed upon registration and user reporting. Use this to define a ruleset for your community. Tip: place an &lt;ol&gt; element to establish a clear numbered list.</p>
<textarea name="ruleset" class="uf" style="width:80%;"></textarea>
<h2>File download acceleration</h2>
<p>Using this feature is highly recommended as it lets Ikibooru outsource IO-intensive file downloads onto the reverse proxy, which has ways of speeding up the process. Otherwise large file downloads could freeze the entire website. Said proxy must also be configured to support the feature (it is typically called X-Sendfile or X-Accel-Redirect).</p>
<input type="text" name="sendfilehdr" autocomplete="off" placeholder="HTTP Header" value="{{ Escapes.htmlescape(BigGlobe.cfg.sendfile) }}" style="display:block;margin-bottom:1em;" />
<input type="text" name="sendfileprefix" autocomplete="off" placeholder="Path Prefix" value="{{ Escapes.htmlescape(BigGlobe.cfg.sendfileprefix) }}" style="display:block;margin-bottom:1em;" />
</div>
<div style="display:inline-block;width:30%">
<h2>Tag Categories</h2>
<p>These exist for ease within searching.</p>
<table>
<tr><td>Id</td><td>Name</td><td>Color</td></tr>
{% for i=1,BigGlobe.cfg.tc.n do %}
<tr>
<td>{{ i }}</td>
<td><input type="text" name="tcn{{ i }}" value="{{ Escapes.htmlescape(BigGlobe.cfg.tc[i].name) }}" autocomplete="off" /></td>
<td><input type="color" name="tcc{{ i }}" value="#{{ string.format("%06x", BigGlobe.cfg.tc[i].col) }}" /></td>
</tr>
{% end %}
</table>
</div>
</form>
<script src="/static/tagbox.js"></script>
{% else %}
<p>You are not authorized to view this page.</p>
{% end %}
{% end %}
{# base.inc