freedombone-controlpanel 62KB

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