import nitcorn
import markdown
import md5
+import config
intrude import wiki_html
fun to_http_response: HttpResponse
do
var resp = new HttpResponse(200)
- resp.body = tpl_page.write_to_string
+ resp.body = tpl_page
return resp
end
end
var file_path = turi.strip_leading_slash
file_path = wiki_root / file_path
- if not file_path.simplify_path.has_prefix(source_dir) then
+ var abs_file_path = file_path.to_absolute_path
+ var abs_source_dir = source_dir.to_absolute_path
+
+ if not abs_file_path.has_prefix(abs_source_dir) then
# Attempting to access a file outside the source directory
var entity = new WikiEditForm(wiki, turi.strip_leading_slash,
"Access denied: ", "", "<p>Target outside of the source directory</p>")
if has_prefix("/") then return substring_from(1)
return self
end
+
+ private fun to_absolute_path: String
+ do
+ return (getcwd / self).simplify_path
+ end
+end
+
+var opt_config = new OptionString("Path to config.ini file", "-c", "--config")
+var opt_host = new OptionString("Host to bind the server to", "--host")
+var opt_port = new OptionInt("Port to bind the server to", 8000, "--port")
+var opt_pass = new OptionString("Password file path", "--pass")
+
+var config = new Config
+config.add_option(opt_config, opt_host, opt_port, opt_pass)
+
+var usage = new Buffer
+usage.append "Usage: wiki_edit [OPTION]...\n"
+usage.append "Web server to server generated files and modify the wiki from a web form."
+config.tool_description = usage.write_to_string
+
+config.parse_options(args)
+
+if config.opt_help.value then
+ config.usage
+ exit 0
end
-var config_file_path = "config.ini"
-var iface = "localhost:8080"
-var password_file_path = "passwords"
+var config_file_path = opt_config.value or else "config.ini"
+var iface = "{opt_host.value or else "localhost"}:{opt_port.value}"
+var password_file_path = opt_pass.value or else "passwords"
# Load passwords for file
var passwords = if password_file_path.file_exists then