Test wysyłania wiadomości za pomocą CTRL+Enter i syntax highlightera

Silas Mariusz

rm -rf /
Help us, GOD!
5 Kwiecień 2008
10 213
31
2 324
153
39
Nowy Sącz
forum.qnap.net.pl
QNAP
TS-x77
Ethernet
1 GbE
tag: code=bash
Bash:
#!/usr/bin/env sh

NAME="rtorrent"
LOCK="/var/run/${NAME}.lock"
RETVAL=0

##
##   Looking for something?
##   To enable debug mode, create dummy file in a PROGDIR
##
##       cd /share/..._DATA/.qpkg/rtorrent/
##       touch DEBUG
##       ./rtorrent.sh restart
##
##

##
##   rtorrent-QNAP
##
##   Copyright © 2013, Silas Mariusz <silas@qnap.com.antispam>
##                     QNAP Club Polska
##
##   This program is free software; you can redistribute it and/or modify
##   it under the terms of the GNU General Public License as published by
##   the Free Software Foundation; either version 2, or (at your option)
##   any later version.
##
##   This program is distributed in the hope that it will be useful,
##   but WITHOUT ANY WARRANTY; without even the implied warranty of
##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##   GNU General Public License for more details.
##
##   You should have received a copy of the GNU General Public License
##   along with this program; if not, write to the Free Software Foundation,
##   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
##   The latest version of this software can be obtained here:
##
##   https://forum.qnap.net.pl/
##
##
##   FILE: rtorrent.sh
##
##   RELEASE: 1.0
##   DATE: 2014-04-07
##


function DEBUG()
{
	[ "$_DEBUG" == "1" ] && $@
}

_exit()
{
	/bin/echo -e "$*"
	/bin/echo
	exit 1
}

available() {
	type -t "$1" >/dev/null && return 0
	return 1
}

help() {
        echo -e "------------------------------------------------------------------------------"
        echo -e " (${NAME}) PID: $$; (parent:${PPID})"
        echo -e "---------------------------------------------------------- || Hello World! ---"
        echo
        echo -e "  Usage:"
        echo -e "          $0 (start|stop|enable|disable)"
        echo
        echo -e "  Available options:"
        echo -e "    start/stop      - start or stop chroot environment"
        echo -e "    enable/disable  - enables or disables application launch"
        echo -e "    status          - checks running state"
	echo
        echo -e "------------------------------------------------------------------------------"
        echo -e "  Note: To make it running while system boots, enable it in QPKG section"
        echo -e "        or through enable/disable param."
        echo -e "------------------------------------------------------------------------------"
	_exit
}


#
# !!! DONT FORGET BOUT ME AFTER DEVELOPEMENT !!!
#
#[[ -z "$1" ]] && help


# Message to terminal and system log
# ###########################################################################
_log() {
	local write_msg="/sbin/log_tool -t0 -u$NAME -p127.0.0.1 -mlocalhost -a"
	local message="(info) $NAME: ${*:-"Unspecified Notice"}"
	
	echo -e "$message"
	
	# save to system Event Log only when in DEBUG mode
	[ "$_DEBUG" == "1" ] && $write_msg "$message"
}

# Warning message to terminal and system log
# ###########################################################################
_warn() {
	local write_warn="/sbin/log_tool -t1 -u$NAME -p127.0.0.1 -mlocalhost -a"
	local message="(warn) $NAME: ${*:-"Unknown Warning"}" && $write_warn "$message"
	echo -e "$message"
}

# Write error log message and exit
# ###########################################################################
_err(){
	local write_err="/sbin/log_tool -t2 -u$NAME -p127.0.0.1 -mlocalhost -a"
	local message="(err!) $NAME: ${*:-"Unknown Error"}" && $write_err "$message"
	_exit "$message \n"
}



# ###########################################################################
# Basics
# ###########################################################################

# find my name and real current directory
# ###########################################################################
PROGNAME=`type $0 | awk '{print $3}'`  # search for executable on path

PROGDIR=`dirname $PROGNAME`            # extract directory of program
PROGNAME=`basename $PROGNAME`          # base name of program

[ "$PROGDIR" == "." ] && PROGDIR=`cd $PROGDIR && pwd || echo $PROGDIR`

Int_dPWD=`cd $PROGDIR && pwd || echo $PROGDIR`
if [ "${Int_dPWD}" = "/etc/init.d" ] || [ "${Int_dPWD}" = "/etc/rcS.d" ] || [ "${Int_dPWD}" = "/etc/rcK.d" ]; then
	[ -L "${PROGDIR}/${PROGNAME}" ] && {
		_SLINK=$(readlink ${PROGDIR}/${PROGNAME})
		PROGDIR=`dirname ${_SLINK}`
		PROGNAME=`basename ${_SLINK}`
}
fi

# Fully qualify directory path (remove relative components and symlinks)
# WARNING: The "bash" "pwd" builtin does not resolve symbolic links
# "sh" (as a link to "bash") also does not,   but "csh" does handle it.
# Symbolic link removal however is not critical.
ORIGDIR=`pwd`                                 # original directory (builtin)
PROGDIR=`cd $PROGDIR && pwd || echo $PROGDIR` # program directory

# Results...
#    $ORIGDIR    -- where the users was when called
#    $PROGDIR    -- script directory location (and now current directory)
#    $PROGNAME   -- This scripts executable name



# alternatively use this...

