2015-08-29 17:26:51 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# A script for using avahi to discover peers and update zeronet trackers
|
|
|
|
|
2015-09-03 12:21:39 +02:00
|
|
|
# Blogs and fora are discovered on the network and then published
|
|
|
|
# to an index file which can be opened in a browser
|
|
|
|
|
2015-08-29 17:26:51 +02:00
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
|
|
|
|
#
|
|
|
|
# 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-09-03 12:21:39 +02:00
|
|
|
WEB_PAGE_TITLE="Freedombone Mesh"
|
2015-08-29 23:44:13 +02:00
|
|
|
TRACKER_PORT=6969
|
2015-09-03 10:18:26 +02:00
|
|
|
ZERONET_INSTALL=/opt/zeronet
|
2015-08-29 17:26:51 +02:00
|
|
|
|
2015-09-03 10:18:26 +02:00
|
|
|
if [ ! -d $ZERONET_INSTALL ]; then
|
|
|
|
if [ -d /home/$USER/zeronet ]; then
|
|
|
|
ZERONET_INSTALL=/home/$USER/zeronet
|
2015-08-29 18:48:43 +02:00
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
2015-08-29 17:26:51 +02:00
|
|
|
fi
|
|
|
|
|
2015-09-03 10:18:26 +02:00
|
|
|
BOOTSTRAP_FILE=$ZERONET_INSTALL/bootstrap
|
2015-09-03 12:21:39 +02:00
|
|
|
BLOGS_FILE=$ZERONET_INSTALL/freedombone-blogs
|
|
|
|
FORUM_FILE=$ZERONET_INSTALL/freedombone-fora
|
|
|
|
ZERONET_INDEX=/home/$USER/mesh.html
|
|
|
|
|
|
|
|
function create_index {
|
|
|
|
if [ -f $ZERONET_INDEX ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo '<!DOCTYPE html>' > $ZERONET_INDEX
|
|
|
|
echo '<html>' >> $ZERONET_INDEX
|
|
|
|
echo '<head>' >> $ZERONET_INDEX
|
|
|
|
echo "<title>$WEB_PAGE_TITLE</title>" >> $ZERONET_INDEX
|
|
|
|
echo '</head>' >> $ZERONET_INDEX
|
|
|
|
echo '<body>' >> $ZERONET_INDEX
|
|
|
|
echo "<H1>$WEB_PAGE_TITLE</H1>" >> $ZERONET_INDEX
|
|
|
|
echo '' >> $ZERONET_INDEX
|
|
|
|
echo '<ol type="square">' >> $ZERONET_INDEX
|
|
|
|
echo " <li><a href=\"${BLOGS_FILE}.html\">Blogs</a></li>" >> $ZERONET_INDEX
|
|
|
|
echo " <li><a href=\"${FORUM_FILE}.html\">Fora</a></li>" >> $ZERONET_INDEX
|
|
|
|
echo '</ol>' >> $ZERONET_INDEX
|
|
|
|
echo '' >> $ZERONET_INDEX
|
|
|
|
echo '</body>' >> $ZERONET_INDEX
|
|
|
|
echo '</html>' >> $ZERONET_INDEX
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_header {
|
|
|
|
header_file=${1}-header.html
|
|
|
|
if [ -f $header_file ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo '<!DOCTYPE html>' > $header_file
|
|
|
|
echo '<html>' >> $header_file
|
|
|
|
echo '<head>' >> $header_file
|
|
|
|
echo "<title>$WEB_PAGE_TITLE - $2</title>" >> $header_file
|
|
|
|
echo '<meta http-equiv="refresh" content="60">' >> $header_file
|
|
|
|
echo '</head>' >> $header_file
|
|
|
|
echo '<body>' >> $header_file
|
|
|
|
echo "<H1>$2</H1>" >> $header_file
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_footer {
|
|
|
|
footer_file=${1}-header.html
|
|
|
|
if [ -f $footer_file ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo '</body>' >> $footer_file
|
|
|
|
echo '</html>' >> $footer_file
|
|
|
|
}
|
2015-09-03 10:18:26 +02:00
|
|
|
|
2015-08-29 17:26:51 +02:00
|
|
|
if [ ! -d /etc/avahi ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-09-03 12:21:39 +02:00
|
|
|
# Create a list of bootstrap nodes
|
2015-09-02 23:50:45 +02:00
|
|
|
TEMPFILE_BASE=/tmp/tmpzeronetavahibase.txt
|
2015-08-29 17:26:51 +02:00
|
|
|
TEMPFILE=/tmp/tmpzeronetavahi.txt
|
2015-09-02 23:50:45 +02:00
|
|
|
avahi-browse -atr > $TEMPFILE_BASE
|
|
|
|
cat $TEMPFILE_BASE | grep "Workstation\|hostname =\|address =\|port =" > $TEMPFILE
|
2015-08-29 17:26:51 +02:00
|
|
|
if [ ! -f $TEMPFILE ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-09-02 23:50:45 +02:00
|
|
|
if [ -f $BOOTSTRAP_FILE.new ]; then
|
|
|
|
rm -f $BOOTSTRAP_FILE.new
|
|
|
|
fi
|
|
|
|
|
2015-08-29 17:26:51 +02:00
|
|
|
state=0
|
|
|
|
address=""
|
|
|
|
peer=""
|
|
|
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
|
|
|
if [ ${state} -eq "2" ]; then
|
|
|
|
if [[ $line == *"address ="* ]]; then
|
|
|
|
address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
2015-08-31 13:20:57 +02:00
|
|
|
echo "http $peer:$TRACKER_PORT/announce None" >> $BOOTSTRAP_FILE.new
|
2015-08-29 17:38:24 +02:00
|
|
|
state=0
|
2015-08-29 17:26:51 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ${state} -eq "1" ]; then
|
|
|
|
if [[ $line == *"hostname ="* ]]; then
|
|
|
|
peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
|
|
state=2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ $line == *"Workstation"* && $line == "= "* ]]; then
|
|
|
|
state=1
|
|
|
|
fi
|
|
|
|
done < "$TEMPFILE"
|
|
|
|
|
2015-09-02 23:50:45 +02:00
|
|
|
# detect blogs in the mesh
|
|
|
|
if [ -f $BLOGS_FILE.new ]; then
|
|
|
|
rm -f $BLOGS_FILE.new
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat $TEMPFILE_BASE | grep "ZeroNet Blog\|hostname =\|address =\|port =\|txt-record =" > $TEMPFILE
|
|
|
|
|
|
|
|
state=0
|
|
|
|
address=""
|
|
|
|
peer=""
|
2015-09-03 12:21:39 +02:00
|
|
|
echo '<ol type="square">' >> $BLOGS_FILE.new
|
2015-09-02 23:50:45 +02:00
|
|
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
|
|
|
if [ ${state} -eq "3" ]; then
|
|
|
|
if [[ $line == *"txt-record ="* ]]; then
|
|
|
|
blog_url=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
2015-09-03 12:21:39 +02:00
|
|
|
echo " <li><a href=\"${blog_url}\">${peer}</a></li>" >> $BLOGS_FILE.new
|
2015-09-02 23:50:45 +02:00
|
|
|
state=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ${state} -eq "2" ]; then
|
|
|
|
if [[ $line == *"address ="* ]]; then
|
|
|
|
address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
|
|
state=3
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ${state} -eq "1" ]; then
|
|
|
|
if [[ $line == *"hostname ="* ]]; then
|
|
|
|
peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
|
|
state=2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ $line == *"ZeroNet Blog"* && $line == "= "* ]]; then
|
|
|
|
state=1
|
|
|
|
fi
|
|
|
|
done < "$TEMPFILE"
|
2015-09-03 12:21:39 +02:00
|
|
|
echo '</ol>' >> $BLOGS_FILE.new
|
2015-09-02 23:50:45 +02:00
|
|
|
|
|
|
|
# detect fora in the mesh
|
|
|
|
if [ -f $FORUM_FILE.new ]; then
|
|
|
|
rm -f $FORUM_FILE.new
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat $TEMPFILE_BASE | grep "ZeroNet Forum\|hostname =\|address =\|port =\|txt-record =" > $TEMPFILE
|
|
|
|
|
|
|
|
state=0
|
|
|
|
address=""
|
|
|
|
peer=""
|
2015-09-03 12:21:39 +02:00
|
|
|
echo '<ol type="square">' >> $FORUM_FILE.new
|
2015-09-02 23:50:45 +02:00
|
|
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
|
|
|
if [ ${state} -eq "3" ]; then
|
|
|
|
if [[ $line == *"txt-record ="* ]]; then
|
|
|
|
forum_url=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
2015-09-03 12:21:39 +02:00
|
|
|
echo " <li><a href=\"${forum_url}\">${peer}</a></li>" >> $FORUM_FILE.new
|
2015-09-02 23:50:45 +02:00
|
|
|
state=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ${state} -eq "2" ]; then
|
|
|
|
if [[ $line == *"address ="* ]]; then
|
|
|
|
address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
|
|
state=3
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ ${state} -eq "1" ]; then
|
|
|
|
if [[ $line == *"hostname ="* ]]; then
|
|
|
|
peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
|
|
state=2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ $line == *"ZeroNet Forum"* && $line == "= "* ]]; then
|
|
|
|
state=1
|
|
|
|
fi
|
|
|
|
done < "$TEMPFILE"
|
2015-09-03 12:21:39 +02:00
|
|
|
echo '<ol>' >> $FORUM_FILE.new
|
2015-09-02 23:50:45 +02:00
|
|
|
|
|
|
|
rm -f $TEMPFILE_BASE
|
2015-08-29 17:26:51 +02:00
|
|
|
rm -f $TEMPFILE
|
2015-09-02 23:50:45 +02:00
|
|
|
|
2015-08-29 17:26:51 +02:00
|
|
|
cp -f $BOOTSTRAP_FILE.new $BOOTSTRAP_FILE
|
|
|
|
rm -f $BOOTSTRAP_FILE.new
|
2015-08-31 13:20:57 +02:00
|
|
|
if [ -d /home/zeronet ]; then
|
|
|
|
sudo chown zeronet:zeronet $BOOTSTRAP_FILE
|
|
|
|
fi
|
2015-08-29 17:26:51 +02:00
|
|
|
|
2015-09-03 12:21:39 +02:00
|
|
|
# make some html headers and footers
|
|
|
|
create_header $BLOGS_FILE "Blogs"
|
|
|
|
create_header $FORUM_FILE "Fora"
|
|
|
|
create_footer $BLOGS_FILE
|
|
|
|
create_footer $FORUM_FILE
|
|
|
|
|
|
|
|
# make the index page
|
|
|
|
create_index
|
|
|
|
|
|
|
|
# create a web page showing the available blogs
|
|
|
|
cat ${BLOGS_FILE}-header.html ${BLOGS_FILE}.new ${BLOGS_FILE}-footer.html > ${BLOGS_FILE}.html
|
|
|
|
rm -f ${BLOGS_FILE}.new
|
2015-09-02 23:50:45 +02:00
|
|
|
if [ -d /home/zeronet ]; then
|
|
|
|
sudo chown zeronet:zeronet $BLOGS_FILE
|
|
|
|
fi
|
|
|
|
|
2015-09-03 12:21:39 +02:00
|
|
|
# create a web page showing the available fora
|
|
|
|
cat ${FORUM_FILE}-header.html ${FORUM_FILE}.new ${FORUM_FILE}-footer.html > ${FORUM_FILE}.html
|
|
|
|
rm -f ${FORUM_FILE}.new
|
2015-09-02 23:50:45 +02:00
|
|
|
if [ -d /home/zeronet ]; then
|
|
|
|
sudo chown zeronet:zeronet $FORUM_FILE
|
|
|
|
fi
|
|
|
|
|
2015-08-29 17:26:51 +02:00
|
|
|
exit 0
|