Skip to content

Commit 4dbf546

Browse files
committed
Merge branch 'ftp'
Enables Anonymous FTP and Admin FTP access.
2 parents dc65871 + 08c4d58 commit 4dbf546

File tree

10 files changed

+448
-2
lines changed

10 files changed

+448
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NAME = librarybox
2-
VERSION = 2.0.0_alpha4
2+
VERSION = 2.0.0_alpha5
33
ARCH = all
44

55
#PIRATEBOX_IMG_URL = "http://piratebox.aod-rpg.de/piratebox_ws_0.6_img.gz"

customization/bin/ftp_enable.sh

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
#!/bin/sh
2+
3+
## Script by Matthias Strubel (c) 2013 GPL3 <matthias.strubel@aod-rpg.de>
4+
##
5+
## Helps users to setup their FTP Server (and user+passwords
6+
7+
8+
### Constants
9+
10+
PIRATEBOX_FOLDER=/opt/piratebox
11+
PIRATEBOX_CONF_FOLDER=$PIRATEBOX_FOLDER/conf
12+
PIRATEBOX_CONF=$PIRATEBOX_CONF_FOLDER/piratebox.conf
13+
PIRATEBOX_HOOK_CONF=$PIRATEBOX_CONF_FOLDER/hook_custom.conf ##Here is the configuration for enabling FTP during startup stored
14+
15+
IS_OPENWRT=' -e /etc/openwrt_version '
16+
17+
FTP_CONF_FOLDER=$PIRATEBOX_CONF_FOLDER/ftp
18+
BASIC_FTP_CONFIG=$FTP_CONF_FOLDER/ftp.conf
19+
20+
21+
## Schema-files
22+
SCHEMA_DEAMON_CONF=$FTP_CONF_FOLDER/proftpd.conf.schema
23+
SCHEMA_SYNC_CONF=$FTP_CONF_FOLDER/sync_access.conf.schema
24+
SCHEMA_ANON_CONF=$FTP_CONF_FOLDER/anon_access.conf.schema
25+
26+
##----------------
27+
# Load known configuration files
28+
29+
. $PIRATEBOX_CONF #This includes the hook-file too
30+
# Used Vars
31+
# FTP_ENABLED
32+
# PROFTPD_PID
33+
# PROFTPD_CONFIG_FILE < - OUPUT_PROFTPD_CONFIG for
34+
# SHARE_FOLDER < - ??
35+
# LIGHTTPD_USER
36+
# LIGHTTPD_GROUP
37+
# IPV6_ENABLE <- yes/no
38+
# HOST <- hostname
39+
40+
. $BASIC_FTP_CONFIG
41+
# uses
42+
# ADMIN_ACCESS
43+
# BOX_USER
44+
# ENABLE_SYNC
45+
# SYNC_PORT
46+
# SYNC_FOLDER
47+
# ENABLE_ANON
48+
# ANON_FOLDER
49+
50+
##---------------
51+
## Final configuration files
52+
#
53+
OUTPUT_DAEMON_CONF=$FTP_CONF_FOLDER/proftpd.conf
54+
OUTPUT_SYNC_CONF=$FTP_CONF_FOLDER/sync_access.conf
55+
OUTPUT_ANON_CONF=$FTP_CONF_FOLDER/anon_access.conf
56+
57+
58+
print_line() {
59+
60+
echo "------------------------------------------------------"
61+
62+
}
63+
64+
print_current_config() {
65+
print_line
66+
echo " FTP enabled : $FTP_ENABLED "
67+
echo " Admin access : $ADMIN_ACCESS "
68+
echo " Special SYNC access : $ENABLE_SYNC "
69+
echo " SYNC Port : $SYNC_PORT "
70+
echo " Anonymous login possible: $ENABLE_ANON "
71+
echo " "
72+
print_line
73+
}
74+
75+
print_help_ftp(){
76+
echo "no help currently available"
77+
}
78+
79+
print_help_anon(){
80+
print_line
81+
echo " Anonymous access is a password-less FTP Login using user 'ftp' or 'anonymous' , which allowes users to get in an easy way to download Files"
82+
echo " Anonymous access is restricted to maximal 2 Clients, and one Client per Host to ensure System stability on OpenWRT"
83+
echo " Anonymous Users can't upload."
84+
echo " You can modify this values by hand editing $SCHEMA_ANON_CONF "
85+
echo ""
86+
print_line
87+
}
88+
89+
print_help_sync(){
90+
print_line
91+
echo " Sync access is on specific daemon running on a separate Port, you can choose"
92+
echo " This feature is designed for ppl who want to synchronize their Boxes like a private cloud from one. The client downloads the data, no upload happens"
93+
echo " The user behind the sync-access has an own password, other than admin and has to be set for successful access."
94+
echo " Sync-Access is restricted to one slot for downloading and has the same TransferSpeed limits like the other accounts. "
95+
print_line
96+
}
97+
98+
print_help_admin(){
99+
print_line
100+
echo " Admin access enables a full-control access to your Box' USB Stick for uploadind, downloading and deleting files"
101+
echo ""
102+
print_line
103+
}
104+
105+
# Generates all config files based upon the configuration
106+
generate() {
107+
echo -n "Generating FTP Configuration"
108+
109+
local l_allow_admin=""
110+
local l_scoreboard=""
111+
local l_allow_anon=""
112+
local l_allow_sync=""
113+
local l_ipv6="no"
114+
115+
[ "$IPV6_ENABLE" = "yes" ] && l_ipv6="on"
116+
117+
118+
#Save the scoreboard in memory on OpenWRT
119+
120+
if [ $IS_OPENWRT ] ; then
121+
l_scoreboard="/tmp/log/proftpd.scoreboard"
122+
else
123+
l_scoreboard=$PIRATEBOX_FOLDER"/tmp/proftpd.scoreboard"
124+
fi
125+
126+
l_allow_sync="Include $OUTPUT_SYNC_CONF \n"
127+
l_allow_anon="Include $OUTPUT_ANON_CONF \n"
128+
l_allow_admin="AllowUser $BOX_SYSTEM_USER"
129+
130+
sed "s|#####HOSTNAME#####|$HOST|" $SCHEMA_DEAMON_CONF > $OUTPUT_DAEMON_CONF
131+
132+
sed "s|#####IPV6#####|$l_ipv6|" -i $OUTPUT_DAEMON_CONF
133+
sed "s|#####BOX_USER#####|$BOX_USER|" -i $OUTPUT_DAEMON_CONF
134+
sed "s|#####ADMIN_ACCESS#####|$l_allow_admin|" -i $OUTPUT_DAEMON_CONF
135+
sed "s|#####SCOREBOARD_PATH#####|$l_scoreboard|" -i $OUTPUT_DAEMON_CONF
136+
sed "s|#####INCLUDE_ANON_ACCESS#####|$l_allow_anon|" -i $OUTPUT_DAEMON_CONF
137+
sed "s|#####INCLUDE_SYNC_ACCESS#####|$l_allow_sync|" -i $OUTPUT_DAEMON_CONF
138+
sed "s|#####PID#####|$PROFTPD_PID|" -i $OUTPUT_DAEMON_CONF
139+
sed "s|#####ADMIN_FOLDER#####|$ADMIN_FOLDER|" -i $OUTPUT_DAEMON_CONF
140+
sed "s|#####BOX_SYSTEM_USER#####|$BOX_SYSTEM_USER|" -i $OUTPUT_DAEMON_CONF
141+
sed "s|#####BOX_SYSTEM_GROUP#####|$BOX_SYSTEM_GROUP|" -i $OUTPUT_DAEMON_CONF
142+
143+
#SYNC Stuff
144+
sed "s|#####HOSTNAME#####|$HOST|" $SCHEMA_SYNC_CONF > $OUTPUT_SYNC_CONF
145+
sed "s|#####SYNC-PORT#####|$SYNC_PORT|" -i $OUTPUT_SYNC_CONF
146+
sed "s|#####SYNC-FOLDER#####|$SYNC_FOLDER|" -i $OUTPUT_SYNC_CONF
147+
sed "s|#####SYNC_SYSTEM_USER#####|$SYNC_SYSTEM_USER|" -i $OUTPUT_SYNC_CONF
148+
149+
#ANON Stuff
150+
sed "s|#####ANON-FOLDER#####|$ANON_FOLDER|" $SCHEMA_ANON_CONF > $OUTPUT_ANON_CONF
151+
152+
153+
echo "..done"
154+
}
155+
156+
_exit_menu_() {
157+
generate
158+
exit 0
159+
}
160+
161+
_toggle_() {
162+
local func=$1
163+
164+
#on default always no
165+
local new="no"
166+
local func_content=$(eval "echo \$${func}")
167+
168+
if [ "$func_content" = "no" ] ; then
169+
new="yes"
170+
fi
171+
172+
local config_file=""
173+
174+
case $func in
175+
("FTP_ENABLED") config_file=$PIRATEBOX_HOOK_CONF ;;
176+
(*) config_file=$BASIC_FTP_CONFIG ;;
177+
esac
178+
179+
sed "s|$func=\"$func_content\"|$func=\"$new\"|" -i $config_file
180+
181+
. $config_file
182+
183+
}
184+
185+
mainmenu() {
186+
while true
187+
do
188+
print_line
189+
echo " Current configuration:"
190+
print_current_config
191+
echo " 1 - Enable / Disable FTP during Startup (Toggle) "
192+
echo " 2 - Enable / Disable Admin access "
193+
echo " 3 - Enable / Disable sync-setup"
194+
echo " 4 - Enable / Disable Anonymous access "
195+
echo " 5 - Set password for Sync-Access "
196+
echo " 6 - Set password for admin-access "
197+
echo " "
198+
echo " With choosing hn like h1 , you get some help about the topic"
199+
echo " Every other button is a clean exit. "
200+
echo " "
201+
read -p " Coose an option: " option
202+
203+
case $option in
204+
("1") _toggle_ "FTP_ENABLED" ;;
205+
("2") _toggle_ "ADMIN_ACCESS" ;;
206+
("3") _toggle_ "ENABLE_SYNC" ;;
207+
("4") _toggle_ "ENABLE_ANON" ;;
208+
("5") passwd $SYNC_SYSTEM_USER ;;
209+
("6") passwd $BOX_SYSTEM_USER ;;
210+
("h1") print_help_ftp ;;
211+
("h2") print_help_admin ;;
212+
("h3") print_help_sync ;;
213+
("h4") print_help_anon ;;
214+
(*) _exit_menu_ ;;
215+
esac
216+
option=""
217+
done
218+
219+
}
220+
221+
222+
if [ "$1" = "generate" ] ; then
223+
generate
224+
else
225+
mainmenu
226+
fi
227+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
# ---- TEMPLATE ----
4+
5+
# Runs on every Startup after the normal init-steps are done
6+
# get config file
7+
8+
if [ ! -f $1 ] ; then
9+
echo "Config-File $1 not found..."
10+
exit 255
11+
fi
12+
13+
#Load config
14+
. $1
15+
16+
# You can uncommend this line to see when hook is starting:
17+
echo "------------------ Running $0 ------------------"
18+
19+
if [ "$FTP_ENABLED" = "yes" ] ; then
20+
echo "starting PROFTPD.."
21+
22+
# Load PirateBox config
23+
. $PIRATEBOX_FOLDER/conf/ftp/ftp.conf
24+
25+
# $PROFTPD_CONFIG_FILE
26+
# $PROFTPD_PID #####PID#####
27+
28+
# Define Options
29+
####### AdminAccess <-> $ADMIN_ACCESS
30+
####### AnonAccess <-> $ENABLE_ANON
31+
####### SyncAccess <-> $ENABLE_SYNC
32+
33+
local proftpd_opt_admin=""
34+
local proftpd_opt_anon=""
35+
local proftpd_opt_sync=""
36+
37+
[ "$ADMIN_ACCESS" = "yes" ] && proftpd_opt_admin="-D AdminAccess"
38+
[ "$ENABLE_ANON" = "yes" ] && proftpd_opt_anon="-D AnonAccess"
39+
[ "$ENABLE_SYNC" = "yes" ] && proftpd_opt_sync="-D SyncAccess"
40+
41+
#Proftpd writes the pidfile for its own
42+
proftpd -c $PROFTPD_CONFIG_FILE $proftpd_opt_admin $proftpd_opt_admin $proftpd_opt_sync
43+
echo $?
44+
45+
fi
46+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# ---- TEMPLATE ----
4+
5+
# Runs on every Stop before anything is stopped
6+
# get config file
7+
8+
if [ ! -f $1 ] ; then
9+
echo "Config-File $1 not found..."
10+
exit 255
11+
fi
12+
13+
#Load config
14+
. $1
15+
16+
# You can uncommend this line to see when hook is starting:
17+
echo "------------------ Running $0 ------------------"
18+
19+
20+
if [ -e "$PROFTPD_PID" ]; then
21+
echo "Stopping proftpd..."
22+
kill $(cat $PROFTPD_PID)
23+
echo $?
24+
rm $PROFTPD_PID
25+
fi

