Start work to drop spp

Start refactoring pages, makefile, ect to drop the simple preprocessor
as a dependency.
This commit is contained in:
Robin Malley 2023-04-06 21:27:28 +00:00
parent 68e73aba3e
commit 60213086dc
6 changed files with 51 additions and 306 deletions

View File

@ -11,20 +11,19 @@ GREP=grep
SORT=sort
# Config
worker_chroot = /var/lib/smr/kore_worker
kmgr_chroot = /var/lib/smr/kore_kmgr
parent_chroot = /var/lib/smr/kore_parent
worker_chroot = $(smr_var)/kore_worker
kmgr_chroot = $(smr_var)/kore_kmgr
parent_chroot = $(smr_var)/kore_parent
conf_path = /etc/smr
host_config = /etc/smr
ifeq ($(DEV),"true")
approot=/
chroot_dir=./kore_chroot$(approot)
else
approot=/var/smr/
chroot_dir=$(worker_chroot)$(approot)
smr_bin_path = /usr/local/lib
ifeq ($(DEV),true)
worker_chroot = ./kore_chroot
kmgr_chroot = ./kore_chroot
parent_chroot = ./kore_chroot
conf_path = ./kore_chroot/conf
smr_bin_path = ./kore_chroot
endif
mirror=http://dl-cdn.alpinelinux.org/alpine/
arch=aarch64
version=2.12.9
@ -33,14 +32,14 @@ certbot_email=--register-unsafely-without-email
user=robin
port=8888
domain=test.monster:$(port)
server_cert=cert/server.pem
server_key=cert/key.pem
server_cert=/root/cert/server.pem
server_key=/root/cert/key.pem
SPPFLAGS=-D port=$(port) -D kore_chroot=$(chroot_dir) -D chuser=$(user) -D domain=$(domain) -D bin_path="$(bin_path)" -D server_cert="$(server_cert)" -D server_key="$(server_key)" -D worker_chroot="$(worker_chroot)" -D kmgr_chroot="$(kmgr_chroot)" -D approot="$(approot)"
SPPFLAGS=-D port=$(port) -D kore_chroot=$(build_dir) -D chuser=$(user) -D domain=$(domain) -D bin_path="$(bin_path)" -D server_cert="$(server_cert)" -D server_key="$(server_key)" -D worker_chroot="$(worker_chroot)" -D kmgr_chroot="$(kmgr_chroot)"
# squelch prints, flip to print verbose information
#Q=@
Q=
LUAROCKS_FLAGS=--tree $(chroot_dir)/usr/lib/luarocks --lua-version 5.1
LUAROCKS_FLAGS=--tree $(build_dir)/usr/lib/luarocks --lua-version 5.1
chroot_packages=\
-p luarocks5.1 \
-p "build-base" \
@ -49,7 +48,6 @@ chroot_packages=\
-p luajit \
-p "lua5.1-dev" \
-p "luajit-dev" \
-p "lua5.1-lpeg" \
-p sqlite \
-p "sqlite-dev" \
-p certbot \
@ -69,20 +67,19 @@ lua_files=$(shell find src/lua/*.lua -type f) $(shell find src/lua/endpoints -ty
src_files=$(shell find src -type f) $(shell find conf -type f)
sql_files=$(shell find src/sql -type f)
test_files=$(shell find spec -type f)
built_tests=$(test_files:%=$(chroot_dir)%)
built_files=$(lua_files:src/lua/%.lua=$(chroot_dir)%.lua)
built_tests=$(test_files:%=$(build_dir)%)
built_files=$(lua_files:src/lua/%.lua=$(build_dir)%.lua)
in_page_files=$(shell find src/pages/*.in -type f)
in_part_files=$(shell find src/pages/parts/*.in -type f)
page_files=$(in_page_files:%.in=%)
part_files=$(in_part_files:%.in=%) $(shell find src/pages/parts/*.etlua -type f)
built_pages=$(page_files:src/pages/%.etlua=$(chroot_dir)pages/%.etlua)
built_sql=$(sql_files:src/sql/%.sql=$(chroot_dir)sql/%.sql)
part_files=$(shell find src/pages/parts/*.etlua -type f)
built_pages=$(page_files:src/pages/%.etlua=$(build_dir)pages/%.etlua)
built_sql=$(sql_files:src/sql/%.sql=$(build_dir)sql/%.sql)
built=$(built_files) $(built_sql) $(built_pages) $(built_tests)
asset_in_files=$(wildcard assets/*.in -type f)
asset_files=$(asset_in_files:%.in=%)
initscript=/lib/systemd/system/smr.service
config=$(conf_path)/smr.conf
bin_path=$(shell pwd)
built_bin=$(smr_bin_path)/smr.so
APK_aarch64_HASH=0164d47954c8a52e8ed10db1633174974a3b1e4182a1993a5a8343e394ee1bbc
APK_x86_64_HASH=5176da3d4c41f12a08b82809aca8e7e2e383b7930979651b8958eca219815af5
@ -91,13 +88,7 @@ apk_hash := $(APK_$(arch)_HASH)
help: ## Print this help
$(Q)$(GREP) -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | $(SORT) | $(AWK) 'BEGIN {FS = ":.*?## "}; {printf "%-10s %s\n", $$1, $$2}'
all: $(chroot_dir) smr.so $(built_files) $(built_pages) $(built_sql) ## Build and run smr in a chroot
$(Q)$(ECHO) "[running] $@"
$(Q)$(KODEV) run
conf/smr.conf : conf/smr.conf.in Makefile
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) -o $@ $(SPPFLAGS) $<
all: $(build_dir) smr.so $(built_files) $(built_pages) $(built_sql) ## Build and run smr in a chroot
apk-tools-static-$(version).apk:
wget -q $(mirror)latest-stable/main/$(arch)/apk-tools-static-$(version).apk
@ -106,30 +97,29 @@ clean: ## clean up all the files generated by this makefile
$(Q)$(ECHO) "[clean] $@"
$(Q)$(KODEV) clean
$(Q)$(RM) $(page_files)
$(Q)$(RM) conf/smr.conf
$(Q)$(RM) src/pages/parts/story_breif.etlua
$(Q)$(RM) src/lua/config.lua
$(Q)$(RM) $(asset_files)
$(Q)$(RM) smr.so
install: $(worker_chroot) $(kmgr_chroot) $(parent_chroot) $(initscript) $(config) smr.so $(built_files) $(built_pages) $(built_sql) ## Install smr into a new host system
$(Q)$(COPY) smr.so $(built_bin)
$(config) : conf/smr.conf
$(Q)$(MKDIR) $(host_config)
$(Q)$(MKDIR) $(conf_path)
$(Q)$(COPY) $< $@
$(initscript) : packaging/systemd/smr.service
$(Q)$(COPY) $< $@
cloc: ## calculate source lines of code in smr
cloc --force-lang="html",etlua.in --force-lang="html",etlua src assets Makefile
cloc --force-lang="html",etlua.in --force-lang="html",etlua --force-lang="lua",lua.in src assets Makefile
$(chroot_dir):
$(Q)$(MKDIR) $(chroot_dir)
$(Q)$(MKDIR) $(chroot_dir)/pages
$(Q)$(MKDIR) $(chroot_dir)/sql
$(Q)$(MKDIR) $(chroot_dir)/data
$(Q)$(MKDIR) $(chroot_dir)/data/archive
$(Q)$(MKDIR) $(chroot_dir)/endpoints
$(build_dir):
$(Q)$(MKDIR) $(build_dir)
$(Q)$(MKDIR) $(build_dir)/pages
$(Q)$(MKDIR) $(build_dir)/sql
$(Q)$(MKDIR) $(build_dir)/data
$(Q)$(MKDIR) $(build_dir)/data/archive
$(Q)$(MKDIR) $(build_dir)/endpoints
alpine-chroot-install:
$(Q)wget https://raw.githubusercontent.com/alpinelinux/alpine-chroot-install/v0.14.0/alpine-chroot-install \
@ -144,13 +134,13 @@ $(worker_chroot) $(kmgr_chroot) $(parent_chroot): alpine-chroot-install
code : $(built_files)
$(built_files): $(chroot_dir)%.lua : src/lua/%.lua $(chroot_dir)
$(built_files): $(build_dir)%.lua : src/lua/%.lua $(build_dir)
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $< $@
$(built_pages): $(chroot_dir)pages/%.etlua : src/pages/%.etlua
$(built_pages): $(build_dir)pages/%.etlua : src/pages/%.etlua $(build_dir)
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $^ $@
$(Q)$(COPY) $< $@
src/lua/config.lua : src/lua/config.lua.in Makefile
$(Q)$(ECHO) "[preprocess] $@"
@ -160,15 +150,11 @@ $(page_files) : % : %.in $(part_files)
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) $(SPPFLAGS) -o $@ $<
src/pages/parts/story_breif.etlua : src/pages/parts/story_breif.etlua.in
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) $(SPPFLAGS) -o $@ $<
$(built_sql): $(chroot_dir)sql/%.sql : src/sql/%.sql
$(built_sql): $(build_dir)sql/%.sql : src/sql/%.sql
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $^ $@
$(built_tests) : $(chroot_dir)% : %
$(built_tests) : $(build_dir)% : src/spec/%
$(Q)$(ECHO) "[copy] $@"
$(Q)$(COPY) $^ $@
@ -176,7 +162,7 @@ $(asset_files) : % : %.in
$(Q)$(ECHO) "[preprocess] $@"
$(Q)$(SPP) $(SPPFLAGS) -o $@ $<
smr.so : $(src_files) conf/smr.conf conf/build.conf $(asset_files) .flavor
smr.so : $(src_files) conf/build.conf $(asset_files)
$(Q)$(ECHO) "[build] $@"
$(Q)$(KODEV) build

View File

@ -1,220 +0,0 @@
# smr configuration
server tls {
bind 0.0.0.0 <{get port}>
}
seccomp_tracing yes
privsep worker {
runas root
root <{get worker_chroot }>
}
privsep keymgr {
runas root
root <{get kmgr_chroot }>
}
load <{get bin_path}>/smr.so
workers 1
http_body_max 8388608
tls_dhparam <{get bin_path}>/dh2048.pem
validator v_any regex [\s\S]*
validator v_storyid regex [a-zA-Z0-9$+!*'(),-]+
validator v_subdomain regex [a-z0-9]{1,30}
validator v_markup regex (plain|imageboard)
validator v_bool regex (0|1)
validator v_checkbox regex (|on)
validator v_hex_128 regex [0-9a-f]{128}
validator v_time regex [0-9]+
domain * {
attach tls
certfile cert/server.pem
certkey cert/key.pem
#I run kore behind a lighttpd reverse proxy, so this is a bit useless to me
accesslog /dev/null
route / {
handler home
methods get
}
route /_css/style.css {
handler asset_serve_style_css
methods get
}
route /_css/suggest_tags.css {
handler asset_serve_style_css
methods get
}
route /_css/milligram.css {
handler asset_serve_milligram_css
methods get
}
route /_css/milligram.min.css.map {
handler asset_serve_milligram_min_css_map
methods get
}
route /_faq {
handler asset_serve_faq_html
methods get
}
route /_js/suggest_tags.js {
handler asset_serve_suggest_tags_js
methods get
}
route /_js/bookmark.js {
handler asset_serve_bookmark_js
methods get
}
route /_js/intervine_deletion.js {
handler asset_serve_intervine_deletion_js
methods get
}
route /_js/index_scroll.js {
handler asset_serve_index_scroll_js
methods get
}
route /favicon.ico {
handler asset_serve_favicon_ico
methods get
}
route /_paste {
handler post_story
methods get post
validate post title v_any
validate post text v_any
validate post pasteas v_subdomain
validate post markup v_markup
validate post tags v_any
validate post unlisted v_checkbox
}
route /_edit {
handler edit_story
methods get post
validate qs:get story v_storyid
validate post title v_any
validate post story v_storyid
validate post text v_any
validate post pasteas v_subdomain
validate post markup v_markup
validate post tags v_any
validate post unlisted v_checkbox
}
route /_bio {
handler edit_bio
methods get post
validate post text v_any
validate post author v_subdomain
}
route /_login {
handler login
methods get post
validate post user v_subdomain
validate post pass v_any
}
route /_logout {
handler logout
methods get
}
route ^/_claim {
handler claim
methods get post
validate post user v_subdomain
}
route /_download {
handler download
methods get
validate qs:get story v_storyid
validate qs:get pwd v_hex_128
validate qs:get fmt v_any
}
route /_preview {
handler preview
methods post
validate post title v_any
validate post text v_any
validate post pasteas v_subdomain
validate post markup v_markup
validate post tags v_any
validate post unlisted v_checkbox
}
route /_search {
handler search
methods get
validate qs:get q v_any
}
route /_archive {
handler archive
methods get
validate qs:get t v_time
}
route /_api {
handler api
methods get
validate qs:get call v_any
validate qs:get data v_any
}
route /_delete {
handler delete
methods post
validate post story v_storyid
}
# Leading ^ is needed for dynamic routes, kore says the route is dynamic if it does not start with '/'
route ^/[^_].* {
handler read_story
methods get post
validate qs:get comments v_bool
validate qs:get pwd v_hex_128
validate post text v_any
validate post postas v_subdomain
validate post pwd v_hex_128
}
}

View File

@ -20,4 +20,8 @@ each worker), and should return a table with at least the following information
order for entrypoints (the strings are the names files)
]]
local oldconfigure = configure
function configure(...)
return oldconfigure(...)
end

View File

@ -21,6 +21,12 @@ local pagenames = {
"search",
"error",
"edit_bio",
"parts/header",
"parts/footer",
"parts/motd",
"parts/search",
"parts/story_breif",
"parts/taglist"
}
local pages = {}
for k,v in pairs(pagenames) do

View File

@ -1,32 +0,0 @@
<tr><td>
<% if story.unlisted then %>
&#9940;
<% end %>
</td><td>
<a href="<%= story.url %>">
<%- story.title %>
</a>
</td><td>
<% if story.isanon then %>
By Anonymous
<% else %>
By <a href="https://<%= story.author %>.<%= domain %>"><%= story.author %></a>
<% end %>
</td><td>
<%= story.hits %> hits
</td><td>
<%= story.ncomments %> comments
</td><td>
<ul class="row tag-list">
<% for i = 1,math.min(#story.tags, 5) do %>
<% local tag = story.tags[i] %>
<{system cat src/pages/parts/taglist.etlua}>
<% end %>
<% if #story.tags > 5 then %>
<li>+<%= #story.tags - 5 %></li>
<% end %>
</ul>
</td><td>
<%= story.posted %>
</td></tr>

View File

@ -184,6 +184,7 @@ This method does not requirei any parameters for GET requests.
This method requiries the following for POST requests:
* user :: [a-z0-9]{1,30} - The username to log in as
* pass :: any - The passfile for this user
***/
int
login(struct http_request *req){
return do_lua(req,"login");