# Get the fully qualified path to the script
# ###########################################################################
case $0 in
	/*)
		SCRIPT="$0"
		;;
	*)
		PWD=`pwd`
		SCRIPT="$PWD/$0"
		;;
esac

# Change spaces to ":" so the tokens can be parsed.
SCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
# Get the real path to this script, resolving any symbolic links
TOKENS=`echo $SCRIPT | sed -e 's;/; ;g'`
REALPATH=
for C in $TOKENS; do
	REALPATH="$REALPATH/$C"
	while [ -h "$REALPATH" ] ; do
		LS="`ls -ld "$REALPATH"`"
		LINK="`expr "$LS" : '.*-> \(.*\)$'`"
		if expr "$LINK" : '/.*' > /dev/null; then
			REALPATH="$LINK"
		else
			REALPATH="`dirname "$REALPATH"`""/$LINK"
		fi
	done
done
# Change ":" chars back to spaces.
REALPATH=`echo $REALPATH | sed -e 's;:; ;g'`
REALPATH="`dirname "$REALPATH"`"
[ "`basename $REALPATH`" == "." ] && \
	REALPATH="`echo $REALPATH | awk '{$0=substr($0,1,length($0)-2); print $0}'`"

# Change the current directory to the location of the script
PROGDIR="`cd $REALPATH && pwd || echo $PROGDIR`"
cd "$PROGDIR"



# ###########################################################################
# Environments
# ###########################################################################

# Set environment paths ...
# ###########################################################################
_PATHS=\
/usr/bin/rtorrent/bin:\
/usr/bin/rtorrent/sbin:\
/usr/bin/rtorrent/perl/bin:\
/usr/bin/rtorrent/perl/site/bin:\
$PROGDIR/bin:\
$PROGDIR/sbin:\
$PROGDIR/perl/bin:\
$PROGDIR/perl/site/bin

export PATH=$_PATHS:$PATH
export LD_LIBRARY_PATH=/usr/bin/rtorrent/lib:$PROGDIR/lib:$LD_LIBRARY_PATH
export TERMCAP="$PROGDIR/etc/termcap"
export TERMINFO="$PROGDIR/share/terminfo"

if [ -f "$PROGDIR/DEBUG" ]; then
		_DEBUG=1
else
		_DEBUG=0
fi

_log ORIGDIR: $ORIGDIR
_log PROGDIR: $PROGDIR

USER_TIMEZONE=

LANGVAR=`/usr/bin/locale | /bin/grep LANG | cut -f 2 -d "="`
[ "x${LANGVAR}" != "x" ] || export LANG=en_US.UTF-8

export HOME=/root
export TERM=xterm
export SHELL=/usr/bin/rtorrent/bin/bash
export USER=admin
export PWD=/root
export EDITOR=/bin/vi
export LOGNAME=admin


SERVICES=(
		"screen-cleanup|"
		"rtorrent|rtorrent.lock"
		"lighttpd|rtorrent-webserver.pid"
	)



# ###########################################################################
# Helpers and Functions
# ###########################################################################

# In-place editing like sed -i but more portable...
# ###########################################################################
sed_i() {
	local cmd="$1"
	local file="$2"
	local addr=","
	echo "$cmd" | grep -qE '^/' && addr=
	ed -s "$file" > /dev/null 2>&1 << EOF
$addr$cmd
w
q
EOF
}


# Determine location of given share and assign to variable in second argument.
# ###########################################################################
get_share_path(){
        [ -n "$1" ] && [ -n "$2" ] || return 1
        local share="$1"
        local path="$2"

        # Get location from smb.conf
        local location=$(getcfg "$share" path -f /etc/config/smb.conf)

        [ -n "$location" ] || return 1
        eval $path=\"$location\"
}

# Determine name and location for all system shares
# ###########################################################################
init_share_settings(){
        SYS_PUBLIC_SHARE=$(getcfg SHARE_DEF defPublic -d Public -f /etc/config/def_share.info)
        SYS_DOWNLOAD_SHARE=$(getcfg SHARE_DEF defDownload -d Qdownload -f /etc/config/def_share.info)
        SYS_MULTIMEDIA_SHARE=$(getcfg SHARE_DEF defMultimedia -d Qmultimedia -f /etc/config/def_share.info)
        SYS_RECORDINGS_SHARE=$(getcfg SHARE_DEF defRecordings -d Qrecordings -f /etc/config/def_share.info)
        SYS_USB_SHARE=$(getcfg SHARE_DEF defUsb -d Qusb -f /etc/config/def_share.info)
        SYS_WEB_SHARE=$(getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info)

        get_share_path $SYS_PUBLIC_SHARE     SYS_PUBLIC_PATH
        get_share_path $SYS_DOWNLOAD_SHARE   SYS_DOWNLOAD_PATH
        get_share_path $SYS_MULTIMEDIA_SHARE SYS_MULTIMEDIA_PATH
        get_share_path $SYS_RECORDINGS_SHARE SYS_RECORDINGS_PATH
        get_share_path $SYS_USB_SHARE        SYS_USB_PATH
        get_share_path $SYS_WEB_SHARE        SYS_WEB_PATH
}

# Determine BASE installation location and assign to SYS_QPKG_DIR
# ###########################################################################
assign_base(){
        local base=""
        if [ -n "$SYS_PUBLIC_PATH" ] && [ -d "$SYS_PUBLIC_PATH" ]; then
                local dirp1=$(echo $SYS_PUBLIC_PATH | cut -d "/" -f 2)
                local dirp2=$(echo $SYS_PUBLIC_PATH | cut -d "/" -f 3)
                local dirp3=$(echo $SYS_PUBLIC_PATH | cut -d "/" -f 4)
                [ -n "$dirp1" ] && [ -n "$dirp2" ] && [ -n "$dirp3" ] &&
                        [ -d "/$dirp1/$dirp2/$SYS_PUBLIC_SHARE" ] && base="/$dirp1/$dirp2"
        fi

        # Determine BASE location by checking where the directory is.
        if [ -z "$base" ]; then
                for datadirtest in /share/HDA_DATA /share/HDB_DATA /share/HDC_DATA \
                                   /share/HDD_DATA /share/HDE_DATA /share/HDF_DATA \
                                   /share/HDG_DATA /share/HDH_DATA /share/MD0_DATA \
                                   /share/MD1_DATA /share/MD2_DATA /share/MD3_DATA
                do
                        [ -d "$datadirtest/$SYS_PUBLIC_SHARE" ] && base="$datadirtest"
                done
        fi
        if [ -z "$base" ] ; then
                _err "Public share not found"
        fi
        SYS_QPKG_BASE="$base"
        SYS_QPKG_ROOT="$SYS_QPKG_BASE/.qpkg"
}



# Install my icons ...
# ###########################################################################
install_icons(){
	cp -af "$PROGDIR/.qpkg_icon.gif" "/home/httpd/RSS/images/${NAME}.gif"		2>/dev/null
	cp -af "$PROGDIR/.qpkg_icon_gray.gif" "/home/httpd/RSS/images/${NAME}_gray.gif"	2>/dev/null
	cp -af "$PROGDIR/.qpkg_icon_80.gif" "/home/httpd/RSS/images/${NAME}_80.gif"	2>/dev/null
}



# Make sure Download share exists
# ###########################################################################
check_paths(){
		#RT_DOWNLOAD_SHARE=`/sbin/getcfg Download path -f /etc/config/smb.conf -d /ERROR`
		RT_DOWNLOAD_SHARE="/share/Download"
		RT_DOWNLOAD_DEF="/share/Download"
		
		if [ ! -d "$RT_DOWNLOAD_SHARE" ] || [ ! -d "$RT_DOWNLOAD_DEF" ]; then
				_err "'Download' share not found or not ready."
		fi
		_log RT_DOWNLOAD_SHARE: $RT_DOWNLOAD_SHARE
}



# Check 
# ###########################################################################
check_my_state(){
	local _tmp_out=

	local _lighttpd_pidfile=/var/run/rtorrent-webserver.pid
	local _lighttpd_pid=
	
	if [ -e "$_lighttpd_pidfile" ]; then
		if [ -s "$_lighttpd_pidfile" ]; then
			_lighttpd_pid=`cat $_lighttpd_pidfile`
			_tmp_out="`ps -A | grep lighttpd | grep $_lighttpd_pid`"
			if [ -n "$_tmp_out" ]; then
				_log process lighttpd $_lighttpd_pid is running...
			else 
				_log process lighttpd $_lighttpd_pid not running!
			fi
		else
			_log process lighttpd pid file is empty $_lighttpd_pidfile
		fi
	else
		_log process lighttpd pid file not found!
	fi

	
	local _rtorrent_pidfile=/share/Download/rtorrent/session/rtorrent.lock
	local _rtorrent_pid=
	
	if [ -e "$_rtorrent_pidfile" ]; then
		if [ -s "$_rtorrent_pidfile" ]; then
			_rtorrent_pid=`cat $_rtorrent_pidfile | awk -F: '{print($2)}' | sed "s/[^0-9]//g"`
			_tmp_out="`ps -A | grep rtorrent | grep $_rtorrent_pid`"
			if [ -n "$_tmp_out" ]; then
				_log process rtorrent $_rtorrent_pid is running...
			else 
				_log process rtorrent $_rtorrent_pid not running!
			fi
		else
			_log process rtorrent pid file is empty $_rtorrent_pidfile
		fi
	else
		_log process rtorrent pid file not found!
	fi
}



# Set Maximum TCP Window Size
# ###########################################################################
set_tcp_buf_size(){
	# [rtorrent.conf]
	# The 'send_buffer_size' and 'receive_buffer_size' options can be used
	# to adjust the socket send and receive buffer sizes.
	# Increasing the send buffer size may help reduce disk seeking
	# as more data is buffered each time the socket is written to.
	# On linux you may use "cat /proc/sys/net/ipv4/tcp_wmem" to see
	# the minimum, default and max buffer size, respectively.
	#local _rcv_buf_sz=$(/sbin/getcfg "TCP" rcv_buf_sz -d 4194304 -f ${PROGDIR}/etc/general.cnf)
	#local _send_buf_sz=$(/sbin/getcfg "TCP" send_buf_sz -d 1048576 -f ${PROGDIR}/etc/general.cnf)
	echo $_rcv_buf_sz > /proc/sys/net/core/rmem_max
	echo $_send_buf_sz > /proc/sys/net/core/wmem_max
}



# Create directories structure
# ###########################################################################
create_directories(){
	   [ ! -d "$RT_DOWNLOAD_SHARE" ] || [ ! -d "$RT_DOWNLOAD_DEF" ]
	if [ ! -d "$RT_DOWNLOAD_SHARE/$NAME/complete" ] || [ ! -d "$RT_DOWNLOAD_SHARE/$NAME/downloads" ] || [ ! -d "$RT_DOWNLOAD_SHARE/$NAME/watch" ]; then
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/game"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/game"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/game"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/game"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/game"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/game"

		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/movie"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/movie"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/movie"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/movie"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/movie"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/movie"

		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/music"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/music"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/music"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/music"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/music"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/music"

		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/other"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/other"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/other"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/other"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/other"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/other"

		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/software"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/software"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/software"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/software"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/software"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/software"

		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/tv"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/tv"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/tv"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/tv"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/tv"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/tv"

		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/complete/video"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/complete/video"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/downloads/video"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/downloads/video"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/watch/video"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/watch/video"
	fi

	local DIRECTORIES=(
			"downloads"
			"complete"
			"session"
			"watch"
			"unpack"
			"temp"
			"logs"
			"settings"
			"settings/certs"
			"settings/ipfilter"
			"settings/users"
			"settings/users/settings"
		)
	local _d=
	for (( i = 0 ; i < ${#DIRECTORIES[@]} ; i++ )) do
		_d=$RT_DOWNLOAD_SHARE/$NAME/${DIRECTORIES[$i]}
		[ -d "$_d" ] || {
			_log Creating directory: $_d
			mkdir -p $_d
			chmod 777 $_d
		} && {
			chmod 777 $_d
		}
	done
}



# Set download paths
# ###########################################################################
set_download_paths(){
	local _d_watch="$RT_DOWNLOAD_SHARE/$NAME/watch"
	local _l_watch=$(expr length "$_d_watch")

	local _d_complete="$RT_DOWNLOAD_SHARE/$NAME/complete"
	local _l_complete=$(expr length "$_d_complete")

	local _users="$RT_DOWNLOAD_SHARE/$NAME/settings/users"
	local _settings="$_users/rtorrent/settings"

	mkdir -p $RT_DOWNLOAD_SHARE/$NAME/settings
	mkdir -p $_users/rtorrent/settings
	mkdir -p $_users/rtorrent/torrents
	chmod -R 777 $RT_DOWNLOAD_SHARE/$NAME/settings

	if [ ! -f "$_settings/autotools.dat" ]; then
		_log Creating Autotools default download paths.
		touch $_settings/autotools.dat
		echo -n "O:10:\"rAutoTools\":9:{s:4:\"hash\";s:13:\"autotools.dat\";s:12:\"enable_label\";s:1:\"1\";s:14:\"label_template\";s:5:\"{DIR}\";s:11:\"enable_move\";s:1:\"1\";s:16:\"path_to_finished\";s:$_l_complete:\"$_d_complete\";s:11:\"fileop_type\";s:8:\"HardLink\";s:12:\"enable_watch\";s:1:\"1\";s:13:\"path_to_watch\";s:$_l_watch:\"$_d_watch\";s:11:\"watch_start\";s:1:\"1\";}" > "$_settings/autotools.dat"
		chmod 666 $_settings/autotools.dat
	else
		_log Omitting autotools.dat default paths
	fi
	
	if [ ! -f "$_settings/cookies.dat" ]; then
		_log Creating UI cookies.dat file.
		touch $_settings/cookies.dat
		echo -n "O:8:\"rCookies\":2:{s:4:\"hash\";s:11:\"cookies.dat\";s:4:\"list\";a:0:{}}" > $_settings/cookies.dat
		chmod 666 $_settings/cookies.dat
	else
		_log Omitting cookies.dat file.
	fi
}



# Create links (/usr/bin/...)
# ###########################################################################
LINKS=(
	"/usr/bin/rtorrent:${PROGDIR}"
)
create_link(){
	local link_d="$1"
	local link_s="$2"
	
	[ -L "${link_d}" ] && [ "$(readlink ${link_d})" = "${link_s}" ] && return
	
	if [ -f "${link_d}" ]; then
		_warn Deleting existing file in place of target symlink: ${link_d}.
		rm -f "${link_d}"
	fi
	
	if [ ! -L "${link_d}" ] && [ -d "${link_d}" ]; then
		_warn Deleting existing directory in place of target symlink: ${link_d}.
		rm -rf "${link_d}"
	fi
	
	if [ ! -L "${link_d}" ] || [ ! "$(readlink ${link_d})" = "${link_s}" ]; then
		[ -L "${link_d}" ] && rm -f "${link_d}"
		_log exec: ln -sf "${link_s}" "${link_d}"
		ln -sf "${link_s}" "${link_d}"
	fi
	return
}
create_links(){
	for (( i = 0 ; i < ${#LINKS[@]} ; i++ )) do
		local _d=$(echo ${LINKS[$i]} | cut -d : -f 1)
		local _s=$(echo ${LINKS[$i]} | cut -d : -f 2)
		_log Creating link: $_d
		create_link "$_d" "$_s"
	done
}
clean_links(){
	for (( i = ${#LINKS[@]} ; i > 0 ; i-- )) do
		local _d=$(echo ${LINKS[$i - 1]} | cut -d : -f 1)
		local _s=$(echo ${LINKS[$i - 1]} | cut -d : -f 2)
		_log Removing link: $_d
		rm "$_d"
	done
}



# Fix 'no more PTYs' issue
# ###########################################################################
fix_pty(){
	_log Fix 'no more PTYs' issue ...
	chmod 666 /dev/ptmx
	chmod 666 /dev/null
}



# Find Timezone and update php.ini
# ###########################################################################
is_valid_tz_name() {
	echo "$1" | LC_ALL=C grep -qE '^[A-Z][^/ ]*(/[A-Z][^/ ]*)?$' && return 0
	return 1
}
detect_time_zone() {
	[ -n "$USER_TIMEZONE" ] && return

	local hash=
	local hasher=
	local files=
	#local zoneinfoPath=/usr/share/zoneinfo
	local zoneinfoPath=/etc/zoneinfo
	if [ ! -d "$zoneinfoPath" ]; then
		_warn Zone info not found /usr/share/zoneinfo
		return
	fi
	
	if hasher=md5sum; available $hasher || hasher=sha1sum; available $hasher; then
		[ -x "$hasher" ] && hasher="$hasher"
		_log Hasher: $hasher
		hash=$($hasher /etc/localtime | awk '{print $1}')
		_log /etc/localtime $hash
		files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "^$hash\\>" | awk '{print $2}')"
	else
		return
	fi

	# Detect all possible timezone names
	local timezones=
	for path in $files; do
		local tz="${path#$zoneinfoPath/}"
		while true; do
			is_valid_tz_name "$tz" && break
			local newTz="${tz#*/}"
			[ "$newTz" = "$tz" ] && tz= && break
			tz="$newTz"
		done
		is_valid_tz_name "$tz" && timezones="$timezones $tz"
	done

	# Now find the ones PHP likes...
	local okRegions="(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)"
	for tz in $timezones; do
		echo "$tz" | grep -qE "^$okRegions/" && USER_TIMEZONE="$tz" && return
	done

	# Return the first one we found
	for tz in $timezones; do
		USER_TIMEZONE="$tz"
		return
	done
}
update_php_timezone() {
	# Replace current TZ in php.ini
	local WWW_PHP_INI="$PROGDIR/etc/php5/php.ini"
	if [ ! -f "$WWW_PHP_INI" ]; then
		_warn File not found $WWW_PHP_INI
		return
	fi

	[ -z "$USER_TIMEZONE" ] && USER_TIMEZONE="UTC"
	#[ -z "$USER_TIMEZONE" ] && return

	# Old
#	local zws="[ 	]*"
#	local newLine="date.timezone = $USER_TIMEZONE"
#	if grep -qE "^${zws}${zws}date\\.timezone[ 	=]" "$WWW_PHP_INI"; then
#		sed_i "s!^${zws}${zws}date\\.timezone[ 	=].*\$!$newLine!" "$WWW_PHP_INI"
#	else
#		cat >> "$WWW_PHP_INI" << EOF
#[Date]
#$newLine
#EOF
#	fi

	# New
	setcfg "Date" "date.timezone" "$USER_TIMEZONE" -f "$WWW_PHP_INI"
}



