mirror of
https://github.com/PirateBox-Dev/PirateBoxScripts_Webserver.git
synced 2023-12-14 07:22:58 +01:00
Merge branch 'release-1.0.7'
* [New] Lock shoutbox when you send a message. * [New] Display disk space usage on front page. * [New] Add webm mime-type to lighttpd * [RPi] [New] RPi2 and Zero support * [RPi] [New] USB activation scripts. * [RPi] [New] udev rules for piratebox activation * [RPi] [New] Script for activating the correct hostap for Realtek chipsets * [RPI] [New] wpa_supplicant fallback if no AP enabled WiFi device was found * [Fix] Send a proper HTTP Reason code back * [Fix] Fix version number in RPi MOTD. * [Fix] Insert mime-type for .svg * [Fix] Improve Shoutbox update speed after sending a message. * [Fix] Do not cleanup the rootfs if Shared folder does not exist. * [Fix] Improved comparison of timestamps on RPi. * [Fix] Improved MOTD for RPi. * [Fix] Improved initialization of the board.
This commit is contained in:
commit
3e0549c3c9
30 changed files with 480 additions and 165 deletions
2
AUTHORS
2
AUTHORS
|
@ -16,12 +16,12 @@ Contributors for modifications:
|
|||
# Liblor - Fixes
|
||||
# Loris Reiff
|
||||
# iamarf
|
||||
# stylesuxx
|
||||
# denis-d
|
||||
# taffy-nay
|
||||
# risca
|
||||
# herr-gabriel
|
||||
# Jess Stubenbord
|
||||
# Mike Weaver
|
||||
# ... and all others I might have forgotten.
|
||||
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
This folder contains the stuff needed to Build *nix packages like i.e. Debian, Fedora ...
|
|
@ -1,32 +0,0 @@
|
|||
PirateBox RPi-Image 1.0.1
|
||||
PirateBox Version 1.0.1
|
||||
Website: http://piratebox.cc
|
||||
Forum: http://forum.piratebox.cc
|
||||
IRC: #piratebox on irc.Freenode.net
|
||||
|
||||
Want to start a not enabled piratebox, run
|
||||
# systemctl start piratebox
|
||||
|
||||
Next Steps after first flashing:
|
||||
1. Change password of alarm user:
|
||||
# passwd
|
||||
2. Switch user to root (password is root) , to proceed with the final steps
|
||||
# su
|
||||
3. Change the password for the root user:
|
||||
# password
|
||||
4. If you want to have PirateBox enabled on startup:
|
||||
# systemctl enable piratebox
|
||||
# systemctl start piratebox
|
||||
5. Enable Fake-Timeservice
|
||||
5.1 Set time like
|
||||
# date 101016112014 for "Fri Oct 10 16:11:00 2014" format is: MMDDhhmmCCYY
|
||||
# /opt/piratebox/bin/timesave.sh /opt/piratebox/conf/piratebox.conf install
|
||||
5.2 Enable for bootup
|
||||
# systemctl enable timesave
|
||||
6. Activate the Kareha Image and Discussion Board.
|
||||
# /opt/piratebox/bin/board-autoconf.sh
|
||||
7. If you want, enable UPnP Media Server
|
||||
# cp /etc/minidlna.conf /etc/minidlna.conf.bkp
|
||||
# cp /opt/piratebox/src/linux.example.minidlna.conf /etc/minidlna.conf
|
||||
# systemctl start minidlna
|
||||
# systemctl enable minidlna
|
|
@ -1,81 +0,0 @@
|
|||
http://blog.mx17.net/2012/07/13/raspberry-pi-tip-mount-raspbmc-images/
|
||||
|
||||
http://schloesser-edv.de/tips-und-tricks/linux/chroot-mount.html
|
||||
|
||||
..
|
||||
|
||||
things done for image preparation
|
||||
|
||||
Download: Raspbian “wheezy”
|
||||
mount image (like first link)
|
||||
|
||||
|
||||
mount -o bind /dev /mnt/dev
|
||||
mount -t proc none /mnt/proc
|
||||
|
||||
sudo chroot /mnt/ /bin/bash
|
||||
|
||||
do:
|
||||
---
|
||||
|
||||
apt-get -y install lighttpd
|
||||
/etc/init.d/lighttpd stop
|
||||
update-rc.d lighttpd remove
|
||||
apt-get -y install dnsmasq
|
||||
/etc/init.d/dnsmasq stop
|
||||
update-rc.d dnsmasq remove
|
||||
apt-get -y install hostapd
|
||||
/etc/init.d/hostapd stop
|
||||
update-rc.d hostapd remove
|
||||
apt-get -y install iw
|
||||
rm /bin/sh
|
||||
ln /bin/bash /bin/sh
|
||||
chmod a+rw /bin/sh
|
||||
|
||||
Edit network config file /etc/network/interfaces
|
||||
auto lo
|
||||
|
||||
iface lo inet loopback
|
||||
iface eth0 inet dhcp
|
||||
|
||||
iface wlan0 inet manual
|
||||
### disalbed for PirateBox
|
||||
#allow-hotplug wlan0
|
||||
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
#iface default inet dhcp
|
||||
|
||||
|
||||
wget http://downloads.piratebox.de/piratebox-ws_current.tar.gz
|
||||
tar xzf piratebox-ws_current.tar.gz
|
||||
cd piratebox
|
||||
mkdir -p /opt
|
||||
cp -rv piratebox /opt
|
||||
cd /opt/piratebox
|
||||
sed 's:DROOPY_USE_USER="no":DROOPY_USE_USER="yes":' -i /opt/piratebox/conf/piratebox.conf
|
||||
sed 's:PROBE_INTERFACE="no":PROBE_INTERFACE="yes":' -i /opt/piratebox/conf/piratebox.conf
|
||||
ln /opt/piratebox/init.d/piratebox /etc/init.d/piratebox
|
||||
cd ../../
|
||||
rm -rv piratebox/ piratebox-ws_current.tar.gz
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
Install Raspberry as normal: http://elinux.org/RPi_Easy_SD_Card_Setup
|
||||
|
||||
Use my Image instead of the rpi.org one
|
||||
Boot as normal with a Monitor, Keyboard & connected LAN (DHCP with Internet access)
|
||||
Do the following steps in Raspi-Config
|
||||
Enable SSH Server via raspberry-config
|
||||
change Password
|
||||
Expand FS
|
||||
Finish & reboot now
|
||||
|
||||
Wait until reboot is finished- needs a while because the OS is resizing the filesystem during this reboot
|
||||
|
||||
If you want to run it via default:
|
||||
|
||||
sudo update-rc.d piratebox defaults
|
||||
sudo /etc/init.d/piratebox start
|
||||
sudo touch /opt/piratebox/conf/init_done
|
18
CHANGELOG
18
CHANGELOG
|
@ -1,5 +1,23 @@
|
|||
CHANGELOG
|
||||
|
||||
=== 1.0.7 ===
|
||||
* [New] Lock shoutbox when you send a message.
|
||||
* [New] Display disk space usage on front page.
|
||||
* [New] Add webm mime-type to lighttpd
|
||||
* [RPi] [New] RPi2 and Zero support
|
||||
* [RPi] [New] USB activation scripts.
|
||||
* [RPi] [New] udev rules for piratebox activation
|
||||
* [RPi] [New] Script for activating the correct hostap for Realtek chipsets
|
||||
* [RPI] [New] wpa_supplicant fallback if no AP enabled WiFi device was found
|
||||
* [Fix] Send a proper HTTP Reason code back
|
||||
* [Fix] Fix version number in RPi MOTD.
|
||||
* [Fix] Insert mime-type for .svg
|
||||
* [Fix] Improve Shoutbox update speed after sending a message.
|
||||
* [Fix] Do not cleanup the rootfs if Shared folder does not exist.
|
||||
* [Fix] Improved comparison of timestamps on RPi.
|
||||
* [Fix] Improved MOTD for RPi.
|
||||
* [Fix] Improved initialization of the board.
|
||||
|
||||
=== 1.0.6 ===
|
||||
* [Fix] Styling of the upload box iframe was quite ugly.
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
NAME = piratebox-ws
|
||||
VERSION = 1.0.6
|
||||
VERSION = 1.0.7
|
||||
ARCH = all
|
||||
PB_FOLDER=piratebox
|
||||
PB_SRC_FOLDER=$(PB_FOLDER)/$(PB_FOLDER)
|
||||
|
|
|
@ -18,5 +18,6 @@ else
|
|||
|
||||
# Remove temporary index page and then try to initialize the board
|
||||
test -e /opt/piratebox/share/board/index.htm && rm /opt/piratebox/share/board/index.htm
|
||||
wget -q -s -O - http://127.0.0.1/board/kareha.pl 2>/dev/null
|
||||
#wget -q -s -O - http://127.0.0.1/board/kareha.pl 2>/dev/null
|
||||
wget -qO- http://127.0.0.1/board/kareha.pl &> /dev/null
|
||||
fi
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script is needed for Piratebox on OpenWrt.
|
||||
# The find utility there has only a limited feature set.
|
||||
|
||||
IFS='
|
||||
'
|
||||
|
||||
|
||||
# Change directory, if not exist exit to not cleanup the
|
||||
# OS filesystem.
|
||||
cd $1 || exit 1
|
||||
|
||||
cd $1
|
||||
ls_list=$( find ./ )
|
||||
ls_list=$( find ./ -type f )
|
||||
|
||||
for filename in $ls_list
|
||||
do
|
||||
|
|
|
@ -122,6 +122,7 @@ generate_lighttpd_env() {
|
|||
local SHOUTBOX_GEN_HTMLFILE=$4
|
||||
local PIRATEBOX=$5
|
||||
local SHOUTBOX_CHATFILE=$6
|
||||
local DISK_GEN_HTMLFILE=$7
|
||||
|
||||
echo "Generating Environment-config for lighttpd ....."
|
||||
|
||||
|
@ -134,6 +135,7 @@ generate_lighttpd_env() {
|
|||
\"PYTHONPATH\" => \"$PYTHONPATH:$PIRATEBOX/python_lib\",
|
||||
\"SHOUTBOX_GEN_HTMLFILE\" => \"$SHOUTBOX_GEN_HTMLFILE\" ,
|
||||
\"SHOUTBOX_CHATFILE\" => \"$SHOUTBOX_CHATFILE\" ,
|
||||
\"DISK_GEN_HTMLFILE\" => \"$DISK_GEN_HTMLFILE\" ,
|
||||
$LIGHTTPD_ENV_BR_LINE
|
||||
|
||||
)"
|
||||
|
@ -171,7 +173,7 @@ if [ "$IPV6_ENABLE" = "yes" ] ; then
|
|||
fi
|
||||
generate_hosts $HOST $IP $IPV6
|
||||
generate_dnsmasq $NET $IP_SHORT $START_LEASE $END_LEASE $LEASE_DURATION $DNSMASQ_INTERFACE
|
||||
generate_lighttpd_env $GLOBAL_CHAT "$GLOBAL_DEST" $PIRATEBOX_PYTHONPATH $GEN_CHATFILE $PIRATEBOX_FOLDER $CHATFILE
|
||||
generate_lighttpd_env $GLOBAL_CHAT "$GLOBAL_DEST" $PIRATEBOX_PYTHONPATH $GEN_CHATFILE $PIRATEBOX_FOLDER $CHATFILE $GEN_DISKFILE
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,15 +19,19 @@ cd python_lib
|
|||
export SHOUTBOX_CHATFILE=$CHATFILE
|
||||
export SHOUTBOX_GEN_HTMLFILE=$GEN_CHATFILE
|
||||
|
||||
export DISK_GEN_HTMLFILE=$GEN_DISKFILE
|
||||
|
||||
#Writing init-message and reset chat..
|
||||
if [ "$RESET_CHAT" = "yes" ] ; then
|
||||
echo $CHATMSG > $CHATFILE
|
||||
fi
|
||||
|
||||
#Generate content file
|
||||
#Generate content file for Shoutbox
|
||||
python psogen.py generate
|
||||
|
||||
#Generate content file for DiskUsage
|
||||
python diskusage.py generate
|
||||
|
||||
$( sleep 20 && touch $GEN_CHATFILE ) &
|
||||
|
||||
#Set correct permissions
|
||||
|
@ -36,4 +40,6 @@ chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $SHOUTBOX_GEN_HTMLFILE
|
|||
chmod ug+rw $SHOUTBOX_CHATFILE
|
||||
chmod ug+rw $SHOUTBOX_GEN_HTMLFILE
|
||||
|
||||
|
||||
#DiskUsage correct permissions
|
||||
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $DISK_GEN_HTMLFILE
|
||||
chmod ug+rw $DISK_GEN_HTMLFILE
|
||||
|
|
|
@ -14,12 +14,15 @@
|
|||
##function for similar saving & getting time
|
||||
get_datetime() {
|
||||
# Get format from piratebox.conf
|
||||
date $TIMESAVE_FORMAT
|
||||
date "${TIMESAVE_FORMAT}"
|
||||
}
|
||||
|
||||
# Strip spaces from datetime
|
||||
sanitize_datetime() {
|
||||
echo $1 | sed s/" "/""/g
|
||||
}
|
||||
|
||||
# Load configfile
|
||||
|
||||
# Print usage if parameters are not provided
|
||||
if [ -z $1 ] || [ -z $2 ] ; then
|
||||
echo "Set up a crontab entry for regulary saving the time"
|
||||
echo "Usage $0 <path to piratebox.conf> <step>"
|
||||
|
@ -31,13 +34,13 @@ if [ -z $1 ] || [ -z $2 ] ; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Load configfile
|
||||
. $1
|
||||
|
||||
|
||||
if [ "$2" = "install" ] ; then
|
||||
crontab -l > $PIRATEBOX_FOLDER/tmp/crontab 2> /dev/null
|
||||
echo "#--- Crontab for PirateBox-Timesave" >> $PIRATEBOX_FOLDER/tmp/crontab
|
||||
echo " */5 * * * * $PIRATEBOX_FOLDER/bin/timesave.sh $PIRATEBOX_FOLDER/conf/piratebox.conf save " >> $PIRATEBOX_FOLDER/tmp/crontab
|
||||
echo " */5 * * * * $PIRATEBOX_FOLDER/bin/timesave.sh $PIRATEBOX_FOLDER/conf/piratebox.conf save" >> $PIRATEBOX_FOLDER/tmp/crontab
|
||||
crontab $PIRATEBOX_FOLDER/tmp/crontab
|
||||
|
||||
echo "initialize timesave file"
|
||||
|
@ -45,35 +48,38 @@ if [ "$2" = "install" ] ; then
|
|||
chmod a+rw $TIMESAVE
|
||||
get_datetime > $TIMESAVE
|
||||
|
||||
|
||||
echo "Remember MAY have to cron active..."
|
||||
echo " on OpenWrt run: /etc/init.d/piratebox enable"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Save current date-time in a recoverable format
|
||||
if [ "$2" = "save" ] ; then
|
||||
if [ -e $TIMESAVE ] ; then
|
||||
if [ `get_datetime` -lt `cat $TIMESAVE` ] ; then
|
||||
logger -s "$0 : sorry, current date-time is lower then saved one, don't save it this time"
|
||||
if [ $(sanitize_datetime "$(get_datetime)") -lt $(sanitize_datetime "$(cat $TIMESAVE)") ] ; then
|
||||
logger -s "$0: Current date-time is lower then saved one. Not saving!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#Save Datetime in a recoverable format...
|
||||
get_datetime > $TIMESAVE
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Recover date-time from a previous state
|
||||
if [ "$2" = "recover" ] ; then
|
||||
if [ `get_datetime` -lt `cat $TIMESAVE` ] ; then
|
||||
date -s `cat $TIMESAVE `
|
||||
[ "$?" != "0" ] && echo "error in recovering time" && exit 255
|
||||
echo "Time recovered"
|
||||
exit 0
|
||||
if [ $(sanitize_datetime "$(get_datetime)") -lt $(sanitize_datetime "$(cat $TIMESAVE)") ] ; then
|
||||
date -s "$(cat $TIMESAVE)" > /dev/null
|
||||
if [ "$?" != "0" ] ; then
|
||||
logger -s "$0: Could not recover date-time."
|
||||
exit 1
|
||||
else
|
||||
echo "Sorry, changing timebackward via timesave is not possible"
|
||||
logger -s "$0: Sucessfully recovered date-time."
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
logger -s "$0: Time can not be changed to the past."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
@ -80,9 +80,12 @@ mimetype.assign = (
|
|||
".oti" => "application/vnd.oasis.opendocument.image-template",
|
||||
".oth" => "application/vnd.oasis.opendocument.text-web",
|
||||
|
||||
".webm" => "video/webm",
|
||||
|
||||
".json" => "application/json",
|
||||
".epub" => "application/epub+zip",
|
||||
".fb2" => "text/xml",
|
||||
".svg" => "image/svg+xml",
|
||||
|
||||
# make the default mime type application/octet-stream.
|
||||
"" => "application/octet-stream",
|
||||
|
|
|
@ -145,6 +145,9 @@ CHATFILE="$WWW_FOLDER/cgi-bin/data.pso"
|
|||
#Generated File
|
||||
GEN_CHATFILE="$WWW_FOLDER/chat_content.html"
|
||||
|
||||
#Generated File for DiskUsage
|
||||
GEN_DISKFILE="$WWW_FOLDER/diskusage.html"
|
||||
|
||||
# Reset Shoutbox on Startup?
|
||||
RESET_CHAT="yes"
|
||||
|
||||
|
|
106
piratebox/piratebox/python_lib/diskusage.py
Normal file
106
piratebox/piratebox/python_lib/diskusage.py
Normal file
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Library to write the current disk usage
|
||||
|
||||
# Heavily Modified version the ShoutBox Library (psogen.py)
|
||||
|
||||
import os, re, datetime
|
||||
from psutil import disk_usage
|
||||
|
||||
htmlfilename = os.environ["DISK_GEN_HTMLFILE"]
|
||||
delay = 60*5 #In seconds
|
||||
|
||||
#--------------
|
||||
# Generates Shoutbox-HTML-Frame ...
|
||||
# Imports:
|
||||
# content - String containing preformatted data
|
||||
#--------------
|
||||
def generate_html(content):
|
||||
htmlstring = "<html><head><meta http-equiv='cache-control' content='no-cache'><meta name='GENERATOR' content='disk usage'><title>DiskUsage Data</title><body>"
|
||||
htmlstring += content
|
||||
htmlstring += "</body></html>"
|
||||
return htmlstring
|
||||
|
||||
def modification_date(filename):
|
||||
moddate = os.path.getmtime(filename)
|
||||
return datetime.datetime.fromtimestamp(moddate)
|
||||
|
||||
#--------------
|
||||
# Generates HTML Data based on given content and write it to static html file
|
||||
# Imports:
|
||||
# content - String containing preformatted data
|
||||
#--------------
|
||||
def generate_html_into_file(content):
|
||||
open(htmlfilename, 'w').close()
|
||||
htmlstring = generate_html ( content )
|
||||
htmlfile = open( htmlfilename , 'w' )
|
||||
htmlfile.truncate()
|
||||
htmlfile.write( htmlstring )
|
||||
htmlfile.close()
|
||||
|
||||
#--------------
|
||||
# Function for saving the disk usage to a file. Called by HTML-Form
|
||||
#--------------
|
||||
def get_usage(drive):
|
||||
|
||||
try:
|
||||
file_mod_time = modification_date(htmlfilename)
|
||||
except OSError:
|
||||
content = prepare_line(drive)
|
||||
generate_html_into_file(content)
|
||||
file_mod_time = modification_date(htmlfilename)
|
||||
|
||||
now = datetime.datetime.today()
|
||||
max_delay = datetime.timedelta(0,delay)
|
||||
age = now - file_mod_time
|
||||
|
||||
#Add delay.
|
||||
if age < max_delay:
|
||||
print "CRITICAL: {} modified {} minutes ago. Threshold set to {} minutes. Cannot update.".format(drive, age.seconds/60, max_delay.seconds/60)
|
||||
else:
|
||||
print "OK. File last modified {} minutes ago. Updating now...".format(age.seconds/60)
|
||||
content = prepare_line(drive)
|
||||
generate_html_into_file(content)
|
||||
|
||||
#--------------
|
||||
# Function for returning the amount of free space as an Integer
|
||||
#--------------
|
||||
def FreeSpace(drive):
|
||||
""" Return the FreeSape of a shared drive in bytes"""
|
||||
try:
|
||||
usage = disk_usage(drive)
|
||||
floatpercent = float(usage.used) / float(usage.total)
|
||||
percent = int(100*floatpercent)
|
||||
return percent
|
||||
except:
|
||||
return 0
|
||||
|
||||
|
||||
#--------------
|
||||
# Function which formats the about of freespace into a nice readable format
|
||||
#--------------
|
||||
def prepare_line (drive):
|
||||
data = str(FreeSpace(drive))
|
||||
# Trying to make it look like this:
|
||||
#<div class='progress'>
|
||||
# <div class='progress-bar' role='progressbar' aria-valuenow='15' aria-valuemin='0' aria-valuemax='100' style='width: 15%'>
|
||||
# <span class='sr-only'>15% Full</span>
|
||||
# </div>
|
||||
#</div>
|
||||
content = "<div class='progress'><div class='progress-bar' role='progressbar' aria-valuenow='" + data + "' aria-valuemin='0' aria-valuemax='100' style='width: " + data + "%'><span class='sr-only'>" + data + "% Full</span></div></div>"
|
||||
return content
|
||||
|
||||
#--------------
|
||||
# Generating static HTML File
|
||||
#--------------
|
||||
if __name__ == "__main__":
|
||||
|
||||
disk = "/opt/piratebox/share/Shared"
|
||||
|
||||
if os.path.exists(htmlfilename) != True:
|
||||
content = prepare_line(disk)
|
||||
generate_html_into_file(content)
|
||||
else:
|
||||
get_usage(disk)
|
||||
|
||||
print "Generated HTML-DiskUsage File."
|
45
piratebox/piratebox/python_lib/psutil.py
Normal file
45
piratebox/piratebox/python_lib/psutil.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Return disk usage statistics about the given path as a (total, used, free)
|
||||
namedtuple. Values are expressed in bytes.
|
||||
"""
|
||||
# Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
|
||||
# License: MIT
|
||||
|
||||
import os
|
||||
import collections
|
||||
|
||||
_ntuple_diskusage = collections.namedtuple('usage', 'total used free')
|
||||
|
||||
if hasattr(os, 'statvfs'): # POSIX
|
||||
def disk_usage(path):
|
||||
st = os.statvfs(path)
|
||||
free = st.f_bavail * st.f_frsize
|
||||
total = st.f_blocks * st.f_frsize
|
||||
used = (st.f_blocks - st.f_bfree) * st.f_frsize
|
||||
return _ntuple_diskusage(total, used, free)
|
||||
|
||||
elif os.name == 'nt': # Windows
|
||||
import ctypes
|
||||
import sys
|
||||
|
||||
def disk_usage(path):
|
||||
_, total, free = ctypes.c_ulonglong(), ctypes.c_ulonglong(), \
|
||||
ctypes.c_ulonglong()
|
||||
if sys.version_info >= (3,) or isinstance(path, unicode):
|
||||
fun = ctypes.windll.kernel32.GetDiskFreeSpaceExW
|
||||
else:
|
||||
fun = ctypes.windll.kernel32.GetDiskFreeSpaceExA
|
||||
ret = fun(path, ctypes.byref(_), ctypes.byref(total), ctypes.byref(free))
|
||||
if ret == 0:
|
||||
raise ctypes.WinError()
|
||||
used = total.value - free.value
|
||||
return _ntuple_diskusage(total.value, used, free.value)
|
||||
else:
|
||||
raise NotImplementedError("platform not supported")
|
||||
|
||||
disk_usage.__doc__ = __doc__
|
||||
|
||||
if __name__ == '__main__':
|
||||
print disk_usage(os.getcwd())
|
3
piratebox/piratebox/rpi/bin/starter.sh
Executable file
3
piratebox/piratebox/rpi/bin/starter.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
# Try to setup WiFi and if it succeeds, start the PirateBox
|
||||
/bin/sh -c /opt/piratebox/rpi/bin/wifi_detect.sh && /usr/bin/systemctl start piratebox
|
42
piratebox/piratebox/rpi/bin/usb_share.sh
Executable file
42
piratebox/piratebox/rpi/bin/usb_share.sh
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Find a vfat partition and configure it as an external share
|
||||
MOUNTPOINT="/mnt/usbshare"
|
||||
FS="vfat"
|
||||
UUIDS=$(blkid | grep "/dev/sd*.*TYPE=\"${FS}\"" | egrep -o " UUID=\"([a-zA-Z0-9-])*\"" | sed 's/ //g')
|
||||
|
||||
if [ $(echo "${UUIDS}" | wc -l) -gt 1 ]; then
|
||||
echo "You seem to have more than one valid ${FS} partition for a USB share:"
|
||||
echo "${UUIDS}\n"
|
||||
echo "Please make sure you have a USB thumb drive attached with a single ${FS} partition."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $(echo "${UUIDS}" | wc -l) -lt 1 ] || [[ $UUIDS == "" ]]; then
|
||||
echo "You seem to have no valid ${FS} partition for a USB share."
|
||||
echo "Please make sure you have a USB thumb drive attached with a single ${FS} partition."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
UUID=$(echo "${UUIDS}" | cut -f2 -d" " | sed s/"\""/""/g)
|
||||
grep "${UUID}" /etc/fstab > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Error: This disk is already configured as an USB share..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "## Adding USB share..."
|
||||
mkdir -p "${MOUNTPOINT}" > /dev/null
|
||||
echo "${UUID} ${MOUNTPOINT} vfat umask=0,noatime,rw,user,uid=nobody,gid=nogroup 0 0" >> /etc/fstab
|
||||
mount "${MOUNTPOINT}" > /dev/null
|
||||
|
||||
if [ $? == 0 ]; then
|
||||
echo "## Moving files..."
|
||||
mv /opt/piratebox/share "${MOUNTPOINT}/share" > /dev/null 2>&1
|
||||
ln -s "${MOUNTPOINT}/share" /opt/piratebox/share > /dev/null
|
||||
else
|
||||
echo "Error: Mounting file system failed, will not move files..."
|
||||
cat "/etc/fstab"
|
||||
fi
|
||||
|
||||
exit 0
|
42
piratebox/piratebox/rpi/bin/wifi_detect.sh
Executable file
42
piratebox/piratebox/rpi/bin/wifi_detect.sh
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Install the proper hostapd package and adjust the hostapd configuration
|
||||
# accordingly.
|
||||
|
||||
PACKAGE_PATH="/prebuild/hostapd"
|
||||
CONFIG_PATH="/opt/piratebox/conf/hostapd.conf"
|
||||
|
||||
# Check if we have an nl80211 enabled device with AP mode, then we are done
|
||||
if iw list | grep > /dev/null "* AP$"; then
|
||||
echo "Found nl80211 device capable of AP mode..."
|
||||
yes | pacman -U --needed "${PACKAGE_PATH}/hostapd-2"* > /dev/null
|
||||
sed -i 's/^#driver=nl80211/driver=nl80211/' "${CONFIG_PATH}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for r8188eu enabled device
|
||||
if dmesg | grep > /dev/null "r8188eu:"; then
|
||||
echo "Found r8188eu enabled device..."
|
||||
yes | pacman -U --needed "${PACKAGE_PATH}/hostapd-8188eu-"* > /dev/null
|
||||
sed -i 's/^driver=nl80211/#driver=nl80211/' "${CONFIG_PATH}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for rtl8192cu enabled device
|
||||
if dmesg | grep > /dev/null "rtl8192cu"; then
|
||||
echo "Found rtl8192cu enabled device..."
|
||||
yes | pacman -U --needed "${PACKAGE_PATH}/hostapd-8192cu-"* > /dev/null
|
||||
sed -i 's/^driver=nl80211/#driver=nl80211/' "${CONFIG_PATH}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Could not find an AP enabled WiFi card..."
|
||||
|
||||
# Try to connect to Wifi if wpa_supplicant.conf is available.
|
||||
if [ -f /boot/wpa_supplicant.conf ]; then
|
||||
echo "Found wpa_supplicant conf, trying to connect..."
|
||||
wpa_supplicant -iwlan0 -c /boot/wpa_supplicant.conf -B -D wext
|
||||
dhcpcd wlan0
|
||||
fi
|
||||
|
||||
exit 1
|
32
piratebox/piratebox/rpi/motd.txt
Normal file
32
piratebox/piratebox/rpi/motd.txt
Normal file
|
@ -0,0 +1,32 @@
|
|||
____________________.__ __ __________
|
||||
\______ \______ \__|___________ _/ |_ ____\______ \ _______ ___
|
||||
| _/| ___/ \_ __ \__ \\ __\/ __ \| | _// _ \ \/ /
|
||||
| | \| | | || | \// __ \| | \ ___/| | ( <_> > <
|
||||
|____|_ /|____| |__||__| (____ /__| \___ >______ /\____/__/\_ \
|
||||
\/ \/ \/ \/ \/
|
||||
|
||||
Website: http://piratebox.cc PirateBox Version: 1.0.7
|
||||
Forum: http://forum.piratebox.cc RPi Image Version: 1.0.7-1
|
||||
IRC: #piratebox irc.freenode.net Be open -- Share freely!
|
||||
|
||||
First Steps After Flashing
|
||||
1. Change password of alarm user
|
||||
> passwd
|
||||
2. Enable Fake-Timeservice
|
||||
2.1 Set date and time
|
||||
# Disable network time sync
|
||||
> sudo timedatectl set-ntp false
|
||||
# Set time to "Mon May 23 17:42:00" (Format: CCYYMMDD hhmm)
|
||||
> sudo date -s "20170523 1742"
|
||||
> cd /opt/piratebox && sudo ./bin/timesave.sh ./conf/piratebox.conf install
|
||||
2.2 Enable on startup
|
||||
> sudo systemctl enable timesave
|
||||
3. Enable the Kareha Image and Discussion Board
|
||||
> sudo /opt/piratebox/bin/board-autoconf.sh
|
||||
4. Enable USB thumb drive share
|
||||
> sudo /opt/piratebox/rpi/bin/usb_share.sh
|
||||
5. Enable UPnP Media Server
|
||||
> sudo cp /etc/minidlna.conf /etc/minidlna.conf.bkp
|
||||
> sudo cp /opt/piratebox/src/linux.example.minidlna.conf /etc/minidlna.conf
|
||||
> sudo systemctl start minidlna
|
||||
> sudo systemctl enable minidlna
|
1
piratebox/piratebox/rpi/udev/99-wifi.rules
Normal file
1
piratebox/piratebox/rpi/udev/99-wifi.rules
Normal file
|
@ -0,0 +1 @@
|
|||
KERNEL=="wlan*", RUN+="/bin/sh -c /opt/piratebox/rpi/bin/starter.sh"
|
|
@ -3,7 +3,7 @@ config minidlna config
|
|||
option port '8200'
|
||||
option interface 'br-lan'
|
||||
option friendly_name 'PirateBox DLNA'
|
||||
option db_dir '/var/run/minidlna'
|
||||
option db_dir '/opt/piratebox/share/minidlna'
|
||||
option log_dir '/var/log'
|
||||
option inotify '1'
|
||||
option enable_tivo '0'
|
||||
|
|
14
piratebox/piratebox/www/cgi-bin/diskwrite.py
Executable file
14
piratebox/piratebox/www/cgi-bin/diskwrite.py
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Disk Write
|
||||
# Writes the total freespace to an HTML file.
|
||||
|
||||
import cgi, datetime
|
||||
from diskusage import get_usage
|
||||
|
||||
|
||||
print "Content-type:text/html\r\n\r\n"
|
||||
|
||||
get_usage("/opt/piratebox/share/Shared/")
|
||||
|
||||
print """<html><body>ok</body></html>"""
|
|
@ -25,5 +25,6 @@ curdate = datetime.datetime.now()
|
|||
|
||||
process_form(rawname, rawdata, color)
|
||||
|
||||
print "Status:200\r\n\r\n"
|
||||
print """<html><body>ok</body></html>"""
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<title>PirateBox - Share Freely!</title>
|
||||
<script src="jquery.min.js"></script>
|
||||
<script src="scripts.js"></script>
|
||||
<link rel="stylesheet" href="jquery-ui.min.css">
|
||||
<script src="jquery-ui.min.js"></script>
|
||||
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
|
||||
</head>
|
||||
<body id="main-index">
|
||||
|
@ -48,6 +50,16 @@
|
|||
<h3><a href="/Shared">Browse Files -></a></h3>
|
||||
<div id="station"></div>
|
||||
</div>
|
||||
<div id="diskusagecard" class="card">
|
||||
<h2>Disk Usage</h2>
|
||||
<div id="diskusage"></div>
|
||||
<div id="refresh-diskusage">
|
||||
<form method="POST" name="diskusage" id="du_form" >
|
||||
<input class="button" type="submit" name="refresh" value="Refresh" id="du_form_button" title="Disk usage can only be refreshed every 5 minutes">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="main">
|
||||
|
@ -58,7 +70,7 @@
|
|||
<div id="shoutbox-input">
|
||||
<input class="nickname" type="text" name="name" value="Anonymous" placeholder="Nickname">
|
||||
<input class="message" type="text" name="data" placeholder="Message...">
|
||||
<input class="button" type="submit" name="submit" value="Send">
|
||||
<input class="button" type="submit" name="submit" value="Send" id="send-button">
|
||||
</div>
|
||||
<div id="shoutbox-options">
|
||||
<h3>Text Color:</h3>
|
||||
|
|
7
piratebox/piratebox/www/jquery-ui.min.css
vendored
Normal file
7
piratebox/piratebox/www/jquery-ui.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6
piratebox/piratebox/www/jquery-ui.min.js
vendored
Normal file
6
piratebox/piratebox/www/jquery-ui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -13,8 +13,18 @@ $(document).ready(function() {
|
|||
post_shoutbox();
|
||||
});
|
||||
|
||||
$("#du_form").submit(function(event) {
|
||||
/* stop form from submitting normally */
|
||||
event.preventDefault();
|
||||
post_diskusage();
|
||||
});
|
||||
|
||||
display_diskusage();
|
||||
display_shoutbox();
|
||||
|
||||
// Add Tooltips
|
||||
$('#du_form_button').tooltip();
|
||||
|
||||
// Spin menu icon and toggle nav
|
||||
$('#menu-icon').click(function() {
|
||||
$(this).toggleClass('rotate');
|
||||
|
@ -105,9 +115,14 @@ function refresh_time_sb () {
|
|||
}
|
||||
|
||||
function post_shoutbox () {
|
||||
$("#send-button").prop('value', 'Sending...');
|
||||
$("#send-button").prop('disabled', true);
|
||||
|
||||
$.post("/cgi-bin/psowrte.py" , $("#sb_form").serialize())
|
||||
.success(function() {
|
||||
refresh_shoutbox();
|
||||
$("#send-button").prop('value', 'Send')
|
||||
$("#send-button").prop('disabled', false);
|
||||
});
|
||||
$('#shoutbox-input .message').val('');
|
||||
}
|
||||
|
@ -117,6 +132,37 @@ function display_shoutbox() {
|
|||
refresh_time_sb();
|
||||
}
|
||||
|
||||
function refresh_diskusage() {
|
||||
$.get('diskusage.html', function(data) {
|
||||
$('div#diskusage').html(data);
|
||||
});
|
||||
}
|
||||
|
||||
function refresh_time_du () {
|
||||
// Refresh rate in milli seconds
|
||||
mytimedu=setTimeout('display_diskusage()', 10000);
|
||||
}
|
||||
|
||||
function post_diskusage() {
|
||||
$("#du_form_button").prop('value', 'Refreshing...');
|
||||
$("#du_form_button").prop('disabled', true);
|
||||
|
||||
$.post("/cgi-bin/diskwrite.py")
|
||||
.success(function() {
|
||||
refresh_diskusage();
|
||||
$("#du_form_button").prop('value', 'Refresh');
|
||||
$("#du_form_button").prop('disabled', false);
|
||||
});
|
||||
$('#diskusage-input .message').val('');
|
||||
|
||||
|
||||
}
|
||||
|
||||
function display_diskusage() {
|
||||
refresh_diskusage();
|
||||
refresh_time_du();
|
||||
}
|
||||
|
||||
function fnGetDomain(url) {
|
||||
return url.match(/:\/\/(.[^/]+)/)[1];
|
||||
}
|
||||
|
|
|
@ -352,3 +352,31 @@ input[type=radio] {
|
|||
display: table-cell;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Progress bar used from the Bootstrap Library:
|
||||
https://github.com/twbs/bootstrap
|
||||
|
||||
Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
.progress {
|
||||
height: 20px;
|
||||
margin-bottom: 20px;
|
||||
overflow: hidden;
|
||||
background-color: #F5F5F5;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1) inset;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
float: left;
|
||||
width: 0px;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
color: #FFF;
|
||||
text-align: center;
|
||||
background-color: #337AB7;
|
||||
box-shadow: 0px -1px 0px rgba(0, 0, 0, 0.15) inset;
|
||||
transition: width 0.6s ease 0s;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue