freedombone-controlpanel 60KB

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