# Is port used ?
# ###########################################################################
is_port_used() {
	local port="$1"
	netstat -an 2>/dev/null | grep tcp | grep -w LISTEN | grep -qE "[.:]$port[ 	]" && return 0
	return 1
}
is_valid_port_number() {
	echo "$1" | grep -qiE '^[0-9]+$' || return 1
	echo "$1" | grep -qiE '[0-9][0-9][0-9][0-9][0-9][0-9]' && return 1
	[ $1 -ge 1024 ] && [ $1 -le 65535 ]
}
get_new_port_number() {
	while true; do
		newPortNumber=$CURRENT_PORT
		CURRENT_PORT=$(expr $CURRENT_PORT + 1)
		is_valid_port_number $newPortNumber || _warn Invalid port number. Change CURRENT_PORT.
		is_port_used $newPortNumber || break
		_warn $newPortNumber is in use, trying next port...
	done
}
check_port_availability(){
	local _t_port=$1
	local _t_name=$2

	if is_port_used $_t_port; then
		rm -f "${LOCK}"
		_err Port $_t_name: $_t_port is already in use.
	else
		_log Port $_t_name: $_t_port is available.
	fi
}



# Get rtorrent ports from its config file
# ###########################################################################
get_rtorrent_ports(){
	CONFIG_DHT_PORT=$(/sbin/getcfg "" dht.port.set -d 6881 -f ${PROGDIR}/etc/rtorrent.conf)

	CONFIG_RT_PORT=$(/sbin/getcfg "" port_range -d 42000 -f ${PROGDIR}/etc/rtorrent.conf | cut -d - -f 1)
}