customization/bin/hooks/hook_pre_init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ mv $PIRATEBOX_FOLDER/www_content/* $WWW_CONTENT
3434
# Link to the USB-Stick
3535
ln -s $WWW_CONTENT $WWW_FOLDER/content
3636

37+
$PIRATEBOX_FOLDER/bin/ftp_enable.sh generate
3738

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
DefaultRoot #####ANON-FOLDER##### ftp
3+
4+
<Anonymous #####ANON-FOLDER##### >
5+
User ftp
6+
Group ftp
7+
8+
UserAlias anonymous ftp
9+
MaxClients 4 "Sorry, max %m users -- try again later"
10+
MaxClientsPerHost 2
11+
12+
<Limit LOGIN>
13+
AllowAll
14+
</Limit>
15+
# Limit WRITE everywhere in the anonymous chroot
16+
<Limit WRITE>
17+
DenyAll
18+
</Limit>
19+
</Anonymous>

customization/conf/ftp/ftp.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#### Configuration for FTP Server
2+
3+
#----------------------------------------------
4+
# Enable sepcial USER with Admin access
5+
# don't forget to run /opt/piratebox/bin/ftp_enable.sh
6+
ADMIN_ACCESS="yes"
7+
BOX_USER="boxadmin"
8+
ADMIN_FOLDER="$PIRATEBOX_FOLDER/share"
9+
BOX_SYSTEM_USER="nobody"
10+
BOX_SYSTEM_GROUP="nogroup"
11+
12+
#----------------------------------------------
13+
# Enable special Port for System-Syncronisation
14+
ENABLE_SYNC="no"
15+
# Which Port should be used for
16+
SYNC_PORT=54321
17+
SYNC_FOLDER="$PIRATEBOX_FOLDER/share/Shared"
18+
SYNC_SYSTEM_USER="ftp"
19+
20+
#----------------------------------------------
21+
# Enable anonymous READ-ONLY FTP Access?
22+
# don't forget to run /opt/piratebox/bin/ftp_enable.sh
23+
ENABLE_ANON="no"
24+
ANON_FOLDER="$PIRATEBOX_FOLDER/share/Shared"

0 commit comments

Comments
 (0)