freedombone-controlpanel 69KB

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