# Get my ip addr
# ###########################################################################
is_valid_ipaddr() {
	# It's not 100% accurate ... ;)
	echo $1 | grep -qE '^[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'
}
get_iface_ipaddr(){
	local SYS_INTERFACE="bond0 eth0 eth1"
	for interface in $SYS_INTERFACE
	do
		IPADDR_IF=`/sbin/ifconfig $interface | grep "inet addr" | cut -f 2 -d ':' | cut -f 1 -d ' '`
		if [ "$IPADDR_IF" != "" ]; then
			_log $interface ipaddr: $IPADDR_IF
			break
		fi
	done
}
get_ext_ipaddr() {
	is_valid_ipaddr "$IPADDR_EXT" && return
	#is_valid_ipaddr "$IPADDR_EXT" || IPADDR_EXT=$(wget --no-check-certificate http://www.whatismyip.com/automation/n09230945.asp -O - -o /dev/null)
	#is_valid_ipaddr "$IPADDR_EXT" || IPADDR_EXT=$(wget --no-check-certificate https://www.packetmail.net/myip.php -O - -q /dev/null)
	is_valid_ipaddr "$IPADDR_EXT" || IPADDR_EXT=$(wget --no-check-certificate http://box.houkouonchi.jp/ip.php -O - -q /dev/null)
	is_valid_ipaddr "$IPADDR_EXT" || IPADDR_EXT=$(ifconfig -a | grep "inet addr" | head -n1 | awk -F: '{print $2}' | awk '{print $1}')
	is_valid_ipaddr "$IPADDR_EXT" || IPADDR_EXT="1.2.3.4"
	_log external ipaddr: $IPADDR_EXT
}



# Get cloud names
# ###########################################################################
get_reg_cloud_name() {
	OUR_CLOUDNAME=$(/sbin/getcfg "QNAP DDNS Service" "Host Name" -d MyServer -f /etc/config/qnapddns.conf)
	if [ -n "$OUR_CLOUDNAME" ]; then
		_log Cloud host name: $OUR_CLOUDNAME
	else
		_warn Could not get registred cloud name!
		OUR_CLOUDNAME=NAS
	fi
}
get_reg_cloud_domain() {
	OUR_CLOUDSRV=$(/sbin/getcfg "QNAP DDNS Service" "Domain Name Server" -d MyCloudNAS.com -f /etc/config/qnapddns.conf)
	if [ -n "$OUR_CLOUDNAME" ]; then
		_log Cloud domain name: $OUR_CLOUDSRV
	else
		_warn Could not get registred cloud name!
		OUR_CLOUDSRV="UnknownCloud.com"
	fi
}


# Read user email addr
# ###########################################################################
get_user_email_addr() {
	# TODO Get from config
	USER_MAILADDR=$(/sbin/getcfg Alert Sender -d "$OUR_CLOUDNAME@$OUR_CLOUDSRV" -f /etc/config/uLinux.conf)

	if [ -n "$OUR_CLOUDNAME" ]; then
		_log User mail address: $USER_MAILADDR
	else
		_warn Could not get user email addr. Using nobody@null.com instead.
		USER_MAILADDR="nobody@null.com"
	fi
}



# Generate https certm
# ###########################################################################
set_authority_identifier() {
	# TODO save defaults into openssl.cnf
	openssl_cnf="${PROGDIR}/share/openssl/openssl.cnf"
	#/sbin/setcfg " req_distinguished_name " countryName "Country Name (2 letter code)" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " stateOrProvinceName "RT Station" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " stateOrProvinceName_default "RT Station" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " localityName "Not for your eyes" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " 0.organizationName "QNAP Storage" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " 0.organizationName_default "QNAP Club" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " organizationalUnitName "RT" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " commonName "$OUR_CLOUDNAME.$OUR_CLOUDSRV" -f "$openssl_cnf"
	/sbin/setcfg " req_distinguished_name " emailAddress "$OUR_CLOUDNAME@$OUR_CLOUDSRV" -f "$openssl_cnf"
	/sbin/setcfg " req_attributes " unstructuredName "QNAP Club Poland" -f "$openssl_cnf"
}
create_self_signed_cert() {
	local pemfile="$1"

	if [ ! -f "$OTHER_PEM_FILE" ]; then
		_log Creating the self-signed certificate.
		rm -f "$pemfile"
		openssl req -new -newkey rsa:1024 -days 1000 -nodes -x509 -keyout "$pemfile" -out "$pemfile" -batch \
			|| _warn Failed to create self-signed certificate.
		OTHER_PEM_FILE="$pemfile"
		CREATED_CERT_FILE=y
	else
		rm -f "$pemfile"
		cp "$OTHER_PEM_FILE" "$pemfile" || _warn Failed to copy self-signed certificate.
	fi

	chmod 0600 "$pemfile"
}
gen_host_certificate() {
	# Detects new machine by IP and restores settings to default
	# Create new self-signed certificate file and etc...
	IPADDR_FILE="$PROGDIR/etc/ipaddr"
	local OLD_IP_ADDRESS=`cat $IPADDR_FILE 2>/dev/null`
	local WWW_PEMFILE="$PROGDIR/etc/lighttpd/lighttpd.pem"
	if [ "$IPADDR_IF" != "$OLD_IP_ADDRESS" ] || [ ! -f "$WWW_PEMFILE" ]; then
		_warn Web server certificate not found...
		set_authority_identifier
		create_self_signed_cert "$WWW_PEMFILE"
		echo "$IPADDR_IF" > $IPADDR_FILE
	else
		_log Web server certificate found.
	fi

}



# Generates each time new password for RPC connection from UI
# ###########################################################################
gen_rand_passwd() {
	local l=$1
	[ "$l" == "" ] && l=16
	tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
set_rand_passwd() {
	_log Generating new RPC password.
	local _passwd=$(gen_rand_passwd 12)
	_log Applying new RPC password.
	/sbin/setcfg "RPC" "Random" "$_passwd" -f $PROGDIR/etc/rtorrent.rpc
	$PROGDIR/bin/lighttpd-setpw.sh RPC "$_passwd"
}



# Update IPfilter list
# ###########################################################################
update_ipfilter_list() {
	local _url_ipfilter="http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz"
	local _timeout=5

	local _d_ipfilter="$RT_DOWNLOAD_SHARE/$NAME/settings/ipfilter"
	mkdir -p "$_d_ipfilter"
	
	local _f_ipfilter="$_d_ipfilter/ipfilter.dat"		;	touch "$_f_ipfilter"
	local _g_ipfilter="$_d_ipfilter/ipfilter.gz"		;	touch "$_g_ipfilter"
	local _r_ipfilter="$_d_ipfilter/ipfilter.response"
	[ -f "$_r_ipfilter" ] && rm -f "$_r_ipfilter" 		; 	touch "$_r_ipfilter"

	# get header
	${PROGDIR}/bin/curl -sIL "$_url_ipfilter" --connect-timeout $_timeout -o $_r_ipfilter

	# make sure file is available for download
	if ! grep -q "302 Found" "$_r_ipfilter" || ! grep -q "200 OK" "$_r_ipfilter" ; then
		_warn "Cannot retrieve ipfilter list file..."
		return
	fi

	# compare local and remote ipfilter size, if different then grab new one...
	local _current_size=$(stat -c \%\s $_g_ipfilter)
	_log Current ipfilter size is $_current_size bytes
	local _remote_size=$(grep "Content-Length" $_r_ipfilter | awk '{print $2}')
	_log Remote ipfilter size is  $_remote_size bytes
	if [ "x$_current_size bytes" == "x$_remote_size bytes" ]; then
		_log ipfilter list is up to date!
		return
	fi

	# we are going to download ipfilter list...
	_log Downloading new ipfilter list...
	#wget --no-check-certificate ${_url_ipfilter} -O "$_d_ipfilter/ipfilter.gz" -o /dev/null
	[ -f "${_g_ipfilter}.new" ] && rm -f "${_g_ipfilter}.new"
	${PROGDIR}/bin/curl -sL "$_url_ipfilter" --connect-timeout $_timeout -o "${_g_ipfilter}.new"
	RETVAL=$?
	if [ "$RETVAL" != "0" ] || [ ! -f "${_g_ipfilter}.new" ]; then
		_warn ipfilter list download failed!
		return
	fi

	# replace old gzipped list with new one
	rm -f "$_g_ipfilter"
	mv -f "${_g_ipfilter}.new" "$_g_ipfilter"

	# unpack and convert list - keep gzipped for future checks
	_log Converting ipfilter list...
	gzip -dc "$_g_ipfilter" | cut -d: -f2 > "${_f_ipfilter}.new"

	# replace converted list...
	_log Replacing old ipfilter list
	[ -f "${_f_ipfilter}.new" ] && mv -f "${_f_ipfilter}.new" "$_f_ipfilter"

	touch "$_f_ipfilter"
}



# Start/stop service
# ###########################################################################
start_services() {
		local _name=
		local _pid=
		RETVAL=0
		local _RETVAL=
		for (( i = 0 ; i < ${#SERVICES[@]} ; i++ )) do
			_name=$(echo ${SERVICES[$i]} | cut -d \| -f 1)
			_pid=$(echo ${SERVICES[$i]} | cut -d \| -f 2)
			$PROGDIR/etc/init.d/$_name start
			_RETVAL=$?
			if [ $_RETVAL -eq 0 ]; then
				_log $_name started.
			else
				_warn $_name start failed.
			fi
			[ $RETVAL -eq 0 ] && RETVAL=$_RETVAL
		done

		return $RETVAL
}
stop_services() {
		local _name=
		local _pid=
		RETVAL=0
		local _RETVAL=
		for (( i = ${#SERVICES[@]} ; i > 0 ; i-- )) do
			_name=$(echo ${SERVICES[$i - 1]} | cut -d \| -f 1)
			_pid=$(echo ${SERVICES[$i - 1]} | cut -d \| -f 2)
			$PROGDIR/etc/init.d/$_name stop
			_RETVAL=$?
			if [ $_RETVAL -eq 0 ]; then
				_log $_name shutted down.
			else
				_warn $_name error occured while executing stop sequence.
			fi
			[ $RETVAL -eq 0 ] && RETVAL=$_RETVAL
		done

		return $RETVAL
}



# Main
# ###########################################################################
init_share_settings
assign_base
install_icons
check_paths

case "$1" in
	"start")
		# ##--> Shall we dance?
		RESULT=`/sbin/getcfg ${NAME} Enable -u -d TRUE -f /etc/config/qpkg.conf`
		if  [ "$RESULT" = "FALSE" ] ; then
			_err application launch is disabled. Enable it first!
		fi

		# Create lock file to prevent double run
		if [ ! -e "${LOCK}" ] ; then
			touch "${LOCK}"
		else
			_err application already started...
		fi

		#set_tcp_buf_size

		create_directories
		set_download_paths
		fix_pty
		create_links

		# remove temp
		rm -rf "$PROGDIR/var/tmp"
		mkdir -p "$PROGDIR/var/tmp"

		rm -rf "$PROGDIR/var/www/tmp"
		mkdir -p "$PROGDIR/var/www/tmp"

		# clear lighttpd cache
		rm -rf "$PROGDIR/var/cache/lighttpd"
		mkdir -p "$PROGDIR/var/cache/lighttpd"

		# clear old logs
		rm -rf "$RT_DOWNLOAD_SHARE/$NAME/logs"
		mkdir -p "$RT_DOWNLOAD_SHARE/$NAME/logs"
		chmod 777 "$RT_DOWNLOAD_SHARE/$NAME/logs"

		[ -f "/etc/config/uLinux.conf" ] && USER_TIMEZONE=`/sbin/getcfg System "Time Zone" -f /etc/config/uLinux.conf`

		if [ -n "$USER_TIMEZONE" ]; then
			detect_time_zone
			if [ -n "$USER_TIMEZONE" ]; then
				_log TZ: $USER_TIMEZONE
				update_php_timezone
			else
				warn TZ: Could not detect timezone! 
			fi
		fi


		check_port_availability 6009 Web
		check_port_availability 6008 SecureWeb
		check_port_availability 5000 SCGI
		
		get_rtorrent_ports
		check_port_availability $CONFIG_DHT_PORT DHT
		check_port_availability $CONFIG_RT_PORT Torrent

		#forward_ports
		sh ${PROGDIR}/bin/portmapper.sh add &
		sleep 3

		get_iface_ipaddr
		get_ext_ipaddr
		
		get_reg_cloud_name
		get_reg_cloud_domain
		
		get_user_email_addr

		gen_host_certificate

		set_rand_passwd

		update_ipfilter_list
		
		start_services
		RETVAL=$?
		
		[ $RETVAL -ne 0 ] && _err Errors occured on startup. Read system logs for details.
		
		exit $RETVAL
		;;
	"stop")
		if [ -e "${LOCK}" ] ; then
			rm -f "${LOCK}"
		else
			_err Lock file not found. Stop aborted.
		fi
		
		#moveLogs
		#restoreSocketBuffer

		#unforward_ports
		sh ${PROGDIR}/bin/portmapper.sh del &
		sleep 3
		
		stop_services
		RETVAL=$?

		sync
		sleep 1
		
		clean_links

		[ $RETVAL -ne 0 ] && _err Errors occured during stop sequence. Read system logs for details.

		exit $RETVAL
		;;
	"restart")
		echo Restarting ...
		_log 1/2 -- Executing shut down sequence
		$0 stop
		RETVAL=$?
		sync ; sleep 1
		if [ $RETVAL -eq 0 ]; then
			_log 2/2 -- Executing application launch
			$0 start
			RETVAL=$?
			[ $RETVAL -eq 0 ] || _err Errors occured during application launch. Code: ${RETVAL}
		else
			_err Errors occured during stop sequence. Code: ${RETVAL}
		fi
		;;
	"enable")
		/sbin/setcfg ${NAME} Enable TRUE -f /etc/config/qpkg.conf
		_log auto launch enabled.
		;;
	"disable")
		/sbin/setcfg ${NAME} Enable FALSE -f /etc/config/qpkg.conf
		_log auto launch disabled.
		;;
	"status")
		check_my_state
		;;
	*)
		help
		_exit
		;;
esac

# Parent process has died so we also better die.
exit 0


tag: code=html5
Kod:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="favicon.ico">

    <title>Welcome | QNAP rtorrent</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/custom.css" rel="stylesheet">
   
    <link href="css/icomoon.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

  <body>

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/">rtorrent QNAP</a>
        </div>
        <div class="navbar-collapse collapse">
          <!--
          <form class="navbar-form navbar-right" role="form">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">Sign in</button>
          </form>
          -->
          <div class="navbar-form navbar-right">
          <a class="btn btn-link" href="/setup/" role="button"><span class="icon-cog"></span> &nbsp; Settings &raquo;</a>
          </div>
        </div>
        <!--/.navbar-collapse -->
      </div>
    </div>

    <!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
      <div class="container">
        <h1>Welcome</h1>
        <p>Check out tutorials and resources, learn how to use the various features, find explanations of basic settings, common integrations and concepts. Articles covers all the basics and will get you up and running in just a few minutes. </p>
        <p><a class="btn btn-primary btn-lg" href="/gettingstarted.html" role="button">Get started! &raquo;</a></p>
      </div>
    </div>

    <div class="container">
      <!-- Example row of columns -->
      <div class="row">
        <div class="col-md-4">
          <h2>Advanced</h2>
          <p>Extra featured, highly extensible front-end, designed to look similar to uTorrent. </p>
          <p><img src="img/ui_rtorrent.png" alt="Advanced" class="img-rounded"></p>
          <p><a class="btn btn-default" href="/ui/rtorrent/" role="button">Log In &raquo;</a></p>
        </div>
        <div class="col-md-4">
          <h2>Light-weight</h2>
          <p>Simple yet sophisticated interface designed in a style that’s similar to Clutch. </p>
          <p><img src="img/ui_avalanche.png" alt="Light-weight" class="img-rounded"></p>
          <p><a class="btn btn-default" href="/ui/avalanche/" role="button">Log In &raquo;</a></p>
       </div>
        <div class="col-md-4">
          <h2>Mobile Access</h2>
          <p>Stay in-touch with your iOS&reg; and Windows Phone&reg; or Android&trade; smartphone device. </p>
          <p><a class="btn btn-default" href="/guide_mobile_access.html" role="button" disabled>Read more &raquo;</a></p>
        </div>
      </div>

      <hr>

      <footer>
        <a class="pull-right btn btn-paypal" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BBFVGUAA4MTZE" role="button"><span class="icon-paypal4"></span>  Donate</a>
        <p class="text-muted">rtorrent-QNAP &copy; 2008-2014<br />Silas Mariusz Grzybacz</p>
      </footer>

     
    </div> <!-- /container -->

   
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>


tag: html
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="favicon.ico">

    <title>Welcome | QNAP rtorrent</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/custom.css" rel="stylesheet">
   
    <link href="css/icomoon.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

  <body>

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/">rtorrent QNAP</a>
        </div>
        <div class="navbar-collapse collapse">
          <!--
          <form class="navbar-form navbar-right" role="form">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">Sign in</button>
          </form>
          -->
          <div class="navbar-form navbar-right">
          <a class="btn btn-link" href="/setup/" role="button"><span class="icon-cog"></span> &nbsp; Settings &raquo;</a>
          </div>
        </div>
        <!--/.navbar-collapse -->
      </div>
    </div>

    <!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
      <div class="container">
        <h1>Welcome</h1>
        <p>Check out tutorials and resources, learn how to use the various features, find explanations of basic settings, common integrations and concepts. Articles covers all the basics and will get you up and running in just a few minutes. </p>
        <p><a class="btn btn-primary btn-lg" href="/gettingstarted.html" role="button">Get started! &raquo;</a></p>
      </div>
    </div>

    <div class="container">
      <!-- Example row of columns -->
      <div class="row">
        <div class="col-md-4">
          <h2>Advanced</h2>
          <p>Extra featured, highly extensible front-end, designed to look similar to uTorrent. </p>
          <p><img src="img/ui_rtorrent.png" alt="Advanced" class="img-rounded"></p>
          <p><a class="btn btn-default" href="/ui/rtorrent/" role="button">Log In &raquo;</a></p>
        </div>
        <div class="col-md-4">
          <h2>Light-weight</h2>
          <p>Simple yet sophisticated interface designed in a style that’s similar to Clutch. </p>
          <p><img src="img/ui_avalanche.png" alt="Light-weight" class="img-rounded"></p>
          <p><a class="btn btn-default" href="/ui/avalanche/" role="button">Log In &raquo;</a></p>
       </div>
        <div class="col-md-4">
          <h2>Mobile Access</h2>
          <p>Stay in-touch with your iOS&reg; and Windows Phone&reg; or Android&trade; smartphone device. </p>
          <p><a class="btn btn-default" href="/guide_mobile_access.html" role="button" disabled>Read more &raquo;</a></p>
        </div>
      </div>

      <hr>

      <footer>
        <a class="pull-right btn btn-paypal" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BBFVGUAA4MTZE" role="button"><span class="icon-paypal4"></span>  Donate</a>
        <p class="text-muted">rtorrent-QNAP &copy; 2008-2014<br />Silas Mariusz Grzybacz</p>
      </footer>

     
    </div> <!-- /container -->

   
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>


tag: code=php
PHP:
<?php

require_once( "xmlrpc.php" );
require_once( 'settings.php' );

define('FLAG_CANT_SHUTDOWN',	0x0080);
define('FLAG_CAN_CHANGE_LAUNCH',0x0100);

$theSettings = rTorrentSettings::get();
$jResult = "";

$cmd = isset($_REQUEST["cmd"]) ? $_REQUEST["cmd"] : "done";

$userPermissions = array( "__hash__"=>"plugins.dat" );
$cache = new rCache();
$cache->get($userPermissions);

if(!isset($HTTP_RAW_POST_DATA))
	$HTTP_RAW_POST_DATA = file_get_contents("php://input");
if(isset($HTTP_RAW_POST_DATA))
{
	$vars = explode('&', $HTTP_RAW_POST_DATA);
	foreach($vars as $var)
	{
		$parts = explode("=",$var);
		if($parts[0]=="plg")
		{
			$perms = $theSettings->getPluginData($parts[1]);
			switch($cmd)
			{
				case "unlaunch":
				{
					if(is_null($perms) || ($perms & FLAG_CAN_CHANGE_LAUNCH))
					{
						$userPermissions[$parts[1]] = false;
						$jResult.="thePlugins.get('".$parts[1]."').unlaunch();";
					}
				}
				case "done":
				{
					if(!is_null($perms) && !($perms & FLAG_CANT_SHUTDOWN))
					{
						$php = "../plugins/".$parts[1]."/done.php";
						if(is_file($php) && is_readable($php))
							require_once($php);
						$theSettings->unregisterPlugin($parts[1]);
						$jResult.="thePlugins.get('".$parts[1]."').remove();";
					}
					break;
				}
				case "launch":
				{
					if(is_null($perms) || ($perms & FLAG_CAN_CHANGE_LAUNCH))
					{
						$userPermissions[$parts[1]] = true;
						$jResult.="thePlugins.get('".$parts[1]."').launch();";
					}
					break;
				}

			}
		}
	}

	if($cmd=="done")
		$theSettings->store();
	else
		$cache->set($userPermissions);
}

echo $jResult;


tag: php
PHP:
<?php

require_once( "xmlrpc.php" );
require_once( 'settings.php' );

define('FLAG_CANT_SHUTDOWN',	0x0080);
define('FLAG_CAN_CHANGE_LAUNCH',0x0100);

$theSettings = rTorrentSettings::get();
$jResult = "";

$cmd = isset($_REQUEST["cmd"]) ? $_REQUEST["cmd"] : "done";

$userPermissions = array( "__hash__"=>"plugins.dat" );
$cache = new rCache();
$cache->get($userPermissions);

if(!isset($HTTP_RAW_POST_DATA))
	$HTTP_RAW_POST_DATA = file_get_contents("php://input");
if(isset($HTTP_RAW_POST_DATA))
{
	$vars = explode('&', $HTTP_RAW_POST_DATA);
	foreach($vars as $var)
	{
		$parts = explode("=",$var);
		if($parts[0]=="plg")
		{
			$perms = $theSettings->getPluginData($parts[1]);
			switch($cmd)
			{
				case "unlaunch":
				{
					if(is_null($perms) || ($perms & FLAG_CAN_CHANGE_LAUNCH))
					{
						$userPermissions[$parts[1]] = false;
						$jResult.="thePlugins.get('".$parts[1]."').unlaunch();";
					}
				}
				case "done":
				{
					if(!is_null($perms) && !($perms & FLAG_CANT_SHUTDOWN))
					{
						$php = "../plugins/".$parts[1]."/done.php";
						if(is_file($php) && is_readable($php))
							require_once($php);
						$theSettings->unregisterPlugin($parts[1]);
						$jResult.="thePlugins.get('".$parts[1]."').remove();";
					}
					break;
				}
				case "launch":
				{
					if(is_null($perms) || ($perms & FLAG_CAN_CHANGE_LAUNCH))
					{
						$userPermissions[$parts[1]] = true;
						$jResult.="thePlugins.get('".$parts[1]."').launch();";
					}
					break;
				}

			}
		}
	}

	if($cmd=="done")
		$theSettings->store();
	else
		$cache->set($userPermissions);
}

echo $jResult;
 

Użytkownicy znaleźli tą stronę używając tych słów:

  1. Warning: XMLRPC call is failed.