Przeglądaj źródła

Create web index pages for mesh blogs and fora

Bob Mottram 9 lat temu
rodzic
commit
4fd7d55c5d
1 zmienionych plików z 74 dodań i 8 usunięć
  1. 74
    8
      src/zeronetavahi

+ 74
- 8
src/zeronetavahi Wyświetl plik

@@ -10,6 +10,9 @@
10 10
 #
11 11
 # A script for using avahi to discover peers and update zeronet trackers
12 12
 
13
+# Blogs and fora are discovered on the network and then published
14
+# to an index file which can be opened in a browser
15
+
13 16
 # License
14 17
 # =======
15 18
 #
@@ -28,6 +31,7 @@
28 31
 # You should have received a copy of the GNU General Public License
29 32
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 33
 
34
+WEB_PAGE_TITLE="Freedombone Mesh"
31 35
 TRACKER_PORT=6969
32 36
 ZERONET_INSTALL=/opt/zeronet
33 37
 
@@ -40,13 +44,60 @@ if [ ! -d $ZERONET_INSTALL ]; then
40 44
 fi
41 45
 
42 46
 BOOTSTRAP_FILE=$ZERONET_INSTALL/bootstrap
43
-BLOGS_FILE=$ZERONET_INSTALL/blogs
44
-FORUM_FILE=$ZERONET_INSTALL/forum
47
+BLOGS_FILE=$ZERONET_INSTALL/freedombone-blogs
48
+FORUM_FILE=$ZERONET_INSTALL/freedombone-fora
49
+ZERONET_INDEX=/home/$USER/mesh.html
50
+
51
+function create_index {
52
+    if [ -f $ZERONET_INDEX ]; then
53
+        return
54
+    fi
55
+    echo '<!DOCTYPE html>' > $ZERONET_INDEX
56
+    echo '<html>' >> $ZERONET_INDEX
57
+    echo '<head>' >> $ZERONET_INDEX
58
+    echo "<title>$WEB_PAGE_TITLE</title>" >> $ZERONET_INDEX
59
+    echo '</head>' >> $ZERONET_INDEX
60
+    echo '<body>' >> $ZERONET_INDEX
61
+    echo "<H1>$WEB_PAGE_TITLE</H1>" >> $ZERONET_INDEX
62
+    echo '' >> $ZERONET_INDEX
63
+    echo '<ol type="square">' >> $ZERONET_INDEX
64
+    echo "  <li><a href=\"${BLOGS_FILE}.html\">Blogs</a></li>" >> $ZERONET_INDEX
65
+    echo "  <li><a href=\"${FORUM_FILE}.html\">Fora</a></li>" >> $ZERONET_INDEX
66
+    echo '</ol>' >> $ZERONET_INDEX
67
+    echo '' >> $ZERONET_INDEX
68
+    echo '</body>' >> $ZERONET_INDEX
69
+    echo '</html>' >> $ZERONET_INDEX
70
+}
71
+
72
+function create_header {
73
+    header_file=${1}-header.html
74
+    if [ -f $header_file ]; then
75
+        return
76
+    fi
77
+    echo '<!DOCTYPE html>' > $header_file
78
+    echo '<html>' >> $header_file
79
+    echo '<head>' >> $header_file
80
+    echo "<title>$WEB_PAGE_TITLE - $2</title>" >> $header_file
81
+    echo '<meta http-equiv="refresh" content="60">' >> $header_file
82
+    echo '</head>' >> $header_file
83
+    echo '<body>' >> $header_file
84
+    echo "<H1>$2</H1>" >> $header_file
85
+}
86
+
87
+function create_footer {
88
+    footer_file=${1}-header.html
89
+    if [ -f $footer_file ]; then
90
+        return
91
+    fi
92
+    echo '</body>' >> $footer_file
93
+    echo '</html>' >> $footer_file
94
+}
45 95
 
46 96
 if [ ! -d /etc/avahi ]; then
47 97
     exit 0
48 98
 fi
49 99
 
