freedombone-controlpanel 70KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Administrator control panel for the Freedombone system
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-controlpanel
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
  34. SELECTED_USERNAME=
  35. SIP_CONFIGURATION_FILE=/etc/sipwitch.conf
  36. ADMIN_USER=
  37. UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
  38. UPDATE_DATE_SCRIPT=/usr/bin/updatedate
  39. # Minimum number of characters in a password
  40. MINIMUM_PASSWORD_LENGTH=8
  41. # voip
  42. VOIP_PORT=64738
  43. VOIP_ONION_PORT=8095
  44. SSH_PORT=2222
  45. IRC_PORT=6697
  46. IRC_ONION_PORT=8093
  47. # outgoing SMTP proxy
  48. SMTP_PROXY_ENABLE=$'no'
  49. SMTP_PROXY_PROTOCOL='smtps'
  50. SMTP_PROXY_SERVER='mail.myispdomain'
  51. SMTP_PROXY_PORT=465
  52. SMTP_PROXY_USERNAME=''
  53. SMTP_PROXY_PASSWORD=''
  54. USB_DRIVE=sdb
  55. # get default USB from config file
  56. CONFIGURATION_FILE=/root/${PROJECT_NAME}.cfg
  57. if [ -f $CONFIGURATION_FILE ]; then
  58. if grep -q "USB_DRIVE=" $CONFIGURATION_FILE; then
  59. USB_DRIVE=$(cat $CONFIGURATION_FILE | grep "USB_DRIVE=" | awk -F '=' '{print $2}')
  60. if [[ $USB_DRIVE == *"dev"* ]]; then
  61. USB_DRIVE=$(echo ${USB_DRIVE} | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g')
  62. fi
  63. fi
  64. if grep -q "SSH_PORT=" $CONFIGURATION_FILE; then
  65. SSH_PORT=$(cat $CONFIGURATION_FILE | grep "SSH_PORT=" | awk -F '=' '{print $2}')
  66. fi
  67. if grep -q "IRC_PORT=" $CONFIGURATION_FILE; then
  68. IRC_PORT=$(cat $CONFIGURATION_FILE | grep "IRC_PORT=" | awk -F '=' '{print $2}')
  69. fi
  70. if grep -q "SMTP_PROXY_ENABLE=" $CONFIGURATION_FILE; then
  71. SMTP_PROXY_ENABLE=$(cat $CONFIGURATION_FILE | grep "SMTP_PROXY_ENABLE=" | awk -F '=' '{print $2}')
  72. fi
  73. if grep -q "SMTP_PROXY_PROTOCOL=" $CONFIGURATION_FILE; then
  74. SMTP_PROXY_PROTOCOL=$(cat $CONFIGURATION_FILE | grep "SMTP_PROXY_PROTOCOL=" | awk -F '=' '{print $2}')
  75. fi
  76. if grep -q "SMTP_PROXY_SERVER=" $CONFIGURATION_FILE; then
  77. SMTP_PROXY_SERVER=$(cat $CONFIGURATION_FILE | grep "SMTP_PROXY_SERVER=" | awk -F '=' '{print $2}')
  78. fi
  79. if grep -q "SMTP_PROXY_PORT=" $CONFIGURATION_FILE; then
  80. SMTP_PROXY_PORT=$(cat $CONFIGURATION_FILE | grep "SMTP_PROXY_PORT=" | awk -F '=' '{print $2}')
  81. fi
  82. if grep -q "SMTP_PROXY_USERNAME=" $CONFIGURATION_FILE; then
  83. SMTP_PROXY_USERNAME=$(cat $CONFIGURATION_FILE | grep "SMTP_PROXY_USERNAME=" | awk -F '=' '{print $2}')
  84. fi
  85. if grep -q "SMTP_PROXY_PASSWORD=" $CONFIGURATION_FILE; then
  86. SMTP_PROXY_PASSWORD=$(cat $CONFIGURATION_FILE | grep "SMTP_PROXY_PASSWORD=" | awk -F '=' '{print $2}')
  87. fi
  88. fi
  89. # Mirrors settings
  90. FRIENDS_MIRRORS_SERVER=
  91. FRIENDS_MIRRORS_SSH_PORT=2222
  92. FRIENDS_MIRRORS_PASSWORD=
  93. MY_MIRRORS_PASSWORD=
  94. function any_key {
  95. echo ' '
  96. read -n1 -r -p $"Press any key to continue..." key
  97. }
  98. function check_for_updates {
  99. if [ ! -f /etc/cron.weekly/$UPGRADE_SCRIPT_NAME ]; then
  100. dialog --title $"Check for updates" \
  101. --msgbox $"Upgrade script was not found" 6 40
  102. return
  103. fi
  104. clear
  105. . /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
  106. any_key
  107. }
  108. function read_repo_servers {
  109. if [ -f $CONFIGURATION_FILE ]; then
  110. if grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
  111. FRIENDS_MIRRORS_SERVER=$(grep "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  112. fi
  113. if grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then
  114. FRIENDS_MIRRORS_SSH_PORT=$(grep "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  115. fi
  116. if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  117. MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  118. fi
  119. if grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  120. FRIENDS_MIRRORS_PASSWORD=$(grep "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  121. fi
  122. fi
  123. if [ ! $FRIENDS_MIRRORS_SERVER ]; then
  124. return
  125. fi
  126. if [ ${#FRIENDS_MIRRORS_SERVER} -lt 2 ]; then
  127. return
  128. fi
  129. MAIN_COMMAND=/usr/local/bin/${PROJECT_NAME}
  130. if [ ! -f $MAIN_COMMAND ]; then
  131. MAIN_COMMAND=/usr/bin/${PROJECT_NAME}
  132. fi
  133. REPOS=($(cat ${MAIN_COMMAND} | grep "_REPO=\"" | uniq -u | sed 's|${PROJECT_NAME}|'"${PROJECT_NAME}"'|g'))
  134. for line in "${REPOS[@]}"
  135. do
  136. repo_name=$(echo "$line" | awk -F '=' '{print $1}')
  137. mirrors_name=$(echo "$repo_name" | sed "s|_REPO||g" | awk '{print tolower($0)}')
  138. friends_repo_url="ssh://mirrors@${FRIENDS_MIRRORS_SERVER}:${FRIENDS_MIRRORS_SSH_PORT}/home/mirrors/${mirrors_name}"
  139. ${repo_name}="${friends_repo_url}"
  140. done
  141. }
  142. function set_main_repo {
  143. data=$(tempfile 2>/dev/null)
  144. trap "rm -f $data" 0 1 2 5 15
  145. dialog --backtitle $"Freedombone Control Panel" \
  146. --title $"Main Repository (Mirrors)" \
  147. --form $"If you do not wish to use the default repositories they can be obtained from mirrors on another ${PROJECT_NAME} server." 14 60 3 \
  148. $"URL:" 1 1 "$FRIENDS_MIRRORS_SERVER" 1 14 40 15 \
  149. $"SSH Port:" 2 1 "$FRIENDS_MIRRORS_SSH_PORT" 2 14 40 10000 \
  150. $"Password:" 3 1 "$FRIENDS_MIRRORS_PASSWORD" 3 14 40 10000 \
  151. 2> $data
  152. sel=$?
  153. case $sel in
  154. 1) return;;
  155. 255) return;;
  156. esac
  157. new_mirrors_url=$(cat $data | sed -n 1p)
  158. new_mirrors_ssh_port=$(cat $data | sed -n 2p)
  159. new_mirrors_password=$(cat $data | sed -n 3p)
  160. if [ ${#new_mirrors_url} -lt 2 ]; then
  161. return
  162. fi
  163. if [ ${#new_mirrors_ssh_port} -lt 1 ]; then
  164. return
  165. fi
  166. if [ ${#new_mirrors_password} -lt 10 ]; then
  167. dialog --title $"Main Repository" \
  168. --msgbox $'Mirrors password was too short. Should be at least 10 characters.' 6 40
  169. return
  170. fi
  171. if [[ $new_mirrors_url == *"."* ]]; then
  172. FRIENDS_MIRRORS_SERVER=$new_mirrors_url
  173. FRIENDS_MIRRORS_SSH_PORT=$new_mirrors_ssh_port
  174. FRIENDS_MIRRORS_PASSWORD=$new_mirrors_password
  175. if ! grep -q "FRIENDS_MIRRORS_SERVER" $CONFIGURATION_FILE; then
  176. echo "FRIENDS_MIRRORS_SERVER=$FRIENDS_MIRRORS_SERVER" >> $CONFIGURATION_FILE
  177. else
  178. sed -i "s|FRIENDS_MIRRORS_SERVER=.*|FRIENDS_MIRRORS_SERVER=$FRIENDS_MIRRORS_SERVER|g" $CONFIGURATION_FILE
  179. fi
  180. if ! grep -q "FRIENDS_MIRRORS_SSH_PORT" $CONFIGURATION_FILE; then
  181. echo "FRIENDS_MIRRORS_SSH_PORT=$FRIENDS_MIRRORS_SSH_PORT" >> $CONFIGURATION_FILE
  182. else
  183. sed -i "s|FRIENDS_MIRRORS_SSH_PORT=.*|FRIENDS_MIRRORS_SSH_PORT=$FRIENDS_MIRRORS_SSH_PORT|g" $CONFIGURATION_FILE
  184. fi
  185. if ! grep -q "FRIENDS_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  186. echo "FRIENDS_MIRRORS_PASSWORD=$FRIENDS_MIRRORS_PASSWORD" >> $CONFIGURATION_FILE
  187. else
  188. sed -i "s|FRIENDS_MIRRORS_PASSWORD=.*|FRIENDS_MIRRORS_PASSWORD=$FRIENDS_MIRRORS_PASSWORD|g" $CONFIGURATION_FILE
  189. fi
  190. # re-read the repos
  191. read_repo_servers
  192. dialog --title $"Main Repository" \
  193. --msgbox $"Main repository set to $FRIENDS_MIRRORS_SERVER" 6 60
  194. fi
  195. }
  196. function add_user {
  197. data=$(tempfile 2>/dev/null)
  198. trap "rm -f $data" 0 1 2 5 15
  199. dialog --backtitle $"Freedombone Control Panel" \
  200. --title $"Add new user" \
  201. --form "\n" 8 60 3 \
  202. $"Username:" 1 1 "" 1 28 16 15 \
  203. $"ssh public key (optional):" 2 1 "" 2 28 40 10000 \
  204. 2> $data
  205. sel=$?
  206. case $sel in
  207. 1) return;;
  208. 255) return;;
  209. esac
  210. new_user_username=$(cat $data | sed -n 1p)
  211. new_user_ssh_public_key=$(cat $data | sed -n 2p)
  212. if [ ${#new_user_username} -lt 2 ]; then
  213. dialog --title $"New username" \
  214. --msgbox $"No username was given" 6 40
  215. return
  216. fi
  217. if [[ "$new_user_username" == *" "* ]]; then
  218. dialog --title $"Invalid username" \
  219. --msgbox $"The username should not contain any spaces" 6 40
  220. return
  221. fi
  222. if [ ${#new_user_ssh_public_key} -lt 20 ]; then
  223. clear
  224. ${PROJECT_NAME}-adduser "$new_user_username"
  225. any_key
  226. else
  227. if [[ "$new_user_ssh_public_key" == "ssh-"* ]]; then
  228. clear
  229. ${PROJECT_NAME}-adduser "$new_user_username" "$new_user_ssh_public_key"
  230. any_key
  231. else
  232. dialog --title $"ssh public key" \
  233. --msgbox $"This does not look like an ssh public key" 6 40
  234. fi
  235. fi
  236. }
  237. function pad_string {
  238. echo -n -e "$1" | sed -e :a -e 's/^.\{1,25\}$/& /;ta'
  239. }
  240. function show_domains {
  241. DEFAULT_DOMAIN_NAME=$(cat $CONFIGURATION_FILE | grep "DEFAULT_DOMAIN_NAME=" | awk -F '=' '{print $2}')
  242. echo 'Domains'
  243. echo '======='
  244. echo ''
  245. echo -n -e "$(pad_string 'Name')"
  246. echo -n -e "$(pad_string 'ICANN')"
  247. echo -n -e "$(pad_string 'Tor')"
  248. echo ''
  249. echo '--------------------------------------------------------------------------'
  250. if grep -q "ssh onion domain" $COMPLETION_FILE; then
  251. echo -n -e "$(pad_string 'ssh')"
  252. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  253. echo "$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')"
  254. fi
  255. if grep -q "Email onion domain" $COMPLETION_FILE; then
  256. echo -n -e "$(pad_string 'Email')"
  257. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  258. echo "$(cat ${COMPLETION_FILE} | grep 'Email onion domain' | awk -F ':' '{print $2}')"
  259. fi
  260. if grep -q "XMPP onion domain" $COMPLETION_FILE; then
  261. echo -n -e "$(pad_string 'XMPP')"
  262. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  263. echo "$(cat ${COMPLETION_FILE} | grep 'XMPP onion domain' | awk -F ':' '{print $2}')"
  264. fi
  265. if grep -q "VoIP onion domain" $COMPLETION_FILE; then
  266. echo -n -e "$(pad_string 'VoIP/Mumble')"
  267. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  268. echo "$(cat ${COMPLETION_FILE} | grep 'VoIP onion domain' | awk -F ':' '{print $2}')"
  269. fi
  270. if grep -q "SIP onion domain" $COMPLETION_FILE; then
  271. echo -n -e "$(pad_string 'SIP')"
  272. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  273. echo "$(cat ${COMPLETION_FILE} | grep 'SIP onion domain' | awk -F ':' '{print $2}')"
  274. fi
  275. if grep -q "IRC onion domain" $COMPLETION_FILE; then
  276. echo -n -e "$(pad_string 'IRC')"
  277. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  278. echo "$(cat ${COMPLETION_FILE} | grep 'IRC onion domain' | awk -F ':' '{print $2}')"
  279. fi
  280. if grep -q "tox onion domain" $COMPLETION_FILE; then
  281. echo -n -e "$(pad_string 'Tox')"
  282. echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
  283. echo "$(cat ${COMPLETION_FILE} | grep 'tox onion domain' | awk -F ':' '{print $2}')"
  284. fi
  285. if grep -q "Wiki domain" $COMPLETION_FILE; then
  286. echo -n -e "$(pad_string 'Wiki')"
  287. WIKIDOM=$(cat ${COMPLETION_FILE} | grep 'Wiki domain' | awk -F ':' '{print $2}')
  288. echo -n -e "$(pad_string ${WIKIDOM})"
  289. if [ -d /var/lib/tor/hidden_service_wiki ]; then
  290. echo -n "$(cat /var/lib/tor/hidden_service_wiki/hostname)"
  291. fi
  292. echo ''
  293. fi
  294. if grep -q "Hubzilla domain" $COMPLETION_FILE; then
  295. echo -n -e "$(pad_string 'Hubzilla')"
  296. HUBZILLADOM=$(cat ${COMPLETION_FILE} | grep 'Hubzilla domain' | awk -F ':' '{print $2}')
  297. echo -n -e "$(pad_string ${HUBZILLADOM})"
  298. if [ -d /var/lib/tor/hidden_service_hubzilla ]; then
  299. echo -n "$(cat /var/lib/tor/hidden_service_hubzilla/hostname)"
  300. fi
  301. echo ''
  302. fi
  303. if grep -q "Blog domain" $COMPLETION_FILE; then
  304. echo -n -e "$(pad_string 'Blog')"
  305. BLOGDOM=$(cat ${COMPLETION_FILE} | grep 'Blog domain' | awk -F ':' '{print $2}')
  306. echo -n -e "$(pad_string ${BLOGDOM})"
  307. if [ -d /var/lib/tor/hidden_service_blog ]; then
  308. echo -n "$(cat /var/lib/tor/hidden_service_blog/hostname)"
  309. fi
  310. echo ''
  311. fi
  312. if grep -q "GNU Social domain" $COMPLETION_FILE; then
  313. echo -n -e "$(pad_string 'GNU Social')"
  314. GNUSOCIALDOM=$(cat ${COMPLETION_FILE} | grep 'GNU Social domain' | awk -F ':' '{print $2}')
  315. echo -n -e "$(pad_string ${GNUSOCIALDOM})"
  316. if [ -d /var/lib/tor/hidden_service_microblog ]; then
  317. echo -n "$(cat /var/lib/tor/hidden_service_microblog/hostname)"
  318. fi
  319. echo ''
  320. fi
  321. if grep -q "Owncloud domain" $COMPLETION_FILE; then
  322. echo -n -e "$(pad_string 'Owncloud')"
  323. OWNCLOUDDOM=$(cat ${COMPLETION_FILE} | grep 'Owncloud domain' | awk -F ':' '{print $2}')
  324. echo -n -e "$(pad_string ${OWNCLOUDDOM})"
  325. if [ -d /var/lib/tor/hidden_service_owncloud ]; then
  326. echo -n "$(cat /var/lib/tor/hidden_service_owncloud/hostname)"
  327. fi
  328. echo ''
  329. fi
  330. if grep -q "Gogs domain" $COMPLETION_FILE; then
  331. echo -n -e "$(pad_string 'Gogs')"
  332. GOGSDOM=$(cat ${COMPLETION_FILE} | grep 'Gogs domain' | awk -F ':' '{print $2}')
  333. echo -n -e "$(pad_string ${GOGSDOM})"
  334. if [ -d /var/lib/tor/hidden_service_gogs ]; then
  335. echo -n "$(cat /var/lib/tor/hidden_service_gogs/hostname)"
  336. fi
  337. echo ''
  338. fi
  339. if grep -q "RSS reader domain" $COMPLETION_FILE; then
  340. if [ -d /var/lib/tor/hidden_service_ttrss ]; then
  341. echo -n -e "$(pad_string 'RSS reader')"
  342. RSSDOM='-'
  343. echo -n -e "$(pad_string ${RSSDOM})"
  344. echo -n "$(cat /var/lib/tor/hidden_service_ttrss/hostname)"
  345. echo ''
  346. fi
  347. if [ -d /var/lib/tor/hidden_service_ttrss_mobile ]; then
  348. echo -n -e "$(pad_string 'RSS mobile')"
  349. RSSMOBILEDOM='-'
  350. echo -n -e "$(pad_string ${RSSMOBILEDOM})"
  351. echo -n "$(cat /var/lib/tor/hidden_service_ttrss_mobile/hostname)"
  352. echo ''
  353. fi
  354. fi
  355. if grep -q "Search engine onion domain" $COMPLETION_FILE; then
  356. echo -n -e "$(pad_string 'Search engine')"
  357. SEARCHDOM='-'
  358. echo -n -e "$(pad_string ${SEARCHDOM})"
  359. if [ -d /var/lib/tor/hidden_service_searx ]; then
  360. echo -n "$(cat /var/lib/tor/hidden_service_searx/hostname)"
  361. fi
  362. echo ''
  363. fi
  364. if grep -q "Mediagoblin domain" $COMPLETION_FILE; then
  365. echo -n -e "$(pad_string 'Mediagoblin')"
  366. MEDIADOM=$(cat ${COMPLETION_FILE} | grep 'Mediagoblin domain' | awk -F ':' '{print $2}')
  367. echo -n -e "$(pad_string ${MEDIADOM})"
  368. if [ -d /var/lib/tor/hidden_service_mediagoblin ]; then
  369. echo -n "$(cat /var/lib/tor/hidden_service_mediagoblin/hostname)"
  370. fi
  371. echo ''
  372. fi
  373. echo ''
  374. }
  375. function show_users {
  376. echo 'Users'
  377. echo '====='
  378. echo ''
  379. echo -n -e "$(pad_string 'Name')"
  380. echo -n -e "$(pad_string 'SIP ext')"
  381. echo -n -e "$(pad_string 'Data')"
  382. echo ''
  383. echo '--------------------------------------------------------------------------'
  384. for d in /home/*/ ; do
  385. USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
  386. if [[ $USRNAME != "git" && $USRNAME != "mirrors" ]]; then
  387. echo -n -e "$(pad_string ${USRNAME})"
  388. # get the SIP extension
  389. SIPEXT=
  390. while read ext; do
  391. if [[ $ext == *"user id"* ]]; then
  392. CURR_UID=$(echo "$ext" | awk -F '"' '{print $2}' | awk -F '"' '{print $1}')
  393. fi
  394. if [[ $ext == *"extension"* ]]; then
  395. if [[ $CURR_UID == $USRNAME ]]; then
  396. SIPEXT=$(echo "$ext" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
  397. fi
  398. fi
  399. done < $SIP_CONFIGURATION_FILE
  400. if [ $SIPEXT ]; then
  401. echo -n -e "$(pad_string SIP:${SIPEXT})"
  402. else
  403. echo -n -e "$(pad_string '')"
  404. fi
  405. # size of the home directory
  406. echo "$(du -s -h /home/${USRNAME} | awk -F ' ' '{print $1}')"
  407. fi
  408. done
  409. echo ''
  410. }
  411. function show_mirrors_password {
  412. if [ ! /home/mirrors ]; then
  413. return
  414. fi
  415. if grep -q "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE; then
  416. MY_MIRRORS_PASSWORD=$(grep "MY_MIRRORS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
  417. fi
  418. echo 'Local Mirrors'
  419. echo '============='
  420. echo ''
  421. echo -n "URL: "
  422. echo "$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')"
  423. echo "SSH Port: $SSH_PORT"
  424. echo "Password: $MY_MIRRORS_PASSWORD"
  425. echo ''
  426. }
  427. function show_about {
  428. clear
  429. show_domains
  430. show_mirrors_password
  431. show_users
  432. any_key
  433. }
  434. function select_user {
  435. SELECTED_USERNAME=
  436. users_array=($(ls /home))
  437. delete=(mirrors git)
  438. for del in ${delete[@]}
  439. do
  440. users_array=(${users_array[@]/$del})
  441. done
  442. i=0
  443. W=()
  444. name=()
  445. for u in ${users_array[@]}
  446. do
  447. i=$((i+1))
  448. W+=($i "$u")
  449. name+=("$u")
  450. done
  451. user_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select User" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
  452. if [ $? -eq 0 ]; then
  453. SELECTED_USERNAME="${name[$((user_index-1))]}"
  454. fi
  455. }
  456. function smtp_proxy {
  457. MUTTRC_FILE=/home/$ADMIN_USER/.muttrc
  458. if [ ! -f $MUTTRC_FILE ]; then
  459. return
  460. fi
  461. data=$(tempfile 2>/dev/null)
  462. trap "rm -f $data" 0 1 2 5 15
  463. dialog --backtitle $"Freedombone Control Panel" \
  464. --title $"SMTP Proxy for $ADMIN_USER" \
  465. --form $"You may need to proxy outgoing email via your ISP's mail server. If so enter the details below." 14 75 6 \
  466. $"Enable proxy:" 1 1 "$SMTP_PROXY_ENABLE" 1 24 5 5 \
  467. $"Protocol (smtp/smtps):" 2 1 "$SMTP_PROXY_PROTOCOL" 2 24 5 5 \
  468. $"ISP mail server:" 3 1 "$SMTP_PROXY_SERVER" 3 24 40 10000 \
  469. $"Port:" 4 1 "$SMTP_PROXY_PORT" 4 24 5 5 \
  470. $"Username:" 5 1 "$SMTP_PROXY_USERNAME" 5 24 40 10000 \
  471. $"Password:" 6 1 "$SMTP_PROXY_PASSWORD" 6 24 40 10000 \
  472. 2> $data
  473. sel=$?
  474. case $sel in
  475. 1) return;;
  476. 255) return;;
  477. esac
  478. SMTP_PROXY_ENABLE=$(cat $data | sed -n 1p)
  479. SMTP_PROXY_PROTOCOL=$(cat $data | sed -n 2p)
  480. SMTP_PROXY_SERVER=$(cat $data | sed -n 3p)
  481. SMTP_PROXY_PORT=$(cat $data | sed -n 4p)
  482. SMTP_PROXY_USERNAME=$(cat $data | sed -n 5p)
  483. SMTP_PROXY_PASSWORD=$(cat $data | sed -n 6p)
  484. # change muttrc
  485. if [ $SMTP_PROXY_ENABLE != $'no' ]; then
  486. if ! grep "set smtp_url" $MUTTRC_FILE; then
  487. echo "set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"" >> $MUTTRC_FILE
  488. else
  489. sed -i "s|set smtp_url=.*|set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"|g" $MUTTRC_FILE
  490. fi
  491. sed -i 's|#set smtp_url|set smtp_url|g' $MUTTRC_FILE
  492. else
  493. if grep "set smtp_url" $MUTTRC_FILE; then
  494. sed -i 's|set smtp_url|#set smtp_url|g' $MUTTRC_FILE
  495. fi
  496. fi
  497. # save settings within the main configuration file
  498. if ! grep -q "SMTP_PROXY_ENABLE=" $CONFIGURATION_FILE; then
  499. echo "SMTP_PROXY_ENABLE=$SMTP_PROXY_ENABLE" >> $CONFIGURATION_FILE
  500. else
  501. sed -i "s|SMTP_PROXY_ENABLE=.*|SMTP_PROXY_ENABLE=$SMTP_PROXY_ENABLE|g" $CONFIGURATION_FILE
  502. fi
  503. if ! grep -q "SMTP_PROXY_PROTOCOL=" $CONFIGURATION_FILE; then
  504. echo "SMTP_PROXY_PROTOCOL=$SMTP_PROXY_PROTOCOL" >> $CONFIGURATION_FILE
  505. else
  506. sed -i "s|SMTP_PROXY_PROTOCOL=.*|SMTP_PROXY_PROTOCOL=$SMTP_PROXY_PROTOCOL|g" $CONFIGURATION_FILE
  507. fi
  508. if ! grep -q "SMTP_PROXY_SERVER=" $CONFIGURATION_FILE; then
  509. echo "SMTP_PROXY_SERVER=$SMTP_PROXY_SERVER" >> $CONFIGURATION_FILE
  510. else
  511. sed -i "s|SMTP_PROXY_SERVER=.*|SMTP_PROXY_SERVER=$SMTP_PROXY_SERVER|g" $CONFIGURATION_FILE
  512. fi
  513. if ! grep -q "SMTP_PROXY_PORT=" $CONFIGURATION_FILE; then
  514. echo "SMTP_PROXY_PORT=$SMTP_PROXY_PORT" >> $CONFIGURATION_FILE
  515. else
  516. sed -i "s|SMTP_PROXY_PORT=.*|SMTP_PROXY_PORT=$SMTP_PROXY_PORT|g" $CONFIGURATION_FILE
  517. fi
  518. if ! grep -q "SMTP_PROXY_USERNAME=" $CONFIGURATION_FILE; then
  519. echo "SMTP_PROXY_USERNAME=$SMTP_PROXY_USERNAME" >> $CONFIGURATION_FILE
  520. else
  521. sed -i "s|SMTP_PROXY_USERNAME=.*|SMTP_PROXY_USERNAME=$SMTP_PROXY_USERNAME|g" $CONFIGURATION_FILE
  522. fi
  523. if ! grep -q "SMTP_PROXY_PASSWORD=" $CONFIGURATION_FILE; then
  524. echo "SMTP_PROXY_PASSWORD=$SMTP_PROXY_PASSWORD" >> $CONFIGURATION_FILE
  525. else
  526. sed -i "s|SMTP_PROXY_PASSWORD=.*|SMTP_PROXY_PASSWORD=$SMTP_PROXY_PASSWORD|g" $CONFIGURATION_FILE
  527. fi
  528. }
  529. function delete_user {
  530. select_user
  531. if [ ! $SELECTED_USERNAME ]; then
  532. return
  533. fi
  534. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  535. dialog --title $"Administrator user" \
  536. --msgbox $"You can't delete the administrator user" 6 40
  537. return
  538. fi
  539. clear
  540. ${PROJECT_NAME}-rmuser $SELECTED_USERNAME
  541. any_key
  542. }
  543. function configure_remote_backups {
  544. if ! grep -Fxq "Admin user:$ADMIN_USER" $COMPLETION_FILE; then
  545. dialog --title $"Administrator user" \
  546. --msgbox $"No Administrator user found. Check $COMPLETION_FILE" 6 40
  547. return
  548. fi
  549. if [ ${#ADMIN_USER} -lt 2 ]; then
  550. dialog --title $"Administrator user" \
  551. --msgbox $"Username not found" 6 40
  552. return
  553. fi
  554. if [ ! -d /home/$ADMIN_USER ]; then
  555. dialog --title $"Administrator user" \
  556. --msgbox $"Home directory not found" 6 40
  557. return
  558. fi
  559. ${PROJECT_NAME}-remote -u $ADMIN_USER
  560. if [ ! "$?" = "0" ]; then
  561. any_key
  562. fi
  563. }
  564. function change_password {
  565. select_user
  566. if [ ! $SELECTED_USERNAME ]; then
  567. return
  568. fi
  569. dialog --title $"Change password" \
  570. --passwordbox $"New password for user $SELECTED_USERNAME" 8 40 2> $data
  571. newpassword=$(<$data)
  572. if [ ${#newpassword} -lt ${MINIMUM_PASSWORD_LENGTH} ]; then
  573. dialog --title $"Change password" \
  574. --msgbox $"The password should be ${MINIMUM_PASSWORD_LENGTH} or more characters" 6 40
  575. return
  576. fi
  577. echo "$SELECTED_USERNAME:$newpassword"|chpasswd
  578. dialog --title $"Change password" \
  579. --msgbox $"Password for $SELECTED_USERNAME was changed" 6 40
  580. }
  581. function irc_set_global_password {
  582. dialog --title $"IRC Password" \
  583. --clear \
  584. --backtitle $"Freedombone Control Panel" \
  585. --passwordbox $"Password for all IRC users, or press Enter for no password" 10 50 2> $data
  586. sel=$?
  587. case $sel in
  588. 0)
  589. NEW_IRC_PASSWORD=$(<$data)
  590. sed -i "0,/RE/s/Password =.*/Password =$NEW_IRC_PASSWORD/" /etc/ngircd/ngircd.conf
  591. dialog --title $"IRC Password" \
  592. --msgbox $"The IRC password was changed" 6 40
  593. systemctl restart ngircd
  594. ;;
  595. esac
  596. }
  597. function change_blog_avatar {
  598. data=$(tempfile 2>/dev/null)
  599. trap "rm -f $data" 0 1 2 5 15
  600. dialog --title $"Change blog avatar" \
  601. --backtitle $"Freedombone Control Panel" \
  602. --inputbox $"Enter a URL for an image. It should be approximately a square image." 8 75 2>$data
  603. sel=$?
  604. case $sel in
  605. 0)
  606. IMAGE_URL=$(<$data)
  607. if [ ${#IMAGE_URL} -gt 5 ]; then
  608. clear
  609. ${PROJECT_NAME}-blog -a $IMAGE_URL
  610. if [ "$?" = "0" ]; then
  611. dialog --title $"Change blog avatar" \
  612. --msgbox $"Your blog avatar has been changed" 6 40
  613. fi
  614. fi
  615. ;;
  616. esac
  617. }
  618. function change_ssh_public_key {
  619. select_user
  620. if [ ! $SELECTED_USERNAME ]; then
  621. return
  622. fi
  623. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  624. dialog --title $"Change ssh public key" \
  625. --backtitle $"Freedombone Control Panel" \
  626. --defaultno \
  627. --yesno $"\nThis is the administrator user.\n\nAre you sure you want to change the ssh public key for the administrator?" 10 60
  628. sel=$?
  629. case $sel in
  630. 1) return;;
  631. 255) return;;
  632. esac
  633. fi
  634. data=$(tempfile 2>/dev/null)
  635. trap "rm -f $data" 0 1 2 5 15
  636. dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
  637. --backtitle $"Freedombone Control Panel" \
  638. --inputbox $"Paste the ssh public key below" 8 60 2>$data
  639. sel=$?
  640. case $sel in
  641. 0)
  642. SSH_PUBLIC_KEY=$(<$data)
  643. if [ "$SSH_PUBLIC_KEY" ]; then
  644. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  645. if [ -f "$SSH_PUBLIC_KEY" ]; then
  646. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  647. mkdir /home/$SELECTED_USERNAME/.ssh
  648. fi
  649. cp $SSH_PUBLIC_KEY \
  650. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  651. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  652. /home/$SELECTED_USERNAME/.ssh
  653. dialog --title $"Change ssh public key" \
  654. --msgbox $"ssh public key was installed" 6 40
  655. else
  656. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  657. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  658. mkdir /home/$SELECTED_USERNAME/.ssh
  659. fi
  660. echo "$SSH_PUBLIC_KEY" > \
  661. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  662. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  663. /home/$SELECTED_USERNAME/.ssh
  664. dialog --title $"Change ssh public key" \
  665. --msgbox $"ssh public key was installed" 6 40
  666. fi
  667. fi
  668. fi
  669. fi
  670. ;;
  671. esac
  672. }
  673. function irc_via_onion {
  674. dialog --title $"IRC Server" \
  675. --backtitle $"Freedombone Control Panel" \
  676. --defaultno \
  677. --yesno $"\nAccess the IRC server via an onion address?" 8 60
  678. sel=$?
  679. irc_onion='no'
  680. case $sel in
  681. 0) irc_onion='yes';;
  682. 255) return;;
  683. esac
  684. if [[ $irc_onion == 'no' ]]; then
  685. if grep -q ";Ports = 6667" /etc/ngircd/ngircd.conf; then
  686. sed -i "s/;Ports =.*/;Ports = $IRC_PORT, $IRC_ONION_PORT/1" /etc/ngircd/ngircd.conf
  687. else
  688. if ! grep -q ";Ports = $IRC_PORT, $IRC_ONION_PORT" /etc/ngircd/ngircd.conf; then
  689. sed -i "s/Ports = $IRC_PORT, $IRC_ONION_PORT/;Ports = $IRC_PORT, $IRC_ONION_PORT/1" /etc/ngircd/ngircd.conf
  690. fi
  691. fi
  692. systemctl restart ngircd
  693. dialog --title $"IRC Server" \
  694. --msgbox $"The IRC server can now be accessed via SSL at your main domain name" 8 50
  695. else
  696. if grep -q ";Ports = $IRC_PORT, $IRC_ONION_PORT" /etc/ngircd/ngircd.conf; then
  697. sed -i "s/;Ports =.*/Ports = $IRC_PORT, $IRC_ONION_PORT/1" /etc/ngircd/ngircd.conf
  698. systemctl restart ngircd
  699. fi
  700. dialog --title $"IRC Server" \
  701. --msgbox $"The IRC server can now be accessed via its onion address without SSL" 8 50
  702. fi
  703. }
  704. function remove_user_from_mailing_list {
  705. select_user
  706. if [ ! $SELECTED_USERNAME ]; then
  707. return
  708. fi
  709. USER_MAILING_LISTS=$(cat "/home/$SELECTED_USERNAME/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
  710. i=0
  711. W=()
  712. list_name=()
  713. while read -r listname; do
  714. i=$((i+1))
  715. W+=($i "$listname")
  716. list_name+=("$listname")
  717. echo $listname
  718. done <<< "$USER_MAILING_LISTS"
  719. i=$((i+1))
  720. W+=($i $"Exit back to user mainenance")
  721. list_selected=$(dialog --default-item "$i" --backtitle $"Freedombone Control Panel" --title $"Remove a mailing list for $SELECTED_USERNAME" --menu $"Select one of the following:" 24 50 17 "${W[@]}" 3>&2 2>&1 1>&3)
  722. if [ $? -eq 0 ]; then # Exit with OK
  723. if [ ${list_selected} -ne ${i} ]; then
  724. remove_list_name="${list_name[$((list_selected-1))]}"
  725. # find the line number where the list is defined
  726. line_number=0
  727. i=0
  728. while read -r line
  729. do
  730. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  731. line_number=${i}
  732. fi
  733. i=$((i+1))
  734. done < "/home/$SELECTED_USERNAME/.procmailrc"
  735. if [ ${line_number} -eq 0 ]; then
  736. # no match was found
  737. return
  738. fi
  739. # recreate the file
  740. if [ -f /home/${SELECTED_USERNAME}/.procmailrc_new ]; then
  741. rm /home/${SELECTED_USERNAME}/.procmailrc_new
  742. fi
  743. i=0
  744. clip=0
  745. while read -r line
  746. do
  747. i=$((i+1))
  748. if [ ${i} -gt $((line_number-1)) ]; then
  749. if [ ${clip} -eq 0 ]; then
  750. clip=1
  751. fi
  752. if [ ${clip} -eq 1 ]; then
  753. if [ ${i} -lt $((line_number+2)) ]; then
  754. continue
  755. else
  756. if [ ${#line} -lt 1 ]; then
  757. clip=2
  758. continue
  759. fi
  760. if [[ "$line" == ":"* || "$line" == "#"* ]]; then
  761. clip=2
  762. else
  763. continue
  764. fi
  765. fi
  766. fi
  767. fi
  768. echo "$line" >> /home/${SELECTED_USERNAME}/.procmailrc_new
  769. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  770. line_number=${i}
  771. fi
  772. done < "/home/$SELECTED_USERNAME/.procmailrc"
  773. cp /home/${SELECTED_USERNAME}/.procmailrc_new /home/${SELECTED_USERNAME}/.procmailrc
  774. rm /home/${SELECTED_USERNAME}/.procmailrc_new
  775. chown ${SELECTED_USERNAME}:${SELECTED_USERNAME} /home/${SELECTED_USERNAME}/.procmailrc
  776. dialog --title $"Remove user from mailing list" \
  777. --msgbox $"${SELECTED_USERNAME} has been removed from ${remove_list_name}" 6 50
  778. fi
  779. fi
  780. }
  781. function add_to_mailing_list {
  782. select_user
  783. if [ ! $SELECTED_USERNAME ]; then
  784. return
  785. fi
  786. data=$(tempfile 2>/dev/null)
  787. trap "rm -f $data" 0 1 2 5 15
  788. dialog --backtitle $"Freedombone Control Panel" \
  789. --title $"Subscribe $SELECTED_USERNAME to a mailing list" \
  790. --form $"You can either enter a subject or an email address\n" 11 68 4 \
  791. $"List folder name:" 1 1 "" 1 35 26 25 \
  792. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  793. $"List email address:" 3 1 "" 3 35 26 25 \
  794. $"Public:" 4 1 $"yes" 4 35 4 25 \
  795. 2> $data
  796. sel=$?
  797. case $sel in
  798. 1) return;;
  799. 255) return;;
  800. esac
  801. LIST_NAME=$(cat $data | sed -n 1p)
  802. LIST_SUBJECT=$(cat $data | sed -n 2p)
  803. LIST_EMAIL=$(cat $data | sed -n 3p)
  804. LIST_PUBLIC=$(cat $data | sed -n 4p)
  805. if [ ${#LIST_PUBLIC} -lt 1 ]; then
  806. LIST_PUBLIC='no'
  807. fi
  808. if [[ $LIST_PUBLIC == $'y' || $LIST_PUBLIC == $'Y' || $LIST_PUBLIC == $'true' || $LIST_PUBLIC == $'True' || $LIST_PUBLIC == $'yes' || $LIST_PUBLIC == $'Yes' || $LIST_PUBLIC == $'YES' ]]; then
  809. LIST_PUBLIC='yes'
  810. else
  811. LIST_PUBLIC='no'
  812. fi
  813. if [ ${#LIST_NAME} -lt 2 ]; then
  814. dialog --title $"Add mailing list" \
  815. --msgbox $"No mailing list name was given" 6 40
  816. return
  817. fi
  818. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  819. if [ ${#LIST_EMAIL} -lt 2 ]; then
  820. dialog --title $"Add mailing list" \
  821. --msgbox $"No mailing list subject or address was given" 6 40
  822. return
  823. fi
  824. fi
  825. if [ ${#LIST_SUBJECT} -gt 1 ]; then
  826. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  827. -s "$LIST_SUBJECT" --public $LIST_PUBLIC
  828. else
  829. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  830. dialog --title $"Add mailing list" \
  831. --msgbox $"Unrecognised email address" 6 40
  832. return
  833. else
  834. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  835. -e "$LIST_EMAIL" --public $LIST_PUBLIC
  836. fi
  837. fi
  838. dialog --title $"Add mailing list" \
  839. --msgbox $"$LIST_NAME list was added" 6 40
  840. }
  841. function email_rule {
  842. select_user
  843. if [ ! $SELECTED_USERNAME ]; then
  844. return
  845. fi
  846. data=$(tempfile 2>/dev/null)
  847. trap "rm -f $data" 0 1 2 5 15
  848. dialog --backtitle $"Freedombone Control Panel" \
  849. --title $"Email rule for user $SELECTED_USERNAME" \
  850. --form "\n" 9 65 4 \
  851. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  852. $"Move to folder:" 2 1 "" 2 35 24 28 \
  853. $"Public:" 3 1 $"no" 3 35 4 25 \
  854. 2> $data
  855. sel=$?
  856. case $sel in
  857. 1) return;;
  858. 255) return;;
  859. esac
  860. RULE_EMAIL=$(cat $data | sed -n 1p)
  861. RULE_FOLDER=$(cat $data | sed -n 2p)
  862. RULE_PUBLIC=$(cat $data | sed -n 3p)
  863. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  864. RULE_PUBLIC='no'
  865. fi
  866. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  867. RULE_PUBLIC='yes'
  868. else
  869. RULE_PUBLIC='no'
  870. fi
  871. if [ ${#RULE_EMAIL} -lt 2 ]; then
  872. dialog --title $"Add email rule" \
  873. --msgbox $"No email address was given" 6 40
  874. return
  875. fi
  876. if [ ${#RULE_FOLDER} -lt 2 ]; then
  877. dialog --title $"Add email rule" \
  878. --msgbox $"No folder name was given" 6 40
  879. return
  880. fi
  881. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  882. dialog --title $"Add email rule" \
  883. --msgbox $"Unrecognised email address" 6 40
  884. return
  885. fi
  886. ${PROJECT_NAME}-addemail -u $SELECTED_USERNAME -e "$RULE_EMAIL" \
  887. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  888. dialog --title $"Add email rule" \
  889. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  890. }
  891. function block_unblock_email {
  892. select_user
  893. if [ ! $SELECTED_USERNAME ]; then
  894. return
  895. fi
  896. blockstr=$"Block/Unblock email going to"
  897. data=$(tempfile 2>/dev/null)
  898. trap "rm -f $data" 0 1 2 5 15
  899. dialog --backtitle $"Freedombone Control Panel" \
  900. --title "$blockstr $SELECTED_USERNAME" \
  901. --form "\n" 8 65 3 \
  902. $"When email arrives from address:" 1 1 "" 1 35 24 100 \
  903. $"Block it:" 2 1 "yes" 2 35 4 4 \
  904. 2> $data
  905. sel=$?
  906. case $sel in
  907. 1) return;;
  908. 255) return;;
  909. esac
  910. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  911. BLOCK=$(cat $data | sed -n 2p)
  912. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  913. dialog --title $"Block/Unblock an email" \
  914. --msgbox $"No email address was given" 6 40
  915. return
  916. fi
  917. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  918. dialog --title $"Block/Unblock an email" \
  919. --msgbox $"Unrecognised email address" 6 40
  920. return
  921. fi
  922. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  923. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  924. dialog --title $"Block an email" \
  925. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME blocked" 6 75
  926. else
  927. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  928. dialog --title $"Unblock an email" \
  929. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME unblocked" 6 75
  930. fi
  931. }
  932. function block_unblock_subject {
  933. select_user
  934. if [ ! $SELECTED_USERNAME ]; then
  935. return
  936. fi
  937. blockstr=$"Block/Unblock email going to"
  938. data=$(tempfile 2>/dev/null)
  939. trap "rm -f $data" 0 1 2 5 15
  940. dialog --backtitle $"Freedombone Control Panel" \
  941. --title "$blockstr $SELECTED_USERNAME" \
  942. --form "\n" 8 70 3 \
  943. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  944. $"Block it:" 2 1 "yes" 2 40 4 4 \
  945. 2> $data
  946. sel=$?
  947. case $sel in
  948. 1) return;;
  949. 255) return;;
  950. esac
  951. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  952. BLOCK=$(cat $data | sed -n 2p)
  953. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  954. dialog --title $"Block/Unblock an email" \
  955. --msgbox $"No subject was given" 6 40
  956. return
  957. fi
  958. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  959. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  960. dialog --title $"Block an email" \
  961. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME blocked" 6 40
  962. else
  963. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  964. dialog --title $"Unblock an email" \
  965. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME unblocked" 6 40
  966. fi
  967. }
  968. function create_keydrive_master {
  969. select_user
  970. if [ ! $SELECTED_USERNAME ]; then
  971. return
  972. fi
  973. dialog --title $"USB Master Keydrive" \
  974. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  975. clear
  976. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME --master 'yes'
  977. any_key
  978. }
  979. function create_keydrive_fragment {
  980. select_user
  981. if [ ! $SELECTED_USERNAME ]; then
  982. return
  983. fi
  984. dialog --title $"USB Fragment Keydrive" \
  985. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  986. clear
  987. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME
  988. any_key
  989. }
  990. function backup_data {
  991. dialog --title $"Backup data to USB" \
  992. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  993. clear
  994. echo ' '
  995. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  996. ${PROJECT_NAME}-backup-local
  997. any_key
  998. }
  999. function restore_from_usb {
  1000. while true
  1001. do
  1002. data=$(tempfile 2>/dev/null)
  1003. trap "rm -f $data" 0 1 2 5 15
  1004. dialog --backtitle $"Freedombone Control Panel" \
  1005. --title $"Restore from USB backup" \
  1006. --radiolist $"Choose an application to restore:" 32 70 28 \
  1007. 1 $"Everything" off \
  1008. 2 $"Return to the backup and restore menu" on \
  1009. 3 $"Configuration files" off \
  1010. 4 $"MariaDB settings" off \
  1011. 5 $"Let's Encrypt account" off \
  1012. 6 $"Mutt email client settings" off \
  1013. 7 $"GPG keys" off \
  1014. 8 $"Email processing rules" off \
  1015. 9 $"Spam filtering rules" off \
  1016. 10 $"Administrator's README file" off \
  1017. 11 $"IPFS" off \
  1018. 12 $"SSH keys" off \
  1019. 13 $"User configuration files" off \
  1020. 14 $"User local files" off \
  1021. 15 $"User fin files" off \
  1022. 16 $"SSL/TLS certificates" off \
  1023. 17 $"Personal settings" off \
  1024. 18 $"Mailing List" off \
  1025. 19 $"XMPP chat" off \
  1026. 20 $"GNU Social" off \
  1027. 21 $"Hubzilla" off \
  1028. 22 $"Owncloud" off \
  1029. 23 $"Gogs" off \
  1030. 24 $"Wiki" off \
  1031. 25 $"Blog" off \
  1032. 26 $"CJDNS" off \
  1033. 27 $"Email" off \
  1034. 28 $"DLNA" off \
  1035. 29 $"VoIP" off \
  1036. 30 $"RSS reader" off \
  1037. 31 $"Tox" off \
  1038. 32 $"Mediagoblin" off 2> $data
  1039. sel=$?
  1040. case $sel in
  1041. 1) break;;
  1042. 255) break;;
  1043. esac
  1044. if [ $(cat $data) -ne 2 ]; then
  1045. clear
  1046. fi
  1047. case $(cat $data) in
  1048. 1) ${PROJECT_NAME}-restore-local $USB_DRIVE;;
  1049. 2) return;;
  1050. 3) ${PROJECT_NAME}-restore-local $USB_DRIVE configuration;;
  1051. 4) ${PROJECT_NAME}-restore-local $USB_DRIVE mariadb;;
  1052. 5) ${PROJECT_NAME}-restore-local $USB_DRIVE letsencrypt;;
  1053. 6) ${PROJECT_NAME}-restore-local $USB_DRIVE mutt;;
  1054. 7) ${PROJECT_NAME}-restore-local $USB_DRIVE gpg;;
  1055. 8) ${PROJECT_NAME}-restore-local $USB_DRIVE procmail;;
  1056. 9) ${PROJECT_NAME}-restore-local $USB_DRIVE spamassassin;;
  1057. 10) ${PROJECT_NAME}-restore-local $USB_DRIVE readme;;
  1058. 11) ${PROJECT_NAME}-restore-local $USB_DRIVE ipfs;;
  1059. 12) ${PROJECT_NAME}-restore-local $USB_DRIVE ssh;;
  1060. 13) ${PROJECT_NAME}-restore-local $USB_DRIVE userconfig;;
  1061. 14) ${PROJECT_NAME}-restore-local $USB_DRIVE userlocal;;
  1062. 15) ${PROJECT_NAME}-restore-local $USB_DRIVE userfin;;
  1063. 16) ${PROJECT_NAME}-restore-local $USB_DRIVE certs;;
  1064. 17) ${PROJECT_NAME}-restore-local $USB_DRIVE personal;;
  1065. 18) ${PROJECT_NAME}-restore-local $USB_DRIVE mailinglist;;
  1066. 19) ${PROJECT_NAME}-restore-local $USB_DRIVE xmpp;;
  1067. 20) ${PROJECT_NAME}-restore-local $USB_DRIVE gnusocial;;
  1068. 21) ${PROJECT_NAME}-restore-local $USB_DRIVE hubzilla;;
  1069. 22) ${PROJECT_NAME}-restore-local $USB_DRIVE owncloud;;
  1070. 23) ${PROJECT_NAME}-restore-local $USB_DRIVE gogs;;
  1071. 24) ${PROJECT_NAME}-restore-local $USB_DRIVE wiki;;
  1072. 25) ${PROJECT_NAME}-restore-local $USB_DRIVE blog;;
  1073. 26) ${PROJECT_NAME}-restore-local $USB_DRIVE cjdns;;
  1074. 27) ${PROJECT_NAME}-restore-local $USB_DRIVE email;;
  1075. 28) ${PROJECT_NAME}-restore-local $USB_DRIVE dlna;;
  1076. 29) ${PROJECT_NAME}-restore-local $USB_DRIVE voip;;
  1077. 30) ${PROJECT_NAME}-restore-local $USB_DRIVE ttrss;;
  1078. 31) ${PROJECT_NAME}-restore-local $USB_DRIVE tox;;
  1079. 32) ${PROJECT_NAME}-restore-local $USB_DRIVE mediagoblin;;
  1080. esac
  1081. done
  1082. any_key
  1083. }
  1084. function restore_from_remote {
  1085. remote_domain_name=$1
  1086. while true
  1087. do
  1088. data=$(tempfile 2>/dev/null)
  1089. trap "rm -f $data" 0 1 2 5 15
  1090. dialog --backtitle $"Freedombone Control Panel" \
  1091. --title $"Restore from ${remote_domain_name}" \
  1092. --radiolist $"Choose an application to restore:" 31 70 28 \
  1093. 1 $"Everything" off \
  1094. 2 $"Return to the backup and restore menu" on \
  1095. 3 $"Configuration files" off \
  1096. 4 $"MariaDB settings" off \
  1097. 5 $"Let's Encrypt account" off \
  1098. 6 $"Mutt email client settings" off \
  1099. 7 $"GPG keys" off \
  1100. 8 $"Email processing rules" off \
  1101. 9 $"Spam filtering rules" off \
  1102. 10 $"Administrator's README file" off \
  1103. 11 $"IPFS" off \
  1104. 12 $"SSH keys" off \
  1105. 13 $"User configuration files" off \
  1106. 14 $"User local files" off \
  1107. 15 $"User fin files" off \
  1108. 16 $"SSL/TLS certificates" off \
  1109. 17 $"Personal settings" off \
  1110. 18 $"Mailing List" off \
  1111. 19 $"XMPP chat" off \
  1112. 20 $"GNU Social" off \
  1113. 21 $"Hubzilla" off \
  1114. 22 $"Owncloud" off \
  1115. 23 $"Gogs" off \
  1116. 24 $"Wiki" off \
  1117. 25 $"Blog" off \
  1118. 26 $"CJDNS" off \
  1119. 27 $"Email" off \
  1120. 28 $"DLNA" off \
  1121. 29 $"VoIP" off \
  1122. 30 $"RSS reader" off \
  1123. 31 $"Tox" off 2> $data
  1124. sel=$?
  1125. case $sel in
  1126. 1) break;;
  1127. 255) break;;
  1128. esac
  1129. if [ $(cat $data) -ne 2 ]; then
  1130. clear
  1131. fi
  1132. case $(cat $data) in
  1133. 1) ${PROJECT_NAME}-restore-remote $remote_domain_name;;
  1134. 2) return;;
  1135. 3) ${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;
  1136. 4) ${PROJECT_NAME}-restore-remote $remote_domain_name mariadb;;
  1137. 5) ${PROJECT_NAME}-restore-remote $remote_domain_name letsencrypt;;
  1138. 6) ${PROJECT_NAME}-restore-remote $remote_domain_name mutt;;
  1139. 7) ${PROJECT_NAME}-restore-remote $remote_domain_name gpg;;
  1140. 8) ${PROJECT_NAME}-restore-remote $remote_domain_name procmail;;
  1141. 9) ${PROJECT_NAME}-restore-remote $remote_domain_name spamassassin;;
  1142. 10) ${PROJECT_NAME}-restore-remote $remote_domain_name readme;;
  1143. 11) ${PROJECT_NAME}-restore-remote $remote_domain_name ipfs;;
  1144. 12) ${PROJECT_NAME}-restore-remote $remote_domain_name ssh;;
  1145. 13) ${PROJECT_NAME}-restore-remote $remote_domain_name userconfig;;
  1146. 14) ${PROJECT_NAME}-restore-remote $remote_domain_name userlocal;;
  1147. 15) ${PROJECT_NAME}-restore-remote $remote_domain_name userfin;;
  1148. 16) ${PROJECT_NAME}-restore-remote $remote_domain_name certs;;
  1149. 17) ${PROJECT_NAME}-restore-remote $remote_domain_name personal;;
  1150. 18) ${PROJECT_NAME}-restore-remote $remote_domain_name mailinglist;;
  1151. 19) ${PROJECT_NAME}-restore-remote $remote_domain_name xmpp;;
  1152. 20) ${PROJECT_NAME}-restore-remote $remote_domain_name gnusocial;;
  1153. 21) ${PROJECT_NAME}-restore-remote $remote_domain_name hubzilla;;
  1154. 22) ${PROJECT_NAME}-restore-remote $remote_domain_name owncloud;;
  1155. 23) ${PROJECT_NAME}-restore-remote $remote_domain_name gogs;;
  1156. 24) ${PROJECT_NAME}-restore-remote $remote_domain_name wiki;;
  1157. 25) ${PROJECT_NAME}-restore-remote $remote_domain_name blog;;
  1158. 26) ${PROJECT_NAME}-restore-remote $remote_domain_name cjdns;;
  1159. 27) ${PROJECT_NAME}-restore-remote $remote_domain_name email;;
  1160. 28) ${PROJECT_NAME}-restore-remote $remote_domain_name dlna;;
  1161. 29) ${PROJECT_NAME}-restore-remote $remote_domain_name voip;;
  1162. 30) ${PROJECT_NAME}-restore-remote $remote_domain_name ttrss;;
  1163. 31) ${PROJECT_NAME}-restore-remote $remote_domain_name tox;;
  1164. esac
  1165. done
  1166. any_key
  1167. }
  1168. function restore_data {
  1169. dialog --title $"Restore data from USB" \
  1170. --msgbox $"Plug in your backup USB drive" 6 40
  1171. clear
  1172. echo ' '
  1173. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  1174. restore_from_usb
  1175. }
  1176. function restore_data_remote {
  1177. if [ ! $ADMIN_USER ]; then
  1178. dialog --title $"Restore data from remote server" \
  1179. --msgbox $"Unknown admin user" 6 40
  1180. return
  1181. fi
  1182. data=$(tempfile 2>/dev/null)
  1183. trap "rm -f $data" 0 1 2 5 15
  1184. dialog --title $"Restore from remote server" \
  1185. --backtitle $"Freedombone Control Panel" \
  1186. --inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>$data
  1187. sel=$?
  1188. case $sel in
  1189. 0)
  1190. friend_server_domain_name=$(<$data)
  1191. if [ ${#friend_server_domain_name} -lt 2 ]; then
  1192. return
  1193. fi
  1194. if [[ $friend_server_domain_name != *"."* ]]; then
  1195. dialog --title $"Remote server domain name" \
  1196. --msgbox $"Invalid domain name" 6 40
  1197. return
  1198. fi
  1199. restore_from_remote $friend_server_domain_name
  1200. ;;
  1201. esac
  1202. }
  1203. function ping_enable_disable {
  1204. ping_str=$"\nDo you want to enable other systems to ping this machine?\n\nPing may be useful for diagnostic purposes, but for added security you may not want to enable it."
  1205. enable_ping="no"
  1206. dialog --title $"Enable Ping / ICMP" \
  1207. --backtitle $"Freedombone Control Panel" \
  1208. --defaultno \
  1209. --yesno "$ping_str" 10 60
  1210. sel=$?
  1211. case $sel in
  1212. 0) enable_ping="yes";;
  1213. 255) return;;
  1214. esac
  1215. if [[ $enable_ping == "yes" ]]; then
  1216. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  1217. iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  1218. echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  1219. else
  1220. iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT
  1221. iptables -D OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  1222. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  1223. fi
  1224. }
  1225. function logging_on_off {
  1226. logging="no"
  1227. dialog --title $"Logging" \
  1228. --backtitle $"Freedombone Control Panel" \
  1229. --yesno $"\nDo you want to turn logging on?" 7 60
  1230. sel=$?
  1231. case $sel in
  1232. 0) logging="yes";;
  1233. 255) return;;
  1234. esac
  1235. clear
  1236. echo ''
  1237. echo $'This may take a few seconds. Please wait...'
  1238. if [[ $logging == "no" ]]; then
  1239. ${PROJECT_NAME}-logging off
  1240. else
  1241. ${PROJECT_NAME}-logging on
  1242. fi
  1243. }
  1244. function restore_gpg_key {
  1245. select_user
  1246. if [ ! $SELECTED_USERNAME ]; then
  1247. return
  1248. fi
  1249. restorestr=$"Restore GPG key for user"
  1250. dialog --title "$restorestr $SELECTED_USERNAME" \
  1251. --msgbox $"Plug in your USB keydrive" 6 40
  1252. clear
  1253. ${PROJECT_NAME}-recoverkey -u $SELECTED_USERNAME
  1254. any_key
  1255. }
  1256. function security_settings {
  1257. ${PROJECT_NAME}-sec
  1258. any_key
  1259. }
  1260. function reset_tripwire {
  1261. clear
  1262. echo $'Resetting the Tripwire...'
  1263. echo ' '
  1264. echo '
  1265. ' | reset-tripwire
  1266. any_key
  1267. }
  1268. function hubzilla_renew_cert {
  1269. dialog --title $"Renew SSL certificate" \
  1270. --backtitle $"Freedombone Control Panel" \
  1271. --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
  1272. sel=$?
  1273. case $sel in
  1274. 1) return;;
  1275. 255) return;;
  1276. esac
  1277. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  1278. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  1279. dialog --title $"Renew SSL certificate" \
  1280. --msgbox $"Hubzilla install directory not found" 6 40
  1281. return
  1282. fi
  1283. ${PROJECT_NAME}-renew-cert -h $HUBZILLA_DOMAIN_NAME -p 'letsencrypt'
  1284. if [ ! "$?" = "0" ]; then
  1285. any_key
  1286. else
  1287. dialog --title $"Renew SSL certificate" \
  1288. --msgbox $"Hubzilla certificate has been renewed" 6 40
  1289. fi
  1290. }
  1291. function hubzilla_channel_directory_server {
  1292. if ! grep -q "Hubzilla domain" $COMPLETION_FILE; then
  1293. dialog --title $"Hubzilla channel directory server" \
  1294. --msgbox $"Hubzilla is not installed on this system" 6 40
  1295. return
  1296. fi
  1297. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  1298. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  1299. dialog --title $"Hubzilla channel directory server" \
  1300. --msgbox $"Hubzilla install directory not found" 6 40
  1301. return
  1302. fi
  1303. data=$(tempfile 2>/dev/null)
  1304. trap "rm -f $data" 0 1 2 5 15
  1305. dialog --title $"Hubzilla channel directory server" \
  1306. --backtitle $"Freedombone Control Panel" \
  1307. --inputbox $"When you click on 'channel directory' this is where Hubzilla will obtain its list from" 8 60 2>$data
  1308. sel=$?
  1309. case $sel in
  1310. 0)
  1311. hubzilla_domain_server=$(<$data)
  1312. if [[ $hubzilla_domain_server != *"."* ]]; then
  1313. return
  1314. fi
  1315. if [[ $hubzilla_domain_server != "https"* ]]; then
  1316. dialog --title $"Hubzilla channel directory server" \
  1317. --msgbox $"Invalid domain - include the https://" 6 40
  1318. return
  1319. fi
  1320. ./var/www/$HUBZILLA_DOMAIN_NAME/htdocs/util/config system directory_server $hubzilla_domain_server
  1321. dialog --title $"Hubzilla channel directory server" \
  1322. --msgbox $"Domain channel directory server changed to $hubzilla_domain_server" 6 40
  1323. ;;
  1324. esac
  1325. }
  1326. function format_drive {
  1327. drive=
  1328. data=$(tempfile 2>/dev/null)
  1329. trap "rm -f $data" 0 1 2 5 15
  1330. dialog --backtitle $"Freedombone Control Panel" \
  1331. --title $"Format a USB drive (LUKS encrypted)" \
  1332. --radiolist $"Choose a drive:" 12 70 5 \
  1333. 1 $"sda (Beaglebone Black)" off \
  1334. 2 $"sdb" off \
  1335. 3 $"sdc" off \
  1336. 4 $"sdd" off \
  1337. 5 $"Back to Backup and Restore menu" on 2> $data
  1338. sel=$?
  1339. case $sel in
  1340. 1) return;;
  1341. 255) return;;
  1342. esac
  1343. case $(cat $data) in
  1344. 1) drive='sda';;
  1345. 2) drive='sdb';;
  1346. 3) drive='sdc';;
  1347. 4) drive='sdd';;
  1348. 5) return;;
  1349. esac
  1350. dialog --title $"Format USB drive" \
  1351. --backtitle $"Freedombone Control Panel" \
  1352. --defaultno \
  1353. --yesno $"\nPlease confirm that you wish to format drive\n\n ${drive}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
  1354. sel=$?
  1355. case $sel in
  1356. 1) return;;
  1357. 255) return;;
  1358. esac
  1359. clear
  1360. ${PROJECT_NAME}-format $drive
  1361. any_key
  1362. }
  1363. function remove_backups {
  1364. drive=
  1365. data=$(tempfile 2>/dev/null)
  1366. trap "rm -f $data" 0 1 2 5 15
  1367. dialog --backtitle $"Freedombone Control Panel" \
  1368. --title $"Remove backups from a USB drive" \
  1369. --radiolist $"Choose a drive:" 12 70 5 \
  1370. 1 $"sda (Beaglebone Black)" off \
  1371. 2 $"sdb" off \
  1372. 3 $"sdc" off \
  1373. 4 $"sdd" off \
  1374. 5 $"Back to Backup and Restore menu" on 2> $data
  1375. sel=$?
  1376. case $sel in
  1377. 1) return;;
  1378. 255) return;;
  1379. esac
  1380. case $(cat $data) in
  1381. 1) drive='sda';;
  1382. 2) drive='sdb';;
  1383. 3) drive='sdc';;
  1384. 4) drive='sdd';;
  1385. 5) return;;
  1386. esac
  1387. dialog --title $"Remove backups from a USB drive" \
  1388. --backtitle $"Freedombone Control Panel" \
  1389. --defaultno \
  1390. --yesno $"\nPlease confirm that you wish to remove backups from this drive\n\n ${drive}\n\nYou will not be able to recover them afterwards." 12 60
  1391. sel=$?
  1392. case $sel in
  1393. 1) return;;
  1394. 255) return;;
  1395. esac
  1396. clear
  1397. ${PROJECT_NAME}-backup-local $drive remove
  1398. any_key
  1399. }
  1400. function shut_down_system {
  1401. dialog --title $"Power off the system" \
  1402. --backtitle $"Freedombone Control Panel" \
  1403. --defaultno \
  1404. --yesno $"\nPlease confirm that you wish to power off the system.\n\nWARNING: to power on again you will need to have physical access to the hardware." 10 60
  1405. sel=$?
  1406. case $sel in
  1407. 1) return;;
  1408. 255) return;;
  1409. esac
  1410. shutdown now
  1411. }
  1412. function restart_system {
  1413. dialog --title $"Restart the system" \
  1414. --backtitle $"Freedombone Control Panel" \
  1415. --defaultno \
  1416. --yesno $"\nPlease confirm that you wish to restart the system.\n\nWARNING: If you are using full disk encryption then you will need physical access to the hardware to type in the password" 10 60
  1417. sel=$?
  1418. case $sel in
  1419. 1) return;;
  1420. 255) return;;
  1421. esac
  1422. reboot
  1423. }
  1424. function change_system_name {
  1425. data=$(tempfile 2>/dev/null)
  1426. trap "rm -f $data" 0 1 2 5 15
  1427. dialog --title $"Change the name of this system" \
  1428. --backtitle $"Freedombone Control Panel" \
  1429. --inputbox $'Enter a new name for this system on your local network\n\nIt will appear as newname.local' 10 60 2>$data
  1430. sel=$?
  1431. case $sel in
  1432. 0) NEW_SYSTEM_NAME=$(<$data)
  1433. if [ "$NEW_SYSTEM_NAME" ]; then
  1434. if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
  1435. sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
  1436. systemctl restart avahi-daemon
  1437. if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
  1438. dialog --title $"New local network name" \
  1439. --msgbox $"The name of this system on your local network was changed successfully" 6 70
  1440. fi
  1441. fi
  1442. fi
  1443. ;;
  1444. esac
  1445. }
  1446. function set_tls_time_source {
  1447. TLS_DATE_SOURCE=$(cat /usr/bin/updatedate | grep "TIMESOURCE='" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  1448. data=$(tempfile 2>/dev/null)
  1449. trap "rm -f $data" 0 1 2 5 15
  1450. dialog --title $"Set the TLS date/time source" \
  1451. --backtitle $"Freedombone Control Panel" \
  1452. --inputbox $"Enter a domain name to use as a TLS time source.\n\nFactors to consider when choosing a source are whether you wish that site to know that your system is 'alive' and also what might happen if an adversary were to try to mess with the date/time from that domain (i.e. how much blowback would there be)." 14 60 "$TLS_DATE_SOURCE" 2>$data
  1453. sel=$?
  1454. case $sel in
  1455. 0) NEW_TLS_DATE_SOURCE=$(<$data)
  1456. if [[ $NEW_TLS_DATE_SOURCE == *"."* && $NEW_TLS_DATE_SOURCE != *'/'* ]]; then
  1457. if [[ $NEW_TLS_DATE_SOURCE != "http"* ]]; then
  1458. sed -i "s|TIMESOURCE='.*|TIMESOURCE='${NEW_TLS_DATE_SOURCE}'|g" $UPDATE_DATE_SCRIPT
  1459. else
  1460. dialog --title $"Invalid domain name" \
  1461. --msgbox $"Don't include the 'https'" 6 70
  1462. fi
  1463. else
  1464. dialog --title $"Invalid domain name" \
  1465. --msgbox $"That doesn't look like a domain name" 6 70
  1466. fi
  1467. ;;
  1468. esac
  1469. }
  1470. function set_static_IP {
  1471. STATIC_IP='192.168.1.60'
  1472. STATIC_GATEWAY='192.168.1.1'
  1473. NEW_STATIC_IP=
  1474. NEW_STATIC_GATEWAY=
  1475. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1476. STATIC_IP=$(cat /etc/network/interfaces | grep "address " | awk -F ' ' '{print $2}' | head -n 1)
  1477. STATIC_GATEWAY=$(cat /etc/network/interfaces | grep "gateway " | awk -F ' ' '{print $2}' | head -n 1)
  1478. fi
  1479. # get the IP for the box
  1480. data=$(tempfile 2>/dev/null)
  1481. trap "rm -f $data" 0 1 2 5 15
  1482. dialog --title $"Set a static local IP address" \
  1483. --backtitle $"Freedombone Control Panel" \
  1484. --inputbox $"In order to forward incoming internet traffic to this system most internet routers need to know a static local IP address to send the data to.\n\n
  1485. Enter a static local IP address for this system.\n\nIt will typically be 192.168.1.x" 15 60 "$STATIC_IP" 2>$data
  1486. sel=$?
  1487. case $sel in
  1488. 0) NEW_STATIC_IP=$(<$data)
  1489. if [[ "$NEW_STATIC_IP" != *"."* ]]; then
  1490. return
  1491. fi
  1492. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1493. if [[ "$NEW_STATIC_IP" != "$STATIC_IP" ]]; then
  1494. sed -i "s|${STATIC_IP}|${NEW_STATIC_IP}|g" /etc/network/interfaces
  1495. fi
  1496. fi
  1497. ;;
  1498. esac
  1499. # get the gateway
  1500. data=$(tempfile 2>/dev/null)
  1501. trap "rm -f $data" 0 1 2 5 15
  1502. dialog --title $"Set the IP address of your internet router/modem" \
  1503. --backtitle $"Freedombone Control Panel" \
  1504. --inputbox $"Set the local IP address for your internet router or ADSL modem.\n\nIt will typically be 192.168.1.1, 192.168.1.254, or similar" 12 60 "$STATIC_GATEWAY" 2>$data
  1505. sel=$?
  1506. case $sel in
  1507. 0) NEW_STATIC_GATEWAY=$(<$data)
  1508. if [[ "$NEW_STATIC_GATEWAY" != *"."* ]]; then
  1509. return
  1510. fi
  1511. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1512. if [[ "$NEW_STATIC_GATEWAY" != "$STATIC_GATEWAY" ]]; then
  1513. sed -i "s|${STATIC_GATEWAY}|${NEW_STATIC_GATEWAY}|g" /etc/network/interfaces
  1514. fi
  1515. return
  1516. fi
  1517. ;;
  1518. esac
  1519. if ! grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1520. if [ "$NEW_STATIC_GATEWAY" && "$NEW_STATIC_IP" ]; then
  1521. echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
  1522. echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
  1523. echo '' >> /etc/network/interfaces
  1524. echo '# The loopback network interface' >> /etc/network/interfaces
  1525. echo 'auto lo' >> /etc/network/interfaces
  1526. echo 'iface lo inet loopback' >> /etc/network/interfaces
  1527. echo '' >> /etc/network/interfaces
  1528. echo '# The primary network interface' >> /etc/network/interfaces
  1529. echo 'auto eth0' >> /etc/network/interfaces
  1530. echo 'iface eth0 inet static' >> /etc/network/interfaces
  1531. echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
  1532. echo ' netmask 255.255.255.0' >> /etc/network/interfaces
  1533. echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
  1534. echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
  1535. echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
  1536. echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
  1537. echo '' >> /etc/network/interfaces
  1538. echo '# The secondary network interface' >> /etc/network/interfaces
  1539. echo '#auto eth1' >> /etc/network/interfaces
  1540. echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
  1541. echo '' >> /etc/network/interfaces
  1542. echo '# WiFi Example' >> /etc/network/interfaces
  1543. echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
  1544. echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
  1545. echo '# wpa-ssid "essid"' >> /etc/network/interfaces
  1546. echo '# wpa-psk "password"' >> /etc/network/interfaces
  1547. echo '' >> /etc/network/interfaces
  1548. echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
  1549. echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
  1550. echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
  1551. echo '#iface usb0 inet static' >> /etc/network/interfaces
  1552. echo '# address 192.168.7.2' >> /etc/network/interfaces
  1553. echo '# netmask 255.255.255.0' >> /etc/network/interfaces
  1554. echo '# network 192.168.7.0' >> /etc/network/interfaces
  1555. echo '# gateway 192.168.7.1' >> /etc/network/interfaces
  1556. fi
  1557. fi
  1558. }
  1559. function menu_backup_restore {
  1560. while true
  1561. do
  1562. data=$(tempfile 2>/dev/null)
  1563. trap "rm -f $data" 0 1 2 5 15
  1564. dialog --backtitle $"Freedombone Control Panel" \
  1565. --title $"Backup and Restore" \
  1566. --radiolist $"Choose an operation:" 18 70 11 \
  1567. 1 $"Backup data to USB drive" off \
  1568. 2 $"Restore GPG key from USB keydrive" off \
  1569. 3 $"Restore data from USB drive" off \
  1570. 4 $"Configure remote backups" off \
  1571. 5 $"Restore from remote backup" off \
  1572. 6 $"Backup GPG key to USB (master keydrive)" off \
  1573. 7 $"Backup GPG key to USB (fragment keydrive)" off \
  1574. 8 $"Format a USB drive (LUKS encrypted)" off \
  1575. 9 $"Remove backups from a USB drive" off \
  1576. 10 $"Back to main menu" on 2> $data
  1577. sel=$?
  1578. case $sel in
  1579. 1) break;;
  1580. 255) break;;
  1581. esac
  1582. case $(cat $data) in
  1583. 1) backup_data;;
  1584. 2) restore_gpg_key;;
  1585. 3) restore_data;;
  1586. 4) configure_remote_backups;;
  1587. 5) restore_data_remote;;
  1588. 6) create_keydrive_master;;
  1589. 7) create_keydrive_fragment;;
  1590. 8) format_drive;;
  1591. 9) remove_backups;;
  1592. 10) break;;
  1593. esac
  1594. done
  1595. }
  1596. function menu_email {
  1597. while true
  1598. do
  1599. data=$(tempfile 2>/dev/null)
  1600. trap "rm -f $data" 0 1 2 5 15
  1601. dialog --backtitle $"Freedombone Control Panel" \
  1602. --title $"Email Filtering Rules" \
  1603. --radiolist $"Choose an operation:" 13 70 6 \
  1604. 1 $"Add a user to a mailing list" off \
  1605. 2 $"Remove a user from a mailing list" off \
  1606. 3 $"Add an email rule" off \
  1607. 4 $"Block/Unblock an email address" off \
  1608. 5 $"Block/Unblock email with subject text" off \
  1609. 6 $"Back to main menu" on 2> $data
  1610. sel=$?
  1611. case $sel in
  1612. 1) break;;
  1613. 255) break;;
  1614. esac
  1615. case $(cat $data) in
  1616. 1) add_to_mailing_list;;
  1617. 2) remove_user_from_mailing_list;;
  1618. 3) email_rule;;
  1619. 4) block_unblock_email;;
  1620. 5) block_unblock_subject;;
  1621. 6) break;;
  1622. esac
  1623. done
  1624. }
  1625. function menu_users {
  1626. while true
  1627. do
  1628. data=$(tempfile 2>/dev/null)
  1629. trap "rm -f $data" 0 1 2 5 15
  1630. dialog --backtitle $"Freedombone Control Panel" \
  1631. --title $"Manage Users" \
  1632. --radiolist $"Choose an operation:" 12 70 5 \
  1633. 1 $"Add a user" off \
  1634. 2 $"Delete a user" off \
  1635. 3 $"Change user password" off \
  1636. 4 $"Change user ssh public key" off \
  1637. 5 $"Back to main menu" on 2> $data
  1638. sel=$?
  1639. case $sel in
  1640. 1) break;;
  1641. 255) break;;
  1642. esac
  1643. case $(cat $data) in
  1644. 1) add_user;;
  1645. 2) delete_user;;
  1646. 3) change_password;;
  1647. 4) change_ssh_public_key;;
  1648. 5) break;;
  1649. esac
  1650. done
  1651. }
  1652. function menu_hubzilla {
  1653. while true
  1654. do
  1655. data=$(tempfile 2>/dev/null)
  1656. trap "rm -f $data" 0 1 2 5 15
  1657. dialog --backtitle $"Freedombone Control Panel" \
  1658. --title $"Hubzilla" \
  1659. --radiolist $"Choose an operation:" 13 70 4 \
  1660. 1 $"Set channel directory server" off \
  1661. 2 $"Renew SSL certificate" off \
  1662. 3 $"Back to main menu" on 2> $data
  1663. sel=$?
  1664. case $sel in
  1665. 1) break;;
  1666. 255) break;;
  1667. esac
  1668. case $(cat $data) in
  1669. 1) hubzilla_channel_directory_server;;
  1670. 2) hubzilla_renew_cert;;
  1671. 3) break;;
  1672. esac
  1673. done
  1674. }
  1675. function menu_media {
  1676. while true
  1677. do
  1678. data=$(tempfile 2>/dev/null)
  1679. trap "rm -f $data" 0 1 2 5 15
  1680. dialog --backtitle $"Freedombone Control Panel" \
  1681. --title $"Media Menu" \
  1682. --radiolist $"Choose an operation:" 13 70 3 \
  1683. 1 $"Attach a drive containing playable media" off \
  1684. 2 $"Remove a drive containing playable media" off \
  1685. 3 $"Exit" on 2> $data
  1686. sel=$?
  1687. case $sel in
  1688. 1) break;;
  1689. 255) break;;
  1690. esac
  1691. case $(cat $data) in
  1692. 1) remove-music
  1693. attach-music;;
  1694. 2) remove-music;;
  1695. 3) break;;
  1696. esac
  1697. done
  1698. }
  1699. function menu_irc {
  1700. if [ ! -d /etc/ngircd ]; then
  1701. dialog --title $"IRC Menu" \
  1702. --msgbox $"No IRC server is installed" 6 70
  1703. return
  1704. fi
  1705. while true
  1706. do
  1707. data=$(tempfile 2>/dev/null)
  1708. trap "rm -f $data" 0 1 2 5 15
  1709. dialog --backtitle $"Freedombone Control Panel" \
  1710. --title $"IRC Menu" \
  1711. --radiolist $"Choose an operation:" 14 70 4 \
  1712. 1 $"Set a password for all IRC users" off \
  1713. 2 $"Access via the onion address" off \
  1714. 3 $"Exit" on 2> $data
  1715. sel=$?
  1716. case $sel in
  1717. 1) break;;
  1718. 255) break;;
  1719. esac
  1720. case $(cat $data) in
  1721. 1) irc_set_global_password;;
  1722. 2) irc_via_onion;;
  1723. 3) break;;
  1724. esac
  1725. done
  1726. }
  1727. function menu_top_level {
  1728. while true
  1729. do
  1730. data=$(tempfile 2>/dev/null)
  1731. trap "rm -f $data" 0 1 2 5 15
  1732. dialog --backtitle $"Freedombone Control Panel" \
  1733. --title $"Control Panel" \
  1734. --radiolist $"Choose an operation:" 28 70 21 \
  1735. 1 $"About this system" off \
  1736. 2 $"Backup and Restore" off \
  1737. 3 $"Reset Tripwire" off \
  1738. 4 $"Logging on/off" off \
  1739. 5 $"Ping enable/disable" off \
  1740. 6 $"Manage Users" off \
  1741. 7 $"Email Filtering Rules" off \
  1742. 8 $"Outgoing Email Proxy" off \
  1743. 9 $"Security Settings" off \
  1744. 10 $"Set the main repository (repo mirrors)" off \
  1745. 11 $"Hubzilla" off \
  1746. 12 $"Media menu" off \
  1747. 13 $"IRC menu" off \
  1748. 14 $"Change your blog avatar" off \
  1749. 15 $"Change the name of this system" off \
  1750. 16 $"Set the TLS date/time source" off \
  1751. 17 $"Set a static local IP address" off \
  1752. 18 $"Check for updates" off \
  1753. 19 $"Power off the system" off \
  1754. 20 $"Restart the system" off \
  1755. 21 $"Exit" on 2> $data
  1756. sel=$?
  1757. case $sel in
  1758. 1) exit 1;;
  1759. 255) exit 1;;
  1760. esac
  1761. case $(cat $data) in
  1762. 1) show_about;;
  1763. 2) menu_backup_restore;;
  1764. 3) reset_tripwire;;
  1765. 4) logging_on_off;;
  1766. 5) ping_enable_disable;;
  1767. 6) menu_users;;
  1768. 7) menu_email;;
  1769. 8) smtp_proxy;;
  1770. 9) security_settings;;
  1771. 10) set_main_repo;;
  1772. 11) menu_hubzilla;;
  1773. 12) menu_media;;
  1774. 13) menu_irc;;
  1775. 14) change_blog_avatar;;
  1776. 15) change_system_name;;
  1777. 16) set_tls_time_source;;
  1778. 17) set_static_IP;;
  1779. 18) check_for_updates;;
  1780. 19) shut_down_system;;
  1781. 20) restart_system;;
  1782. 21) break;;
  1783. esac
  1784. done
  1785. }
  1786. if [[ $USER != 'root' ]]; then
  1787. # show the user version of the control panel
  1788. freedombone-controlpanel-user
  1789. exit 0
  1790. fi
  1791. if [ ! -f $COMPLETION_FILE ]; then
  1792. echo $'This command should only be run on an installed Freedombone system'
  1793. exit 1
  1794. fi
  1795. ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  1796. read_repo_servers
  1797. menu_top_level
  1798. clear
  1799. cat /etc/motd
  1800. exit 0