From 6f934c0dbe089c532e2eef8b4008618ae2945ab0 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sun, 6 Apr 2008 12:08:05 +0000 Subject: [PATCH] * Added file upload capabilities --- contrib/ffluci-upload | 4 ++++ contrib/package/ffluci/Makefile | 1 + contrib/package/ffluci/ipkg/ffluci.postinst | 9 +++++++-- src/ffluci/http.lua | 8 +++++++- src/ffluci/template.lua | 3 ++- 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100755 contrib/ffluci-upload diff --git a/contrib/ffluci-upload b/contrib/ffluci-upload new file mode 100755 index 000000000..0128c2dd7 --- /dev/null +++ b/contrib/ffluci-upload @@ -0,0 +1,4 @@ +#!/usr/bin/haserl --shell=luac --upload-limit=6144 +-- This is a bit hacky: remove -upload from SCRIPT_NAME +ENV.SCRIPT_NAME = ENV.SCRIPT_NAME:sub(1, #ENV.SCRIPT_NAME - 7) +dofile("ffluci") \ No newline at end of file diff --git a/contrib/package/ffluci/Makefile b/contrib/package/ffluci/Makefile index 9ec4f311a..f10476e89 100644 --- a/contrib/package/ffluci/Makefile +++ b/contrib/package/ffluci/Makefile @@ -44,6 +44,7 @@ define Package/ffluci/install $(CP) $(PKG_BUILD_DIR)/dist/* $(1)/usr/lib/lua/ -R $(CP) $(PKG_BUILD_DIR)/contrib/media $(1)/www/ffluci/ -R $(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/ffluci $(1)/www/cgi-bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/ffluci-upload $(1)/www/cgi-bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/index.cgi $(1)/www/cgi-bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/index.html $(1)/www $(CP) $(PKG_BUILD_DIR)/contrib/uci/luci $(1)/etc/config/luci diff --git a/contrib/package/ffluci/ipkg/ffluci.postinst b/contrib/package/ffluci/ipkg/ffluci.postinst index 7265cb96b..97ada182d 100755 --- a/contrib/package/ffluci/ipkg/ffluci.postinst +++ b/contrib/package/ffluci/ipkg/ffluci.postinst @@ -1,4 +1,9 @@ #!/bin/sh -PATTERN='/cgi-bin/ffluci/admin:root:$p$root' -grep $PATTERN ${IPKG_INSTROOT}/etc/httpd.conf >/dev/null 2>/dev/null || echo $PATTERN >> ${IPKG_INSTROOT}/etc/httpd.conf +PATTERNS='/cgi-bin/ffluci/admin:root:$p$root /cgi-bin/ffluci-upload:root:$p$root' + +for i in "$PATTERNS" +do + grep "$i" ${IPKG_INSTROOT}/etc/httpd.conf >/dev/null 2>/dev/null || echo "$i" >> ${IPKG_INSTROOT}/etc/httpd.conf +done + [ -n ${IPKG_INSTROOT} ] || /etc/init.d/httpd restart diff --git a/src/ffluci/http.lua b/src/ffluci/http.lua index b7ce92ffa..06e1c43bd 100644 --- a/src/ffluci/http.lua +++ b/src/ffluci/http.lua @@ -54,11 +54,17 @@ function request_redirect(category, module, action, ...) module = module or "index" action = action or "index" - local pattern = os.getenv("SCRIPT_NAME") .. "/%s/%s/%s" + local pattern = script_name() .. "/%s/%s/%s" redirect(pattern:format(category, module, action), ...) end +-- Returns the script name +function script_name() + return ENV.SCRIPT_NAME +end + + -- Gets form value from key function formvalue(key, default) local c = formvalues() diff --git a/src/ffluci/template.lua b/src/ffluci/template.lua index 589f43c67..502013684 100644 --- a/src/ffluci/template.lua +++ b/src/ffluci/template.lua @@ -29,6 +29,7 @@ require("ffluci.config") require("ffluci.util") require("ffluci.fs") require("ffluci.i18n") +require("ffluci.http") require("ffluci.model.uci") viewdir = ffluci.config.path .. "/view/" @@ -53,7 +54,7 @@ compiler_enable_bytecode = false viewns = { translate = ffluci.i18n.translate, config = function(...) return ffluci.model.uci.get(...) or "" end, - controller = os.getenv("SCRIPT_NAME"), + controller = ffluci.http.script_name(), media = ffluci.config.main.mediaurlbase, write = io.write, include = function(name) Template(name):render(getfenv(2)) end, -- 2.25.1