freedombone-controlpanel 62KB

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