From c1debe2a205e9d760ece4aaa8c7833945b267e58 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Sun, 4 Sep 2016 18:50:13 +0100
Subject: [PATCH] An easy way to visit ipfs mesh sites

---
 img/avatars/ipfs.jpg            | Bin 0 -> 1164 bytes
 src/freedombone-image-customise |  13 ++++++
 src/freedombone-mesh-visit-site |  79 ++++++++++++++++++++++++++++++++
 src/zeronetavahi                |   6 +--
 4 files changed, 93 insertions(+), 5 deletions(-)
 create mode 100644 img/avatars/ipfs.jpg
 create mode 100755 src/freedombone-mesh-visit-site

diff --git a/img/avatars/ipfs.jpg b/img/avatars/ipfs.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..cfd19a8e56115ac5304064d383419d11a56569b3
GIT binary patch
literal 1164
zcmex=<NpH&0WUXCHwH#VMg|WcWcYuZ!I^=Ni<_65laH5&SAd^SP)tQ!OhiOXM?q0a
z#YE5C%vjIJ$jUL;&C1r#&dA6k$<r?^A~r78!Zj^7H7X}KIyMqy2qV9MfS9nDmbkc9
zq_vTCB+20aAqGJX1_uTQW=25<CP7AKLB{__7$g}On3x$EkO3<bGYd#c9Owz4H;@4%
zGt>WD3_L&$OajaT3=E8p_Zh@3yRI!@R7o$&EbdsAwJ-aCOpHXF4%5Pv%ktLg%forg
zXUx@go$OQdcG}z+v$%w)Nup;BKW~e=Tby0=GAm@|&RgxJjmgu>?YPx81c2-U+N><V
zz{JGJ%*+b6n~{lug;_w*P{_zcK~c%T80ZQPpxYQ(nXVdcKJGMc0=G=)f&gWO#A(|u
z^ln}Mv+c^3Eq12IzNzLNQhVZGHal1MWAw?XyOj$pru|s^<V@tQqz#5UWXv2Eo5k(y
z-DQ-qE=(=quxjsO!{o2^KnKVGLkJiwNS<e85>#LiFbp&R+YFSlXS|tUAi1&L)I$E2
zdDiT@t7dms<xZQ}wb4nP>ln)c<>#Of6hsd}Mh69m2}~dpmYhDg8mLSO7?P|kj0oQX
z16Dv#k%?Ksph!r`FfbA7TQ+;92;m;~mDMgQ%>?YaQ|hd?L_J+}T_yQwM{xM!(uQMF
zGlkcK%>%{{FaTMYVd2NfAShs{=$NQb*tpOja3U=9>=n;Vbbs3!`18v(-p!|eypnd*
z>=d5<SukL^@&viWJ(=enb~<c$%Fwz%xz|8)b-~+;hD+Js=R5XV2xKJ3@A<_ez_xma
zZlA2sn<aAU;^iWfE-j0G`q5<JXO4H?#`}*0Z2_kg29PrZ7z`L#W;^gK_2=Pu%^&xg
zsl9aaswI;=RluPQbT2SS5y8#KU<eEV1xG|^3!H6{stkB-SFpQDtL8y@oXWYyZ}bnY
zjM$@pB<;f<tv4ML4$Koe%+tI0tK@6u=FdP=rGRmW5{2MURWL+^zrZYQPmzFYVi7+d
z*g0MNBz&~DU(Ea^P^+o{&_TfThe&|H05lX(bPOz9IPu~K1%t+o2jO8TaCJ7{8Q*z+
zZ1PJUM>k9ldwk)0qhsu1<;#b1#S2USGf2#BoM^aK!>=rL_UtV$dk*D2{nGS{(eo0^
zqJ>FuCLf=<+j_kJE@RjxIP009)AEk_=GXn@o$_Y)U05la`tou5*{_%O_ck1V#x7j3
z+*sw~<HY8vw*-@R_iPAb(J^^lzUFD-^c64HUpDhljcmRbr}cQ@?YI9K{@(-uTBdo#

literal 0
HcmV?d00001

diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise
index 568d6f71f..7f1461fa8 100755
--- a/src/freedombone-image-customise
+++ b/src/freedombone-image-customise
@@ -775,6 +775,16 @@ if [ \$no_of_users -gt 0 ]; then
     chmod +x /home/$MY_USERNAME/Desktop/Users.desktop
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/Users.desktop
 
+    if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
+        echo 'Type=Application' >> /home/$MY_USERNAME/Desktop/sites.desktop
+        echo 'Comment=Visit a site' >> /home/$MY_USERNAME/Desktop/sites.desktop
+        echo 'Exec=bash /usr/local/bin/freedombone-mesh-visit-site' >> /home/$MY_USERNAME/Desktop/sites.desktop
+        echo 'Icon=/usr/share/freedombone/avatars/ipfs.jpg' >> /home/$MY_USERNAME/Desktop/sites.desktop
+        echo 'StartupNotify=false' >> /home/$MY_USERNAME/Desktop/sites.desktop
+        chmod +x /home/$MY_USERNAME/Desktop/sites.desktop
+        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Desktop/sites.desktop
+    fi
+
     if [ ! -f /home/$MY_USERNAME/runtox ]; then
         echo 'qtox_running=\$(ps aux | grep qtox | grep data)' > /home/$MY_USERNAME/runtox
         echo 'if [ \${#qtox_running} -eq 0 ]; then' >> /home/$MY_USERNAME/runtox
@@ -801,6 +811,9 @@ else
         if [ -f /home/$MY_USERNAME/Desktop/Users.desktop ]; then
             rm /home/$MY_USERNAME/Desktop/Users.desktop
         fi
+        if [ -f /home/$MY_USERNAME/Desktop/sites.desktop ]; then
+            rm /home/$MY_USERNAME/Desktop/sites.desktop
+        fi
         if [ -f /home/$MY_USERNAME/Desktop/tox.desktop ]; then
             rm /home/$MY_USERNAME/Desktop/tox.desktop
         fi
diff --git a/src/freedombone-mesh-visit-site b/src/freedombone-mesh-visit-site
new file mode 100755
index 000000000..a23bb6454
--- /dev/null
+++ b/src/freedombone-mesh-visit-site
@@ -0,0 +1,79 @@
+#!/bin/bash
+#
+# .---.                  .              .
+# |                      |              |
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
+#
+#                    Freedom in the Cloud
+#
+# Visit ipfs sites by entering a username
+#
+# License
+# =======
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+PROJECT_NAME='freedombone'
+
+export TEXTDOMAIN=${PROJECT_NAME}-mesh-visit-site
+export TEXTDOMAINDIR="/usr/share/locale"
+
+IPFS_URL='http://127.0.0.1:8080/ipns'
+
+# The browser application to use
+BROWSER=iceweasel
+
+IPFS_USERS_FILE=/home/$USER/.ipfs-users
+if [ ! -f $IPFS_USERS_FILE ]; then
+    exit 0
+fi
+USERS_FILE=/home/$USER/Users.txt
+if [ ! -f $USERS_FILE ]; then
+    exit 0
+fi
+
+data=$(tempfile 2>/dev/null)
+trap "rm -f $data" 0 1 2 5 15
+dialog --title $"Visit IPFS site" \
+    --backtitle $"Freedombone mesh" \
+    --inputbox $"Enter the username for the site you wish to visit" 8 60 2>$data
+sel=$?
+case $sel in
+    0)
+        TOX_USERNAME=$(<$data)
+        if [ ${#TOX_USERNAME} -gt 0 ]; then
+            if ! grep -q "$TOX_USERNAME" $USERS_FILE; then
+                dialog --title $"Visit IPFS site" \
+                       --backtitle $"Freedombone mesh" \
+                       --msgbox $"The user '$TOX_USERNAME' was not found on the mesh" 8 60
+                exit 2
+            fi
+            TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME" | head -n 1 | awk -F ' ' '{print $2}')
+            if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
+                dialog --title $"Visit IPFS site" \
+                       --backtitle $"Freedombone mesh" \
+                       --msgbox $"An IPFS site was not found for the user '$TOX_USERNAME'" 8 60
+                exit 3
+            fi
+            IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
+            $BROWSER $IPFS_FULL_URL
+        else
+            exit 1
+        fi
+    ;;
+esac
+
+exit 0
diff --git a/src/zeronetavahi b/src/zeronetavahi
index 94f186414..e4345aea8 100755
--- a/src/zeronetavahi
+++ b/src/zeronetavahi
@@ -56,7 +56,6 @@ IPFS_PATH=/usr/bin
 IPFS_COMMAND=$IPFS_PATH/ipfs
 IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users
 IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
-IPFS_URL='http://127.0.0.1:8080/ipns'
 
 MY_BLOG_STR=$"My Blog"
 MY_MAIL_STR=$"My Mail"
@@ -133,10 +132,7 @@ function ipfs_bootstrap {
                 ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}')
                 $IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id}
                 if [ -d /home/$MY_USERNAME/Desktop ]; then
-                    if grep -q "$ipfs_tox_id" $TOX_USERS_FILE; then
-                        ipfs_tox_nick=$(cat $TOX_USERS_FILE | grep $ipfs_tox_id | awk -F ' ' '{print $1}')
-                        echo "$ipfs_tox_nick:${IPFS_URL}/$ipfs_peer_id" >> ${IPFS_USERS_FILE}.new
-                    fi
+                    echo "$ipfs_tox_id:$ipfs_peer_id" >> ${IPFS_USERS_FILE}.new
                 fi
                 state=0
             fi
-- 
GitLab