100
+# Create a list of bootstrap nodes
50 101
 TEMPFILE_BASE=/tmp/tmpzeronetavahibase.txt
51 102
 TEMPFILE=/tmp/tmpzeronetavahi.txt
52 103
 avahi-browse -atr > $TEMPFILE_BASE
@@ -91,11 +142,12 @@ cat $TEMPFILE_BASE | grep "ZeroNet Blog\|hostname =\|address =\|port =\|txt-reco
91 142
 state=0
92 143
 address=""
93 144
 peer=""
145
+echo '<ol type="square">' >> $BLOGS_FILE.new
94 146
 while IFS='' read -r line || [[ -n "$line" ]]; do
95 147
     if [ ${state} -eq "3" ]; then
96 148
         if [[ $line == *"txt-record ="* ]]; then
97 149
             blog_url=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
98
-            echo "$peer $blog_url" >> $BLOGS_FILE.new
150
+            echo "  <li><a href=\"${blog_url}\">${peer}</a></li>" >> $BLOGS_FILE.new
99 151
             state=0
100 152
         fi
101 153
     fi
@@ -115,6 +167,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
115 167
         state=1
116 168
     fi
117 169
 done < "$TEMPFILE"
170
+echo '</ol>' >> $BLOGS_FILE.new
118 171
 
119 172
 # detect fora in the mesh
120 173
 if [ -f $FORUM_FILE.new ]; then
@@ -126,11 +179,12 @@ cat $TEMPFILE_BASE | grep "ZeroNet Forum\|hostname =\|address =\|port =\|txt-rec
126 179
 state=0
127 180
 address=""
128 181
 peer=""
182
+echo '<ol type="square">' >> $FORUM_FILE.new
129 183
 while IFS='' read -r line || [[ -n "$line" ]]; do
130 184
     if [ ${state} -eq "3" ]; then
131 185
         if [[ $line == *"txt-record ="* ]]; then
132 186
             forum_url=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
133
-            echo "$peer $forum_url" >> $FORUM_FILE.new
187
+            echo "  <li><a href=\"${forum_url}\">${peer}</a></li>" >> $FORUM_FILE.new
134 188
             state=0
135 189
         fi
136 190
     fi
@@ -150,6 +204,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
150 204
         state=1
151 205
     fi
152 206
 done < "$TEMPFILE"
207
+echo '<ol>' >> $FORUM_FILE.new
153 208
 
154 209
 rm -f $TEMPFILE_BASE
155 210
 rm -f $TEMPFILE
@@ -160,14 +215,25 @@ if [ -d /home/zeronet ]; then
160 215
     sudo chown zeronet:zeronet $BOOTSTRAP_FILE
161 216
 fi
162 217
 
163
-cp -f $BLOGS_FILE.new $BLOGS_FILE
164
-rm -f $BLOGS_FILE.new
218
+# make some html headers and footers
219
+create_header $BLOGS_FILE "Blogs"
220
+create_header $FORUM_FILE "Fora"
221
+create_footer $BLOGS_FILE
222
+create_footer $FORUM_FILE
223
+
224
+# make the index page
225
+create_index
226
+
227
+# create a web page showing the available blogs
228
+cat ${BLOGS_FILE}-header.html ${BLOGS_FILE}.new ${BLOGS_FILE}-footer.html > ${BLOGS_FILE}.html
229
+rm -f ${BLOGS_FILE}.new
165 230
 if [ -d /home/zeronet ]; then
166 231
     sudo chown zeronet:zeronet $BLOGS_FILE
167 232
 fi
168 233
 
169
-cp -f $FORUM_FILE.new $FORUM_FILE
170
-rm -f $FORUM_FILE.new
234
+# create a web page showing the available fora
235
+cat ${FORUM_FILE}-header.html ${FORUM_FILE}.new ${FORUM_FILE}-footer.html > ${FORUM_FILE}.html
236
+rm -f ${FORUM_FILE}.new
171 237
 if [ -d /home/zeronet ]; then
172 238
     sudo chown zeronet:zeronet $FORUM_FILE
173 239
 fi