freedombone-controlpanel 70KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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_show_password {
  582. IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
  583. dialog --title $"IRC Password" \
  584. --msgbox "$IRC_PASSWORD" 6 40
  585. }
  586. function irc_set_global_password {
  587. dialog --title $"IRC Password" \
  588. --clear \
  589. --backtitle $"Freedombone Control Panel" \
  590. --passwordbox $"Password for all IRC users, or press Enter for no password" 10 50 2> $data
  591. sel=$?
  592. case $sel in
  593. 0)
  594. NEW_IRC_PASSWORD=$(<$data)
  595. sed -i "0,/RE/s/Password =.*/Password =$NEW_IRC_PASSWORD/" /etc/ngircd/ngircd.conf
  596. dialog --title $"IRC Password" \
  597. --msgbox $"The IRC password was changed" 6 40
  598. systemctl restart ngircd
  599. ;;
  600. esac
  601. }
  602. function change_blog_avatar {
  603. data=$(tempfile 2>/dev/null)
  604. trap "rm -f $data" 0 1 2 5 15
  605. dialog --title $"Change blog avatar" \
  606. --backtitle $"Freedombone Control Panel" \
  607. --inputbox $"Enter a URL for an image. It should be approximately a square image." 8 75 2>$data
  608. sel=$?
  609. case $sel in
  610. 0)
  611. IMAGE_URL=$(<$data)
  612. if [ ${#IMAGE_URL} -gt 5 ]; then
  613. clear
  614. ${PROJECT_NAME}-blog -a $IMAGE_URL
  615. if [ "$?" = "0" ]; then
  616. dialog --title $"Change blog avatar" \
  617. --msgbox $"Your blog avatar has been changed" 6 40
  618. fi
  619. fi
  620. ;;
  621. esac
  622. }
  623. function change_ssh_public_key {
  624. select_user
  625. if [ ! $SELECTED_USERNAME ]; then
  626. return
  627. fi
  628. if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
  629. dialog --title $"Change ssh public key" \
  630. --backtitle $"Freedombone Control Panel" \
  631. --defaultno \
  632. --yesno $"\nThis is the administrator user.\n\nAre you sure you want to change the ssh public key for the administrator?" 10 60
  633. sel=$?
  634. case $sel in
  635. 1) return;;
  636. 255) return;;
  637. esac
  638. fi
  639. data=$(tempfile 2>/dev/null)
  640. trap "rm -f $data" 0 1 2 5 15
  641. dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
  642. --backtitle $"Freedombone Control Panel" \
  643. --inputbox $"Paste the ssh public key below" 8 60 2>$data
  644. sel=$?
  645. case $sel in
  646. 0)
  647. SSH_PUBLIC_KEY=$(<$data)
  648. if [ "$SSH_PUBLIC_KEY" ]; then
  649. if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
  650. if [ -f "$SSH_PUBLIC_KEY" ]; then
  651. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  652. mkdir /home/$SELECTED_USERNAME/.ssh
  653. fi
  654. cp $SSH_PUBLIC_KEY \
  655. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  656. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  657. /home/$SELECTED_USERNAME/.ssh
  658. dialog --title $"Change ssh public key" \
  659. --msgbox $"ssh public key was installed" 6 40
  660. else
  661. if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
  662. if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
  663. mkdir /home/$SELECTED_USERNAME/.ssh
  664. fi
  665. echo "$SSH_PUBLIC_KEY" > \
  666. /home/$SELECTED_USERNAME/.ssh/authorized_keys
  667. chown -R $SELECTED_USERNAME:$SELECTED_USERNAME \
  668. /home/$SELECTED_USERNAME/.ssh
  669. dialog --title $"Change ssh public key" \
  670. --msgbox $"ssh public key was installed" 6 40
  671. fi
  672. fi
  673. fi
  674. fi
  675. ;;
  676. esac
  677. }
  678. function irc_via_onion {
  679. dialog --title $"IRC Server" \
  680. --backtitle $"Freedombone Control Panel" \
  681. --defaultno \
  682. --yesno $"\nAccess the IRC server via an onion address?" 8 60
  683. sel=$?
  684. irc_onion='no'
  685. case $sel in
  686. 0) irc_onion='yes';;
  687. 255) return;;
  688. esac
  689. if [[ $irc_onion == 'no' ]]; then
  690. if grep -q ";Ports = 6667" /etc/ngircd/ngircd.conf; then
  691. sed -i "s/;Ports =.*/;Ports = $IRC_PORT, $IRC_ONION_PORT/1" /etc/ngircd/ngircd.conf
  692. else
  693. if ! grep -q ";Ports = $IRC_PORT, $IRC_ONION_PORT" /etc/ngircd/ngircd.conf; then
  694. sed -i "s/Ports = $IRC_PORT, $IRC_ONION_PORT/;Ports = $IRC_PORT, $IRC_ONION_PORT/1" /etc/ngircd/ngircd.conf
  695. fi
  696. fi
  697. systemctl restart ngircd
  698. dialog --title $"IRC Server" \
  699. --msgbox $"The IRC server can now be accessed via SSL at your main domain name" 8 50
  700. else
  701. if grep -q ";Ports = $IRC_PORT, $IRC_ONION_PORT" /etc/ngircd/ngircd.conf; then
  702. sed -i "s/;Ports =.*/Ports = $IRC_PORT, $IRC_ONION_PORT/1" /etc/ngircd/ngircd.conf
  703. systemctl restart ngircd
  704. fi
  705. dialog --title $"IRC Server" \
  706. --msgbox $"The IRC server can now be accessed via its onion address without SSL" 8 50
  707. fi
  708. }
  709. function remove_user_from_mailing_list {
  710. select_user
  711. if [ ! $SELECTED_USERNAME ]; then
  712. return
  713. fi
  714. USER_MAILING_LISTS=$(cat "/home/$SELECTED_USERNAME/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
  715. i=0
  716. W=()
  717. list_name=()
  718. while read -r listname; do
  719. i=$((i+1))
  720. W+=($i "$listname")
  721. list_name+=("$listname")
  722. echo $listname
  723. done <<< "$USER_MAILING_LISTS"
  724. i=$((i+1))
  725. W+=($i $"Exit back to user mainenance")
  726. 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)
  727. if [ $? -eq 0 ]; then # Exit with OK
  728. if [ ${list_selected} -ne ${i} ]; then
  729. remove_list_name="${list_name[$((list_selected-1))]}"
  730. # find the line number where the list is defined
  731. line_number=0
  732. i=0
  733. while read -r line
  734. do
  735. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  736. line_number=${i}
  737. fi
  738. i=$((i+1))
  739. done < "/home/$SELECTED_USERNAME/.procmailrc"
  740. if [ ${line_number} -eq 0 ]; then
  741. # no match was found
  742. return
  743. fi
  744. # recreate the file
  745. if [ -f /home/${SELECTED_USERNAME}/.procmailrc_new ]; then
  746. rm /home/${SELECTED_USERNAME}/.procmailrc_new
  747. fi
  748. i=0
  749. clip=0
  750. while read -r line
  751. do
  752. i=$((i+1))
  753. if [ ${i} -gt $((line_number-1)) ]; then
  754. if [ ${clip} -eq 0 ]; then
  755. clip=1
  756. fi
  757. if [ ${clip} -eq 1 ]; then
  758. if [ ${i} -lt $((line_number+2)) ]; then
  759. continue
  760. else
  761. if [ ${#line} -lt 1 ]; then
  762. clip=2
  763. continue
  764. fi
  765. if [[ "$line" == ":"* || "$line" == "#"* ]]; then
  766. clip=2
  767. else
  768. continue
  769. fi
  770. fi
  771. fi
  772. fi
  773. echo "$line" >> /home/${SELECTED_USERNAME}/.procmailrc_new
  774. if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
  775. line_number=${i}
  776. fi
  777. done < "/home/$SELECTED_USERNAME/.procmailrc"
  778. cp /home/${SELECTED_USERNAME}/.procmailrc_new /home/${SELECTED_USERNAME}/.procmailrc
  779. rm /home/${SELECTED_USERNAME}/.procmailrc_new
  780. chown ${SELECTED_USERNAME}:${SELECTED_USERNAME} /home/${SELECTED_USERNAME}/.procmailrc
  781. dialog --title $"Remove user from mailing list" \
  782. --msgbox $"${SELECTED_USERNAME} has been removed from ${remove_list_name}" 6 50
  783. fi
  784. fi
  785. }
  786. function add_to_mailing_list {
  787. select_user
  788. if [ ! $SELECTED_USERNAME ]; then
  789. return
  790. fi
  791. data=$(tempfile 2>/dev/null)
  792. trap "rm -f $data" 0 1 2 5 15
  793. dialog --backtitle $"Freedombone Control Panel" \
  794. --title $"Subscribe $SELECTED_USERNAME to a mailing list" \
  795. --form $"You can either enter a subject or an email address\n" 11 68 4 \
  796. $"List folder name:" 1 1 "" 1 35 26 25 \
  797. $"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
  798. $"List email address:" 3 1 "" 3 35 26 25 \
  799. $"Public:" 4 1 $"yes" 4 35 4 25 \
  800. 2> $data
  801. sel=$?
  802. case $sel in
  803. 1) return;;
  804. 255) return;;
  805. esac
  806. LIST_NAME=$(cat $data | sed -n 1p)
  807. LIST_SUBJECT=$(cat $data | sed -n 2p)
  808. LIST_EMAIL=$(cat $data | sed -n 3p)
  809. LIST_PUBLIC=$(cat $data | sed -n 4p)
  810. if [ ${#LIST_PUBLIC} -lt 1 ]; then
  811. LIST_PUBLIC='no'
  812. fi
  813. if [[ $LIST_PUBLIC == $'y' || $LIST_PUBLIC == $'Y' || $LIST_PUBLIC == $'true' || $LIST_PUBLIC == $'True' || $LIST_PUBLIC == $'yes' || $LIST_PUBLIC == $'Yes' || $LIST_PUBLIC == $'YES' ]]; then
  814. LIST_PUBLIC='yes'
  815. else
  816. LIST_PUBLIC='no'
  817. fi
  818. if [ ${#LIST_NAME} -lt 2 ]; then
  819. dialog --title $"Add mailing list" \
  820. --msgbox $"No mailing list name was given" 6 40
  821. return
  822. fi
  823. if [ ${#LIST_SUBJECT} -lt 2 ]; then
  824. if [ ${#LIST_EMAIL} -lt 2 ]; then
  825. dialog --title $"Add mailing list" \
  826. --msgbox $"No mailing list subject or address was given" 6 40
  827. return
  828. fi
  829. fi
  830. if [ ${#LIST_SUBJECT} -gt 1 ]; then
  831. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  832. -s "$LIST_SUBJECT" --public $LIST_PUBLIC
  833. else
  834. if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
  835. dialog --title $"Add mailing list" \
  836. --msgbox $"Unrecognised email address" 6 40
  837. return
  838. else
  839. ${PROJECT_NAME}-addlist -u $SELECTED_USERNAME -l "$LIST_NAME" \
  840. -e "$LIST_EMAIL" --public $LIST_PUBLIC
  841. fi
  842. fi
  843. dialog --title $"Add mailing list" \
  844. --msgbox $"$LIST_NAME list was added" 6 40
  845. }
  846. function email_rule {
  847. select_user
  848. if [ ! $SELECTED_USERNAME ]; then
  849. return
  850. fi
  851. data=$(tempfile 2>/dev/null)
  852. trap "rm -f $data" 0 1 2 5 15
  853. dialog --backtitle $"Freedombone Control Panel" \
  854. --title $"Email rule for user $SELECTED_USERNAME" \
  855. --form "\n" 9 65 4 \
  856. $"When email arrives from address:" 1 1 "" 1 35 24 28 \
  857. $"Move to folder:" 2 1 "" 2 35 24 28 \
  858. $"Public:" 3 1 $"no" 3 35 4 25 \
  859. 2> $data
  860. sel=$?
  861. case $sel in
  862. 1) return;;
  863. 255) return;;
  864. esac
  865. RULE_EMAIL=$(cat $data | sed -n 1p)
  866. RULE_FOLDER=$(cat $data | sed -n 2p)
  867. RULE_PUBLIC=$(cat $data | sed -n 3p)
  868. if [ ${#RULE_PUBLIC} -lt 1 ]; then
  869. RULE_PUBLIC='no'
  870. fi
  871. if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
  872. RULE_PUBLIC='yes'
  873. else
  874. RULE_PUBLIC='no'
  875. fi
  876. if [ ${#RULE_EMAIL} -lt 2 ]; then
  877. dialog --title $"Add email rule" \
  878. --msgbox $"No email address was given" 6 40
  879. return
  880. fi
  881. if [ ${#RULE_FOLDER} -lt 2 ]; then
  882. dialog --title $"Add email rule" \
  883. --msgbox $"No folder name was given" 6 40
  884. return
  885. fi
  886. if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
  887. dialog --title $"Add email rule" \
  888. --msgbox $"Unrecognised email address" 6 40
  889. return
  890. fi
  891. ${PROJECT_NAME}-addemail -u $SELECTED_USERNAME -e "$RULE_EMAIL" \
  892. -g "$RULE_FOLDER" --public $RULE_PUBLIC
  893. dialog --title $"Add email rule" \
  894. --msgbox $"Email rule for $RULE_EMAIL was added" 6 40
  895. }
  896. function block_unblock_email {
  897. select_user
  898. if [ ! $SELECTED_USERNAME ]; then
  899. return
  900. fi
  901. blockstr=$"Block/Unblock email going to"
  902. data=$(tempfile 2>/dev/null)
  903. trap "rm -f $data" 0 1 2 5 15
  904. dialog --backtitle $"Freedombone Control Panel" \
  905. --title "$blockstr $SELECTED_USERNAME" \
  906. --form "\n" 8 65 3 \
  907. $"When email arrives from address:" 1 1 "" 1 35 24 100 \
  908. $"Block it:" 2 1 "yes" 2 35 4 4 \
  909. 2> $data
  910. sel=$?
  911. case $sel in
  912. 1) return;;
  913. 255) return;;
  914. esac
  915. BLOCK_EMAIL=$(cat $data | sed -n 1p)
  916. BLOCK=$(cat $data | sed -n 2p)
  917. if [ ${#BLOCK_EMAIL} -lt 2 ]; then
  918. dialog --title $"Block/Unblock an email" \
  919. --msgbox $"No email address was given" 6 40
  920. return
  921. fi
  922. if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
  923. dialog --title $"Block/Unblock an email" \
  924. --msgbox $"Unrecognised email address" 6 40
  925. return
  926. fi
  927. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  928. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  929. dialog --title $"Block an email" \
  930. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME blocked" 6 75
  931. else
  932. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -e "$BLOCK_EMAIL"
  933. dialog --title $"Unblock an email" \
  934. --msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME unblocked" 6 75
  935. fi
  936. }
  937. function block_unblock_subject {
  938. select_user
  939. if [ ! $SELECTED_USERNAME ]; then
  940. return
  941. fi
  942. blockstr=$"Block/Unblock email going to"
  943. data=$(tempfile 2>/dev/null)
  944. trap "rm -f $data" 0 1 2 5 15
  945. dialog --backtitle $"Freedombone Control Panel" \
  946. --title "$blockstr $SELECTED_USERNAME" \
  947. --form "\n" 8 70 3 \
  948. $"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
  949. $"Block it:" 2 1 "yes" 2 40 4 4 \
  950. 2> $data
  951. sel=$?
  952. case $sel in
  953. 1) return;;
  954. 255) return;;
  955. esac
  956. BLOCK_SUBJECT=$(cat $data | sed -n 1p)
  957. BLOCK=$(cat $data | sed -n 2p)
  958. if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
  959. dialog --title $"Block/Unblock an email" \
  960. --msgbox $"No subject was given" 6 40
  961. return
  962. fi
  963. if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
  964. ${PROJECT_NAME}-ignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  965. dialog --title $"Block an email" \
  966. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME blocked" 6 40
  967. else
  968. ${PROJECT_NAME}-unignore -u $SELECTED_USERNAME -t "$BLOCK_SUBJECT"
  969. dialog --title $"Unblock an email" \
  970. --msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME unblocked" 6 40
  971. fi
  972. }
  973. function create_keydrive_master {
  974. select_user
  975. if [ ! $SELECTED_USERNAME ]; then
  976. return
  977. fi
  978. dialog --title $"USB Master Keydrive" \
  979. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  980. clear
  981. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME --master 'yes'
  982. any_key
  983. }
  984. function create_keydrive_fragment {
  985. select_user
  986. if [ ! $SELECTED_USERNAME ]; then
  987. return
  988. fi
  989. dialog --title $"USB Fragment Keydrive" \
  990. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  991. clear
  992. ${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME
  993. any_key
  994. }
  995. function backup_data {
  996. dialog --title $"Backup data to USB" \
  997. --msgbox $"Plug in a LUKS encrypted USB drive" 6 40
  998. clear
  999. echo ' '
  1000. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  1001. ${PROJECT_NAME}-backup-local
  1002. any_key
  1003. }
  1004. function restore_from_usb {
  1005. while true
  1006. do
  1007. data=$(tempfile 2>/dev/null)
  1008. trap "rm -f $data" 0 1 2 5 15
  1009. dialog --backtitle $"Freedombone Control Panel" \
  1010. --title $"Restore from USB backup" \
  1011. --radiolist $"Choose an application to restore:" 32 70 28 \
  1012. 1 $"Everything" off \
  1013. 2 $"Return to the backup and restore menu" on \
  1014. 3 $"Configuration files" off \
  1015. 4 $"MariaDB settings" off \
  1016. 5 $"Let's Encrypt account" off \
  1017. 6 $"Mutt email client settings" off \
  1018. 7 $"GPG keys" off \
  1019. 8 $"Email processing rules" off \
  1020. 9 $"Spam filtering rules" off \
  1021. 10 $"Administrator's README file" off \
  1022. 11 $"IPFS" off \
  1023. 12 $"SSH keys" off \
  1024. 13 $"User configuration files" off \
  1025. 14 $"User local files" off \
  1026. 15 $"User fin files" off \
  1027. 16 $"SSL/TLS certificates" off \
  1028. 17 $"Personal settings" off \
  1029. 18 $"Mailing List" off \
  1030. 19 $"XMPP chat" off \
  1031. 20 $"GNU Social" off \
  1032. 21 $"Hubzilla" off \
  1033. 22 $"Owncloud" off \
  1034. 23 $"Gogs" off \
  1035. 24 $"Wiki" off \
  1036. 25 $"Blog" off \
  1037. 26 $"CJDNS" off \
  1038. 27 $"Email" off \
  1039. 28 $"DLNA" off \
  1040. 29 $"VoIP" off \
  1041. 30 $"RSS reader" off \
  1042. 31 $"Tox" off \
  1043. 32 $"Mediagoblin" off 2> $data
  1044. sel=$?
  1045. case $sel in
  1046. 1) break;;
  1047. 255) break;;
  1048. esac
  1049. if [ $(cat $data) -ne 2 ]; then
  1050. clear
  1051. fi
  1052. case $(cat $data) in
  1053. 1) ${PROJECT_NAME}-restore-local $USB_DRIVE;;
  1054. 2) return;;
  1055. 3) ${PROJECT_NAME}-restore-local $USB_DRIVE configuration;;
  1056. 4) ${PROJECT_NAME}-restore-local $USB_DRIVE mariadb;;
  1057. 5) ${PROJECT_NAME}-restore-local $USB_DRIVE letsencrypt;;
  1058. 6) ${PROJECT_NAME}-restore-local $USB_DRIVE mutt;;
  1059. 7) ${PROJECT_NAME}-restore-local $USB_DRIVE gpg;;
  1060. 8) ${PROJECT_NAME}-restore-local $USB_DRIVE procmail;;
  1061. 9) ${PROJECT_NAME}-restore-local $USB_DRIVE spamassassin;;
  1062. 10) ${PROJECT_NAME}-restore-local $USB_DRIVE readme;;
  1063. 11) ${PROJECT_NAME}-restore-local $USB_DRIVE ipfs;;
  1064. 12) ${PROJECT_NAME}-restore-local $USB_DRIVE ssh;;
  1065. 13) ${PROJECT_NAME}-restore-local $USB_DRIVE userconfig;;
  1066. 14) ${PROJECT_NAME}-restore-local $USB_DRIVE userlocal;;
  1067. 15) ${PROJECT_NAME}-restore-local $USB_DRIVE userfin;;
  1068. 16) ${PROJECT_NAME}-restore-local $USB_DRIVE certs;;
  1069. 17) ${PROJECT_NAME}-restore-local $USB_DRIVE personal;;
  1070. 18) ${PROJECT_NAME}-restore-local $USB_DRIVE mailinglist;;
  1071. 19) ${PROJECT_NAME}-restore-local $USB_DRIVE xmpp;;
  1072. 20) ${PROJECT_NAME}-restore-local $USB_DRIVE gnusocial;;
  1073. 21) ${PROJECT_NAME}-restore-local $USB_DRIVE hubzilla;;
  1074. 22) ${PROJECT_NAME}-restore-local $USB_DRIVE owncloud;;
  1075. 23) ${PROJECT_NAME}-restore-local $USB_DRIVE gogs;;
  1076. 24) ${PROJECT_NAME}-restore-local $USB_DRIVE wiki;;
  1077. 25) ${PROJECT_NAME}-restore-local $USB_DRIVE blog;;
  1078. 26) ${PROJECT_NAME}-restore-local $USB_DRIVE cjdns;;
  1079. 27) ${PROJECT_NAME}-restore-local $USB_DRIVE email;;
  1080. 28) ${PROJECT_NAME}-restore-local $USB_DRIVE dlna;;
  1081. 29) ${PROJECT_NAME}-restore-local $USB_DRIVE voip;;
  1082. 30) ${PROJECT_NAME}-restore-local $USB_DRIVE ttrss;;
  1083. 31) ${PROJECT_NAME}-restore-local $USB_DRIVE tox;;
  1084. 32) ${PROJECT_NAME}-restore-local $USB_DRIVE mediagoblin;;
  1085. esac
  1086. done
  1087. any_key
  1088. }
  1089. function restore_from_remote {
  1090. remote_domain_name=$1
  1091. while true
  1092. do
  1093. data=$(tempfile 2>/dev/null)
  1094. trap "rm -f $data" 0 1 2 5 15
  1095. dialog --backtitle $"Freedombone Control Panel" \
  1096. --title $"Restore from ${remote_domain_name}" \
  1097. --radiolist $"Choose an application to restore:" 31 70 28 \
  1098. 1 $"Everything" off \
  1099. 2 $"Return to the backup and restore menu" on \
  1100. 3 $"Configuration files" off \
  1101. 4 $"MariaDB settings" off \
  1102. 5 $"Let's Encrypt account" off \
  1103. 6 $"Mutt email client settings" off \
  1104. 7 $"GPG keys" off \
  1105. 8 $"Email processing rules" off \
  1106. 9 $"Spam filtering rules" off \
  1107. 10 $"Administrator's README file" off \
  1108. 11 $"IPFS" off \
  1109. 12 $"SSH keys" off \
  1110. 13 $"User configuration files" off \
  1111. 14 $"User local files" off \
  1112. 15 $"User fin files" off \
  1113. 16 $"SSL/TLS certificates" off \
  1114. 17 $"Personal settings" off \
  1115. 18 $"Mailing List" off \
  1116. 19 $"XMPP chat" off \
  1117. 20 $"GNU Social" off \
  1118. 21 $"Hubzilla" off \
  1119. 22 $"Owncloud" off \
  1120. 23 $"Gogs" off \
  1121. 24 $"Wiki" off \
  1122. 25 $"Blog" off \
  1123. 26 $"CJDNS" off \
  1124. 27 $"Email" off \
  1125. 28 $"DLNA" off \
  1126. 29 $"VoIP" off \
  1127. 30 $"RSS reader" off \
  1128. 31 $"Tox" off 2> $data
  1129. sel=$?
  1130. case $sel in
  1131. 1) break;;
  1132. 255) break;;
  1133. esac
  1134. if [ $(cat $data) -ne 2 ]; then
  1135. clear
  1136. fi
  1137. case $(cat $data) in
  1138. 1) ${PROJECT_NAME}-restore-remote $remote_domain_name;;
  1139. 2) return;;
  1140. 3) ${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;
  1141. 4) ${PROJECT_NAME}-restore-remote $remote_domain_name mariadb;;
  1142. 5) ${PROJECT_NAME}-restore-remote $remote_domain_name letsencrypt;;
  1143. 6) ${PROJECT_NAME}-restore-remote $remote_domain_name mutt;;
  1144. 7) ${PROJECT_NAME}-restore-remote $remote_domain_name gpg;;
  1145. 8) ${PROJECT_NAME}-restore-remote $remote_domain_name procmail;;
  1146. 9) ${PROJECT_NAME}-restore-remote $remote_domain_name spamassassin;;
  1147. 10) ${PROJECT_NAME}-restore-remote $remote_domain_name readme;;
  1148. 11) ${PROJECT_NAME}-restore-remote $remote_domain_name ipfs;;
  1149. 12) ${PROJECT_NAME}-restore-remote $remote_domain_name ssh;;
  1150. 13) ${PROJECT_NAME}-restore-remote $remote_domain_name userconfig;;
  1151. 14) ${PROJECT_NAME}-restore-remote $remote_domain_name userlocal;;
  1152. 15) ${PROJECT_NAME}-restore-remote $remote_domain_name userfin;;
  1153. 16) ${PROJECT_NAME}-restore-remote $remote_domain_name certs;;
  1154. 17) ${PROJECT_NAME}-restore-remote $remote_domain_name personal;;
  1155. 18) ${PROJECT_NAME}-restore-remote $remote_domain_name mailinglist;;
  1156. 19) ${PROJECT_NAME}-restore-remote $remote_domain_name xmpp;;
  1157. 20) ${PROJECT_NAME}-restore-remote $remote_domain_name gnusocial;;
  1158. 21) ${PROJECT_NAME}-restore-remote $remote_domain_name hubzilla;;
  1159. 22) ${PROJECT_NAME}-restore-remote $remote_domain_name owncloud;;
  1160. 23) ${PROJECT_NAME}-restore-remote $remote_domain_name gogs;;
  1161. 24) ${PROJECT_NAME}-restore-remote $remote_domain_name wiki;;
  1162. 25) ${PROJECT_NAME}-restore-remote $remote_domain_name blog;;
  1163. 26) ${PROJECT_NAME}-restore-remote $remote_domain_name cjdns;;
  1164. 27) ${PROJECT_NAME}-restore-remote $remote_domain_name email;;
  1165. 28) ${PROJECT_NAME}-restore-remote $remote_domain_name dlna;;
  1166. 29) ${PROJECT_NAME}-restore-remote $remote_domain_name voip;;
  1167. 30) ${PROJECT_NAME}-restore-remote $remote_domain_name ttrss;;
  1168. 31) ${PROJECT_NAME}-restore-remote $remote_domain_name tox;;
  1169. esac
  1170. done
  1171. any_key
  1172. }
  1173. function restore_data {
  1174. dialog --title $"Restore data from USB" \
  1175. --msgbox $"Plug in your backup USB drive" 6 40
  1176. clear
  1177. echo ' '
  1178. echo $'Enter the passphrase for your LUKS encrypted backup drive:'
  1179. restore_from_usb
  1180. }
  1181. function restore_data_remote {
  1182. if [ ! $ADMIN_USER ]; then
  1183. dialog --title $"Restore data from remote server" \
  1184. --msgbox $"Unknown admin user" 6 40
  1185. return
  1186. fi
  1187. data=$(tempfile 2>/dev/null)
  1188. trap "rm -f $data" 0 1 2 5 15
  1189. dialog --title $"Restore from remote server" \
  1190. --backtitle $"Freedombone Control Panel" \
  1191. --inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>$data
  1192. sel=$?
  1193. case $sel in
  1194. 0)
  1195. friend_server_domain_name=$(<$data)
  1196. if [ ${#friend_server_domain_name} -lt 2 ]; then
  1197. return
  1198. fi
  1199. if [[ $friend_server_domain_name != *"."* ]]; then
  1200. dialog --title $"Remote server domain name" \
  1201. --msgbox $"Invalid domain name" 6 40
  1202. return
  1203. fi
  1204. restore_from_remote $friend_server_domain_name
  1205. ;;
  1206. esac
  1207. }
  1208. function ping_enable_disable {
  1209. 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."
  1210. enable_ping="no"
  1211. dialog --title $"Enable Ping / ICMP" \
  1212. --backtitle $"Freedombone Control Panel" \
  1213. --defaultno \
  1214. --yesno "$ping_str" 10 60
  1215. sel=$?
  1216. case $sel in
  1217. 0) enable_ping="yes";;
  1218. 255) return;;
  1219. esac
  1220. if [[ $enable_ping == "yes" ]]; then
  1221. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  1222. iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  1223. echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  1224. else
  1225. iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT
  1226. iptables -D OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
  1227. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
  1228. fi
  1229. }
  1230. function logging_on_off {
  1231. logging="no"
  1232. dialog --title $"Logging" \
  1233. --backtitle $"Freedombone Control Panel" \
  1234. --yesno $"\nDo you want to turn logging on?" 7 60
  1235. sel=$?
  1236. case $sel in
  1237. 0) logging="yes";;
  1238. 255) return;;
  1239. esac
  1240. clear
  1241. echo ''
  1242. echo $'This may take a few seconds. Please wait...'
  1243. if [[ $logging == "no" ]]; then
  1244. ${PROJECT_NAME}-logging off
  1245. else
  1246. ${PROJECT_NAME}-logging on
  1247. fi
  1248. }
  1249. function restore_gpg_key {
  1250. select_user
  1251. if [ ! $SELECTED_USERNAME ]; then
  1252. return
  1253. fi
  1254. restorestr=$"Restore GPG key for user"
  1255. dialog --title "$restorestr $SELECTED_USERNAME" \
  1256. --msgbox $"Plug in your USB keydrive" 6 40
  1257. clear
  1258. ${PROJECT_NAME}-recoverkey -u $SELECTED_USERNAME
  1259. any_key
  1260. }
  1261. function security_settings {
  1262. ${PROJECT_NAME}-sec
  1263. any_key
  1264. }
  1265. function reset_tripwire {
  1266. clear
  1267. echo $'Resetting the Tripwire...'
  1268. echo ' '
  1269. echo '
  1270. ' | reset-tripwire
  1271. any_key
  1272. }
  1273. function hubzilla_renew_cert {
  1274. dialog --title $"Renew SSL certificate" \
  1275. --backtitle $"Freedombone Control Panel" \
  1276. --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
  1277. sel=$?
  1278. case $sel in
  1279. 1) return;;
  1280. 255) return;;
  1281. esac
  1282. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  1283. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  1284. dialog --title $"Renew SSL certificate" \
  1285. --msgbox $"Hubzilla install directory not found" 6 40
  1286. return
  1287. fi
  1288. ${PROJECT_NAME}-renew-cert -h $HUBZILLA_DOMAIN_NAME -p 'letsencrypt'
  1289. if [ ! "$?" = "0" ]; then
  1290. any_key
  1291. else
  1292. dialog --title $"Renew SSL certificate" \
  1293. --msgbox $"Hubzilla certificate has been renewed" 6 40
  1294. fi
  1295. }
  1296. function hubzilla_channel_directory_server {
  1297. if ! grep -q "Hubzilla domain" $COMPLETION_FILE; then
  1298. dialog --title $"Hubzilla channel directory server" \
  1299. --msgbox $"Hubzilla is not installed on this system" 6 40
  1300. return
  1301. fi
  1302. HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
  1303. if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
  1304. dialog --title $"Hubzilla channel directory server" \
  1305. --msgbox $"Hubzilla install directory not found" 6 40
  1306. return
  1307. fi
  1308. data=$(tempfile 2>/dev/null)
  1309. trap "rm -f $data" 0 1 2 5 15
  1310. dialog --title $"Hubzilla channel directory server" \
  1311. --backtitle $"Freedombone Control Panel" \
  1312. --inputbox $"When you click on 'channel directory' this is where Hubzilla will obtain its list from" 8 60 2>$data
  1313. sel=$?
  1314. case $sel in
  1315. 0)
  1316. hubzilla_domain_server=$(<$data)
  1317. if [[ $hubzilla_domain_server != *"."* ]]; then
  1318. return
  1319. fi
  1320. if [[ $hubzilla_domain_server != "https"* ]]; then
  1321. dialog --title $"Hubzilla channel directory server" \
  1322. --msgbox $"Invalid domain - include the https://" 6 40
  1323. return
  1324. fi
  1325. ./var/www/$HUBZILLA_DOMAIN_NAME/htdocs/util/config system directory_server $hubzilla_domain_server
  1326. dialog --title $"Hubzilla channel directory server" \
  1327. --msgbox $"Domain channel directory server changed to $hubzilla_domain_server" 6 40
  1328. ;;
  1329. esac
  1330. }
  1331. function format_drive {
  1332. drive=
  1333. data=$(tempfile 2>/dev/null)
  1334. trap "rm -f $data" 0 1 2 5 15
  1335. dialog --backtitle $"Freedombone Control Panel" \
  1336. --title $"Format a USB drive (LUKS encrypted)" \
  1337. --radiolist $"Choose a drive:" 12 70 5 \
  1338. 1 $"sda (Beaglebone Black)" off \
  1339. 2 $"sdb" off \
  1340. 3 $"sdc" off \
  1341. 4 $"sdd" off \
  1342. 5 $"Back to Backup and Restore menu" on 2> $data
  1343. sel=$?
  1344. case $sel in
  1345. 1) return;;
  1346. 255) return;;
  1347. esac
  1348. case $(cat $data) in
  1349. 1) drive='sda';;
  1350. 2) drive='sdb';;
  1351. 3) drive='sdc';;
  1352. 4) drive='sdd';;
  1353. 5) return;;
  1354. esac
  1355. dialog --title $"Format USB drive" \
  1356. --backtitle $"Freedombone Control Panel" \
  1357. --defaultno \
  1358. --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
  1359. sel=$?
  1360. case $sel in
  1361. 1) return;;
  1362. 255) return;;
  1363. esac
  1364. clear
  1365. ${PROJECT_NAME}-format $drive
  1366. any_key
  1367. }
  1368. function remove_backups {
  1369. drive=
  1370. data=$(tempfile 2>/dev/null)
  1371. trap "rm -f $data" 0 1 2 5 15
  1372. dialog --backtitle $"Freedombone Control Panel" \
  1373. --title $"Remove backups from a USB drive" \
  1374. --radiolist $"Choose a drive:" 12 70 5 \
  1375. 1 $"sda (Beaglebone Black)" off \
  1376. 2 $"sdb" off \
  1377. 3 $"sdc" off \
  1378. 4 $"sdd" off \
  1379. 5 $"Back to Backup and Restore menu" on 2> $data
  1380. sel=$?
  1381. case $sel in
  1382. 1) return;;
  1383. 255) return;;
  1384. esac
  1385. case $(cat $data) in
  1386. 1) drive='sda';;
  1387. 2) drive='sdb';;
  1388. 3) drive='sdc';;
  1389. 4) drive='sdd';;
  1390. 5) return;;
  1391. esac
  1392. dialog --title $"Remove backups from a USB drive" \
  1393. --backtitle $"Freedombone Control Panel" \
  1394. --defaultno \
  1395. --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
  1396. sel=$?
  1397. case $sel in
  1398. 1) return;;
  1399. 255) return;;
  1400. esac
  1401. clear
  1402. ${PROJECT_NAME}-backup-local $drive remove
  1403. any_key
  1404. }
  1405. function shut_down_system {
  1406. dialog --title $"Power off the system" \
  1407. --backtitle $"Freedombone Control Panel" \
  1408. --defaultno \
  1409. --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
  1410. sel=$?
  1411. case $sel in
  1412. 1) return;;
  1413. 255) return;;
  1414. esac
  1415. shutdown now
  1416. }
  1417. function restart_system {
  1418. dialog --title $"Restart the system" \
  1419. --backtitle $"Freedombone Control Panel" \
  1420. --defaultno \
  1421. --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
  1422. sel=$?
  1423. case $sel in
  1424. 1) return;;
  1425. 255) return;;
  1426. esac
  1427. reboot
  1428. }
  1429. function change_system_name {
  1430. data=$(tempfile 2>/dev/null)
  1431. trap "rm -f $data" 0 1 2 5 15
  1432. dialog --title $"Change the name of this system" \
  1433. --backtitle $"Freedombone Control Panel" \
  1434. --inputbox $'Enter a new name for this system on your local network\n\nIt will appear as newname.local' 10 60 2>$data
  1435. sel=$?
  1436. case $sel in
  1437. 0) NEW_SYSTEM_NAME=$(<$data)
  1438. if [ "$NEW_SYSTEM_NAME" ]; then
  1439. if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
  1440. sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
  1441. systemctl restart avahi-daemon
  1442. if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
  1443. dialog --title $"New local network name" \
  1444. --msgbox $"The name of this system on your local network was changed successfully" 6 70
  1445. fi
  1446. fi
  1447. fi
  1448. ;;
  1449. esac
  1450. }
  1451. function set_tls_time_source {
  1452. TLS_DATE_SOURCE=$(cat /usr/bin/updatedate | grep "TIMESOURCE='" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
  1453. data=$(tempfile 2>/dev/null)
  1454. trap "rm -f $data" 0 1 2 5 15
  1455. dialog --title $"Set the TLS date/time source" \
  1456. --backtitle $"Freedombone Control Panel" \
  1457. --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
  1458. sel=$?
  1459. case $sel in
  1460. 0) NEW_TLS_DATE_SOURCE=$(<$data)
  1461. if [[ $NEW_TLS_DATE_SOURCE == *"."* && $NEW_TLS_DATE_SOURCE != *'/'* ]]; then
  1462. if [[ $NEW_TLS_DATE_SOURCE != "http"* ]]; then
  1463. sed -i "s|TIMESOURCE='.*|TIMESOURCE='${NEW_TLS_DATE_SOURCE}'|g" $UPDATE_DATE_SCRIPT
  1464. else
  1465. dialog --title $"Invalid domain name" \
  1466. --msgbox $"Don't include the 'https'" 6 70
  1467. fi
  1468. else
  1469. dialog --title $"Invalid domain name" \
  1470. --msgbox $"That doesn't look like a domain name" 6 70
  1471. fi
  1472. ;;
  1473. esac
  1474. }
  1475. function set_static_IP {
  1476. STATIC_IP='192.168.1.60'
  1477. STATIC_GATEWAY='192.168.1.1'
  1478. NEW_STATIC_IP=
  1479. NEW_STATIC_GATEWAY=
  1480. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1481. STATIC_IP=$(cat /etc/network/interfaces | grep "address " | awk -F ' ' '{print $2}' | head -n 1)
  1482. STATIC_GATEWAY=$(cat /etc/network/interfaces | grep "gateway " | awk -F ' ' '{print $2}' | head -n 1)
  1483. fi
  1484. # get the IP for the box
  1485. data=$(tempfile 2>/dev/null)
  1486. trap "rm -f $data" 0 1 2 5 15
  1487. dialog --title $"Set a static local IP address" \
  1488. --backtitle $"Freedombone Control Panel" \
  1489. --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
  1490. Enter a static local IP address for this system.\n\nIt will typically be 192.168.1.x" 15 60 "$STATIC_IP" 2>$data
  1491. sel=$?
  1492. case $sel in
  1493. 0) NEW_STATIC_IP=$(<$data)
  1494. if [[ "$NEW_STATIC_IP" != *"."* ]]; then
  1495. return
  1496. fi
  1497. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1498. if [[ "$NEW_STATIC_IP" != "$STATIC_IP" ]]; then
  1499. sed -i "s|${STATIC_IP}|${NEW_STATIC_IP}|g" /etc/network/interfaces
  1500. fi
  1501. fi
  1502. ;;
  1503. esac
  1504. # get the gateway
  1505. data=$(tempfile 2>/dev/null)
  1506. trap "rm -f $data" 0 1 2 5 15
  1507. dialog --title $"Set the IP address of your internet router/modem" \
  1508. --backtitle $"Freedombone Control Panel" \
  1509. --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
  1510. sel=$?
  1511. case $sel in
  1512. 0) NEW_STATIC_GATEWAY=$(<$data)
  1513. if [[ "$NEW_STATIC_GATEWAY" != *"."* ]]; then
  1514. return
  1515. fi
  1516. if grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1517. if [[ "$NEW_STATIC_GATEWAY" != "$STATIC_GATEWAY" ]]; then
  1518. sed -i "s|${STATIC_GATEWAY}|${NEW_STATIC_GATEWAY}|g" /etc/network/interfaces
  1519. fi
  1520. return
  1521. fi
  1522. ;;
  1523. esac
  1524. if ! grep -q 'iface eth0 inet static' /etc/network/interfaces; then
  1525. if [ "$NEW_STATIC_GATEWAY" && "$NEW_STATIC_IP" ]; then
  1526. echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
  1527. echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
  1528. echo '' >> /etc/network/interfaces
  1529. echo '# The loopback network interface' >> /etc/network/interfaces
  1530. echo 'auto lo' >> /etc/network/interfaces
  1531. echo 'iface lo inet loopback' >> /etc/network/interfaces
  1532. echo '' >> /etc/network/interfaces
  1533. echo '# The primary network interface' >> /etc/network/interfaces
  1534. echo 'auto eth0' >> /etc/network/interfaces
  1535. echo 'iface eth0 inet static' >> /etc/network/interfaces
  1536. echo " address ${NEW_STATIC_IP}" >> /etc/network/interfaces
  1537. echo ' netmask 255.255.255.0' >> /etc/network/interfaces
  1538. echo " gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
  1539. echo " dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
  1540. echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
  1541. echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
  1542. echo '' >> /etc/network/interfaces
  1543. echo '# The secondary network interface' >> /etc/network/interfaces
  1544. echo '#auto eth1' >> /etc/network/interfaces
  1545. echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
  1546. echo '' >> /etc/network/interfaces
  1547. echo '# WiFi Example' >> /etc/network/interfaces
  1548. echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
  1549. echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
  1550. echo '# wpa-ssid "essid"' >> /etc/network/interfaces
  1551. echo '# wpa-psk "password"' >> /etc/network/interfaces
  1552. echo '' >> /etc/network/interfaces
  1553. echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
  1554. echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
  1555. echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
  1556. echo '#iface usb0 inet static' >> /etc/network/interfaces
  1557. echo '# address 192.168.7.2' >> /etc/network/interfaces
  1558. echo '# netmask 255.255.255.0' >> /etc/network/interfaces
  1559. echo '# network 192.168.7.0' >> /etc/network/interfaces
  1560. echo '# gateway 192.168.7.1' >> /etc/network/interfaces
  1561. fi
  1562. fi
  1563. }
  1564. function menu_backup_restore {
  1565. while true
  1566. do
  1567. data=$(tempfile 2>/dev/null)
  1568. trap "rm -f $data" 0 1 2 5 15
  1569. dialog --backtitle $"Freedombone Control Panel" \
  1570. --title $"Backup and Restore" \
  1571. --radiolist $"Choose an operation:" 18 70 11 \
  1572. 1 $"Backup data to USB drive" off \
  1573. 2 $"Restore GPG key from USB keydrive" off \
  1574. 3 $"Restore data from USB drive" off \
  1575. 4 $"Configure remote backups" off \
  1576. 5 $"Restore from remote backup" off \
  1577. 6 $"Backup GPG key to USB (master keydrive)" off \
  1578. 7 $"Backup GPG key to USB (fragment keydrive)" off \
  1579. 8 $"Format a USB drive (LUKS encrypted)" off \
  1580. 9 $"Remove backups from a USB drive" off \
  1581. 10 $"Back to main menu" on 2> $data
  1582. sel=$?
  1583. case $sel in
  1584. 1) break;;
  1585. 255) break;;
  1586. esac
  1587. case $(cat $data) in
  1588. 1) backup_data;;
  1589. 2) restore_gpg_key;;
  1590. 3) restore_data;;
  1591. 4) configure_remote_backups;;
  1592. 5) restore_data_remote;;
  1593. 6) create_keydrive_master;;
  1594. 7) create_keydrive_fragment;;
  1595. 8) format_drive;;
  1596. 9) remove_backups;;
  1597. 10) break;;
  1598. esac
  1599. done
  1600. }
  1601. function menu_email {
  1602. while true
  1603. do
  1604. data=$(tempfile 2>/dev/null)
  1605. trap "rm -f $data" 0 1 2 5 15
  1606. dialog --backtitle $"Freedombone Control Panel" \
  1607. --title $"Email Filtering Rules" \
  1608. --radiolist $"Choose an operation:" 13 70 6 \
  1609. 1 $"Add a user to a mailing list" off \
  1610. 2 $"Remove a user from a mailing list" off \
  1611. 3 $"Add an email rule" off \
  1612. 4 $"Block/Unblock an email address" off \
  1613. 5 $"Block/Unblock email with subject text" off \
  1614. 6 $"Back to main menu" on 2> $data
  1615. sel=$?
  1616. case $sel in
  1617. 1) break;;
  1618. 255) break;;
  1619. esac
  1620. case $(cat $data) in
  1621. 1) add_to_mailing_list;;
  1622. 2) remove_user_from_mailing_list;;
  1623. 3) email_rule;;
  1624. 4) block_unblock_email;;
  1625. 5) block_unblock_subject;;
  1626. 6) break;;
  1627. esac
  1628. done
  1629. }
  1630. function menu_users {
  1631. while true
  1632. do
  1633. data=$(tempfile 2>/dev/null)
  1634. trap "rm -f $data" 0 1 2 5 15
  1635. dialog --backtitle $"Freedombone Control Panel" \
  1636. --title $"Manage Users" \
  1637. --radiolist $"Choose an operation:" 12 70 5 \
  1638. 1 $"Add a user" off \
  1639. 2 $"Delete a user" off \
  1640. 3 $"Change user password" off \
  1641. 4 $"Change user ssh public key" off \
  1642. 5 $"Back to main menu" on 2> $data
  1643. sel=$?
  1644. case $sel in
  1645. 1) break;;
  1646. 255) break;;
  1647. esac
  1648. case $(cat $data) in
  1649. 1) add_user;;
  1650. 2) delete_user;;
  1651. 3) change_password;;
  1652. 4) change_ssh_public_key;;
  1653. 5) break;;
  1654. esac
  1655. done
  1656. }
  1657. function menu_hubzilla {
  1658. while true
  1659. do
  1660. data=$(tempfile 2>/dev/null)
  1661. trap "rm -f $data" 0 1 2 5 15
  1662. dialog --backtitle $"Freedombone Control Panel" \
  1663. --title $"Hubzilla" \
  1664. --radiolist $"Choose an operation:" 13 70 4 \
  1665. 1 $"Set channel directory server" off \
  1666. 2 $"Renew SSL certificate" off \
  1667. 3 $"Back to main menu" on 2> $data
  1668. sel=$?
  1669. case $sel in
  1670. 1) break;;
  1671. 255) break;;
  1672. esac
  1673. case $(cat $data) in
  1674. 1) hubzilla_channel_directory_server;;
  1675. 2) hubzilla_renew_cert;;
  1676. 3) break;;
  1677. esac
  1678. done
  1679. }
  1680. function menu_media {
  1681. while true
  1682. do
  1683. data=$(tempfile 2>/dev/null)
  1684. trap "rm -f $data" 0 1 2 5 15
  1685. dialog --backtitle $"Freedombone Control Panel" \
  1686. --title $"Media Menu" \
  1687. --radiolist $"Choose an operation:" 13 70 3 \
  1688. 1 $"Attach a drive containing playable media" off \
  1689. 2 $"Remove a drive containing playable media" off \
  1690. 3 $"Exit" on 2> $data
  1691. sel=$?
  1692. case $sel in
  1693. 1) break;;
  1694. 255) break;;
  1695. esac
  1696. case $(cat $data) in
  1697. 1) remove-music
  1698. attach-music;;
  1699. 2) remove-music;;
  1700. 3) break;;
  1701. esac
  1702. done
  1703. }
  1704. function menu_irc {
  1705. if [ ! -d /etc/ngircd ]; then
  1706. dialog --title $"IRC Menu" \
  1707. --msgbox $"No IRC server is installed" 6 70
  1708. return
  1709. fi
  1710. while true
  1711. do
  1712. data=$(tempfile 2>/dev/null)
  1713. trap "rm -f $data" 0 1 2 5 15
  1714. dialog --backtitle $"Freedombone Control Panel" \
  1715. --title $"IRC Menu" \
  1716. --radiolist $"Choose an operation:" 14 70 4 \
  1717. 1 $"Set a password for all IRC users" off \
  1718. 2 $"Show current IRC login password" off \
  1719. 3 $"Access via the onion address" off \
  1720. 4 $"Exit" on 2> $data
  1721. sel=$?
  1722. case $sel in
  1723. 1) break;;
  1724. 255) break;;
  1725. esac
  1726. case $(cat $data) in
  1727. 1) irc_set_global_password;;
  1728. 2) irc_show_password;;
  1729. 3) irc_via_onion;;
  1730. 4) break;;
  1731. esac
  1732. done
  1733. }
  1734. function menu_top_level {
  1735. while true
  1736. do
  1737. data=$(tempfile 2>/dev/null)
  1738. trap "rm -f $data" 0 1 2 5 15
  1739. dialog --backtitle $"Freedombone Control Panel" \
  1740. --title $"Control Panel" \
  1741. --radiolist $"Choose an operation:" 28 70 21 \
  1742. 1 $"About this system" off \
  1743. 2 $"Backup and Restore" off \
  1744. 3 $"Reset Tripwire" off \
  1745. 4 $"Logging on/off" off \
  1746. 5 $"Ping enable/disable" off \
  1747. 6 $"Manage Users" off \
  1748. 7 $"Email Filtering Rules" off \
  1749. 8 $"Outgoing Email Proxy" off \
  1750. 9 $"Security Settings" off \
  1751. 10 $"Set the main repository (repo mirrors)" off \
  1752. 11 $"Hubzilla" off \
  1753. 12 $"Media menu" off \
  1754. 13 $"IRC menu" off \
  1755. 14 $"Change your blog avatar" off \
  1756. 15 $"Change the name of this system" off \
  1757. 16 $"Set the TLS date/time source" off \
  1758. 17 $"Set a static local IP address" off \
  1759. 18 $"Check for updates" off \
  1760. 19 $"Power off the system" off \
  1761. 20 $"Restart the system" off \
  1762. 21 $"Exit" on 2> $data
  1763. sel=$?
  1764. case $sel in
  1765. 1) exit 1;;
  1766. 255) exit 1;;
  1767. esac
  1768. case $(cat $data) in
  1769. 1) show_about;;
  1770. 2) menu_backup_restore;;
  1771. 3) reset_tripwire;;
  1772. 4) logging_on_off;;
  1773. 5) ping_enable_disable;;
  1774. 6) menu_users;;
  1775. 7) menu_email;;
  1776. 8) smtp_proxy;;
  1777. 9) security_settings;;
  1778. 10) set_main_repo;;
  1779. 11) menu_hubzilla;;
  1780. 12) menu_media;;
  1781. 13) menu_irc;;
  1782. 14) change_blog_avatar;;
  1783. 15) change_system_name;;
  1784. 16) set_tls_time_source;;
  1785. 17) set_static_IP;;
  1786. 18) check_for_updates;;
  1787. 19) shut_down_system;;
  1788. 20) restart_system;;
  1789. 21) break;;
  1790. esac
  1791. done
  1792. }
  1793. if [[ $USER != 'root' ]]; then
  1794. # show the user version of the control panel
  1795. freedombone-controlpanel-user
  1796. exit 0
  1797. fi
  1798. if [ ! -f $COMPLETION_FILE ]; then
  1799. echo $'This command should only be run on an installed Freedombone system'
  1800. exit 1
  1801. fi
  1802. ADMIN_USER=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  1803. read_repo_servers
  1804. menu_top_level
  1805. clear
  1806. cat /etc/motd
  1807. exit 0