summaryrefslogtreecommitdiffhomepage
path: root/module/admin-core/contrib
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-04-11 18:24:25 +0000
committerSteven Barth <steven@midlink.org>2008-04-11 18:24:25 +0000
commit0268c3491f5b14ffdba097e6a983ffc7c53daa13 (patch)
tree2c1e23726f304a85cd0d75ac5836a6e6c7e7dc71 /module/admin-core/contrib
parent84889c281cffb8f05248e967e1897bd8a55cecd9 (diff)
* Major repository revision
Diffstat (limited to 'module/admin-core/contrib')
-rw-r--r--module/admin-core/contrib/ffluci-flash88
-rw-r--r--module/admin-core/contrib/init.d/luci_fw121
-rw-r--r--module/admin-core/contrib/uci/luci_fw2
3 files changed, 211 insertions, 0 deletions
diff --git a/module/admin-core/contrib/ffluci-flash b/module/admin-core/contrib/ffluci-flash
new file mode 100644
index 0000000000..3ff478f0f5
--- /dev/null
+++ b/module/admin-core/contrib/ffluci-flash
@@ -0,0 +1,88 @@
+#!/bin/sh
+. /etc/functions.sh
+
+# initialize defaults
+RAMFS_COPY_BIN="" # extra programs for temporary ramfs root
+RAMFS_COPY_DATA="" # extra data files
+export KEEP_PATTERN=""
+export VERBOSE=1
+
+# parse options
+while [ -n "$1" ]; do
+ case "$1" in
+ -k)
+ shift
+ export KEEP_PATTERN="$1"
+ ;;
+ -*)
+ echo "Invalid option: $1"
+ exit 1
+ ;;
+ *) break;;
+ esac
+ shift;
+done
+
+export CONFFILES=/tmp/sysupgrade.conffiles
+export CONF_TAR=/tmp/sysupgrade.tgz
+
+[ -f $CONFFILES ] && rm $CONFFILES
+[ -f $CONF_TAR ] && rm $CONF_TAR
+
+export ARGV="$*"
+export ARGC="$#"
+
+[ -z "$ARGV" ] && {
+ cat <<EOF
+Usage: $0 [options] <image file or URL>
+
+Options:
+ -k <"file 1, file 2, ..."> Files to be kept
+EOF
+ exit 1
+}
+
+add_pattern_conffiles() {
+ local file="$1"
+ find $KEEP_PATTERN >> "$file" 2>/dev/null
+ return 0
+}
+
+# hooks
+sysupgrade_image_check="platform_check_image"
+sysupgrade_init_conffiles=""
+
+[ -n "$KEEP_PATTERN" ] && append sysupgrade_init_conffiles "add_pattern_conffiles"
+
+include /lib/upgrade
+
+do_save_conffiles() {
+ [ -z "$(rootfs_type)" ] && {
+ echo "Cannot save config while running from ramdisk."
+ exit 3
+ return 0
+ }
+ run_hooks "$CONFFILES" $sysupgrade_init_conffiles
+
+ v "Saving config files..."
+ [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
+ tar c${TAR_V}zf "$CONF_TAR" -T "$CONFFILES" 2>/dev/null
+}
+
+type platform_check_image >/dev/null 2>/dev/null || {
+ echo "Firmware upgrade is not implemented for this platform."
+ exit 1
+}
+
+for check in $sysupgrade_image_check; do
+ ( eval "$check \"\$ARGV\"" ) || {
+ echo "Image check '$check' failed."
+ exit 2
+ }
+done
+
+[ -n "$sysupgrade_init_conffiles" ] && do_save_conffiles
+run_hooks "" $sysupgrade_pre_upgrade
+
+v "Switching to ramdisk..."
+run_ramfs '. /etc/functions.sh; include /lib/upgrade; do_upgrade' \ No newline at end of file
diff --git a/module/admin-core/contrib/init.d/luci_fw b/module/admin-core/contrib/init.d/luci_fw
new file mode 100644
index 0000000000..880c87dbe3
--- /dev/null
+++ b/module/admin-core/contrib/init.d/luci_fw
@@ -0,0 +1,121 @@
+#!/bin/sh /etc/rc.common
+START=46
+
+apply_portfw() {
+ local cfg="$1"
+ config_get proto "$cfg" proto
+ config_get dport "$cfg" dport
+ config_get iface "$cfg" iface
+ config_get to "$cfg" to
+
+ ports=$(echo $to | cut -sd: -f2)
+ if [ -n "$ports" ]; then
+ ports="--dport $(echo $ports | sed -e 's/-/:/')"
+ else
+ ports="--dport $dport"
+ fi
+
+ ip=$(echo $to | cut -d: -f1)
+
+ if ([ "$proto" == "tcpudp" ] || [ "$proto" == "tcp" ]); then
+ iptables -t nat -A luci_prerouting -i "$iface" -p tcp --dport "$dport" -j DNAT --to "$to"
+ iptables -A luci_forward -i "$iface" -p tcp -d "$ip" $ports -j ACCEPT
+ fi
+
+ if ([ "$proto" == "tcpudp" ] || [ "$proto" == "udp" ]); then
+ iptables -t nat -A luci_prerouting -i "$iface" -p udp --dport "$dport" -j DNAT --to "$to"
+ iptables -A luci_forward -i "$iface" -p udp -d "$ip" $ports -j ACCEPT
+ fi
+}
+
+apply_rule() {
+ local cfg="$1"
+ local cmd=""
+
+ config_get chain "$cfg" chain
+ [ -n "$chain" ] || return 0
+ [ "$chain" == "forward" ] && cmd="$cmd -A luci_forward"
+ [ "$chain" == "input" ] && cmd="$cmd -A luci_input"
+ [ "$chain" == "output" ] && cmd="$cmd -A luci_output"
+ [ "$chain" == "prerouting" ] && cmd="$cmd -t nat -A luci_prerouting"
+ [ "$chain" == "postrouting" ] && cmd="$cmd -t nat -A luci_postrouting"
+
+ config_get iface "$cfg" iface
+ [ -n "$iface" ] && cmd="$cmd -i $iface"
+
+ config_get oface "$cfg" oface
+ [ -n "$oface" ] && cmd="$cmd -o $oface"
+
+ config_get proto "$cfg" proto
+ [ -n "$proto" ] && cmd="$cmd -p $proto"
+
+ config_get source "$cfg" source
+ [ -n "$source" ] && cmd="$cmd -s $source"
+
+ config_get destination "$cfg" destination
+ [ -n "$destination" ] && cmd="$cmd -d $destination"
+
+ config_get sport "$cfg" sport
+ [ -n "$sport" ] && cmd="$cmd --sport $sport"
+
+ config_get dport "$cfg" dport
+ [ -n "$dport" ] && cmd="$cmd --dport $dport"
+
+ config_get todest "$cfg" todest
+ [ -n "$todest" ] && cmd="$cmd --to-destination $todest"
+
+ config_get tosrc "$cfg" tosrc
+ [ -n "$tosrc" ] && cmd="$cmd --to-source $tosrc"
+
+ config_get jump "$cfg" jump
+ [ -n "$jump" ] && cmd="$cmd -j $jump"
+
+ config_get command "$cfg" command
+ [ -n "$command" ] && cmd="$cmd $command"
+
+ iptables $cmd
+}
+
+start() {
+ ### Create subchains
+ iptables -N luci_input
+ iptables -N luci_output
+ iptables -N luci_forward
+ iptables -t nat -N luci_prerouting
+ iptables -t nat -N luci_postrouting
+
+ ### Hook in the chains
+ iptables -A input_rule -j luci_input
+ iptables -A output_rule -j luci_output
+ iptables -A forwarding_rule -j luci_forward
+ iptables -t nat -A prerouting_rule -j luci_prerouting
+ iptables -t nat -A postrouting_rule -j luci_postrouting
+
+ ### Read chains from config
+ config_load luci_fw
+ config_foreach apply_portfw portfw
+ config_foreach apply_rule rule
+}
+
+stop() {
+ ### Hook out the chains
+ iptables -D input_rule -j luci_input
+ iptables -D output_rule -j luci_output
+ iptables -D forwarding_rule -j luci_forward
+ iptables -t nat -D prerouting_rule -j luci_prerouting
+ iptables -t nat -D postrouting_rule -j luci_postrouting
+
+ ### Clear subchains
+ iptables -F luci_input
+ iptables -F luci_output
+ iptables -F luci_forward
+ iptables -t nat -F luci_prerouting
+ iptables -t nat -F luci_postrouting
+
+ ### Delete subchains
+ iptables -X luci_input
+ iptables -X luci_output
+ iptables -X luci_forward
+ iptables -t nat -X luci_prerouting
+ iptables -t nat -X luci_postrouting
+}
diff --git a/module/admin-core/contrib/uci/luci_fw b/module/admin-core/contrib/uci/luci_fw
new file mode 100644
index 0000000000..c7dec7f2c5
--- /dev/null
+++ b/module/admin-core/contrib/uci/luci_fw
@@ -0,0 +1,2 @@
+
+ \ No newline at end of file