From d1bba40c1bd59d88be7bc7be06ae3114721de39f Mon Sep 17 00:00:00 2001 From: milisarge Date: Wed, 28 Jun 2017 23:19:20 +0300 Subject: [PATCH] milisia-ag-sistemi --- bin/mas | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 bin/mas diff --git a/bin/mas b/bin/mas new file mode 100755 index 000000000..5307a5aea --- /dev/null +++ b/bin/mas @@ -0,0 +1,141 @@ +#! /bin/bash +# milisia ağ sistemi (mas) bash tabanlı konsol uygulaması. +# milisarge 2017 +surum="0.0.1" +surumbilgi=" 2017" +anayer="/opt/milisia" +servis="cjdroute" +servisk="cjdns" +pingkontrol="fcf4:e309:14b5:5498:cafd:4f59:4b9c:7f84" # hia.cjdns.ca +ayardosya="ayarlar/milisia_genel.conf" +noktadepo="noktalar" +nokta_adres="https://github.com/milisarge/$noktadepo" + +[ ! -d $anayer ] && mkdir -p $anayer +[ ! -d $anayer/ayarlar ] && mkdir -p $anayer/ayarlar +[ ! -c /dev/net/tun ] && aygit_ekle +[ ! -f /usr/bin/$servis ] && mps kur $servisk +[ ! -f /usr/bin/json ] && json_kur + +aygit_ekle(){ + mkdir -p /dev/net && + mknod /dev/net/tun c 10 200 && + chmod 0666 /dev/net/tun +} + +json_kur(){ + curl -L https://github.com/trentm/json/raw/master/lib/json.js > /usr/bin/json && chmod +x /usr/bin/json +} + +baslat(){ + cjdroute < $anayer/$ayardosya +} + +durdur(){ + echo "servis durduruluyor" + killall -9 cjdroute + echo "servis durduruldu" +} + +olustur(){ + if [ ! -f $anayer/$ayardosya ]; then + cjdroute --genconf | cjdroute --cleanconf > $anayer/$ayardosya + echo "ayar dosyası oluşturuldu" + else + echo "zaten ayar dosyası mevcut!" + echo "yeniden oluşturmak için --zo kullanın" + fi +} + +yeniden_olustur(){ + mv $anayer/$ayardosya $anayer/$ayardosya-"`date +%m-%d-%y.%H%M%S`" + cjdroute --genconf | cjdroute --cleanconf > $anayer/$ayardosya + echo "ayar dosyası oluşturuldu" +} + +genel_kimlik(){ + cat $anayer/$ayardosya | egrep -m 1 '"publicKey"' | awk -F '"' '{ print $4 }' +} + +ozel_kimlik(){ + cat $anayer/$ayardosya | egrep -m 1 '"privateKey"' | awk -F '"' '{ print $4 }' +} + +ipv6_al(){ + #grep -Eo '"ipv6" :.*?[^\\]",' $ayardosya | awk '{print $3}' ;; + #cat $ayardosya | json.js ipv6 + cat $anayer/$ayardosya | egrep -m 1 '"ipv6"' | awk -F '"' '{ print $4 }' +} + +nokta_ekle(){ + if [ ! -f $anayer/$ayardosya ]; then + olustur + fi + ipadres="`json -f $1 -Ma key | sed -n 1p`" + icerik="`json -f $1 -Ma value`" + json -I -f $anayer/$ayardosya -e 'this.interfaces.UDPInterface[0]["connectTo"]["'$ipadres'"]='"$icerik"' ' +} + +depo_guncelle(){ + if [ ! -d $anayer/$noktadepo ];then + git clone $nokta_adres $anayer/$noktadepo + else + cd $anayer/$noktadepo + git pull + cd - + fi +} + +rpc_sifre(){ + cat $anayer/$ayardosya | json admin.password + #cat $ayardosya | egrep -m 3 '"password"' | awk -F '"' '{ print $4 }' | sed -n 1p +} + +menu() { + + while [ "$1" ]; do + case $1 in + yeni|--o) + olustur ;; + zyeni|--zo) + yeniden_olustur ;; + basla|--b) + baslat ;; + yebas|--b) + durdur && baslat ;; + ping|--p) + ping6 $pingkontrol ;; + guncelle|--g) + depo_guncelle ;; + kimlik|--k) + genel_kimlik ;; + okimlik|--ok) + ozel_kimlik ;; + ip|--i) + ipv6_al ;; + ekle|--e) + if [ ! "$2" ]; then + echo "nokta ayar dosyası belirtin!" + exit 1 + fi + nokta_ekle $anayer/$noktadepo/$2 ;; + sil|--s) + if [ ! "$2" ]; then + echo "nokta ayar dosyası belirtin!" + exit 1 + fi + nokta_sil $anayer/$noktadepo/$2 ;; + rpcs|--rs) + rpc_sifre ;; + dur|--d) + durdur ;; + ekle|--e) + peer_ekle "$2" ;; + surum|--s) + echo "$surum $surumbilgi" ;; + esac + shift + done +} + +menu "$@"