├── .gitignore ├── luci ├── build │ ├── lucid.lua │ ├── makedocs.sh │ ├── luci.cgi │ ├── hostenv.sh │ ├── config.mk │ ├── mkbasepot.sh │ ├── i18n-sync.sh │ ├── mkversion.sh │ ├── i18n-init.sh │ ├── mkrevision.sh │ ├── i18n-po2lua.pl │ ├── gccconfig.mk │ ├── i18n-update.pl │ ├── setup.lua │ ├── module.mk │ ├── i18n-scan.pl │ └── zoneinfo2lua.pl ├── applications │ └── luci-aria2 │ │ ├── Makefile │ │ ├── root │ │ └── etc │ │ │ ├── uci-defaults │ │ │ └── luci-aria2 │ │ │ ├── config │ │ │ └── aria2 │ │ │ └── init.d │ │ │ └── aria2 │ │ └── luasrc │ │ ├── controller │ │ └── aria2.lua │ │ └── model │ │ └── cbi │ │ └── aria2.lua ├── libs │ └── lmo │ │ ├── src │ │ ├── template_lualib.h │ │ ├── template_utils.h │ │ ├── template_parser.h │ │ ├── template_lmo.h │ │ ├── template_lualib.c │ │ ├── po2lmo.c │ │ ├── template_lmo.c │ │ ├── template_parser.c │ │ └── template_utils.c │ │ ├── Makefile │ │ └── standalone.mk ├── luci-extra │ └── Makefile ├── po │ └── zh_CN │ │ └── aria2.po └── Makefile ├── packages ├── shadowsocks-libev │ ├── files │ │ ├── shadowsocks.json │ │ └── shadowsocks.init │ └── Makefile ├── sniproxy │ ├── files │ │ ├── sniproxy.init │ │ └── sniproxy.conf │ └── Makefile ├── dnscrypt-proxy │ ├── files │ │ ├── init │ │ └── config │ └── Makefile ├── yaaw │ └── Makefile └── webui-aria2 │ └── Makefile ├── README.md ├── libs └── libudns │ ├── patches │ └── 100-cross-compile-dirty-fix.patch │ └── Makefile └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /luci/build/lucid.lua: -------------------------------------------------------------------------------- 1 | dofile "build/setup.lua" 2 | require "luci.lucid".start() 3 | -------------------------------------------------------------------------------- /luci/applications/luci-aria2/Makefile: -------------------------------------------------------------------------------- 1 | PO = aria2 2 | 3 | include ../../build/config.mk 4 | include ../../build/module.mk 5 | -------------------------------------------------------------------------------- /luci/build/makedocs.sh: -------------------------------------------------------------------------------- 1 | luadoc -d $2 --no-files $(for f in $(find $1 -name '*.lua' -type f); do if grep -q -- "@return" $f; then echo $f; fi; done) 2 | echo API-Documentation was created in $2. 3 | -------------------------------------------------------------------------------- /luci/build/luci.cgi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/lua 2 | 3 | dofile "../../build/setup.lua" 4 | 5 | require "luci.cacheloader" 6 | require "luci.sgi.cgi" 7 | luci.dispatcher.indexcache = "/tmp/luci-indexcache" 8 | luci.sgi.cgi.run() 9 | -------------------------------------------------------------------------------- /packages/shadowsocks-libev/files/shadowsocks.json: -------------------------------------------------------------------------------- 1 | { 2 | "server":"127.0.0.1", 3 | "server_port":8388, 4 | "local_port":1080, 5 | "password":"barfoo!", 6 | "timeout":60, 7 | "method":null 8 | } 9 | -------------------------------------------------------------------------------- /luci/applications/luci-aria2/root/etc/uci-defaults/luci-aria2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | uci -q batch <<-EOF >/dev/null 4 | delete ucitrack.@aria2[-1] 5 | add ucitrack aria2 6 | set ucitrack.@aria2[-1].init=aria2 7 | commit ucitrack 8 | EOF 9 | 10 | rm -f /tmp/luci-indexcache 11 | exit 0 12 | -------------------------------------------------------------------------------- /luci/applications/luci-aria2/root/etc/config/aria2: -------------------------------------------------------------------------------- 1 | 2 | config aria2 'main' 3 | option enabled '0' 4 | option file_allocation 'none' 5 | option bt_enable_lpd 'true' 6 | option enable_dht 'true' 7 | option follow_torrent 'true' 8 | option user 'root' 9 | option dir '/mnt/sda1' 10 | option save_session_interval '30' 11 | -------------------------------------------------------------------------------- /luci/build/hostenv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export LD_LIBRARY_PATH="$1/usr/lib:$LD_LIBRARY_PATH" 3 | [ `uname -s` = "Darwin" ] && export DYLD_LIBRARY_PATH="$1/usr/lib:$DYLD_LIBRARY_PATH" 4 | export PATH="$1/bin:$1/usr/bin:$PATH" 5 | export LUA_PATH="$1/$2/?.lua;$1/$2/?/init.lua;;" 6 | export LUA_CPATH="$1/$3/?.so;;" 7 | export LUCI_SYSROOT="$1" 8 | $4 9 | -------------------------------------------------------------------------------- /packages/sniproxy/files/sniproxy.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # 3 | # Copyright (C) 2017 nanpuyue , https://blog.nanpuyue.com 4 | # 5 | 6 | START=95 7 | 8 | SERVICE_USE_PID=1 9 | 10 | start() { 11 | service_start /usr/bin/sniproxy -c /etc/sniproxy.conf 12 | } 13 | 14 | stop() { 15 | service_stop /usr/bin/sniproxy 16 | } 17 | -------------------------------------------------------------------------------- /packages/shadowsocks-libev/files/shadowsocks.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # Copyright (C) 2006-2011 OpenWrt.org 3 | 4 | START=95 5 | 6 | SERVICE_USE_PID=1 7 | SERVICE_WRITE_PID=1 8 | SERVICE_DAEMONIZE=1 9 | 10 | start() { 11 | service_start /usr/bin/ss-local -c /etc/shadowsocks.json 12 | } 13 | 14 | stop() { 15 | service_stop /usr/bin/ss-local 16 | } 17 | -------------------------------------------------------------------------------- /packages/sniproxy/files/sniproxy.conf: -------------------------------------------------------------------------------- 1 | ### do not edit ### 2 | user daemon 3 | pidfile /var/run/sniproxy.pid 4 | ### end ### 5 | 6 | resolver { 7 | nameserver 8.8.8.8 8 | } 9 | 10 | error_log { 11 | syslog daemon 12 | priority notice 13 | } 14 | 15 | listen 0.0.0.0:443 { 16 | proto tls 17 | table https_hosts 18 | } 19 | 20 | table https_hosts { 21 | .* *:443 22 | } 23 | -------------------------------------------------------------------------------- /luci/build/config.mk: -------------------------------------------------------------------------------- 1 | LUAC = luac 2 | LUAC_OPTIONS = -s 3 | LUA_TARGET ?= source 4 | 5 | LUA_MODULEDIR = /usr/lib/lua 6 | LUA_LIBRARYDIR = /usr/lib/lua 7 | 8 | LUCI_MODULEDIR = $(LUA_MODULEDIR)/luci 9 | LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci 10 | LUCI_I18NDIR = $(LUA_MODULEDIR)/luci/i18n 11 | 12 | UVL_SCHEMEDIR = host/lib/uci/schema 13 | 14 | HTDOCS = /www 15 | 16 | LUA=$(shell which lua) 17 | -------------------------------------------------------------------------------- /luci/build/mkbasepot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | [ -d ./build ] || { 4 | echo "Please execute as ./build/mkbasepot.sh" >&2 5 | exit 1 6 | } 7 | 8 | echo -n "Updating po/templates/base.pot ... " 9 | 10 | ./build/i18n-scan.pl \ 11 | libs/core/ libs/web/ protocols/ \ 12 | modules/admin-core/ modules/admin-full/ \ 13 | themes/base/ themes/openwrt/ \ 14 | > po/templates/base.pot 15 | 16 | echo "done" 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenWrt-Extra 2 | ============= 3 | 4 | Some extra packages for OpenWrt 5 | 6 | Add "src-git extra git://github.com/nanpuyue/openwrt-extra.git" to feeds.conf.default. 7 | 8 | ```bash 9 | ./scripts/feeds update -a 10 | ./scripts/feeds install -a 11 | ``` 12 | 13 | the list of packages: 14 | * dnscrypt-proxy 15 | * libsodium (depended by dnscrypt-proxy, but have no ipk) 16 | * luci-app-aria2 17 | * shadowsocks-libev 18 | * webui-aria2 19 | * yaaw 20 | -------------------------------------------------------------------------------- /luci/build/i18n-sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for m in */*/Makefile; do 4 | if grep -qE '^PO *=' $m; then 5 | p="${m%/Makefile}" 6 | t="$(sed -ne 's/^PO *= *//p' $m)" 7 | 8 | case "$t" in 9 | *\ *) 10 | echo "WARNING: Cannot handle $p" >&2 11 | continue 12 | ;; 13 | *base*) 14 | continue 15 | ;; 16 | esac 17 | 18 | if [ -f "po/templates/$t.pot" ]; then 19 | ./build/i18n-scan.pl "$p" > "po/templates/$t.pot" 20 | fi 21 | fi 22 | done 23 | 24 | ./build/mkbasepot.sh 25 | ./build/i18n-update.pl po 26 | -------------------------------------------------------------------------------- /luci/build/mkversion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ "${4%%/*}" = "branches" ]; then 3 | variant="LuCI ${4##*[-/]} Branch" 4 | elif [ "${4%%/*}" = "tags" ]; then 5 | variant="LuCI ${4##*[-/]} Release" 6 | else 7 | variant="LuCI Trunk" 8 | fi 9 | 10 | cat < $1 11 | local pcall, dofile, _G = pcall, dofile, _G 12 | 13 | module "luci.version" 14 | 15 | if pcall(dofile, "/etc/openwrt_release") and _G.DISTRIB_DESCRIPTION then 16 | distname = "" 17 | distversion = _G.DISTRIB_DESCRIPTION 18 | else 19 | distname = "${2:-OpenWrt}" 20 | distversion = "${3:-Development Snapshot}" 21 | end 22 | 23 | luciname = "$variant" 24 | luciversion = "${5:-svn}" 25 | EOF 26 | -------------------------------------------------------------------------------- /luci/build/i18n-init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PATTERN=$1 4 | SCM= 5 | 6 | [ -d .svn ] && SCM="svn" 7 | git=$( which git 2>/dev/null ) 8 | [ "$git" ] && "$git" status >/dev/null && SCM="git" 9 | 10 | [ -z "$SCM" ] && { 11 | echo "Unsupported SCM tool" >&2 12 | exit 1 13 | } 14 | 15 | [ -z "$PATTERN" ] && PATTERN="*.pot" 16 | 17 | for lang in $(cd po; echo ?? ??_??); do 18 | for file in $(cd po/templates; echo $PATTERN); do 19 | if [ -f po/templates/$file -a ! -f "po/$lang/${file%.pot}.po" ]; then 20 | msginit --no-translator -l "$lang" -i "po/templates/$file" -o "po/$lang/${file%.pot}.po" 21 | $SCM add "po/$lang/${file%.pot}.po" 22 | fi 23 | done 24 | done 25 | -------------------------------------------------------------------------------- /luci/build/mkrevision.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TOPDIR="${0%mkrevision.sh}" 4 | 5 | [ -d "$TOPDIR/../build" ] || { 6 | echo "Please execute as ./build/mkrevision.sh" >&2 7 | exit 1 8 | } 9 | 10 | ( 11 | cd "$TOPDIR" 12 | if svn info >/dev/null 2>/dev/null; then 13 | revision="svn-r$(LC_ALL=C svn info | sed -ne 's/^Revision: //p')" 14 | elif git log -1 >/dev/null 2>/dev/null; then 15 | revision="svn-r$(LC_ALL=C git log -1 | sed -ne 's/.*git-svn-id: .*@\([0-9]\+\) .*/\1/p')" 16 | if [ "$revision" = "svn-r" ]; then 17 | revision="git-$(LC_ALL=C git log -1 --pretty=%h)" 18 | fi 19 | else 20 | revision="unknown" 21 | fi 22 | 23 | echo "$revision" 24 | ) 25 | -------------------------------------------------------------------------------- /luci/applications/luci-aria2/luasrc/controller/aria2.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | LuCI - Lua Configuration Interface - aria2 support 3 | 4 | Copyright 2014 nanpuyue 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | ]]-- 12 | 13 | module("luci.controller.aria2", package.seeall) 14 | 15 | function index() 16 | if not nixio.fs.access("/etc/config/aria2") then 17 | return 18 | end 19 | 20 | local page = entry({"admin", "services", "aria2"}, cbi("aria2"), _("Aria2 Settings")) 21 | page.dependent = true 22 | 23 | end 24 | -------------------------------------------------------------------------------- /luci/build/i18n-po2lua.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | @ARGV == 2 || die "Usage: $0 \n"; 4 | 5 | my $source_dir = shift @ARGV; 6 | my $target_dir = shift @ARGV; 7 | 8 | if( ! -d $target_dir ) 9 | { 10 | system('mkdir', '-p', $target_dir); 11 | } 12 | 13 | if( open F, "find $source_dir -type f -name '*.po' |" ) 14 | { 15 | while( chomp( my $file = readline F ) ) 16 | { 17 | my ( $lang, $basename ) = $file =~ m{.+/(\w+)/([^/]+)\.po$}; 18 | $lang = lc $lang; 19 | $lang =~ s/_/-/g; 20 | 21 | printf "Generating %-40s ", "$target_dir/$basename.$lang.lmo"; 22 | system("./build/po2lmo", $file, "$target_dir/$basename.$lang.lmo"); 23 | print ( -f "$target_dir/$basename.$lang.lmo" ? "done\n" : "empty\n" ); 24 | } 25 | 26 | close F; 27 | } 28 | -------------------------------------------------------------------------------- /luci/build/gccconfig.mk: -------------------------------------------------------------------------------- 1 | OS ?= $(shell uname) 2 | 3 | LUA_SHLIBS = $(shell pkg-config --silence-errors --libs lua5.1 || pkg-config --silence-errors --libs lua-5.1 || pkg-config --silence-errors --libs lua) 4 | LUA_LIBS = $(if $(LUA_SHLIBS),$(LUA_SHLIBS),$(firstword $(wildcard /usr/lib/liblua.a /usr/local/lib/liblua.a /opt/local/lib/liblua.a))) 5 | LUA_CFLAGS = $(shell pkg-config --silence-errors --cflags lua5.1 || pkg-config --silence-errors --cflags lua-5.1 || pkg-config --silence-errors --cflags lua) 6 | 7 | CC = gcc 8 | AR = ar 9 | RANLIB = ranlib 10 | CFLAGS = -O2 11 | FPIC = -fPIC 12 | EXTRA_CFLAGS = --std=gnu99 13 | WFLAGS = -Wall -pedantic 14 | CPPFLAGS = 15 | COMPILE = $(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(WFLAGS) 16 | ifeq ($(OS),Darwin) 17 | SHLIB_FLAGS = -bundle -undefined dynamic_lookup 18 | else 19 | SHLIB_FLAGS = -shared 20 | endif 21 | LINK = $(CC) $(LDFLAGS) 22 | 23 | -------------------------------------------------------------------------------- /luci/build/i18n-update.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | @ARGV >= 1 || die "Usage: $0 []\n"; 4 | 5 | my $source = shift @ARGV; 6 | my $pattern = shift @ARGV || '*.po'; 7 | 8 | sub fixup_header_order 9 | { 10 | my $file = shift || return; 11 | local $/; 12 | 13 | open P, "< $file" || die "open(): $!"; 14 | my $data = readline P; 15 | close P; 16 | 17 | $data =~ s/("Language-Team: .*?\\n"\n)(.+?)("Language: .*?\\n"\n)/$1$3$2/s; 18 | 19 | open P, "> $file" || die "open(): $!"; 20 | print P $data; 21 | close P; 22 | } 23 | 24 | if( open F, "find $source -type f -name '$pattern' |" ) 25 | { 26 | while( chomp( my $file = readline F ) ) 27 | { 28 | my ( $basename ) = $file =~ m{.+/([^/]+)\.po$}; 29 | 30 | if( -f "$source/templates/$basename.pot" ) 31 | { 32 | printf "Updating %-40s", $file; 33 | system("msgmerge", "-U", "-N", $file, "$source/templates/$basename.pot"); 34 | fixup_header_order($file); 35 | } 36 | } 37 | 38 | close F; 39 | } 40 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LuCI Template - Lua library header 3 | * 4 | * Copyright (C) 2009 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _TEMPLATE_LUALIB_H_ 20 | #define _TEMPLATE_LUALIB_H_ 21 | 22 | #include "template_parser.h" 23 | #include "template_utils.h" 24 | #include "template_lmo.h" 25 | 26 | #define TEMPLATE_LUALIB_META "template.parser" 27 | 28 | LUALIB_API int luaopen_luci_template_parser(lua_State *L); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /luci/build/setup.lua: -------------------------------------------------------------------------------- 1 | local SYSROOT = os.getenv("LUCI_SYSROOT") 2 | 3 | -- override uci access 4 | local uci_core = require "uci" 5 | local uci_model = require "luci.model.uci" 6 | 7 | uci_model.cursor = function(config, save) 8 | return uci_core.cursor(config or SYSROOT .. "/etc/config", save or SYSROOT .. "/tmp/.uci") 9 | end 10 | 11 | uci_model.cursor_state = function() 12 | return uci_core.cursor(SYSROOT .. "/etc/config", SYSROOT .. "/var/state") 13 | end 14 | 15 | uci_model.inst = uci_model.cursor() 16 | uci_model.inst_state = uci_model.cursor_state() 17 | 18 | -- allow any password in local sdk 19 | local sys = require "luci.sys" 20 | sys.user.checkpasswd = function() return true end 21 | sys.user.getpasswd = function() return "x" end 22 | 23 | -- dummy sysinfo on Darwin 24 | require "nixio" 25 | 26 | if not nixio.sysinfo then 27 | function nixio.sysinfo() 28 | return { 29 | bufferram = 0, 30 | freehigh = 0, 31 | freeram = 0, 32 | freeswap = 0, 33 | loads = { 0.0, 0.0, 0.0 }, 34 | mem_unit = 1024, 35 | procs = 0, 36 | sharedram = 0, 37 | totalhigh = 0 38 | } 39 | end 40 | end 41 | 42 | -- override nixio.fs.access() to check sysroot first 43 | local _access = nixio.fs.access 44 | function nixio.fs.access(file) 45 | return _access(SYSROOT .. "/" .. file) or _access(file) 46 | end 47 | -------------------------------------------------------------------------------- /packages/dnscrypt-proxy/files/init: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # Copyright (C) 2014 nanpuyue 3 | 4 | START=60 5 | SERVICE_WRITE_PID=1 6 | SERVICE_DAEMONIZE=1 7 | SERVICE_UID='nobody' 8 | 9 | OPTIONS="" 10 | 11 | append_args() { 12 | [ -n "$2" ] && OPTIONS="$OPTIONS $1 $2" 13 | } 14 | 15 | trans_args() { 16 | case "$1" in 17 | 'local_address' ) append_args '-a' "$2";; 18 | 'edns_payload_size' ) append_args '-e' "$2";; 19 | 'provider_key' ) append_args '-k' "$2";; 20 | 'logfile' ) append_args '-l' "$2";; 21 | 'loglevel' ) append_args '-m' "$2";; 22 | 'max_active_requests' ) append_args '-n' "$2";; 23 | 'resolver_address' ) append_args '-r' "$2";; 24 | 'provider_name' ) append_args '-N' "$2";; 25 | 'user' ) SERVICE_UID="$2";; 26 | 'tcp_only' ) [ "$2" -eq '1' ] && OPTIONS="$OPTIONS -T";; 27 | esac 28 | } 29 | 30 | option_cb() { 31 | trans_args "$1" "$2" 32 | } 33 | 34 | section_enabled() { 35 | local result 36 | config_get_bool result "$1" 'enabled' 0 37 | [ $result -eq 1 ] 38 | } 39 | 40 | start_instance() { 41 | section_enabled "$1" && service_start /usr/sbin/dnscrypt-proxy $OPTIONS 42 | } 43 | 44 | start() { 45 | config_load 'dnscrypt-proxy' 46 | config_foreach start_instance 'dnscrypt-proxy' 47 | } 48 | 49 | stop() { 50 | service_stop /usr/sbin/dnscrypt-proxy 51 | } 52 | -------------------------------------------------------------------------------- /luci/libs/lmo/Makefile: -------------------------------------------------------------------------------- 1 | ifneq (,$(wildcard ../../build/config.mk)) 2 | include ../../build/config.mk 3 | include ../../build/module.mk 4 | include ../../build/gccconfig.mk 5 | else 6 | include standalone.mk 7 | endif 8 | 9 | TPL_LDFLAGS = 10 | TPL_CFLAGS = 11 | TPL_SO = parser.so 12 | TPL_PO2LMO = po2lmo 13 | TPL_PO2LMO_OBJ = src/po2lmo.o 14 | TPL_LMO_OBJ = src/template_lmo.o 15 | TPL_COMMON_OBJ = src/template_parser.o src/template_utils.o 16 | TPL_LUALIB_OBJ = src/template_lualib.o 17 | 18 | %.o: %.c 19 | $(COMPILE) $(TPL_CFLAGS) $(LUA_CFLAGS) $(FPIC) -c -o $@ $< 20 | 21 | compile: build-clean $(TPL_COMMON_OBJ) $(TPL_LUALIB_OBJ) $(TPL_LMO_OBJ) $(TPL_PO2LMO_OBJ) 22 | $(LINK) $(SHLIB_FLAGS) $(TPL_LDFLAGS) -o src/$(TPL_SO) \ 23 | $(TPL_COMMON_OBJ) $(TPL_LMO_OBJ) $(TPL_LUALIB_OBJ) 24 | $(LINK) -o src/$(TPL_PO2LMO) \ 25 | $(TPL_LMO_OBJ) $(TPL_PO2LMO_OBJ) 26 | mkdir -p dist$(LUCI_LIBRARYDIR)/template 27 | cp src/$(TPL_SO) dist$(LUCI_LIBRARYDIR)/template/$(TPL_SO) 28 | 29 | install: build 30 | cp -pR dist$(LUA_LIBRARYDIR)/* $(LUA_LIBRARYDIR) 31 | 32 | clean: build-clean 33 | 34 | build-clean: 35 | rm -f src/*.o src/$(TPL_SO) 36 | 37 | host-compile: build-clean host-clean $(TPL_LMO_OBJ) $(TPL_PO2LMO_OBJ) 38 | $(LINK) -o src/$(TPL_PO2LMO) $(TPL_LMO_OBJ) $(TPL_PO2LMO_OBJ) 39 | 40 | host-install: host-compile 41 | cp src/$(TPL_PO2LMO) ../../build/$(TPL_PO2LMO) 42 | 43 | host-clean: 44 | rm -f ../../build/$(TPL_PO2LMO) 45 | -------------------------------------------------------------------------------- /packages/yaaw/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 nanpuyue 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=yaaw 11 | PKG_VERSION:=2014-07-12 12 | PKG_RELEASE:=1 13 | PKG_MAINTAINER:=nanpuyue 14 | 15 | PKG_SOURCE_PROTO:=git 16 | PKG_SOURCE_URL:=git://github.com/binux/yaaw.git 17 | PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) 18 | PKG_SOURCE_VERSION:=c23ae2456ec95778651411e5b148b836307f6d8d 19 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz 20 | 21 | include $(INCLUDE_DIR)/package.mk 22 | 23 | define Package/yaaw 24 | SECTION:=net 25 | CATEGORY:=Network 26 | SUBMENU:=Download Manager 27 | DEPENDS:=+aria2 28 | TITLE:=Yet another aria2 web frontend 29 | URL:=https://github.com/binux/yaaw 30 | PKGARCH:=all 31 | endef 32 | 33 | define Package/yaaw/description 34 | Yet Another Aria2 Web Frontend in pure HTML/CSS/Javascirpt. 35 | endef 36 | 37 | define Build/Compile 38 | endef 39 | 40 | define Package/yaaw/install 41 | $(INSTALL_DIR) $(1)/www/yaaw 42 | $(CP) $(PKG_BUILD_DIR)/js $(1)/www/yaaw 43 | $(CP) $(PKG_BUILD_DIR)/img $(1)/www/yaaw 44 | $(CP) $(PKG_BUILD_DIR)/css $(1)/www/yaaw 45 | $(CP) $(PKG_BUILD_DIR)/index.html $(1)/www/yaaw 46 | $(CP) $(PKG_BUILD_DIR)/offline.appcache $(1)/www/yaaw 47 | endef 48 | 49 | $(eval $(call BuildPackage,yaaw)) 50 | -------------------------------------------------------------------------------- /libs/libudns/patches/100-cross-compile-dirty-fix.patch: -------------------------------------------------------------------------------- 1 | from https://github.com/hqvv/openwrt-udns 2 | diff --git a/configure b/configure 3 | index dda98b3..54be3c3 100755 4 | --- a/configure 5 | +++ b/configure 6 | @@ -12,7 +12,7 @@ else 7 | exit 1 8 | fi 9 | 10 | -options="ipv6" 11 | +options="ipv6 cross_compile" 12 | 13 | for opt in $options; do 14 | eval enable_$opt= 15 | @@ -26,6 +26,7 @@ enable() { 16 | opt=`echo "$1" | sed 's/^--[^-]*-//'` 17 | case "$opt" in 18 | ipv6) ;; 19 | + cross_compile) ;; 20 | *) echo "configure: unrecognized option \`$1'" >&2; exit 1;; 21 | esac 22 | eval enable_$opt=$2 23 | @@ -47,6 +48,7 @@ where options are: 24 | --help - print this help and exit 25 | Optional features (all enabled by default if system supports a feature): 26 | ipv6 - enable/disable IP version 6 (IPv6) support 27 | + cross_compile - enable/disable cross compile support 28 | EOF 29 | exit 0 30 | ;; 31 | diff --git a/configure.lib b/configure.lib 32 | index 541177a..5af49db 100644 33 | --- a/configure.lib 34 | +++ b/configure.lib 35 | @@ -46,6 +46,10 @@ ac_ign() { 36 | # ac_run command... 37 | # captures output in conftest.out 38 | ac_run() { 39 | + # cross compile does not running target 40 | + if [ n != "$enable_cross_compile" ]; then 41 | + return 0 42 | + fi 43 | # apparently UnixWare (for one) /bin/sh optimizes the following "if" 44 | # "away", by checking if there's such a command BEFORE redirecting 45 | # output. So error message (like "gcc: command not found") goes 46 | -------------------------------------------------------------------------------- /packages/webui-aria2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 nanpuyue 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=webui-aria2 11 | PKG_VERSION:=20140302 12 | PKG_RELEASE:=1 13 | PKG_MAINTAINER:=nanpuyue 14 | 15 | PKG_SOURCE_PROTO:=git 16 | PKG_SOURCE_URL:=https://github.com/ziahamza/webui-aria2.git 17 | PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) 18 | PKG_SOURCE_VERSION:=c129b53b13 19 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz 20 | 21 | include $(INCLUDE_DIR)/package.mk 22 | 23 | define Package/webui-aria2 24 | SECTION:=net 25 | CATEGORY:=Network 26 | SUBMENU:=Download Manager 27 | DEPENDS:=+aria2 28 | TITLE:=An interface to interact with aria2 29 | URL:=https://github.com/ziahamza/webui-aria2 30 | PKGARCH:=all 31 | endef 32 | 33 | define Package/webui-aria2/description 34 | The aim for this project is to create the worlds best and hottest interface to interact with aria2. Very simple to use. 35 | endef 36 | 37 | define Build/Compile 38 | endef 39 | 40 | define Package/webui-aria2/install 41 | $(INSTALL_DIR) $(1)/www/webui-aria2 42 | $(CP) $(PKG_BUILD_DIR)/font $(1)/www/webui-aria2 43 | $(CP) $(PKG_BUILD_DIR)/js $(1)/www/webui-aria2 44 | $(CP) $(PKG_BUILD_DIR)/img $(1)/www/webui-aria2 45 | $(CP) $(PKG_BUILD_DIR)/css $(1)/www/webui-aria2 46 | $(CP) $(PKG_BUILD_DIR)/index.html $(1)/www/webui-aria2 47 | $(CP) $(PKG_BUILD_DIR)/favicon.ico $(1)/www/webui-aria2 48 | endef 49 | 50 | $(eval $(call BuildPackage,webui-aria2)) 51 | -------------------------------------------------------------------------------- /packages/dnscrypt-proxy/files/config: -------------------------------------------------------------------------------- 1 | # 2 | # Available options: 3 | # 4 | # enabled <0|1> 5 | # enable the dnscrypt-proxy service or not. 6 | # local_address [:port] 7 | # what local IP the daemon will listen to, with an optional port. 8 | # edns_payload_size 9 | # transparently add an OPT pseudo-RR to outgoing queries in order 10 | # to enable the EDNS0 extension mechanism. The payload size is the 11 | # size of the largest response we accept from the resolver before 12 | # retrying over TCP. This feature is enabled by default, with a pay- 13 | # load size of 1252 bytes. Any value below 512 disables it. 14 | # provider_key 15 | # specify the provider public key. 16 | # logfile 17 | # log events to this file instead of the standard output. 18 | # loglevel 19 | # don't log events with priority above this level after the service 20 | # has been started up. Default is the value for LOG_INFO. 21 | # max_active_requests 22 | # set the maximum number of simultaneous active requests. The 23 | # default value is 250. 24 | # resolver_address [:port] 25 | # a DNSCrypt-capable resolver IP address with an optional port. The 26 | # default port is 443. 27 | # user 28 | # run the dnscrypt-proxy service as the user, default is "nobody". 29 | # provider_name 30 | # the fully-qualified name of the dnscrypt certificate provider. 31 | # tcp_only <0|1> 32 | # always use TCP. A connection made using UDP will get a truncated 33 | # response, so that the (stub) resolver retries using TCP. 34 | # 35 | 36 | config dnscrypt-proxy 37 | option enabled '1' 38 | option local_address '127.0.0.1:5300' 39 | option max_active_requests '64' 40 | -------------------------------------------------------------------------------- /luci/build/module.mk: -------------------------------------------------------------------------------- 1 | MAKEPATH:=$(dir $(lastword $(MAKEFILE_LIST))) 2 | -include $(MAKEPATH)config.mk 3 | -include $(MAKEPATH)gccconfig.mk 4 | 5 | .PHONY: all build compile luacompile luasource clean luaclean 6 | 7 | all: build 8 | 9 | build: luabuild gccbuild 10 | 11 | luabuild: lua$(LUA_TARGET) 12 | 13 | gccbuild: compile 14 | compile: 15 | 16 | clean: luaclean 17 | 18 | luasource: 19 | mkdir -p dist$(LUA_MODULEDIR) 20 | mkdir -p dist$(LUCI_MODULEDIR) 21 | mkdir -p dist$(HTDOCS) 22 | cp -pR root/* dist 2>/dev/null || true 23 | cp -pR luasrc/* dist$(LUCI_MODULEDIR) 2>/dev/null || true 24 | cp -pR lua/* dist$(LUA_MODULEDIR) 2>/dev/null || true 25 | cp -pR htdocs/* dist$(HTDOCS) 2>/dev/null || true 26 | for i in $$(find dist -name .svn -o -name .gitignore); do rm -rf $$i || true; done 27 | ifneq ($(PO),) 28 | mkdir -p dist$(LUCI_I18NDIR) 29 | for file in $(PO); do \ 30 | cp $(HOST)/lua-po/$$file.$(if $(PO_LANG),$(PO_LANG),*).* dist$(LUCI_I18NDIR)/ 2>/dev/null || true; \ 31 | done 32 | endif 33 | 34 | 35 | luadiet: luasource 36 | for i in $$(find dist -type f -name '*.lua'); do LUA_PATH="../../contrib/luasrcdiet/lua/?.lua" $(LUA) ../../contrib/luasrcdiet/lua/LuaSrcDiet.lua --maximum $$i -o $$i.diet && mv $$i.diet $$i; done 37 | 38 | luastrip: luasource 39 | for i in $$(find dist -type f -name '*.lua'); do perl -e 'undef $$/; open( F, "< $$ARGV[0]" ) || die $$!; $$src = ; close F; $$src =~ s/--\[\[.*?\]\](--)?//gs; $$src =~ s/^\s*--.*?\n//gm; open( F, "> $$ARGV[0]" ) || die $$!; print F $$src; close F' $$i; done 40 | 41 | luacompile: luasource 42 | for i in $$(find dist -name *.lua -not -name debug.lua| sort); do if ! $(LUAC) $(LUAC_OPTIONS) -o $$i $$i; then echo "Error compiling $$i"; exit 1; fi; done 43 | 44 | luaclean: 45 | rm -rf dist 46 | 47 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LuCI Template - Utility header 3 | * 4 | * Copyright (C) 2010-2012 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _TEMPLATE_UTILS_H_ 20 | #define _TEMPLATE_UTILS_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | /* buffer object */ 28 | struct template_buffer { 29 | char *data; 30 | char *dptr; 31 | unsigned int size; 32 | unsigned int fill; 33 | }; 34 | 35 | struct template_buffer * buf_init(int size); 36 | int buf_grow(struct template_buffer *buf, int size); 37 | int buf_putchar(struct template_buffer *buf, char c); 38 | int buf_append(struct template_buffer *buf, const char *s, int len); 39 | int buf_length(struct template_buffer *buf); 40 | char * buf_destroy(struct template_buffer *buf); 41 | 42 | char * utf8(const char *s, unsigned int l); 43 | char * pcdata(const char *s, unsigned int l); 44 | char * striptags(const char *s, unsigned int l); 45 | 46 | void luastr_escape(struct template_buffer *out, const char *s, unsigned int l, int escape_xml); 47 | void luastr_translate(struct template_buffer *out, const char *s, unsigned int l, int escape_xml); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /packages/sniproxy/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 nanpuyue , https://blog.nanpuyue.com 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=sniproxy 11 | PKG_VERSION:=2017-03-01 12 | PKG_RELEASE=1 13 | 14 | PKG_SOURCE_PROTO:=git 15 | PKG_SOURCE_URL:=https://github.com/dlundquist/sniproxy.git 16 | PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) 17 | PKG_SOURCE_VERSION:=302b6efda9d7b3493ed1f09d8de4e75c6c004b71 18 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 19 | PKG_MAINTAINER:=nanpuyue 20 | 21 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)/$(PKG_NAME)-$(PKG_VERSION) 22 | 23 | PKG_INSTALL:=1 24 | PKG_FIXUP:=autoreconf 25 | PKG_USE_MIPS16:=0 26 | 27 | include $(INCLUDE_DIR)/package.mk 28 | 29 | define Package/sniproxy 30 | SECTION:=net 31 | CATEGORY:=Network 32 | TITLE:=SNI Proxy 33 | URL:=https://github.com/dlundquist/sniproxy 34 | MAINTAINER:=Dustin Lundquist 35 | DEPENDS:=+libev +libpcre +libudns 36 | endef 37 | 38 | define Package/sniproxy/description 39 | Proxies incoming HTTP and TLS connections based on the hostname contained in the initial request of the TCP session. 40 | endef 41 | 42 | define Package/sniproxy/conffiles 43 | /etc/sniproxy.conf 44 | endef 45 | 46 | TARGET_CFLAGS += \ 47 | -std=c99 \ 48 | -fdata-sections \ 49 | -ffunction-sections 50 | 51 | TARGET_LDFLAGS += \ 52 | -Wl,-gc-sections 53 | 54 | MAKE_FLAGS += \ 55 | CFLAGS="$(TARGET_CFLAGS)" \ 56 | LDFLAGS="$(TARGET_LDFLAGS)" 57 | 58 | define Package/sniproxy/install 59 | $(INSTALL_DIR) $(1)/etc/init.d 60 | $(INSTALL_CONF) ./files/sniproxy.conf $(1)/etc/ 61 | $(INSTALL_BIN) ./files/sniproxy.init $(1)/etc/init.d/sniproxy 62 | $(INSTALL_DIR) $(1)/usr/bin 63 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/sniproxy $(1)/usr/bin 64 | endef 65 | 66 | $(eval $(call BuildPackage,sniproxy)) 67 | -------------------------------------------------------------------------------- /luci/libs/lmo/standalone.mk: -------------------------------------------------------------------------------- 1 | LUAC = luac 2 | LUAC_OPTIONS = -s 3 | LUA_TARGET ?= source 4 | 5 | LUA_MODULEDIR = /usr/local/share/lua/5.1 6 | LUA_LIBRARYDIR = /usr/local/lib/lua/5.1 7 | 8 | OS ?= $(shell uname) 9 | 10 | LUA_SHLIBS = $(shell pkg-config --silence-errors --libs lua5.1 || pkg-config --silence-errors --libs lua-5.1 || pkg-config --silence-errors --libs lua) 11 | LUA_LIBS = $(if $(LUA_SHLIBS),$(LUA_SHLIBS),$(firstword $(wildcard /usr/lib/liblua.a /usr/local/lib/liblua.a /opt/local/lib/liblua.a))) 12 | LUA_CFLAGS = $(shell pkg-config --silence-errors --cflags lua5.1 || pkg-config --silence-errors --cflags lua-5.1 || pkg-config --silence-errors --cflags lua) 13 | 14 | CC = gcc 15 | AR = ar 16 | RANLIB = ranlib 17 | CFLAGS = -O2 18 | FPIC = -fPIC 19 | EXTRA_CFLAGS = --std=gnu99 20 | WFLAGS = -Wall -Werror -pedantic 21 | CPPFLAGS = 22 | COMPILE = $(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(WFLAGS) 23 | ifeq ($(OS),Darwin) 24 | SHLIB_FLAGS = -bundle -undefined dynamic_lookup 25 | else 26 | SHLIB_FLAGS = -shared 27 | endif 28 | LINK = $(CC) $(LDFLAGS) 29 | 30 | .PHONY: all build compile luacompile luasource clean luaclean 31 | 32 | all: build 33 | 34 | build: luabuild gccbuild 35 | 36 | luabuild: lua$(LUA_TARGET) 37 | 38 | gccbuild: compile 39 | compile: 40 | 41 | clean: luaclean 42 | 43 | luasource: 44 | mkdir -p dist$(LUA_MODULEDIR) 45 | cp -pR root/* dist 2>/dev/null || true 46 | cp -pR lua/* dist$(LUA_MODULEDIR) 2>/dev/null || true 47 | for i in $$(find dist -name .svn); do rm -rf $$i || true; done 48 | 49 | luastrip: luasource 50 | for i in $$(find dist -type f -name '*.lua'); do perl -e 'undef $$/; open( F, "< $$ARGV[0]" ) || die $$!; $$src = ; close F; $$src =~ s/--\[\[.*?\]\](--)?//gs; $$src =~ s/^\s*--.*?\n//gm; open( F, "> $$ARGV[0]" ) || die $$!; print F $$src; close F' $$i; done 51 | 52 | luacompile: luasource 53 | for i in $$(find dist -name *.lua -not -name debug.lua); do $(LUAC) $(LUAC_OPTIONS) -o $$i $$i; done 54 | 55 | luaclean: 56 | rm -rf dist 57 | -------------------------------------------------------------------------------- /libs/libudns/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 nanpuyue https://blog.nanpuyue.com 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=udns 11 | PKG_VERSION:=0.4 12 | PKG_RELEASE:=1 13 | PKG_FIXUP:=autoreconf 14 | PKG_LICENSE:=LGPL 15 | 16 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 17 | PKG_SOURCE_URL:=http://www.corpit.ru/mjt/udns 18 | PKG_MD5SUM:=51e141b044b078d71ebb71f823959c1b 19 | PKG_MAINTAINER:=nanpuyue 20 | 21 | include $(INCLUDE_DIR)/package.mk 22 | 23 | define Package/udns/Default 24 | SECTION:=net 25 | CATEGORY:=Network 26 | DEPENDS:=+libc 27 | URL:=http://www.corpit.ru/mjt/udns.html 28 | TITLE:=UDNS 29 | MAINTAINER:=Michael Tokarev 30 | SUBMENU:=IP Addresses and Names 31 | endef 32 | 33 | define Package/libudns 34 | $(call Package/udns/Default) 35 | TITLE+= (library) 36 | endef 37 | 38 | define Package/libudns/description 39 | UDNS is a stub DNS resolver library with ability to perform both syncronous and asyncronous DNS queries. 40 | endef 41 | 42 | define Package/udns-utils 43 | $(call Package/udns/Default) 44 | TITLE+= (utils) 45 | endef 46 | 47 | export CC="$(TARGET_CC)" 48 | 49 | define Build/Configure 50 | (cd $(PKG_BUILD_DIR); \ 51 | ./configure \ 52 | --enable-ipv6 \ 53 | --enable-cross_compile \ 54 | ) 55 | endef 56 | define Build/Compile 57 | $(MAKE) -C $(PKG_BUILD_DIR) all 58 | $(MAKE) -C $(PKG_BUILD_DIR) shared 59 | endef 60 | 61 | define Build/InstallDev 62 | $(INSTALL_DIR) $(1)/usr/include 63 | $(CP) $(PKG_BUILD_DIR)/udns.h $(1)/usr/include 64 | $(INSTALL_DIR) $(1)/usr/lib 65 | $(CP) $(PKG_BUILD_DIR)/lib*.{a,so*} $(1)/usr/lib 66 | endef 67 | 68 | define Package/libudns/install 69 | $(INSTALL_DIR) $(1)/usr/lib 70 | $(CP) $(PKG_BUILD_DIR)/lib*.so* $(1)/usr/lib 71 | endef 72 | 73 | define Package/udns-utils/install 74 | $(INSTALL_DIR) $(1)/usr/bin 75 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/{dnsget,ex-rdns,rblcheck} $(1)/usr/bin/ 76 | endef 77 | 78 | $(eval $(call BuildPackage,libudns)) 79 | $(eval $(call BuildPackage,udns-utils)) 80 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LuCI Template - Parser header 3 | * 4 | * Copyright (C) 2009 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _TEMPLATE_PARSER_H_ 20 | #define _TEMPLATE_PARSER_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | /* code types */ 39 | #define T_TYPE_INIT 0 40 | #define T_TYPE_TEXT 1 41 | #define T_TYPE_COMMENT 2 42 | #define T_TYPE_EXPR 3 43 | #define T_TYPE_INCLUDE 4 44 | #define T_TYPE_I18N 5 45 | #define T_TYPE_I18N_RAW 6 46 | #define T_TYPE_CODE 7 47 | #define T_TYPE_EOF 8 48 | 49 | 50 | struct template_chunk { 51 | const char *s; 52 | const char *e; 53 | int type; 54 | int line; 55 | }; 56 | 57 | /* parser state */ 58 | struct template_parser { 59 | int fd; 60 | uint32_t size; 61 | char *mmap; 62 | char *off; 63 | char *gc; 64 | int line; 65 | int in_expr; 66 | int strip_before; 67 | int strip_after; 68 | struct template_chunk prv_chunk; 69 | struct template_chunk cur_chunk; 70 | const char *file; 71 | }; 72 | 73 | struct template_parser * template_open(const char *file); 74 | void template_close(struct template_parser *parser); 75 | 76 | const char *template_reader(lua_State *L, void *ud, size_t *sz); 77 | int template_error(lua_State *L, struct template_parser *parser); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /luci/applications/luci-aria2/root/etc/init.d/aria2: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # Copyright (C) 2014 nanpuyue 3 | 4 | START=99 5 | SERVICE_WRITE_PID=1 6 | SERVICE_DAEMONIZE=1 7 | 8 | 9 | append_params() { 10 | local p; local v; local s="$1"; shift 11 | for p in $*; do 12 | config_get v "$s" "$p" 13 | [ -n "$v" ] && ( 14 | p=$(echo "$p" | sed -e 's|_|-|g'); 15 | echo "$p=$v" >> $config_file 16 | ) 17 | done 18 | } 19 | 20 | section_enabled() { 21 | local result 22 | config_get_bool result "$1" 'enabled' 0 23 | [ $result -eq 1 ] 24 | } 25 | 26 | option_disabled() { 27 | local result 28 | config_get_bool result "$1" "$2" 1 29 | [ $result -eq 0 ] 30 | } 31 | 32 | start_instance() { 33 | local s="$1" 34 | local user 35 | 36 | section_enabled "$s" || return 1 37 | 38 | config_get config_dir "$s" 'config_dir' '/var/etc/aria2' 39 | config_get user "$s" 'user' 40 | 41 | config_file="$config_dir/aria2.conf" 42 | session_file="$config_dir/aria2.session" 43 | dht_file="$config_dir/dht.dat" 44 | [ -d "$config_dir" ] || { 45 | mkdir -m 0755 -p "$config_dir" 46 | touch "$config_file" 47 | [ -z "$user" ] || chown -R $user $config_dir 48 | } 49 | touch "$session_file" 50 | 51 | echo -e "enable-rpc=true\nrpc-allow-origin-all=true\nrpc-listen-all=true\nquiet=true" > $config_file 52 | echo -e "continue=true\ninput-file=$session_file\nsave-session=$session_file" >> $config_file 53 | option_disabled "$s" 'enable_dht' || echo "dht-file-path=$dht_file" >> $config_file 54 | 55 | append_params "$s" \ 56 | file_allocation bt_enable_lpd enable_dht rpc_user rpc_passwd rpc_listen_port dir bt_tracker disk_cache \ 57 | max_overall_download_limit max_overall_upload_limit max_download_limit max_upload_limit max_concurrent_downloads \ 58 | max_connection_per_server min_split_size split save_session_interval follow_torrent listen_port bt_max_peers \ 59 | peer_id_prefix user_agent rpc_secret 60 | 61 | config_list_foreach "$s" extra_settings append_extrasettings 62 | 63 | SERVICE_UID="$user" \ 64 | service_start /usr/bin/aria2c --conf-path="$config_file" 65 | } 66 | 67 | append_extrasettings() { 68 | echo "$1" >> $config_file 69 | } 70 | 71 | start() { 72 | config_load 'aria2' 73 | config_foreach start_instance 'aria2' 74 | } 75 | 76 | stop() { 77 | service_stop /usr/bin/aria2c 78 | } 79 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_lmo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lmo - Lua Machine Objects - General header 3 | * 4 | * Copyright (C) 2009-2012 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef _TEMPLATE_LMO_H_ 20 | #define _TEMPLATE_LMO_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #if (defined(__GNUC__) && defined(__i386__)) 38 | #define sfh_get16(d) (*((const uint16_t *) (d))) 39 | #else 40 | #define sfh_get16(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ 41 | +(uint32_t)(((const uint8_t *)(d))[0]) ) 42 | #endif 43 | 44 | 45 | struct lmo_entry { 46 | uint32_t key_id; 47 | uint32_t val_id; 48 | uint32_t offset; 49 | uint32_t length; 50 | } __attribute__((packed)); 51 | 52 | typedef struct lmo_entry lmo_entry_t; 53 | 54 | 55 | struct lmo_archive { 56 | int fd; 57 | int length; 58 | uint32_t size; 59 | lmo_entry_t *index; 60 | char *mmap; 61 | char *end; 62 | struct lmo_archive *next; 63 | }; 64 | 65 | typedef struct lmo_archive lmo_archive_t; 66 | 67 | 68 | struct lmo_catalog { 69 | char lang[6]; 70 | struct lmo_archive *archives; 71 | struct lmo_catalog *next; 72 | }; 73 | 74 | typedef struct lmo_catalog lmo_catalog_t; 75 | 76 | 77 | uint32_t sfh_hash(const char *data, int len); 78 | uint32_t lmo_canon_hash(const char *data, int len); 79 | 80 | lmo_archive_t * lmo_open(const char *file); 81 | void lmo_close(lmo_archive_t *ar); 82 | 83 | 84 | extern lmo_catalog_t *_lmo_catalogs; 85 | extern lmo_catalog_t *_lmo_active_catalog; 86 | 87 | int lmo_load_catalog(const char *lang, const char *dir); 88 | int lmo_change_catalog(const char *lang); 89 | int lmo_translate(const char *key, int keylen, char **out, int *outlen); 90 | void lmo_close_catalog(const char *lang); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /luci/build/i18n-scan.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | use Text::Balanced qw(extract_bracketed extract_delimited extract_tagged); 6 | 7 | @ARGV >= 1 || die "Usage: $0 \n"; 8 | 9 | 10 | my %stringtable; 11 | 12 | sub dec_lua_str 13 | { 14 | my $s = shift; 15 | $s =~ s/[\s\n]+/ /g; 16 | $s =~ s/\\n/\n/g; 17 | $s =~ s/\\t/\t/g; 18 | $s =~ s/\\(.)/$1/g; 19 | $s =~ s/^ //; 20 | $s =~ s/ $//; 21 | return $s; 22 | } 23 | 24 | sub dec_tpl_str 25 | { 26 | my $s = shift; 27 | $s =~ s/-$//; 28 | $s =~ s/[\s\n]+/ /g; 29 | $s =~ s/^ //; 30 | $s =~ s/ $//; 31 | $s =~ s/\\/\\\\/g; 32 | return $s; 33 | } 34 | 35 | 36 | if( open F, "find @ARGV -type f '(' -name '*.htm' -o -name '*.lua' ')' |" ) 37 | { 38 | while( defined( my $file = readline F ) ) 39 | { 40 | chomp $file; 41 | 42 | if( open S, "< $file" ) 43 | { 44 | local $/ = undef; 45 | my $raw = ; 46 | close S; 47 | 48 | 49 | my $text = $raw; 50 | 51 | while( $text =~ s/ ^ .*? (?:translate|translatef|i18n|_) [\n\s]* \( /(/sgx ) 52 | { 53 | ( my $code, $text ) = extract_bracketed($text, q{('")}); 54 | 55 | $code =~ s/\\\n/ /g; 56 | $code =~ s/^\([\n\s]*//; 57 | $code =~ s/[\n\s]*\)$//; 58 | 59 | my $res = ""; 60 | my $sub = ""; 61 | 62 | if( $code =~ /^['"]/ ) 63 | { 64 | while( defined $sub ) 65 | { 66 | ( $sub, $code ) = extract_delimited($code, q{'"}, q{\s*(?:\.\.\s*)?}); 67 | 68 | if( defined $sub && length($sub) > 2 ) 69 | { 70 | $res .= substr $sub, 1, length($sub) - 2; 71 | } 72 | else 73 | { 74 | undef $sub; 75 | } 76 | } 77 | } 78 | elsif( $code =~ /^(\[=*\[)/ ) 79 | { 80 | my $stag = quotemeta $1; 81 | my $etag = $stag; 82 | $etag =~ s/\[/]/g; 83 | 84 | ( $res ) = extract_tagged($code, $stag, $etag); 85 | 86 | $res =~ s/^$stag//; 87 | $res =~ s/$etag$//; 88 | } 89 | 90 | $res = dec_lua_str($res); 91 | $stringtable{$res}++ if $res; 92 | } 93 | 94 | 95 | $text = $raw; 96 | 97 | while( $text =~ s/ ^ .*? <% -? [:_] /<%/sgx ) 98 | { 99 | ( my $code, $text ) = extract_tagged($text, '<%', '%>'); 100 | 101 | if( defined $code ) 102 | { 103 | $code = dec_tpl_str(substr $code, 2, length($code) - 4); 104 | $stringtable{$code}++; 105 | } 106 | } 107 | } 108 | } 109 | 110 | close F; 111 | } 112 | 113 | 114 | if( open C, "| msgcat -" ) 115 | { 116 | printf C "msgid \"\"\nmsgstr \"Content-Type: text/plain; charset=UTF-8\"\n\n"; 117 | 118 | foreach my $key ( sort keys %stringtable ) 119 | { 120 | if( length $key ) 121 | { 122 | $key =~ s/"/\\"/g; 123 | printf C "msgid \"%s\"\nmsgstr \"\"\n\n", $key; 124 | } 125 | } 126 | 127 | close C; 128 | } 129 | -------------------------------------------------------------------------------- /luci/luci-extra/Makefile: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | LUCI_TOPDIR=.. 4 | 5 | PKG_NAME:=luci-extra 6 | PKG_RELEASE:=1 7 | 8 | PKG_BUILD_PARALLEL:=0 9 | 10 | PKG_VERSION:=2014-09-04 11 | 12 | PKG_BUILD_DEPENDS:=$(if $(STAGING_DIR_ROOT),lua/host) 13 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 14 | PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install 15 | 16 | LUA_TARGET:=source 17 | LUCI_CFLAGS:= 18 | LUCI_BUILD_PACKAGES:= 19 | LUCI_SELECTED_MODULES:= 20 | 21 | ifeq ($(BOARD),brcm-2.4) 22 | MAKE_FLAGS += CRAP="1" 23 | endif 24 | 25 | 26 | ### Templates ### 27 | define Package/luci/install/template 28 | $(CP) -a $(PKG_BUILD_DIR)/$(2)/dist/* $(1)/ -R 29 | $(CP) -a $(PKG_BUILD_DIR)/$(2)/ipkg/* $(1)/CONTROL/ 2>/dev/null || true 30 | endef 31 | 32 | ### Applications ### 33 | define application 34 | define Package/luci-app-$(1) 35 | SECTION:=luci 36 | CATEGORY:=LuCI 37 | TITLE:=LuCI - Lua Configuration Interface 38 | URL:=https://github.com/nanpuyue/openwrt-extra/ 39 | MAINTAINER:=nanpuyue 40 | PKGARCH:=all 41 | SUBMENU:=3. Applications 42 | TITLE:=$(if $(2),$(2),LuCI $(1) application) 43 | DEPENDS:=$(3) 44 | endef 45 | 46 | define Package/luci-app-$(1)/install 47 | $(call Package/luci/install/template,$$(1),applications/luci-$(1)) 48 | endef 49 | 50 | ifneq ($(CONFIG_PACKAGE_luci-app-$(1)),) 51 | LUCI_SELECTED_MODULES+=applications/luci-$(1) 52 | endif 53 | 54 | LUCI_BUILD_PACKAGES += luci-app-$(1) 55 | endef 56 | 57 | define Package/luci-app-aria2/conffiles 58 | /etc/config/aria2 59 | endef 60 | 61 | $(eval $(call application,aria2,LuCI Support for Aria2,\ 62 | +PACKAGE_luci-app-aria2:aria2 \ 63 | +PACKAGE_luci-app-aria2:yaaw)) 64 | 65 | 66 | ### Compile ### 67 | PKG_CONFIG_DEPENDS=$(patsubst %,CONFIG_PACKAGE_%,$(LUCI_BUILD_PACKAGES)) 68 | 69 | include $(INCLUDE_DIR)/package.mk 70 | 71 | define Build/Prepare 72 | @if [ ! -x $(LUCI_TOPDIR)/build/mkrevision.sh ]; then \ 73 | echo "*** Repository layout changed!" >&2; \ 74 | echo "*** Please change the LuCI url in feeds.conf to http://svn.luci.subsignal.org/luci/trunk and reinstall the feed with" >&2; \ 75 | echo "*** ./scripts/feeds update luci; ./scripts/feeds install -a -p luci" >&2; \ 76 | exit 1; \ 77 | fi 78 | mkdir -p $(PKG_BUILD_DIR) 79 | $(TAR) c -C $(LUCI_TOPDIR) . \ 80 | --exclude=.pc --exclude=.svn --exclude=.git \ 81 | --exclude='boa-0*' --exclude='*.o' --exclude='*.so' \ 82 | --exclude=dist | \ 83 | tar x -C $(PKG_BUILD_DIR)/ 84 | endef 85 | 86 | define Build/Configure 87 | endef 88 | 89 | MAKE_FLAGS += \ 90 | MODULES="$(LUCI_SELECTED_MODULES)" \ 91 | LUA_TARGET="$(LUA_TARGET)" \ 92 | LUA_SHLIBS="-llua -lm -ldl -lcrypt" \ 93 | CFLAGS="$(TARGET_CFLAGS) $(LUCI_CFLAGS) -I$(STAGING_DIR)/usr/include" \ 94 | LDFLAGS="$(TARGET_LDFLAGS) -L$(STAGING_DIR)/usr/lib" \ 95 | NIXIO_TLS="$(NIXIO_TLS)" OS="Linux" 96 | 97 | 98 | $(foreach b,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(b)))) 99 | -------------------------------------------------------------------------------- /packages/dnscrypt-proxy/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2014 nanpuyue 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=dnscrypt-proxy 11 | PKG_VERSION:=1.4.0 12 | PKG_RELEASE:=1 13 | 14 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 15 | PKG_SOURCE_URL:=http://download.dnscrypt.org/dnscrypt-proxy/ 16 | PKG_MD5SUM:=40b5b73f5042330b86084460d7c839c6 17 | 18 | PKG_FIXUP:=autoreconf 19 | PKG_INSTALL:=1 20 | PKG_BUILD_PARALLEL:=1 21 | PKG_BUILD_DEPENDS:=libsodium 22 | 23 | include $(INCLUDE_DIR)/package.mk 24 | 25 | define Package/dnscrypt-proxy/default 26 | SECTION:=net 27 | CATEGORY:=Network 28 | SUBMENU:=IP Addresses and Names 29 | URL:=http://dnscrypt.org/ 30 | DEPENDS:=+libsodium 31 | MAINTAINER:=nanpuyue 32 | endef 33 | 34 | define Package/dnscrypt-proxy 35 | $(call Package/dnscrypt-proxy/default) 36 | TITLE:=A tool for securing communications between a client and a DNS resolver 37 | endef 38 | 39 | define Package/dnscrypt-proxy/description 40 | dnscrypt-proxy provides local service which can be used directly as your local resolver or as a DNS forwarder, encrypting and authenticating requests using the DNSCrypt protocol and passing them to an upstream server. 41 | The DNSCrypt protocol uses high-speed high-security elliptic-curve cryptography and is very similar to DNSCurve, but focuses on securing communications between a client and its first-level resolver. 42 | While not providing end-to-end security, it protects the local network, which is often the weakest point of the chain, against man-in-the-middle attacks. It also provides some confidentiality to DNS queries. 43 | endef 44 | 45 | define Package/hostip 46 | $(call Package/dnscrypt-proxy/default) 47 | TITLE:=A tool for resolving a name to IPv4 or IPv6 addresses 48 | endef 49 | 50 | define Package/hostip/description 51 | The DNSCrypt proxy ships with a simple tool named hostip that resolves a name to IPv4 or IPv6 addresses. 52 | This tool can be useful for starting some services before dnscrypt-proxy. 53 | Queries made by hostip are not authenticated. 54 | endef 55 | 56 | CONFIGURE_ARGS += \ 57 | --prefix=/usr 58 | 59 | TARGET_CFLAGS += \ 60 | -fdata-sections \ 61 | -ffunction-sections 62 | 63 | TARGET_LDFLAGS += \ 64 | -Wl,-gc-sections 65 | 66 | MAKE_FLAGS += \ 67 | CFLAGS="$(TARGET_CFLAGS)" \ 68 | LDFLAGS="$(TARGET_LDFLAGS)" 69 | 70 | define Package/dnscrypt-proxy/conffiles 71 | /etc/config/dnscrypt-proxy 72 | endef 73 | 74 | define Package/dnscrypt-proxy/install 75 | $(INSTALL_DIR) $(1)/usr/sbin 76 | $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/dnscrypt-proxy $(1)/usr/sbin/ 77 | $(INSTALL_DIR) $(1)/etc/config 78 | $(INSTALL_DATA) files/config $(1)/etc/config/dnscrypt-proxy 79 | $(INSTALL_DIR) $(1)/etc/init.d 80 | $(INSTALL_BIN) files/init $(1)/etc/init.d/dnscrypt-proxy 81 | endef 82 | 83 | define Package/hostip/install 84 | $(INSTALL_DIR) $(1)/usr/bin 85 | $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/hostip $(1)/usr/bin/ 86 | endef 87 | 88 | $(eval $(call BuildPackage,dnscrypt-proxy)) 89 | $(eval $(call BuildPackage,hostip)) 90 | -------------------------------------------------------------------------------- /luci/po/zh_CN/aria2.po: -------------------------------------------------------------------------------- 1 | msgid "Aria2 Settings" 2 | msgstr "Aria2配置" 3 | 4 | msgid "Aria2 is a multi-protocol & multi-source download utility, here you can configure the settings." 5 | msgstr "Aria2是一个支持多协议多线程的下载器,你可以在这里对其进行配置." 6 | 7 | msgid "Open Web Interface" 8 | msgstr "打开Web界面" 9 | 10 | msgid "Global settings" 11 | msgstr "全局设置" 12 | 13 | msgid "Enabled" 14 | msgstr "启用" 15 | 16 | msgid "Config file directory" 17 | msgstr "配置文件目录" 18 | 19 | msgid "Run daemon as user" 20 | msgstr "以此用户权限运行" 21 | 22 | msgid "Files and Locations" 23 | msgstr "文件和目录" 24 | 25 | msgid "Default download directory" 26 | msgstr "默认下载目录" 27 | 28 | msgid "Disk cache" 29 | msgstr "磁盘缓存" 30 | 31 | msgid "Preallocation" 32 | msgstr "磁盘预分配" 33 | 34 | msgid "\"falloc\" is not available in all cases" 35 | msgstr "\"falloc\"并不是在所有情况下都可用" 36 | 37 | msgid "Task Settings" 38 | msgstr "任务设置" 39 | 40 | msgid "Overall speed limit enabled" 41 | msgstr "启用全局限速" 42 | 43 | msgid "Overall download limit" 44 | msgstr "全局下载限速" 45 | 46 | msgid "Overall upload limit" 47 | msgstr "全局上传限速" 48 | 49 | msgid "Per task speed limit enabled" 50 | msgstr "启用单任务限速" 51 | 52 | msgid "Per task download limit" 53 | msgstr "单任务下载限速" 54 | 55 | msgid "Per task upload limit" 56 | msgstr "单任务上传限速" 57 | 58 | msgid "Max concurrent downloads" 59 | msgstr "最大同时下载任务数" 60 | 61 | msgid "Max connection per server" 62 | msgstr "单服务器最大连接数" 63 | 64 | msgid "in bytes, You can append K or M" 65 | msgstr "B, 你可以在数字后跟上\"M\"或\"K\"" 66 | 67 | msgid "in bytes/sec, You can append K or M" 68 | msgstr "B/s, 你可以在数字后跟上\"M\"或\"K\"" 69 | 70 | msgid "Min split size" 71 | msgstr "最小文件分片大小" 72 | 73 | msgid "Max number of split" 74 | msgstr "单文件最大线程数" 75 | 76 | msgid "Autosave session interval" 77 | msgstr "定时保存会话间隔" 78 | 79 | msgid "Sec" 80 | msgstr "秒" 81 | 82 | msgid "BitTorrent Settings" 83 | msgstr "BT设置" 84 | 85 | msgid "DHT enabled" 86 | msgstr "启用DHT" 87 | 88 | msgid "LPD enabled" 89 | msgstr "启用LPD" 90 | 91 | msgid "Follow torrent" 92 | msgstr "自动添加下载的种子" 93 | 94 | msgid "BitTorrent listen port" 95 | msgstr "BT监听端口" 96 | 97 | msgid "Max number of peers per torrent" 98 | msgstr "单个种子最大连接数" 99 | 100 | msgid "Additional Bt tracker enabled" 101 | msgstr "添加额外的Tracker" 102 | 103 | msgid "List of additional Bt tracker" 104 | msgstr "附加Tracker列表" 105 | 106 | msgid "RPC settings" 107 | msgstr "RPC设置" 108 | 109 | msgid "RPC port" 110 | msgstr "RPC端口" 111 | 112 | msgid "RPC username" 113 | msgstr "RPC用户名" 114 | 115 | msgid "RPC password" 116 | msgstr "RPC密码" 117 | 118 | msgid "User agent value" 119 | msgstr "用户代理(UA)" 120 | 121 | msgid "Prefix of peer ID" 122 | msgstr "peer ID前缀" 123 | 124 | msgid "Extra Settings" 125 | msgstr "附加选项" 126 | 127 | msgid "List of extra settings" 128 | msgstr "附加选项列表" 129 | 130 | msgid "View Json-RPC URL" 131 | msgstr "查看 Json-RPC URL" 132 | 133 | msgid "RPC authentication method" 134 | msgstr "RPC认证方式" 135 | 136 | msgid "No Authentication" 137 | msgstr "无认证" 138 | 139 | msgid "Username & Password" 140 | msgstr "用户名与密码" 141 | 142 | msgid "Token" 143 | msgstr "令牌" 144 | 145 | msgid "RPC Token" 146 | msgstr "RPC令牌" 147 | 148 | msgid "Generate Randomly" 149 | msgstr "随机生成" 150 | 151 | msgid "Use WebSocket" 152 | msgstr "使用WebSocket" 153 | 154 | -------------------------------------------------------------------------------- /luci/Makefile: -------------------------------------------------------------------------------- 1 | include build/config.mk 2 | 3 | MODULES = applications/* libs/* 4 | 5 | OS:=$(shell uname) 6 | MODULES:=$(foreach item,$(wildcard $(MODULES)),$(if $(realpath $(wildcard $(item)/Makefile)),$(item))) 7 | 8 | export OS 9 | 10 | .PHONY: all build gccbuild luabuild clean host gcchost luahost hostcopy hostclean 11 | 12 | all: build 13 | 14 | build: gccbuild luabuild 15 | 16 | gccbuild: 17 | make -C libs/lmo CC="cc" CFLAGS="" LDFLAGS="" SDK="$(shell test -f .running-sdk && echo 1)" host-install 18 | for i in $(MODULES); do \ 19 | make -C$$i SDK="$(shell test -f .running-sdk && echo 1)" compile || { \ 20 | echo "*** Compilation of $$i failed!"; \ 21 | exit 1; \ 22 | }; \ 23 | done 24 | 25 | luabuild: i18nbuild 26 | for i in $(MODULES); do HOST=$(realpath host) \ 27 | SDK="$(shell test -f .running-sdk && echo 1)" make -C$$i luabuild; done 28 | 29 | i18nbuild: 30 | mkdir -p host/lua-po 31 | ./build/i18n-po2lua.pl ./po host/lua-po 32 | 33 | clean: 34 | rm -f .running-sdk 35 | rm -rf docs 36 | make -C libs/lmo host-clean 37 | for i in $(MODULES); do make -C$$i clean; done 38 | 39 | 40 | host: build hostcopy 41 | 42 | gcchost: gccbuild hostcopy 43 | 44 | luahost: luabuild hostcopy 45 | 46 | hostcopy: 47 | mkdir -p host/tmp 48 | mkdir -p host/var/state 49 | for i in $(MODULES); do cp -pR $$i/dist/* host/ 2>/dev/null || true; done 50 | for i in $(MODULES); do cp -pR $$i/hostfiles/* host/ 2>/dev/null || true; done 51 | rm -f host/luci 52 | ln -s .$(LUCI_MODULEDIR) host/luci 53 | rm -rf /tmp/luci-* || true 54 | 55 | hostenv: sdk host ucidefaults 56 | 57 | sdk: 58 | touch .running-sdk 59 | 60 | ucidefaults: 61 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) "$(realpath host)/bin/uci-defaults --exclude luci-freifunk-*" 62 | 63 | runhttpd: hostenv 64 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) "lua build/lucid.lua" 65 | 66 | runuhttpd: hostenv 67 | cp $(realpath build)/luci.cgi $(realpath host)/www/cgi-bin/luci 68 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) "$(realpath host)/usr/sbin/uhttpd -p 8080 -h $(realpath host)/www -f" 69 | 70 | runlua: hostenv 71 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) "lua -i build/setup.lua" 72 | 73 | runshell: hostenv 74 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) $$SHELL 75 | 76 | hostclean: clean 77 | rm -rf host 78 | 79 | apidocs: hostenv 80 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) "build/makedocs.sh host/luci/ docs" 81 | 82 | nixiodocs: hostenv 83 | build/hostenv.sh $(realpath host) $(LUA_MODULEDIR) $(LUA_LIBRARYDIR) "build/makedocs.sh libs/nixio/ nixiodocs" 84 | 85 | po: host 86 | for L in $${LANGUAGE:-$$(find i18n/ -path 'i18n/*/luasrc/i18n/*' -name 'default.*.lua' | \ 87 | sed -e 's!.*/default\.\(.*\)\.lua!\1!')}; do \ 88 | build/i18n-lua2po.pl . $(realpath host)/po $$L; \ 89 | done 90 | 91 | run: 92 | # make run is deprecated # 93 | # Please use: # 94 | # # 95 | # To run LuCI WebUI using LuCIttpd # 96 | # make runhttpd # 97 | # # 98 | # To run LuCI WebUI using Boa/Webuci # 99 | # make runboa # 100 | # # 101 | # To start a shell in the LuCI environment # 102 | # make runshell # 103 | # # 104 | # To run Lua CLI in the LuCI environment # 105 | # make runlua # 106 | -------------------------------------------------------------------------------- /packages/shadowsocks-libev/Makefile: -------------------------------------------------------------------------------- 1 | include $(TOPDIR)/rules.mk 2 | 3 | PKG_NAME:=shadowsocks-libev 4 | PKG_VERSION:=1.4.7 5 | PKG_RELEASE=1 6 | 7 | PKG_SOURCE_PROTO:=git 8 | PKG_SOURCE_URL:=https://github.com/madeye/shadowsocks-libev.git 9 | PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) 10 | PKG_SOURCE_VERSION:=v$(PKG_VERSION) 11 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 12 | PKG_MAINTAINER:=Max Lv 13 | 14 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION) 15 | 16 | PKG_INSTALL:=1 17 | PKG_FIXUP:=autoreconf 18 | PKG_BUILD_PARALLEL:=1 19 | PKG_USE_MIPS16:=0 20 | 21 | include $(INCLUDE_DIR)/package.mk 22 | 23 | define Package/shadowsocks-libev/Default 24 | SECTION:=net 25 | CATEGORY:=Network 26 | TITLE:=Lightweight Secured Socks5 Proxy 27 | URL:=https://github.com/madeye/shadowsocks-libev 28 | endef 29 | 30 | define Package/shadowsocks-libev 31 | $(call Package/shadowsocks-libev/Default) 32 | TITLE+= (OpenSSL) 33 | VARIANT:=openssl 34 | DEPENDS:=+libopenssl 35 | endef 36 | 37 | define Package/shadowsocks-libev-polarssl 38 | $(call Package/shadowsocks-libev/Default) 39 | TITLE+= (PolarSSL) 40 | VARIANT:=polarssl 41 | DEPENDS:=+libpolarssl 42 | endef 43 | 44 | define Package/shadowsocks-libev-server 45 | $(call Package/shadowsocks-libev/Default) 46 | TITLE+= (OpenSSL) 47 | VARIANT:=openssl 48 | DEPENDS:=+libopenssl +libpthread 49 | endef 50 | 51 | define Package/shadowsocks-libev-server-polarssl 52 | $(call Package/shadowsocks-libev/Default) 53 | TITLE+= (PolarSSL) 54 | VARIANT:=polarssl 55 | DEPENDS:=+libpolarssl +libpthread 56 | endef 57 | 58 | define Package/shadowsocks-libev/description 59 | Shadowsocks-libev is a lightweight secured scoks5 proxy for embedded devices and low end boxes. 60 | endef 61 | 62 | Package/shadowsocks-libev-polarssl/description=$(Package/shadowsocks-libev/description) 63 | 64 | Package/shadowsocks-libev-server/description=$(Package/shadowsocks-libev/description) 65 | 66 | Package/shadowsocks-libev-server-polarssl/description=$(Package/shadowsocks-libev/description) 67 | 68 | define Package/shadowsocks-libev/conffiles 69 | /etc/shadowsocks.json 70 | endef 71 | 72 | ifeq ($(BUILD_VARIANT),polarssl) 73 | CONFIGURE_ARGS += --with-crypto-library=polarssl 74 | endif 75 | 76 | TARGET_CFLAGS += \ 77 | -fdata-sections \ 78 | -ffunction-sections 79 | 80 | TARGET_LDFLAGS += \ 81 | -Wl,-gc-sections 82 | 83 | MAKE_FLAGS += \ 84 | CFLAGS="$(TARGET_CFLAGS)" \ 85 | LDFLAGS="$(TARGET_LDFLAGS)" 86 | 87 | define Package/shadowsocks-libev/install 88 | $(INSTALL_DIR) $(1)/etc/init.d 89 | $(INSTALL_CONF) ./files/shadowsocks.json $(1)/etc 90 | $(INSTALL_BIN) ./files/shadowsocks.init $(1)/etc/init.d/shadowsocks 91 | $(INSTALL_DIR) $(1)/usr/bin 92 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/ss-{local,redir,tunnel} $(1)/usr/bin 93 | endef 94 | 95 | Package/shadowsocks-libev-polarssl/install=$(Package/shadowsocks-libev/install) 96 | 97 | define Package/shadowsocks-libev-server/install 98 | $(INSTALL_DIR) $(1)/usr/bin 99 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/ss-server $(1)/usr/bin 100 | endef 101 | 102 | Package/shadowsocks-libev-server-polarssl/install=$(Package/shadowsocks-libev-server/install) 103 | 104 | $(eval $(call BuildPackage,shadowsocks-libev)) 105 | $(eval $(call BuildPackage,shadowsocks-libev-polarssl)) 106 | $(eval $(call BuildPackage,shadowsocks-libev-server)) 107 | $(eval $(call BuildPackage,shadowsocks-libev-server-polarssl)) 108 | -------------------------------------------------------------------------------- /luci/build/zoneinfo2lua.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo 3 | # Execute from within /usr/share/zoneinfo 4 | # $Id$ 5 | 6 | use strict; 7 | 8 | my %TZ; 9 | 10 | my $tzdin = $ARGV[0] || "/usr/share/zoneinfo"; 11 | my $tzdout = $ARGV[1] || "./libs/sys/luasrc/sys/zoneinfo"; 12 | 13 | local $/ = "\012"; 14 | open( ZTAB, "< $tzdin/zone.tab" ) || die "open($tzdin/zone.tab): $!"; 15 | 16 | while( ! eof ZTAB ) { 17 | chomp( my $line = readline ZTAB ); 18 | next if $line =~ /^#/ || $line =~ /^\s+$/; 19 | 20 | my ( undef, undef, $zone, @comment ) = split /\s+/, $line; 21 | 22 | printf STDERR "%-40s", $zone; 23 | 24 | if( open ZONE, "< $tzdin/$zone" ) { 25 | seek ZONE, -2, 2; 26 | 27 | while( tell(ZONE) > 0 ) { 28 | read ZONE, my $char, 1; 29 | ( $char eq "\012" ) ? last : seek ZONE, -2, 1; 30 | } 31 | 32 | chomp( my $tz = readline ZONE ); 33 | print STDERR ( $tz || "(no tzinfo found)" ), "\n"; 34 | close ZONE; 35 | 36 | if( $tz ) { 37 | $zone =~ s/_/ /g; 38 | $TZ{$zone} = $tz; 39 | } 40 | } 41 | else 42 | { 43 | print STDERR "open($tzdin/$zone): $!\n"; 44 | } 45 | } 46 | 47 | close ZTAB; 48 | 49 | 50 | open(O, "> $tzdout/tzdata.lua") || die "open($tzdout/tzdata.lua): $!\n"; 51 | 52 | print STDERR "Writing time zones to $tzdout/tzdata.lua ... "; 53 | print O < $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n"; 81 | 82 | print STDERR "Writing time offsets to $tzdout/tzoffset.lua ... "; 83 | print O < 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "template_lualib.h" 20 | 21 | int template_L_parse(lua_State *L) 22 | { 23 | const char *file = luaL_checkstring(L, 1); 24 | struct template_parser *parser = template_open(file); 25 | int lua_status, rv; 26 | 27 | if (!parser) 28 | { 29 | lua_pushnil(L); 30 | lua_pushinteger(L, errno); 31 | lua_pushstring(L, strerror(errno)); 32 | return 3; 33 | } 34 | 35 | lua_status = lua_load(L, template_reader, parser, file); 36 | 37 | if (lua_status == 0) 38 | rv = 1; 39 | else 40 | rv = template_error(L, parser); 41 | 42 | template_close(parser); 43 | 44 | return rv; 45 | } 46 | 47 | int template_L_utf8(lua_State *L) 48 | { 49 | size_t len = 0; 50 | const char *str = luaL_checklstring(L, 1, &len); 51 | char *res = utf8(str, len); 52 | 53 | if (res != NULL) 54 | { 55 | lua_pushstring(L, res); 56 | free(res); 57 | 58 | return 1; 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | int template_L_pcdata(lua_State *L) 65 | { 66 | size_t len = 0; 67 | const char *str = luaL_checklstring(L, 1, &len); 68 | char *res = pcdata(str, len); 69 | 70 | if (res != NULL) 71 | { 72 | lua_pushstring(L, res); 73 | free(res); 74 | 75 | return 1; 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | int template_L_striptags(lua_State *L) 82 | { 83 | size_t len = 0; 84 | const char *str = luaL_checklstring(L, 1, &len); 85 | char *res = striptags(str, len); 86 | 87 | if (res != NULL) 88 | { 89 | lua_pushstring(L, res); 90 | free(res); 91 | 92 | return 1; 93 | } 94 | 95 | return 0; 96 | } 97 | 98 | static int template_L_load_catalog(lua_State *L) { 99 | const char *lang = luaL_optstring(L, 1, "en"); 100 | const char *dir = luaL_optstring(L, 2, NULL); 101 | lua_pushboolean(L, !lmo_load_catalog(lang, dir)); 102 | return 1; 103 | } 104 | 105 | static int template_L_close_catalog(lua_State *L) { 106 | const char *lang = luaL_optstring(L, 1, "en"); 107 | lmo_close_catalog(lang); 108 | return 0; 109 | } 110 | 111 | static int template_L_change_catalog(lua_State *L) { 112 | const char *lang = luaL_optstring(L, 1, "en"); 113 | lua_pushboolean(L, !lmo_change_catalog(lang)); 114 | return 1; 115 | } 116 | 117 | static int template_L_translate(lua_State *L) { 118 | size_t len; 119 | char *tr; 120 | int trlen; 121 | const char *key = luaL_checklstring(L, 1, &len); 122 | 123 | switch (lmo_translate(key, len, &tr, &trlen)) 124 | { 125 | case 0: 126 | lua_pushlstring(L, tr, trlen); 127 | return 1; 128 | 129 | case -1: 130 | return 0; 131 | } 132 | 133 | lua_pushnil(L); 134 | lua_pushstring(L, "no catalog loaded"); 135 | return 2; 136 | } 137 | 138 | static int template_L_hash(lua_State *L) { 139 | size_t len; 140 | const char *key = luaL_checklstring(L, 1, &len); 141 | lua_pushinteger(L, sfh_hash(key, len)); 142 | return 1; 143 | } 144 | 145 | 146 | /* module table */ 147 | static const luaL_reg R[] = { 148 | { "parse", template_L_parse }, 149 | { "utf8", template_L_utf8 }, 150 | { "pcdata", template_L_pcdata }, 151 | { "striptags", template_L_striptags }, 152 | { "load_catalog", template_L_load_catalog }, 153 | { "close_catalog", template_L_close_catalog }, 154 | { "change_catalog", template_L_change_catalog }, 155 | { "translate", template_L_translate }, 156 | { "hash", template_L_hash }, 157 | { NULL, NULL } 158 | }; 159 | 160 | LUALIB_API int luaopen_luci_template_parser(lua_State *L) { 161 | luaL_register(L, TEMPLATE_LUALIB_META, R); 162 | return 1; 163 | } 164 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/po2lmo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lmo - Lua Machine Objects - PO to LMO conversion tool 3 | * 4 | * Copyright (C) 2009-2012 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "template_lmo.h" 20 | 21 | static void die(const char *msg) 22 | { 23 | fprintf(stderr, "Error: %s\n", msg); 24 | exit(1); 25 | } 26 | 27 | static void usage(const char *name) 28 | { 29 | fprintf(stderr, "Usage: %s input.po output.lmo\n", name); 30 | exit(1); 31 | } 32 | 33 | static void print(const void *ptr, size_t size, size_t nmemb, FILE *stream) 34 | { 35 | if( fwrite(ptr, size, nmemb, stream) == 0 ) 36 | die("Failed to write stdout"); 37 | } 38 | 39 | static int extract_string(const char *src, char *dest, int len) 40 | { 41 | int pos = 0; 42 | int esc = 0; 43 | int off = -1; 44 | 45 | for( pos = 0; (pos < strlen(src)) && (pos < len); pos++ ) 46 | { 47 | if( (off == -1) && (src[pos] == '"') ) 48 | { 49 | off = pos + 1; 50 | } 51 | else if( off >= 0 ) 52 | { 53 | if( esc == 1 ) 54 | { 55 | switch (src[pos]) 56 | { 57 | case '"': 58 | case '\\': 59 | off++; 60 | break; 61 | } 62 | dest[pos-off] = src[pos]; 63 | esc = 0; 64 | } 65 | else if( src[pos] == '\\' ) 66 | { 67 | dest[pos-off] = src[pos]; 68 | esc = 1; 69 | } 70 | else if( src[pos] != '"' ) 71 | { 72 | dest[pos-off] = src[pos]; 73 | } 74 | else 75 | { 76 | dest[pos-off] = '\0'; 77 | break; 78 | } 79 | } 80 | } 81 | 82 | return (off > -1) ? strlen(dest) : -1; 83 | } 84 | 85 | static int cmp_index(const void *a, const void *b) 86 | { 87 | uint32_t x = ((const lmo_entry_t *)a)->key_id; 88 | uint32_t y = ((const lmo_entry_t *)b)->key_id; 89 | 90 | if (x < y) 91 | return -1; 92 | else if (x > y) 93 | return 1; 94 | 95 | return 0; 96 | } 97 | 98 | static void print_uint32(uint32_t x, FILE *out) 99 | { 100 | uint32_t y = htonl(x); 101 | print(&y, sizeof(uint32_t), 1, out); 102 | } 103 | 104 | static void print_index(void *array, int n, FILE *out) 105 | { 106 | lmo_entry_t *e; 107 | 108 | qsort(array, n, sizeof(*e), cmp_index); 109 | 110 | for (e = array; n > 0; n--, e++) 111 | { 112 | print_uint32(e->key_id, out); 113 | print_uint32(e->val_id, out); 114 | print_uint32(e->offset, out); 115 | print_uint32(e->length, out); 116 | } 117 | } 118 | 119 | int main(int argc, char *argv[]) 120 | { 121 | char line[4096]; 122 | char key[4096]; 123 | char val[4096]; 124 | char tmp[4096]; 125 | int state = 0; 126 | int offset = 0; 127 | int length = 0; 128 | int n_entries = 0; 129 | void *array = NULL; 130 | lmo_entry_t *entry = NULL; 131 | uint32_t key_id, val_id; 132 | 133 | FILE *in; 134 | FILE *out; 135 | 136 | if( (argc != 3) || ((in = fopen(argv[1], "r")) == NULL) || ((out = fopen(argv[2], "w")) == NULL) ) 137 | usage(argv[0]); 138 | 139 | memset(line, 0, sizeof(key)); 140 | memset(key, 0, sizeof(val)); 141 | memset(val, 0, sizeof(val)); 142 | 143 | while( (NULL != fgets(line, sizeof(line), in)) || (state >= 2 && feof(in)) ) 144 | { 145 | if( state == 0 && strstr(line, "msgid \"") == line ) 146 | { 147 | switch(extract_string(line, key, sizeof(key))) 148 | { 149 | case -1: 150 | die("Syntax error in msgid"); 151 | case 0: 152 | state = 1; 153 | break; 154 | default: 155 | state = 2; 156 | } 157 | } 158 | else if( state == 1 || state == 2 ) 159 | { 160 | if( strstr(line, "msgstr \"") == line || state == 2 ) 161 | { 162 | switch(extract_string(line, val, sizeof(val))) 163 | { 164 | case -1: 165 | state = 4; 166 | break; 167 | default: 168 | state = 3; 169 | } 170 | } 171 | else 172 | { 173 | switch(extract_string(line, tmp, sizeof(tmp))) 174 | { 175 | case -1: 176 | state = 2; 177 | break; 178 | default: 179 | strcat(key, tmp); 180 | } 181 | } 182 | } 183 | else if( state == 3 ) 184 | { 185 | switch(extract_string(line, tmp, sizeof(tmp))) 186 | { 187 | case -1: 188 | state = 4; 189 | break; 190 | default: 191 | strcat(val, tmp); 192 | } 193 | } 194 | 195 | if( state == 4 ) 196 | { 197 | if( strlen(key) > 0 && strlen(val) > 0 ) 198 | { 199 | key_id = sfh_hash(key, strlen(key)); 200 | val_id = sfh_hash(val, strlen(val)); 201 | 202 | if( key_id != val_id ) 203 | { 204 | n_entries++; 205 | array = realloc(array, n_entries * sizeof(lmo_entry_t)); 206 | entry = (lmo_entry_t *)array + n_entries - 1; 207 | 208 | if (!array) 209 | die("Out of memory"); 210 | 211 | entry->key_id = key_id; 212 | entry->val_id = val_id; 213 | entry->offset = offset; 214 | entry->length = strlen(val); 215 | 216 | length = strlen(val) + ((4 - (strlen(val) % 4)) % 4); 217 | 218 | print(val, length, 1, out); 219 | offset += length; 220 | } 221 | } 222 | 223 | state = 0; 224 | memset(key, 0, sizeof(key)); 225 | memset(val, 0, sizeof(val)); 226 | } 227 | 228 | memset(line, 0, sizeof(line)); 229 | } 230 | 231 | print_index(array, n_entries, out); 232 | 233 | if( offset > 0 ) 234 | { 235 | print_uint32(offset, out); 236 | fsync(fileno(out)); 237 | fclose(out); 238 | } 239 | else 240 | { 241 | fclose(out); 242 | unlink(argv[2]); 243 | } 244 | 245 | fclose(in); 246 | return(0); 247 | } 248 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_lmo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lmo - Lua Machine Objects - Base functions 3 | * 4 | * Copyright (C) 2009-2010 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "template_lmo.h" 20 | 21 | /* 22 | * Hash function from http://www.azillionmonkeys.com/qed/hash.html 23 | * Copyright (C) 2004-2008 by Paul Hsieh 24 | */ 25 | 26 | uint32_t sfh_hash(const char *data, int len) 27 | { 28 | uint32_t hash = len, tmp; 29 | int rem; 30 | 31 | if (len <= 0 || data == NULL) return 0; 32 | 33 | rem = len & 3; 34 | len >>= 2; 35 | 36 | /* Main loop */ 37 | for (;len > 0; len--) { 38 | hash += sfh_get16(data); 39 | tmp = (sfh_get16(data+2) << 11) ^ hash; 40 | hash = (hash << 16) ^ tmp; 41 | data += 2*sizeof(uint16_t); 42 | hash += hash >> 11; 43 | } 44 | 45 | /* Handle end cases */ 46 | switch (rem) { 47 | case 3: hash += sfh_get16(data); 48 | hash ^= hash << 16; 49 | hash ^= data[sizeof(uint16_t)] << 18; 50 | hash += hash >> 11; 51 | break; 52 | case 2: hash += sfh_get16(data); 53 | hash ^= hash << 11; 54 | hash += hash >> 17; 55 | break; 56 | case 1: hash += *data; 57 | hash ^= hash << 10; 58 | hash += hash >> 1; 59 | } 60 | 61 | /* Force "avalanching" of final 127 bits */ 62 | hash ^= hash << 3; 63 | hash += hash >> 5; 64 | hash ^= hash << 4; 65 | hash += hash >> 17; 66 | hash ^= hash << 25; 67 | hash += hash >> 6; 68 | 69 | return hash; 70 | } 71 | 72 | uint32_t lmo_canon_hash(const char *str, int len) 73 | { 74 | char res[4096]; 75 | char *ptr, prev; 76 | int off; 77 | 78 | if (!str || len >= sizeof(res)) 79 | return 0; 80 | 81 | for (prev = ' ', ptr = res, off = 0; off < len; prev = *str, off++, str++) 82 | { 83 | if (isspace(*str)) 84 | { 85 | if (!isspace(prev)) 86 | *ptr++ = ' '; 87 | } 88 | else 89 | { 90 | *ptr++ = *str; 91 | } 92 | } 93 | 94 | if ((ptr > res) && isspace(*(ptr-1))) 95 | ptr--; 96 | 97 | return sfh_hash(res, ptr - res); 98 | } 99 | 100 | lmo_archive_t * lmo_open(const char *file) 101 | { 102 | int in = -1; 103 | uint32_t idx_offset = 0; 104 | struct stat s; 105 | 106 | lmo_archive_t *ar = NULL; 107 | 108 | if (stat(file, &s) == -1) 109 | goto err; 110 | 111 | if ((in = open(file, O_RDONLY)) == -1) 112 | goto err; 113 | 114 | if ((ar = (lmo_archive_t *)malloc(sizeof(*ar))) != NULL) 115 | { 116 | memset(ar, 0, sizeof(*ar)); 117 | 118 | ar->fd = in; 119 | ar->size = s.st_size; 120 | 121 | fcntl(ar->fd, F_SETFD, fcntl(ar->fd, F_GETFD) | FD_CLOEXEC); 122 | 123 | if ((ar->mmap = mmap(NULL, ar->size, PROT_READ, MAP_SHARED, ar->fd, 0)) == MAP_FAILED) 124 | goto err; 125 | 126 | idx_offset = ntohl(*((const uint32_t *) 127 | (ar->mmap + ar->size - sizeof(uint32_t)))); 128 | 129 | if (idx_offset >= ar->size) 130 | goto err; 131 | 132 | ar->index = (lmo_entry_t *)(ar->mmap + idx_offset); 133 | ar->length = (ar->size - idx_offset - sizeof(uint32_t)) / sizeof(lmo_entry_t); 134 | ar->end = ar->mmap + ar->size; 135 | 136 | return ar; 137 | } 138 | 139 | err: 140 | if (in > -1) 141 | close(in); 142 | 143 | if (ar != NULL) 144 | { 145 | if ((ar->mmap != NULL) && (ar->mmap != MAP_FAILED)) 146 | munmap(ar->mmap, ar->size); 147 | 148 | free(ar); 149 | } 150 | 151 | return NULL; 152 | } 153 | 154 | void lmo_close(lmo_archive_t *ar) 155 | { 156 | if (ar != NULL) 157 | { 158 | if ((ar->mmap != NULL) && (ar->mmap != MAP_FAILED)) 159 | munmap(ar->mmap, ar->size); 160 | 161 | close(ar->fd); 162 | free(ar); 163 | 164 | ar = NULL; 165 | } 166 | } 167 | 168 | 169 | lmo_catalog_t *_lmo_catalogs = NULL; 170 | lmo_catalog_t *_lmo_active_catalog = NULL; 171 | 172 | int lmo_load_catalog(const char *lang, const char *dir) 173 | { 174 | DIR *dh = NULL; 175 | char pattern[16]; 176 | char path[PATH_MAX]; 177 | struct dirent *de = NULL; 178 | 179 | lmo_archive_t *ar = NULL; 180 | lmo_catalog_t *cat = NULL; 181 | 182 | if (!lmo_change_catalog(lang)) 183 | return 0; 184 | 185 | if (!dir || !(dh = opendir(dir))) 186 | goto err; 187 | 188 | if (!(cat = malloc(sizeof(*cat)))) 189 | goto err; 190 | 191 | memset(cat, 0, sizeof(*cat)); 192 | 193 | snprintf(cat->lang, sizeof(cat->lang), "%s", lang); 194 | snprintf(pattern, sizeof(pattern), "*.%s.lmo", lang); 195 | 196 | while ((de = readdir(dh)) != NULL) 197 | { 198 | if (!fnmatch(pattern, de->d_name, 0)) 199 | { 200 | snprintf(path, sizeof(path), "%s/%s", dir, de->d_name); 201 | ar = lmo_open(path); 202 | 203 | if (ar) 204 | { 205 | ar->next = cat->archives; 206 | cat->archives = ar; 207 | } 208 | } 209 | } 210 | 211 | closedir(dh); 212 | 213 | cat->next = _lmo_catalogs; 214 | _lmo_catalogs = cat; 215 | 216 | if (!_lmo_active_catalog) 217 | _lmo_active_catalog = cat; 218 | 219 | return 0; 220 | 221 | err: 222 | if (dh) closedir(dh); 223 | if (cat) free(cat); 224 | 225 | return -1; 226 | } 227 | 228 | int lmo_change_catalog(const char *lang) 229 | { 230 | lmo_catalog_t *cat; 231 | 232 | for (cat = _lmo_catalogs; cat; cat = cat->next) 233 | { 234 | if (!strncmp(cat->lang, lang, sizeof(cat->lang))) 235 | { 236 | _lmo_active_catalog = cat; 237 | return 0; 238 | } 239 | } 240 | 241 | return -1; 242 | } 243 | 244 | static lmo_entry_t * lmo_find_entry(lmo_archive_t *ar, uint32_t hash) 245 | { 246 | unsigned int m, l, r; 247 | uint32_t k; 248 | 249 | l = 0; 250 | r = ar->length - 1; 251 | 252 | while (1) 253 | { 254 | m = l + ((r - l) / 2); 255 | 256 | if (r < l) 257 | break; 258 | 259 | k = ntohl(ar->index[m].key_id); 260 | 261 | if (k == hash) 262 | return &ar->index[m]; 263 | 264 | if (k > hash) 265 | { 266 | if (!m) 267 | break; 268 | 269 | r = m - 1; 270 | } 271 | else 272 | { 273 | l = m + 1; 274 | } 275 | } 276 | 277 | return NULL; 278 | } 279 | 280 | int lmo_translate(const char *key, int keylen, char **out, int *outlen) 281 | { 282 | uint32_t hash; 283 | lmo_entry_t *e; 284 | lmo_archive_t *ar; 285 | 286 | if (!key || !_lmo_active_catalog) 287 | return -2; 288 | 289 | hash = lmo_canon_hash(key, keylen); 290 | 291 | for (ar = _lmo_active_catalog->archives; ar; ar = ar->next) 292 | { 293 | if ((e = lmo_find_entry(ar, hash)) != NULL) 294 | { 295 | *out = ar->mmap + ntohl(e->offset); 296 | *outlen = ntohl(e->length); 297 | return 0; 298 | } 299 | } 300 | 301 | return -1; 302 | } 303 | 304 | void lmo_close_catalog(const char *lang) 305 | { 306 | lmo_archive_t *ar, *next; 307 | lmo_catalog_t *cat, *prev; 308 | 309 | for (prev = NULL, cat = _lmo_catalogs; cat; prev = cat, cat = cat->next) 310 | { 311 | if (!strncmp(cat->lang, lang, sizeof(cat->lang))) 312 | { 313 | if (prev) 314 | prev->next = cat->next; 315 | else 316 | _lmo_catalogs = cat->next; 317 | 318 | for (ar = cat->archives; ar; ar = next) 319 | { 320 | next = ar->next; 321 | lmo_close(ar); 322 | } 323 | 324 | free(cat); 325 | break; 326 | } 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LuCI Template - Parser implementation 3 | * 4 | * Copyright (C) 2009-2012 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "template_parser.h" 20 | #include "template_utils.h" 21 | #include "template_lmo.h" 22 | 23 | 24 | /* leading and trailing code for different types */ 25 | const char *gen_code[9][2] = { 26 | { NULL, NULL }, 27 | { "write(\"", "\")" }, 28 | { NULL, NULL }, 29 | { "write(tostring(", " or \"\"))" }, 30 | { "include(\"", "\")" }, 31 | { "write(\"", "\")" }, 32 | { "write(\"", "\")" }, 33 | { NULL, " " }, 34 | { NULL, NULL }, 35 | }; 36 | 37 | /* Simple strstr() like function that takes len arguments for both haystack and needle. */ 38 | static char *strfind(char *haystack, int hslen, const char *needle, int ndlen) 39 | { 40 | int match = 0; 41 | int i, j; 42 | 43 | for( i = 0; i < hslen; i++ ) 44 | { 45 | if( haystack[i] == needle[0] ) 46 | { 47 | match = ((ndlen == 1) || ((i + ndlen) <= hslen)); 48 | 49 | for( j = 1; (j < ndlen) && ((i + j) < hslen); j++ ) 50 | { 51 | if( haystack[i+j] != needle[j] ) 52 | { 53 | match = 0; 54 | break; 55 | } 56 | } 57 | 58 | if( match ) 59 | return &haystack[i]; 60 | } 61 | } 62 | 63 | return NULL; 64 | } 65 | 66 | struct template_parser * template_open(const char *file) 67 | { 68 | struct stat s; 69 | static struct template_parser *parser; 70 | 71 | if (!(parser = malloc(sizeof(*parser)))) 72 | goto err; 73 | 74 | memset(parser, 0, sizeof(*parser)); 75 | parser->fd = -1; 76 | parser->file = file; 77 | 78 | if (stat(file, &s)) 79 | goto err; 80 | 81 | if ((parser->fd = open(file, O_RDONLY)) < 0) 82 | goto err; 83 | 84 | parser->size = s.st_size; 85 | parser->mmap = mmap(NULL, parser->size, PROT_READ, MAP_PRIVATE, 86 | parser->fd, 0); 87 | 88 | if (parser->mmap != MAP_FAILED) 89 | { 90 | parser->off = parser->mmap; 91 | parser->cur_chunk.type = T_TYPE_INIT; 92 | parser->cur_chunk.s = parser->mmap; 93 | parser->cur_chunk.e = parser->mmap; 94 | 95 | return parser; 96 | } 97 | 98 | err: 99 | template_close(parser); 100 | return NULL; 101 | } 102 | 103 | void template_close(struct template_parser *parser) 104 | { 105 | if (!parser) 106 | return; 107 | 108 | if (parser->gc != NULL) 109 | free(parser->gc); 110 | 111 | if ((parser->mmap != NULL) && (parser->mmap != MAP_FAILED)) 112 | munmap(parser->mmap, parser->size); 113 | 114 | if (parser->fd >= 0) 115 | close(parser->fd); 116 | 117 | free(parser); 118 | } 119 | 120 | void template_text(struct template_parser *parser, const char *e) 121 | { 122 | const char *s = parser->off; 123 | 124 | if (s < (parser->mmap + parser->size)) 125 | { 126 | if (parser->strip_after) 127 | { 128 | while ((s <= e) && isspace(*s)) 129 | s++; 130 | } 131 | 132 | parser->cur_chunk.type = T_TYPE_TEXT; 133 | } 134 | else 135 | { 136 | parser->cur_chunk.type = T_TYPE_EOF; 137 | } 138 | 139 | parser->cur_chunk.line = parser->line; 140 | parser->cur_chunk.s = s; 141 | parser->cur_chunk.e = e; 142 | } 143 | 144 | void template_code(struct template_parser *parser, const char *e) 145 | { 146 | const char *s = parser->off; 147 | 148 | parser->strip_before = 0; 149 | parser->strip_after = 0; 150 | 151 | if (*s == '-') 152 | { 153 | parser->strip_before = 1; 154 | for (s++; (s <= e) && (*s == ' ' || *s == '\t'); s++); 155 | } 156 | 157 | if (*(e-1) == '-') 158 | { 159 | parser->strip_after = 1; 160 | for (e--; (e >= s) && (*e == ' ' || *e == '\t'); e--); 161 | } 162 | 163 | switch (*s) 164 | { 165 | /* comment */ 166 | case '#': 167 | s++; 168 | parser->cur_chunk.type = T_TYPE_COMMENT; 169 | break; 170 | 171 | /* include */ 172 | case '+': 173 | s++; 174 | parser->cur_chunk.type = T_TYPE_INCLUDE; 175 | break; 176 | 177 | /* translate */ 178 | case ':': 179 | s++; 180 | parser->cur_chunk.type = T_TYPE_I18N; 181 | break; 182 | 183 | /* translate raw */ 184 | case '_': 185 | s++; 186 | parser->cur_chunk.type = T_TYPE_I18N_RAW; 187 | break; 188 | 189 | /* expr */ 190 | case '=': 191 | s++; 192 | parser->cur_chunk.type = T_TYPE_EXPR; 193 | break; 194 | 195 | /* code */ 196 | default: 197 | parser->cur_chunk.type = T_TYPE_CODE; 198 | break; 199 | } 200 | 201 | parser->cur_chunk.line = parser->line; 202 | parser->cur_chunk.s = s; 203 | parser->cur_chunk.e = e; 204 | } 205 | 206 | static const char * 207 | template_format_chunk(struct template_parser *parser, size_t *sz) 208 | { 209 | const char *s, *p; 210 | const char *head, *tail; 211 | struct template_chunk *c = &parser->prv_chunk; 212 | struct template_buffer *buf; 213 | 214 | *sz = 0; 215 | s = parser->gc = NULL; 216 | 217 | if (parser->strip_before && c->type == T_TYPE_TEXT) 218 | { 219 | while ((c->e > c->s) && isspace(*(c->e - 1))) 220 | c->e--; 221 | } 222 | 223 | /* empty chunk */ 224 | if (c->s == c->e) 225 | { 226 | if (c->type == T_TYPE_EOF) 227 | { 228 | *sz = 0; 229 | s = NULL; 230 | } 231 | else 232 | { 233 | *sz = 1; 234 | s = " "; 235 | } 236 | } 237 | 238 | /* format chunk */ 239 | else if ((buf = buf_init(c->e - c->s)) != NULL) 240 | { 241 | if ((head = gen_code[c->type][0]) != NULL) 242 | buf_append(buf, head, strlen(head)); 243 | 244 | switch (c->type) 245 | { 246 | case T_TYPE_TEXT: 247 | luastr_escape(buf, c->s, c->e - c->s, 0); 248 | break; 249 | 250 | case T_TYPE_EXPR: 251 | buf_append(buf, c->s, c->e - c->s); 252 | for (p = c->s; p < c->e; p++) 253 | parser->line += (*p == '\n'); 254 | break; 255 | 256 | case T_TYPE_INCLUDE: 257 | luastr_escape(buf, c->s, c->e - c->s, 0); 258 | break; 259 | 260 | case T_TYPE_I18N: 261 | luastr_translate(buf, c->s, c->e - c->s, 1); 262 | break; 263 | 264 | case T_TYPE_I18N_RAW: 265 | luastr_translate(buf, c->s, c->e - c->s, 0); 266 | break; 267 | 268 | case T_TYPE_CODE: 269 | buf_append(buf, c->s, c->e - c->s); 270 | for (p = c->s; p < c->e; p++) 271 | parser->line += (*p == '\n'); 272 | break; 273 | } 274 | 275 | if ((tail = gen_code[c->type][1]) != NULL) 276 | buf_append(buf, tail, strlen(tail)); 277 | 278 | *sz = buf_length(buf); 279 | s = parser->gc = buf_destroy(buf); 280 | 281 | if (!*sz) 282 | { 283 | *sz = 1; 284 | s = " "; 285 | } 286 | } 287 | 288 | return s; 289 | } 290 | 291 | const char *template_reader(lua_State *L, void *ud, size_t *sz) 292 | { 293 | struct template_parser *parser = ud; 294 | int rem = parser->size - (parser->off - parser->mmap); 295 | char *tag; 296 | 297 | parser->prv_chunk = parser->cur_chunk; 298 | 299 | /* free previous string */ 300 | if (parser->gc) 301 | { 302 | free(parser->gc); 303 | parser->gc = NULL; 304 | } 305 | 306 | /* before tag */ 307 | if (!parser->in_expr) 308 | { 309 | if ((tag = strfind(parser->off, rem, "<%", 2)) != NULL) 310 | { 311 | template_text(parser, tag); 312 | parser->off = tag + 2; 313 | parser->in_expr = 1; 314 | } 315 | else 316 | { 317 | template_text(parser, parser->mmap + parser->size); 318 | parser->off = parser->mmap + parser->size; 319 | } 320 | } 321 | 322 | /* inside tag */ 323 | else 324 | { 325 | if ((tag = strfind(parser->off, rem, "%>", 2)) != NULL) 326 | { 327 | template_code(parser, tag); 328 | parser->off = tag + 2; 329 | parser->in_expr = 0; 330 | } 331 | else 332 | { 333 | /* unexpected EOF */ 334 | template_code(parser, parser->mmap + parser->size); 335 | 336 | *sz = 1; 337 | return "\033"; 338 | } 339 | } 340 | 341 | return template_format_chunk(parser, sz); 342 | } 343 | 344 | int template_error(lua_State *L, struct template_parser *parser) 345 | { 346 | const char *err = luaL_checkstring(L, -1); 347 | const char *off = parser->prv_chunk.s; 348 | const char *ptr; 349 | char msg[1024]; 350 | int line = 0; 351 | int chunkline = 0; 352 | 353 | if ((ptr = strfind((char *)err, strlen(err), "]:", 2)) != NULL) 354 | { 355 | chunkline = atoi(ptr + 2) - parser->prv_chunk.line; 356 | 357 | while (*ptr) 358 | { 359 | if (*ptr++ == ' ') 360 | { 361 | err = ptr; 362 | break; 363 | } 364 | } 365 | } 366 | 367 | if (strfind((char *)err, strlen(err), "'char(27)'", 10) != NULL) 368 | { 369 | off = parser->mmap + parser->size; 370 | err = "'%>' expected before end of file"; 371 | chunkline = 0; 372 | } 373 | 374 | for (ptr = parser->mmap; ptr < off; ptr++) 375 | if (*ptr == '\n') 376 | line++; 377 | 378 | snprintf(msg, sizeof(msg), "Syntax error in %s:%d: %s", 379 | parser->file, line + chunkline, err ? err : "(unknown error)"); 380 | 381 | lua_pushnil(L); 382 | lua_pushinteger(L, line + chunkline); 383 | lua_pushstring(L, msg); 384 | 385 | return 3; 386 | } 387 | -------------------------------------------------------------------------------- /luci/applications/luci-aria2/luasrc/model/cbi/aria2.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | LuCI - Lua Configuration Interface - Aria2 support 3 | 4 | Copyright 2014 nanpuyue 5 | Modified by maz-1 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | ]]-- 13 | 14 | require("luci.sys") 15 | require("luci.util") 16 | require("luci.model.ipkg") 17 | 18 | 19 | local uci = require "luci.model.uci".cursor() 20 | local cfgcmd = "var Token=document.getElementById('cbid.aria2.main.rpc_secret');" .. 21 | "function randomString(len){" .. 22 | "len=len||32;var $chars='abcdefghijklmnopqrstuvwxyz1234567890';" .. 23 | "var maxPos=$chars.length;var pwd='';" .. 24 | "for(i = 0; i < len; i++){pwd+=$chars.charAt(Math.floor(Math.random() * maxPos));}" .. 25 | "return pwd;};Token.value=randomString(32)" 26 | 27 | local cfgbtn = " " 28 | local spaces="      " 29 | 30 | local viewrpc = "var websocket=document.getElementById(\"use_websocket\");" .. 31 | "var protocol=(websocket.checked) ? \"ws\" : \"http\";" .. 32 | "var newTextNode=document.getElementById(\"aria2rpcpath\");" .. 33 | "var auth_method=document.getElementById(\"cbid.aria2.main.rpc_auth_method\");" .. 34 | "var auth_port=document.getElementById(\"cbid.aria2.main.rpc_listen_port\");" .. 35 | "if(auth_port.value==\"\"){auth_port_value=\"6800\"}else{auth_port_value=auth_port.value};" .. 36 | "if(auth_method.value==\"token\"){" .. 37 | "var auth_token=document.getElementById(\"cbid.aria2.main.rpc_secret\");" .. 38 | "newTextNode.value=protocol+\"://token:\"+auth_token.value+\"@\"+document.domain+\":\"+auth_port_value+\"/jsonrpc\";" .. 39 | "}else if(auth_method.value==\"user_pass\"){" .. 40 | "var auth_user=document.getElementById(\"cbid.aria2.main.rpc_user\");" .. 41 | "var auth_passwd=document.getElementById(\"cbid.aria2.main.rpc_passwd\");" .. 42 | "newTextNode.value=protocol+\"://\"+auth_user.value+\":\"+auth_passwd.value+\"@\"+document.domain+\":\"+auth_port_value+\"/jsonrpc\";" .. 43 | "}else{" .. 44 | "newTextNode.value=protocol+\"://\"+document.domain+\":\"+auth_port_value+\"/jsonrpc\";" .. 45 | "}" 46 | local sessionbtn = spaces .. "" 47 | local aria2rpctxt = spaces .. "" 48 | local use_websocket = spaces .. "  " 49 | 50 | 51 | local webui="yaaw" 52 | local running = (luci.sys.call("pidof aria2c > /dev/null") == 0) 53 | local webinstalled = luci.model.ipkg.installed(webui) 54 | local button = "" 55 | local openyaaw = "var curWwwPath=window.document.location.href;" .. 56 | "var pathName=window.document.location.pathname;" .. 57 | "var pos=curWwwPath.indexOf(pathName);" .. 58 | "var localhostPath=curWwwPath.substring(0, pos);" .. 59 | "var yaawpath=\"http:\"+localhostPath.substring(window.location.protocol.length)+\"/yaaw\";" .. 60 | "window.open(yaawpath)" 61 | 62 | if running and webinstalled then 63 | button = spaces .. "" 64 | end 65 | 66 | function ipkg_ver(pkg) 67 | local version = nil 68 | local control = io.open("/usr/lib/opkg/info/%s.control" % pkg, "r") 69 | if control then 70 | local ln 71 | repeat 72 | ln = control:read("*l") 73 | if ln and ln:match("^Version: ") then 74 | version = ln:gsub("^Version: ", ""):gsub("-%d", "") 75 | break 76 | end 77 | until not ln 78 | control:close() 79 | end 80 | return version 81 | end 82 | function ipkg_ver_lined(pkg) 83 | return ipkg_ver(pkg):gsub("%.", "-") 84 | end 85 | 86 | m = Map("aria2", translate("Aria2 Settings"), translate("Aria2 is a multi-protocol & multi-source download utility, here you can configure the settings.") .. button) 87 | 88 | s=m:section(NamedSection, "main", "aria2", translate("Global settings")) 89 | s.addremove=false 90 | s.anonymous=true 91 | enable=s:option(Flag, "enabled", translate("Enabled")) 92 | enable.rmempty=false 93 | user=s:option(ListValue, "user", translate("Run daemon as user")) 94 | local p_user 95 | for _, p_user in luci.util.vspairs(luci.util.split(luci.sys.exec("cat /etc/passwd | cut -f 1 -d :"))) do 96 | user:value(p_user) 97 | end 98 | 99 | file=m:section(TypedSection, "aria2", translate("Files and Locations")) 100 | file.anonymous=true 101 | config_dir=file:option(Value, "config_dir", translate("Config file directory")) 102 | config_dir.placeholder="/var/etc/aria2" 103 | dir=file:option(Value, "dir", translate("Default download directory")) 104 | disk_cache=file:option(Value, "disk_cache", translate("Disk cache"), translate("in bytes, You can append K or M")) 105 | file_allocation=file:option(ListValue, "file_allocation", translate("Preallocation"), translate("\"falloc\" is not available in all cases")) 106 | file_allocation:value("none", translate("off")) 107 | file_allocation:value("prealloc", translate("prealloc")) 108 | file_allocation:value("trunc", translate("trunc")) 109 | file_allocation:value("falloc", translate("falloc")) 110 | 111 | task=m:section(TypedSection, "aria2", translate("Task Settings")) 112 | task.anonymous=true 113 | overall_speed_limit=task:option(Flag, "overall_speed_limit", translate("Overall speed limit enabled")) 114 | max_overall_download_limit=task:option(Value, "max_overall_download_limit", translate("Overall download limit"), translate("in bytes/sec, You can append K or M")) 115 | max_overall_download_limit:depends("overall_speed_limit", "1") 116 | max_overall_upload_limit=task:option(Value, "max_overall_upload_limit", translate("Overall upload limit"), translate("in bytes/sec, You can append K or M")) 117 | max_overall_upload_limit:depends("overall_speed_limit", "1") 118 | task_speed_limit=task:option(Flag, "task_speed_limit", translate("Per task speed limit enabled")) 119 | max_download_limit=task:option(Value, "max_download_limit", translate("Per task download limit"), translate("in bytes/sec, You can append K or M")) 120 | max_download_limit:depends("task_speed_limit", "1") 121 | max_upload_limit=task:option(Value, "max_upload_limit", translate("Per task upload limit"), translate("in bytes/sec, You can append K or M")) 122 | max_upload_limit:depends("task_speed_limit", "1") 123 | max_concurrent_downloads=task:option(Value, "max_concurrent_downloads", translate("Max concurrent downloads")) 124 | max_concurrent_downloads.placeholder="5" 125 | max_connection_per_server=task:option(Value, "max_connection_per_server", translate("Max connection per server"), "1-16") 126 | max_connection_per_server.datetype="range(1, 16)" 127 | max_connection_per_server.placeholder="1" 128 | min_split_size=task:option(Value, "min_split_size", translate("Min split size"), "1M-1024M") 129 | min_split_size.placeholder="20M" 130 | split=task:option(Value, "split", translate("Max number of split")) 131 | split.placeholder="5" 132 | save_session_interval=task:option(Value, "save_session_interval", translate("Autosave session interval"), translate("Sec")) 133 | save_session_interval.default="30" 134 | user_agent=task:option(Value, "user_agent", translate("User agent value")) 135 | user_agent.placeholder="aria2/" .. ipkg_ver("aria2") 136 | 137 | bittorrent=m:section(TypedSection, "aria2", translate("BitTorrent Settings")) 138 | bittorrent.anonymous=true 139 | enable_dht=bittorrent:option(Flag, "enable_dht", translate("DHT enabled")) 140 | enable_dht.enabled="true" 141 | enable_dht.disabled="false" 142 | bt_enable_lpd=bittorrent:option(Flag, "bt_enable_lpd", translate("LPD enabled")) 143 | bt_enable_lpd.enabled="true" 144 | bt_enable_lpd.disabled="false" 145 | follow_torrent=bittorrent:option(Flag, "follow_torrent", translate("Follow torrent")) 146 | follow_torrent.enabled="true" 147 | follow_torrent.disabled="false" 148 | listen_port=bittorrent:option(Value, "listen_port", translate("BitTorrent listen port")) 149 | listen_port.placeholder="6881-6999" 150 | bt_max_peers=bittorrent:option(Value, "bt_max_peers", translate("Max number of peers per torrent")) 151 | bt_max_peers.placeholder="55" 152 | bt_tracker_enable=bittorrent:option(Flag, "bt_tracker_enable", translate("Additional Bt tracker enabled")) 153 | bt_tracker=bittorrent:option(DynamicList, "bt_tracker", translate("List of additional Bt tracker")) 154 | bt_tracker:depends("bt_tracker_enable", "1") 155 | bt_tracker.rmempty=true 156 | peer_id_prefix=bittorrent:option(Value, "peer_id_prefix", translate("Prefix of peer ID")) 157 | peer_id_prefix.placeholder="A2-" .. ipkg_ver_lined("aria2") .. "-" 158 | 159 | function bt_tracker.cfgvalue(self, section) 160 | local rv = { } 161 | 162 | local val = Value.cfgvalue(self, section) 163 | if type(val) == "table" then 164 | val = table.concat(val, ",") 165 | elseif not val then 166 | val = "" 167 | end 168 | 169 | for v in val:gmatch("[^,%s]+") do 170 | rv[#rv+1] = v 171 | end 172 | 173 | return rv 174 | end 175 | 176 | function bt_tracker.write(self, section, value) 177 | local rv = { } 178 | for v in luci.util.imatch(value) do 179 | rv[#rv+1] = v 180 | end 181 | Value.write(self, section, table.concat(rv, ",")) 182 | end 183 | 184 | rpc=m:section(TypedSection, "aria2", translate("RPC settings") .. sessionbtn .. use_websocket .. aria2rpctxt) 185 | rpc.anonymous=true 186 | rpc_listen_port=rpc:option(Value, "rpc_listen_port", translate("RPC port")) 187 | rpc_listen_port.datatype="port" 188 | rpc_listen_port.placeholder="6800" 189 | 190 | rpc_auth_method=rpc:option(ListValue, "rpc_auth_method", translate("RPC authentication method")) 191 | rpc_auth_method:value("none", translate("No Authentication")) 192 | rpc_auth_method:value("user_pass", translate("Username & Password")) 193 | rpc_auth_method:value("token", translate("Token")) 194 | 195 | rpc_user=rpc:option(Value, "rpc_user", translate("RPC username")) 196 | rpc_user:depends("rpc_auth_method", "user_pass") 197 | 198 | rpc_passwd=rpc:option(Value, "rpc_passwd", translate("RPC password")) 199 | rpc_passwd:depends("rpc_auth_method", "user_pass") 200 | rpc_passwd.password = true 201 | 202 | rpc_secret=rpc:option(Value, "rpc_secret", translate("RPC Token"), "
" .. cfgbtn) 203 | rpc_secret:depends("rpc_auth_method", "token") 204 | 205 | extra=m:section(TypedSection, "aria2", translate("Extra Settings")) 206 | extra.addremove=false 207 | extra.anonymous=true 208 | extra_settings=extra:option(DynamicList, "extra_settings", translate("List of extra settings")) 209 | extra_settings.placeholder="option=value" 210 | extra_settings.rmempty=true 211 | 212 | 213 | 214 | return m 215 | -------------------------------------------------------------------------------- /luci/libs/lmo/src/template_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LuCI Template - Utility functions 3 | * 4 | * Copyright (C) 2010 Jo-Philipp Wich 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "template_utils.h" 20 | #include "template_lmo.h" 21 | 22 | /* initialize a buffer object */ 23 | struct template_buffer * buf_init(int size) 24 | { 25 | struct template_buffer *buf; 26 | 27 | if (size <= 0) 28 | size = 1024; 29 | 30 | buf = (struct template_buffer *)malloc(sizeof(struct template_buffer)); 31 | 32 | if (buf != NULL) 33 | { 34 | buf->fill = 0; 35 | buf->size = size; 36 | buf->data = malloc(buf->size); 37 | 38 | if (buf->data != NULL) 39 | { 40 | buf->dptr = buf->data; 41 | buf->data[0] = 0; 42 | 43 | return buf; 44 | } 45 | 46 | free(buf); 47 | } 48 | 49 | return NULL; 50 | } 51 | 52 | /* grow buffer */ 53 | int buf_grow(struct template_buffer *buf, int size) 54 | { 55 | unsigned int off = (buf->dptr - buf->data); 56 | char *data; 57 | 58 | if (size <= 0) 59 | size = 1024; 60 | 61 | data = realloc(buf->data, buf->size + size); 62 | 63 | if (data != NULL) 64 | { 65 | buf->data = data; 66 | buf->dptr = data + off; 67 | buf->size += size; 68 | 69 | return buf->size; 70 | } 71 | 72 | return 0; 73 | } 74 | 75 | /* put one char into buffer object */ 76 | int buf_putchar(struct template_buffer *buf, char c) 77 | { 78 | if( ((buf->fill + 1) >= buf->size) && !buf_grow(buf, 0) ) 79 | return 0; 80 | 81 | *(buf->dptr++) = c; 82 | *(buf->dptr) = 0; 83 | 84 | buf->fill++; 85 | return 1; 86 | } 87 | 88 | /* append data to buffer */ 89 | int buf_append(struct template_buffer *buf, const char *s, int len) 90 | { 91 | if ((buf->fill + len + 1) >= buf->size) 92 | { 93 | if (!buf_grow(buf, len + 1)) 94 | return 0; 95 | } 96 | 97 | memcpy(buf->dptr, s, len); 98 | buf->fill += len; 99 | buf->dptr += len; 100 | 101 | *(buf->dptr) = 0; 102 | 103 | return len; 104 | } 105 | 106 | /* read buffer length */ 107 | int buf_length(struct template_buffer *buf) 108 | { 109 | return buf->fill; 110 | } 111 | 112 | /* destroy buffer object and return pointer to data */ 113 | char * buf_destroy(struct template_buffer *buf) 114 | { 115 | char *data = buf->data; 116 | 117 | free(buf); 118 | return data; 119 | } 120 | 121 | 122 | /* calculate the number of expected continuation chars */ 123 | static inline int mb_num_chars(unsigned char c) 124 | { 125 | if ((c & 0xE0) == 0xC0) 126 | return 2; 127 | else if ((c & 0xF0) == 0xE0) 128 | return 3; 129 | else if ((c & 0xF8) == 0xF0) 130 | return 4; 131 | else if ((c & 0xFC) == 0xF8) 132 | return 5; 133 | else if ((c & 0xFE) == 0xFC) 134 | return 6; 135 | 136 | return 1; 137 | } 138 | 139 | /* test whether the given byte is a valid continuation char */ 140 | static inline int mb_is_cont(unsigned char c) 141 | { 142 | return ((c >= 0x80) && (c <= 0xBF)); 143 | } 144 | 145 | /* test whether the byte sequence at the given pointer with the given 146 | * length is the shortest possible representation of the code point */ 147 | static inline int mb_is_shortest(unsigned char *s, int n) 148 | { 149 | switch (n) 150 | { 151 | case 2: 152 | /* 1100000x (10xxxxxx) */ 153 | return !(((*s >> 1) == 0x60) && 154 | ((*(s+1) >> 6) == 0x02)); 155 | 156 | case 3: 157 | /* 11100000 100xxxxx (10xxxxxx) */ 158 | return !((*s == 0xE0) && 159 | ((*(s+1) >> 5) == 0x04) && 160 | ((*(s+2) >> 6) == 0x02)); 161 | 162 | case 4: 163 | /* 11110000 1000xxxx (10xxxxxx 10xxxxxx) */ 164 | return !((*s == 0xF0) && 165 | ((*(s+1) >> 4) == 0x08) && 166 | ((*(s+2) >> 6) == 0x02) && 167 | ((*(s+3) >> 6) == 0x02)); 168 | 169 | case 5: 170 | /* 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) */ 171 | return !((*s == 0xF8) && 172 | ((*(s+1) >> 3) == 0x10) && 173 | ((*(s+2) >> 6) == 0x02) && 174 | ((*(s+3) >> 6) == 0x02) && 175 | ((*(s+4) >> 6) == 0x02)); 176 | 177 | case 6: 178 | /* 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) */ 179 | return !((*s == 0xF8) && 180 | ((*(s+1) >> 2) == 0x20) && 181 | ((*(s+2) >> 6) == 0x02) && 182 | ((*(s+3) >> 6) == 0x02) && 183 | ((*(s+4) >> 6) == 0x02) && 184 | ((*(s+5) >> 6) == 0x02)); 185 | } 186 | 187 | return 1; 188 | } 189 | 190 | /* test whether the byte sequence at the given pointer with the given 191 | * length is an UTF-16 surrogate */ 192 | static inline int mb_is_surrogate(unsigned char *s, int n) 193 | { 194 | return ((n == 3) && (*s == 0xED) && (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF)); 195 | } 196 | 197 | /* test whether the byte sequence at the given pointer with the given 198 | * length is an illegal UTF-8 code point */ 199 | static inline int mb_is_illegal(unsigned char *s, int n) 200 | { 201 | return ((n == 3) && (*s == 0xEF) && (*(s+1) == 0xBF) && 202 | (*(s+2) >= 0xBE) && (*(s+2) <= 0xBF)); 203 | } 204 | 205 | 206 | /* scan given source string, validate UTF-8 sequence and store result 207 | * in given buffer object */ 208 | static int _validate_utf8(unsigned char **s, int l, struct template_buffer *buf) 209 | { 210 | unsigned char *ptr = *s; 211 | unsigned int o = 0, v, n; 212 | 213 | /* ascii byte without null */ 214 | if ((*(ptr+0) >= 0x01) && (*(ptr+0) <= 0x7F)) 215 | { 216 | if (!buf_putchar(buf, *ptr++)) 217 | return 0; 218 | 219 | o = 1; 220 | } 221 | 222 | /* multi byte sequence */ 223 | else if ((n = mb_num_chars(*ptr)) > 1) 224 | { 225 | /* count valid chars */ 226 | for (v = 1; (v <= n) && ((o+v) < l) && mb_is_cont(*(ptr+v)); v++); 227 | 228 | switch (n) 229 | { 230 | case 6: 231 | case 5: 232 | /* five and six byte sequences are always invalid */ 233 | if (!buf_putchar(buf, '?')) 234 | return 0; 235 | 236 | break; 237 | 238 | default: 239 | /* if the number of valid continuation bytes matches the 240 | * expected number and if the sequence is legal, copy 241 | * the bytes to the destination buffer */ 242 | if ((v == n) && mb_is_shortest(ptr, n) && 243 | !mb_is_surrogate(ptr, n) && !mb_is_illegal(ptr, n)) 244 | { 245 | /* copy sequence */ 246 | if (!buf_append(buf, (char *)ptr, n)) 247 | return 0; 248 | } 249 | 250 | /* the found sequence is illegal, skip it */ 251 | else 252 | { 253 | /* invalid sequence */ 254 | if (!buf_putchar(buf, '?')) 255 | return 0; 256 | } 257 | 258 | break; 259 | } 260 | 261 | /* advance beyound the last found valid continuation char */ 262 | o = v; 263 | ptr += v; 264 | } 265 | 266 | /* invalid byte (0x00) */ 267 | else 268 | { 269 | if (!buf_putchar(buf, '?')) /* or 0xEF, 0xBF, 0xBD */ 270 | return 0; 271 | 272 | o = 1; 273 | ptr++; 274 | } 275 | 276 | *s = ptr; 277 | return o; 278 | } 279 | 280 | /* sanitize given string and replace all invalid UTF-8 sequences with "?" */ 281 | char * utf8(const char *s, unsigned int l) 282 | { 283 | struct template_buffer *buf = buf_init(l); 284 | unsigned char *ptr = (unsigned char *)s; 285 | unsigned int v, o; 286 | 287 | if (!buf) 288 | return NULL; 289 | 290 | for (o = 0; o < l; o++) 291 | { 292 | /* ascii char */ 293 | if ((*ptr >= 0x01) && (*ptr <= 0x7F)) 294 | { 295 | if (!buf_putchar(buf, (char)*ptr++)) 296 | break; 297 | } 298 | 299 | /* invalid byte or multi byte sequence */ 300 | else 301 | { 302 | if (!(v = _validate_utf8(&ptr, l - o, buf))) 303 | break; 304 | 305 | o += (v - 1); 306 | } 307 | } 308 | 309 | return buf_destroy(buf); 310 | } 311 | 312 | /* Sanitize given string and strip all invalid XML bytes 313 | * Validate UTF-8 sequences 314 | * Escape XML control chars */ 315 | char * pcdata(const char *s, unsigned int l) 316 | { 317 | struct template_buffer *buf = buf_init(l); 318 | unsigned char *ptr = (unsigned char *)s; 319 | unsigned int o, v; 320 | char esq[8]; 321 | int esl; 322 | 323 | if (!buf) 324 | return NULL; 325 | 326 | for (o = 0; o < l; o++) 327 | { 328 | /* Invalid XML bytes */ 329 | if (((*ptr >= 0x00) && (*ptr <= 0x08)) || 330 | ((*ptr >= 0x0B) && (*ptr <= 0x0C)) || 331 | ((*ptr >= 0x0E) && (*ptr <= 0x1F)) || 332 | (*ptr == 0x7F)) 333 | { 334 | ptr++; 335 | } 336 | 337 | /* Escapes */ 338 | else if ((*ptr == 0x26) || 339 | (*ptr == 0x27) || 340 | (*ptr == 0x22) || 341 | (*ptr == 0x3C) || 342 | (*ptr == 0x3E)) 343 | { 344 | esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); 345 | 346 | if (!buf_append(buf, esq, esl)) 347 | break; 348 | 349 | ptr++; 350 | } 351 | 352 | /* ascii char */ 353 | else if (*ptr <= 0x7F) 354 | { 355 | buf_putchar(buf, (char)*ptr++); 356 | } 357 | 358 | /* multi byte sequence */ 359 | else 360 | { 361 | if (!(v = _validate_utf8(&ptr, l - o, buf))) 362 | break; 363 | 364 | o += (v - 1); 365 | } 366 | } 367 | 368 | return buf_destroy(buf); 369 | } 370 | 371 | char * striptags(const char *s, unsigned int l) 372 | { 373 | struct template_buffer *buf = buf_init(l); 374 | unsigned char *ptr = (unsigned char *)s; 375 | unsigned char *end = ptr + l; 376 | unsigned char *tag; 377 | unsigned char prev; 378 | char esq[8]; 379 | int esl; 380 | 381 | for (prev = ' '; ptr < end; ptr++) 382 | { 383 | if ((*ptr == '<') && ((ptr + 2) < end) && 384 | ((*(ptr + 1) == '/') || isalpha(*(ptr + 1)))) 385 | { 386 | for (tag = ptr; tag < end; tag++) 387 | { 388 | if (*tag == '>') 389 | { 390 | if (!isspace(prev)) 391 | buf_putchar(buf, ' '); 392 | 393 | ptr = tag; 394 | prev = ' '; 395 | break; 396 | } 397 | } 398 | } 399 | else if (isspace(*ptr)) 400 | { 401 | if (!isspace(prev)) 402 | buf_putchar(buf, *ptr); 403 | 404 | prev = *ptr; 405 | } 406 | else 407 | { 408 | switch(*ptr) 409 | { 410 | case '"': 411 | case '\'': 412 | case '<': 413 | case '>': 414 | case '&': 415 | esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); 416 | buf_append(buf, esq, esl); 417 | break; 418 | 419 | default: 420 | buf_putchar(buf, *ptr); 421 | break; 422 | } 423 | 424 | prev = *ptr; 425 | } 426 | } 427 | 428 | return buf_destroy(buf); 429 | } 430 | 431 | void luastr_escape(struct template_buffer *out, const char *s, unsigned int l, 432 | int escape_xml) 433 | { 434 | int esl; 435 | char esq[8]; 436 | char *ptr; 437 | 438 | for (ptr = (char *)s; ptr < (s + l); ptr++) 439 | { 440 | switch (*ptr) 441 | { 442 | case '\\': 443 | buf_append(out, "\\\\", 2); 444 | break; 445 | 446 | case '"': 447 | if (escape_xml) 448 | buf_append(out, """, 5); 449 | else 450 | buf_append(out, "\\\"", 2); 451 | break; 452 | 453 | case '\n': 454 | buf_append(out, "\\n", 2); 455 | break; 456 | 457 | case '\'': 458 | case '&': 459 | case '<': 460 | case '>': 461 | if (escape_xml) 462 | { 463 | esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); 464 | buf_append(out, esq, esl); 465 | break; 466 | } 467 | 468 | default: 469 | buf_putchar(out, *ptr); 470 | } 471 | } 472 | } 473 | 474 | void luastr_translate(struct template_buffer *out, const char *s, unsigned int l, 475 | int escape_xml) 476 | { 477 | char *tr; 478 | int trlen; 479 | 480 | switch (lmo_translate(s, l, &tr, &trlen)) 481 | { 482 | case 0: 483 | luastr_escape(out, tr, trlen, escape_xml); 484 | break; 485 | 486 | case -1: 487 | luastr_escape(out, s, l, escape_xml); 488 | break; 489 | 490 | default: 491 | /* no catalog loaded */ 492 | break; 493 | } 494 | } 495 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., [http://fsf.org/] 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) 2014 南浦月 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. --------------------------------------------------------------------------------