From 28110a19b933815b4f976c32390ef78a41cd4869 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 17 Jul 2016 13:07:06 +0100 Subject: [PATCH] Advertise zeronet ID services --- src/freedombone-image-mesh | 2 +- src/zeronetavahi | 61 +++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/freedombone-image-mesh b/src/freedombone-image-mesh index db60d8ab..0bee4815 100755 --- a/src/freedombone-image-mesh +++ b/src/freedombone-image-mesh @@ -363,7 +363,7 @@ function configure_zeronet_id { echo '' > /tmp/zeronet-id.service echo '' >> /tmp/zeronet-id.service echo '' >> /tmp/zeronet-id.service - echo ' %h ZeroID' >> /tmp/zeronet-id.service + echo ' %h ZeroNet ID Service' >> /tmp/zeronet-id.service echo ' ' >> /tmp/zeronet-id.service echo ' _zeronet._udp' >> /tmp/zeronet-id.service echo " $ZERONET_PORT" >> /tmp/zeronet-id.service diff --git a/src/zeronetavahi b/src/zeronetavahi index ad05fdf6..3ca73467 100755 --- a/src/zeronetavahi +++ b/src/zeronetavahi @@ -46,6 +46,7 @@ BLOGS_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-blogs MAIL_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-mail FORUM_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-fora TOX_USERS_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-tox-users +ID_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-id ZERONET_INDEX=$ZERONET_INSTALL/mesh.html ZERONET_CONFIG=$ZERONET_INSTALL/bootstrap @@ -54,14 +55,21 @@ IPFS_PORT=4001 MY_BLOG_STR=$"My Blog" MY_MAIL_STR=$"My Mail" MY_FORUM_STR=$"My Forum" +MY_ID_STR=$"My ID Service" + BLOGS_STR=$"Blogs" MAIL_STR=$"Mail" FORA_STR=$"Fora" -ZERONET_BLOG_STR=$"ZeroNet Blog" -ZERONET_MAIL_STR=$"ZeroNet Mail" -ZERONET_FORUM_STR=$"ZeroNet Forum" +TOX_STR=$"Tox Users" +ID_STR=$"ID Services" NO_USERS_STR=$"No users found" +# service names advertised by avahi +ZERONET_BLOG_STR="ZeroNet Blog" +ZERONET_MAIL_STR="ZeroNet Mail" +ZERONET_FORUM_STR="ZeroNet Forum" +ZERONET_ID_STR="ZeroNet ID Service" + # contains the output of the avahi command TEMPFILE_BASE=/tmp/tmpzeronetavahibase.txt TEMPFILE=/tmp/tmpzeronetavahi.txt @@ -128,10 +136,12 @@ function create_index { blogaddress=$(cat /home/$MY_USERNAME/.config/zeronet/myblog) mailaddress=$(cat /home/$MY_USERNAME/.config/zeronet/mymail) forumaddress=$(cat /home/$MY_USERNAME/.config/zeronet/myforum) + idaddress=$(cat /home/$MY_USERNAME/.config/zeronet/myzeroid) if [ -f $ZERONET_INDEX ]; then sed -i "s|.*${MY_BLOG_STR}.*|
  • ${MY_BLOG_STR}
  • |g" $ZERONET_INDEX sed -i "s|.*${MY_MAIL_STR}.*|
  • ${MY_MAIL_STR}
  • |g" $ZERONET_INDEX sed -i "s|.*${MY_FORUM_STR}.*|
  • ${MY_FORUM_STR}
  • |g" $ZERONET_INDEX + sed -i "s|.*${MY_ID_STR}.*|
  • ${MY_ID_STR}
  • |g" $ZERONET_INDEX return fi echo '' > $ZERONET_INDEX @@ -148,6 +158,7 @@ function create_index { echo "
  • ${MY_BLOG_STR}
  • " >> $ZERONET_INDEX echo "
  • ${MY_MAIL_STR}
  • " >> $ZERONET_INDEX echo "
  • ${MY_FORUM_STR}
  • " >> $ZERONET_INDEX + echo "
  • ${MY_ID_STR}
  • " >> $ZERONET_INDEX # echo "
  • File Share
  • " >> $ZERONET_INDEX echo '' >> $ZERONET_INDEX echo '' >> $ZERONET_INDEX @@ -157,7 +168,8 @@ function create_index { echo "
  • ${BLOGS_STR}
  • " >> $ZERONET_INDEX echo "
  • ${MAIL_STR}
  • " >> $ZERONET_INDEX echo "
  • ${FORA_STR}
  • " >> $ZERONET_INDEX - echo "
  • Tox Users
  • " >> $ZERONET_INDEX + echo "
  • ${ID_STR}
  • " >> $ZERONET_INDEX + echo "
  • ${TOX_STR}
  • " >> $ZERONET_INDEX echo '' >> $ZERONET_INDEX echo '' >> $ZERONET_INDEX echo '' >> $ZERONET_INDEX @@ -341,6 +353,44 @@ function zeronet_detect_fora { echo '
      ' >> $FORUM_FILE.new } +function zeronet_detect_id { + if [ -f $ID_FILE.new ]; then + rm -f $ID_FILE.new + fi + + cat $TEMPFILE_BASE | grep "${ZERONET_ID_STR}\|hostname =\|address =\|port =\|txt =" > $TEMPFILE + + state=0 + address="" + peer="" + echo '
        ' >> $ID_FILE.new + while IFS='' read -r line || [[ -n "$line" ]]; do + if [ ${state} -eq "3" ]; then + if [[ $line == *"txt ="* ]]; then + id_url=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}') + echo "
      1. ${peer}
      2. " >> $ID_FILE.new + 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_ID_STR}"* && $line == "= "* ]]; then + state=1 + fi + done < "$TEMPFILE" + echo '
      ' >> $ID_FILE.new +} + function avahi_remove_info { rm -f $TEMPFILE_BASE rm -f $TEMPFILE @@ -366,6 +416,7 @@ fi avahi_extract_info zeronet_detect +zeronet_detect_id zeronet_detect_blog zeronet_detect_mail zeronet_detect_fora @@ -375,6 +426,7 @@ avahi_remove_info zeronet_update_config # make some html headers and footers +create_header $ID_FILE $ID_STR create_header $BLOGS_FILE $BLOGS_STR create_header $MAIL_FILE $MAIL_STR create_header $FORUM_FILE $FORA_STR @@ -387,6 +439,7 @@ create_footer $TOX_USERS_FILE # make the index page create_index +assemble_web_page ${ID_FILE} $ZERONET_INSTALL assemble_web_page ${BLOGS_FILE} $ZERONET_INSTALL assemble_web_page ${MAIL_FILE} $ZERONET_INSTALL assemble_web_page ${FORUM_FILE} $ZERONET_INSTALL