Software-daemons.tex 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. %
  2. % Software-daemons.tex
  3. %
  4. % Fork Sand IT Manual
  5. %
  6. % Copyright (C) 2018, Fork Sand, Inc.
  7. % Copyright (C) 2017, Jeff Moe
  8. % Copyright (C) 2014, 2015, 2016, 2017 Aleph Objects, Inc.
  9. %
  10. % This document is licensed under the Creative Commons Attribution 4.0
  11. % International Public License (CC BY-SA 4.0) by Fork Sand, Inc.
  12. %
  13. \section{Server Daemons}
  14. These are the server daemons used to drive the enterprise.
  15. \section{\href{http://sourceforge.net/projects/acpid2/}{ACPID}}
  16. Monitors ACPI events. Runs on nearly all servers and workstations.
  17. \section{\href{http://httpd.apache.org/}{Apache}}
  18. Web daemon, used on many servers.
  19. \section{\href{http://www.isc.org/}{BIND}}
  20. Nameserver used for caching.
  21. \section{\href{https://borgbackup.github.io/borgbackup/}{Borg}}
  22. Backup program.
  23. \section{\href{https://www.collaboraoffice.com/code/}{code}}
  24. Collabora Online Development Edition (CODE) is LibreOffice Online (LOOL)
  25. for Nextcloud.
  26. \section{\href{https://github.com/coturn/coturn}{coturn}}
  27. TURN and STUN server. Used for videoconferencing.
  28. \section{\href{http://ftp.isc.org/isc/cron/}{cron}}
  29. Scheduled triggering of applications (cf. at).
  30. \section{\href{http://dnsmasq.org/}{DHCP}}
  31. dnsmasq DHCP for 350+ hosts.
  32. \section{\href{https://www.discourse.org/}{Discourse}}
  33. Mailing list, discussion board, forum.
  34. \section{\href{https://dockerproject.org/}{Docker}}
  35. \begin{picture}(0,0)\put(-10000,0){
  36. \gls{docker}
  37. }\end{picture}
  38. System containers, virtual servers.
  39. \section{\href{http://dnsmasq.org/}{DNS}}
  40. dnsmasq DNS caching.
  41. \section{\href{http://dnsmasq.org/}{Dovecot}}
  42. IMAP mail services. Employees check their mail via the
  43. IMAP server, typically using Icedove or aomail (roundcube using IMAP).
  44. \section{\href{https://www.erlang.org/}{Erlang}}
  45. Virtual machine (ejabberd).
  46. \section{{iptables}{\Glspl{firewall}}}
  47. Linux's iptables.
  48. \section{\href{http://www.fail2ban.org/}{fail2ban}}
  49. Block out scripts, bots, crackers, and network noise on servers.
  50. \section{\href{http://www.debian.org/}{Init}}
  51. Init, woo!
  52. \section{\href{http://mariadb.org/}{MariaDB}}
  53. Used on many servers for a database. Replacing MySQL.
  54. \section{md RAID}
  55. Linux RAID, md, mdadm.
  56. \section{\href{http://www.memcached.org/}{memcached}}
  57. Used to speed up websites, such as Nextcloud.
  58. \section{\href{http://www.mysql.org/}{MySQL}}
  59. Used on many servers for a database.
  60. \section{\href{https://nextcloud.com/}{Nextcloud}}
  61. Shared calendars, files, collaborative document editing with
  62. LibreOffice Online, videoconferencing.
  63. Some of this is from owncloud era...
  64. \begin{minted}{sh}
  65. #Install debian jessie, ssh server, standard system utilities
  66. #install jebba ssh key
  67. #install sudo
  68. #disable password ssh
  69. #disable root ssh
  70. #==================================
  71. #
  72. #Set up DNS
  73. #Set up Server
  74. #Create new jessie server, and boot it up.
  75. #Copy over key:
  76. ssh-copy-id jebba@pwn.themoes.org
  77. #Log in to new machine:
  78. ssh jebba@pwn.themoes.org
  79. #Change jebba's password.
  80. passwd jebba
  81. #Set a root password:
  82. su -
  83. passwd root
  84. #Disable source repos:
  85. sed -i -e 's/deb-src/#deb-src/g' /etc/apt/sources.list
  86. #Set up `git` as kludge to track /etc
  87. apt-get -y install git
  88. cd /etc
  89. git init
  90. chmod og-rwx /etc/.git
  91. vi /etc/.gitignore
  92. \end{minted}
  93. Add these lines to /etc/.gitignore
  94. \begin{minted}{sh}
  95. prelink.cache
  96. *.swp
  97. ld.so.cache
  98. adjtime
  99. blkid.tab
  100. blkid.tab.old
  101. mtab
  102. resolv.conf
  103. asound.state
  104. mtab.fuselock
  105. aliases.db
  106. \end{minted}
  107. \subsection{Set up a git user:}
  108. vi ~/.gitconfig
  109. \begin{minted}{sh}
  110. [user]
  111. name = Jeff Moe
  112. [color]
  113. branch = auto
  114. diff = auto
  115. status = auto
  116. \end{minted}
  117. \subsection{Create and populate the git repo for /etc:}
  118. \begin{minted}{sh}
  119. git add .
  120. EDITOR=vi git commit -a
  121. \end{minted}
  122. Intial setup of pwn.themoes.org jessie owncloud server
  123. \begin{minted}{sh}
  124. #Install some needed stuff:
  125. apt-get -y install sudo vim curl exuberant-ctags rsync ntp vim-scripts
  126. host strace telnet lsb-release unzip bzip2 && apt-get clean
  127. #Set up vim:
  128. echo :syntax on > ~/.vimrc
  129. #Add jebba to sudo group:
  130. adduser jebba sudo
  131. #Make sudoers passwordless:
  132. vim /etc/sudoers
  133. #Change:
  134. %sudo ALL=(ALL:ALL) ALL
  135. #To:
  136. %sudo ALL=(ALL) NOPASSWD: ALL
  137. #Edit /etc/ssh/sshd_config (dodgy way to do this):
  138. sed -i \
  139. -e 's/PermitRootLogin yes/PermitRootLogin no/g' \
  140. -e 's/\#PasswordAuthentication yes/PasswordAuthentication no/g' \
  141. -e 's/RSAAuthentication yes/RSAAuthentication no/g' \
  142. -e 's/Port 22/Port 43827/g'\
  143. -e 's/X11Forwarding yes/X11Forwarding no/g' \
  144. /etc/ssh/sshd_config
  145. #Disable unneeded services:
  146. for i in nfs-common rpcbind mountkernfs.sh rsync exim4 ; do echo $i ;
  147. sudo /usr/sbin/update-rc.d $i disable ; done
  148. \end{minted}
  149. Todo. Should these be dropped too? mountnfs-bootclean.sh mountnfs.sh
  150. Reboot
  151. \begin{minted}{sh}
  152. #Log in as jebba (from workstation):
  153. ssh -p 43827 -C jebba@pwn.themoes.org
  154. #VIM:
  155. echo :syntax on > ~/.vimrc
  156. \end{minted}
  157. \subsection{Setup}
  158. Update /etc/hosts:
  159. \begin{minted}{sh}
  160. 5.152.179.226 pwn pwn.themoes.org
  161. #Comment out:
  162. #127.0.1.1 pwn.themoes.org pwn
  163. #Update /etc/hostname:
  164. pwn
  165. #Commit everything so far to git
  166. sudo su -
  167. cd /etc
  168. git add .
  169. EDITOR=vi git commit -a
  170. # Additional base config for server.
  171. \end{minted}
  172. \subsection{Make IP Static}
  173. \begin{minted}{sh}
  174. vim /etc/network/interfaces
  175. \end{minted}
  176. Comment out:
  177. \begin{minted}{sh}
  178. #allow-hotplug eth0
  179. #iface eth0 inet dhcp
  180. \end{minted}
  181. Add:
  182. \begin{minted}{sh}
  183. auto eth0
  184. iface eth0 inet static
  185. address 5.152.179.226
  186. netmask 255.255.255.0
  187. gateway 5.152.179.1
  188. \end{minted}
  189. \subsection{Install Firewall}\label{ssec:nextcloudfirewall}
  190. \url{https://wiki.debian.org/iptables}
  191. \begin{minted}{sh}
  192. #Create /etc/iptables.up.rules and /etc/network/if-pre-up.d/iptables
  193. touch /etc/iptables.up.rules /etc/network/if-pre-up.d/iptables
  194. /etc/iptables.test.rules
  195. chmod 600 /etc/iptables.test.rules /etc/iptables.up.rules
  196. \end{minted}
  197. \begin{minted}{sh}
  198. vim /etc/iptables.test.rules
  199. \end{minted}
  200. *filter
  201. \begin{minted}{sh}
  202. # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that
  203. doesn't use lo0
  204. -A INPUT -i lo -j ACCEPT
  205. #-A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
  206. # Accepts all established inbound connections
  207. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  208. # Allows all outbound traffic
  209. # You could modify this to only allow certain traffic
  210. -A OUTPUT -j ACCEPT
  211. # Allows HTTP and HTTPS connections from anywhere (the normal ports for
  212. websites)
  213. #-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
  214. #-A INPUT -p tcp --dport 80 -j ACCEPT
  215. # Accept 443 from everywhere
  216. #-A INPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
  217. #-A INPUT -p tcp --dport 443 -j ACCEPT
  218. # SSH Access Port 43827
  219. -A INPUT -p tcp -s 67.54.153.124 --dport 43827 -j ACCEPT
  220. # Allow ssh from anywhere
  221. -A INPUT -p tcp --dport 43827 -j ACCEPT
  222. # Allow ping
  223. -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
  224. # Opsview access
  225. #-A INPUT -s 999.999.999.999/32 -p icmp -m icmp --icmp-type 8 -j ACCEPT
  226. #-A INPUT -s 999.999.999.999/32 -p tcp -m tcp -m multiport --dports
  227. 2222,37,4949,5666 -j ACCEPT
  228. # log iptables denied calls (access via 'dmesg' command)
  229. -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: "
  230. --log-level 7
  231. # Reject all other inbound - default deny unless explicitly allowed policy:
  232. -A INPUT -j REJECT
  233. -A FORWARD -j REJECT
  234. COMMIT
  235. \end{minted}
  236. \begin{minted}{sh}
  237. touch /etc/network/if-pre-up.d/iptables
  238. chmod 755 /etc/network/if-pre-up.d/iptables
  239. vim /etc/network/if-pre-up.d/iptables
  240. \end{minted}
  241. \begin{minted}{sh}
  242. #!/bin/bash
  243. /sbin/iptables-restore < /etc/iptables.up.rules
  244. \end{minted}
  245. Then run:
  246. \begin{minted}{sh}
  247. iptables-restore < /etc/iptables.test.rules
  248. iptables -L
  249. iptables-save > /etc/iptables.up.rules
  250. \end{minted}
  251. Disable IPv6
  252. \begin{minted}{sh}
  253. vim /etc/sysctl.conf
  254. \end{minted}
  255. Add:
  256. \begin{minted}{sh}
  257. # Disable IPv6
  258. net.ipv6.conf.all.disable_ipv6 = 1
  259. net.ipv6.conf.default.disable_ipv6 = 1
  260. net.ipv6.conf.lo.disable_ipv6 = 1
  261. net.ipv6.conf.eth0.disable_ipv6 = 1
  262. \end{minted}
  263. \begin{minted}{sh}
  264. sysctl -p
  265. \end{minted}
  266. Add this to kernel boot line /etc/default/grub:
  267. \begin{minted}{sh}
  268. GRUB_CMDLINE_LINUX="ipv6.disable=1"
  269. \end{minted}
  270. then run:
  271. \begin{minted}{sh}
  272. update-grub
  273. \end{minted}
  274. \begin{minted}{sh}
  275. # Also need to change anything in /etc/apache2/sites-enabled/* that has
  276. *:80 to 0.0.0.0, so no IPv6.
  277. # Comment out IPv6 stuff in /etc/hosts:
  278. #::1 localhost ip6-localhost ip6-loopback
  279. #ff02::1 ip6-allnodes
  280. #ff02::2 ip6-allrouters
  281. # Also need to change anything in /etc/apache2/sites-enabled/* that has
  282. *:80 to 0.0.0.0, so no IPv6.
  283. \end{minted}
  284. Blacklist the module, don't even load it:
  285. \begin{minted}{sh}
  286. echo blacklist ipv6 > /etc/modprobe.d/ipv6.conf
  287. \end{minted}
  288. Tell the module not to use IPv6 (hit it with the hammer over and over):
  289. \begin{minted}{sh}
  290. echo alias net-pf-10 off >> /etc/modprobe.d/aliases.conf
  291. echo alias ivp6 off >> /etc/modprobe.d/aliases.conf
  292. \end{minted}
  293. \begin{minted}{sh}
  294. reboot
  295. \end{minted}
  296. \subsection{Install nextcloud}
  297. Copied from Owncloud installation sequence. Todo: review difference to Nextcloud
  298. Add Debian Backports (eh?)
  299. \begin{minted}{sh}
  300. sh -c "echo 'deb http://mirrors.kernel.org/debian/ jessie-backports
  301. main' >> /etc/apt/sources.list.d/backports.list"
  302. apt-get update
  303. apt-get dist-upgrade -t jessie-backports
  304. apt-get clean
  305. sync
  306. reboot & exit
  307. \end{minted}
  308. Add owncloud repos (ToDo)
  309. \begin{minted}{sh}
  310. cd
  311. wget -nv \
  312. https://download.owncloud.org/download/repositories/stable/Debian_8.0/Release.key \
  313. -O Release.key
  314. apt-key add - < Release.key
  315. sh -c "echo 'deb
  316. http://download.owncloud.org/download/repositories/stable/Debian_8.0/ /'
  317. >> /etc/apt/sources.list.d/owncloud.list"
  318. apt-get update
  319. apt-get install -t jessie-backports php5-apcu php-apc php5-imagick \
  320. ffmpeg libreoffice php5-mysql php5-mcrypt php5-gmp php5-apcu \
  321. php5-memcache php5-memcached memcached php5-redis php5-imagick apache2 \
  322. libapache2-mod-php5 php5-gd php5-json php5-mysql php5-curl php5-intl \
  323. php5-mcrypt php5-imagick mysql-server
  324. apt-get clean
  325. \end{minted}
  326. Set up database
  327. \begin{minted}{sh}
  328. vim ~/.mysqlpw
  329. \end{minted}
  330. \begin{minted}{sh}
  331. # meh
  332. update-rc.d saned disable
  333. \end{minted}
  334. \begin{minted}{sh}
  335. # Configure Apache2 on a Debian Jessie Server
  336. # Setup default https configuration:
  337. cd /etc/apache2/sites-enabled
  338. ln -s ../sites-available/default-ssl .
  339. # Enable SSL modules
  340. cd /etc/apache2/mods-enabled
  341. ln -s ../mods-available/*ssl* .
  342. ln -s ../mods-available/socache_shmcb.load .
  343. # XXX left this out:
  344. #vim /etc/apache2/sites-available/default-ssl.conf
  345. # make sure that each <Directory > has AllowOverride All
  346. # Generate SSL certificate
  347. cd /etc/ssl/private/
  348. openssl genrsa -out pwn.themoes.org.key 2048
  349. openssl req -new -key pwn.themoes.org.key -out pwn.themoes.org.csr
  350. #* After the last command answer the following:
  351. #** Country Name : US
  352. #** State or Province Name: Colorado
  353. #** Locality Name: Redstone Canyon
  354. #** Organization Name: Moe
  355. #** Organizational Unit Name: IT
  356. #** Common Name: pwn.themoes.org
  357. #** Email Address: pwn@themoes.org
  358. #** Leave Challenge password and An optional company name blank.
  359. # Sent csr to SSL registrar.
  360. \end{minted}
  361. Open up port 80 to do SSL registrar verification:
  362. \begin{minted}{sh}
  363. vim /etc/iptables.test.rules
  364. \end{minted}
  365. Enable the port 80 lines for registar, and port 443 lines for owncloud
  366. later at the file
  367. \begin{minted}{sh}
  368. iptables-restore < /etc/iptables.test.rules
  369. iptables -L
  370. iptables-save > /etc/iptables.up.rules
  371. \end{minted}
  372. Copy Gandi file for SSL authentication to /var/www/html/
  373. After Gandi verifies it, remove the file.
  374. Then disable port 80 in the \gls{firewall} again:
  375. \begin{minted}{sh}
  376. vim /etc/iptables.test.rules
  377. \end{minted}
  378. \begin{minted}{sh}
  379. iptables-restore < /etc/iptables.test.rules
  380. iptables -L
  381. iptables-save > /etc/iptables.up.rules
  382. \end{minted}
  383. Move the cert in place
  384. \begin{minted}{sh}
  385. mv /home/jebba/certificate-323281.crt /etc/ssl/private/pwn.themoes.org.crt
  386. chown root:root /etc/ssl/private/pwn.themoes.org.crt
  387. # Gandi intermediate certs XXX
  388. # http://crt.gandi.net/GandiStandardSSLCA2.crt OR
  389. # https://www.gandi.net/static/CAs/GandiStandardSSLCA2.pem
  390. # Gah, wtf, add this?
  391. # Comodo Cross-Signed Certificate
  392. # http://crt.usertrust.com/USERTrustRSAAddTrustCA.crt
  393. #* Generate certificate:
  394. # XXX gah, gandi root certs ?
  395. # WTF does this do.
  396. openssl x509 -req -in pwn.themoes.org.csr -CA AOrootCA.pem \
  397. -CAkey AOrootCA.key -CAserial AOrootCA.srl \
  398. -out pwn.themoes.org.crt -days 65000
  399. \end{minted}
  400. ToDo: consider adding rm pwn.themoes.org.csr
  401. Place the .crt and .key files on pwn.themoes.org in /etc/ssl/private
  402. directory.
  403. Make sure the they can't be read by the others.
  404. Configure SSL part of the Apache Server:
  405. \begin{minted}{sh}
  406. vim /etc/apache2/sites-available/default-ssl.conf
  407. \end{minted}
  408. change to:
  409. \begin{minted}{sh}
  410. ServerName pwn.themoes.org
  411. ServerAdmin pwn@themoes.org
  412. \end{minted}
  413. comment out snakeoil keys
  414. add
  415. \begin{minted}{sh}
  416. SSLProtocol all -SSLv2
  417. SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
  418. SSLCertificateFile /etc/ssl/private/pwn.themoes.org.crt
  419. SSLCertificateKeyFile /etc/ssl/private/pwn.themoes.org.key
  420. \end{minted}
  421. \subsection{Enable the SSL server}
  422. \begin{minted}{sh}
  423. cd /etc/apache2/sites-enabled
  424. ln -s ../sites-available/default-ssl.conf .
  425. \end{minted}
  426. Restart Apache2
  427. \begin{minted}{sh}
  428. /etc/init.d/apache2 restart
  429. \end{minted}
  430. \begin{minted}{sh}
  431. echo pwn > /var/www/html/index.html
  432. \end{minted}
  433. Install owncloud
  434. \begin{minted}{sh}
  435. apt-get install -t jessie-backports owncloud
  436. \end{minted}
  437. set up mysql owncloud user
  438. \begin{minted}{sh}
  439. vim ~/.mysqlpw-own
  440. cat ~/.mysqlpw-own
  441. mysql -uroot -p`cat ~/.mysqlpw`
  442. CREATE USER 'owncloud'@'localhost' IDENTIFIED BY 'password';
  443. CREATE DATABASE IF NOT EXISTS owncloud;
  444. GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED
  445. BY 'password';
  446. ##############
  447. # Migrate db to sql.themoes.org
  448. ##############
  449. # Set up mysql config with sql.themoes.org (NOT on traccar, but on db
  450. server)
  451. mysql> CREATE DATABASE owncloud;
  452. mysql> CREATE USER 'owncloud'@'192.168.22.2' IDENTIFIED BY 'XXX';
  453. mysql> GRANT ALL ON owncloud.* TO 'owncloud'@'192.168.22.2';
  454. mysql> FLUSH PRIVILEGES;
  455. \end{minted}
  456. \begin{minted}{sh}
  457. mkdir /srv/owncloud
  458. chown www-data:www-data /srv/owncloud
  459. chmod 770 /srv/owncloud
  460. \end{minted}
  461. \begin{minted}{sh}
  462. # Do web stuff
  463. # https://pwn.themoes.org/owncloud/
  464. # Create admin account
  465. # Data folder:
  466. # /srv/owncloud
  467. # MySQL:
  468. # User: owncloud
  469. # Password:
  470. # Database Name: owncloud
  471. \end{minted}
  472. set up crontab in web and here:
  473. \begin{minted}{sh}
  474. crontab -u www-data -e
  475. \end{minted}
  476. Add:
  477. \begin{minted}{sh}
  478. */15 * * * * php -f /var/www/owncloud/cron.php
  479. \end{minted}
  480. Check it:
  481. \begin{minted}{sh}
  482. crontab -u www-data -l
  483. \end{minted}
  484. \begin{minted}{sh}
  485. root@pwn:/etc/ssl/private# chmod o-r *
  486. root@pwn:/etc/ssl/private# rm ssl-cert-snakeoil.key
  487. wget https://www.gandi.net/static/CAs/GandiStandardSSLCA2.pem
  488. mv GandiStandardSSLCA2.pem /etc/ssl/certs/
  489. chown root:root /etc/ssl/certs/GandiStandardSSLCA2.pem
  490. \end{minted}
  491. Add this to
  492. Configure SSL part of the Apache Server:
  493. \begin{minted}{sh}
  494. vim /etc/apache2/sites-available/default-ssl.conf
  495. \end{minted}
  496. \begin{minted}{sh}
  497. SSLCertificateChainFile /etc/ssl/certs/GandiStandardSSLCA2.pem
  498. SSLVerifyClient None
  499. \end{minted}
  500. \subsection{Libreoffice}
  501. \begin{minted}{sh}
  502. vim /var/www/owncloud/config/config.php
  503. \end{minted}
  504. \begin{minted}{sh}
  505. 'preview_libreoffice_path' => '/usr/bin/libreoffice',
  506. \end{minted}
  507. POSTFIX XXX ...
  508. \begin{minted}{sh}
  509. apt-get remove exim4 exim4-base exim4-config exim4-daemon-light
  510. apt-get purge exim4 exim4-base exim4-config exim4-daemon-light
  511. apt-get install postfix
  512. #apt-get install bsd-mailx
  513. \end{minted}
  514. Use APCu and Redis for caching
  515. \begin{minted}{sh}
  516. vim /var/www/owncloud/config/config.php
  517. \end{minted}
  518. add
  519. \begin{minted}{sh}
  520. 'memcache.local' => '\OC\Memcache\APCu',
  521. 'redis' => array(
  522. 'host' => '/var/run/redis/redis.sock',
  523. 'port' => 0,
  524. ),
  525. 'memcache.locking' => '\OC\Memcache\Redis',
  526. \end{minted}
  527. \begin{minted}{sh}
  528. vim /etc/redis/redis.conf
  529. \end{minted}
  530. \begin{minted}{sh}
  531. unixsocket /var/run/redis/redis.sock
  532. unixsocketperm 770
  533. \end{minted}
  534. \begin{minted}{sh}
  535. adduser www-data redis
  536. \end{minted}
  537. Todo: consider reboot
  538. \begin{minted}{sh}
  539. # Secure https some moar
  540. #
  541. https://doc.owncloud.org/server/9.0/admin_manual/configuration_server/harden_server.html#enable-hsts-label
  542. cd /etc/apache2/mods-enabled
  543. ln -s ../mods-available/headers.load .
  544. vim /etc/apache2/sites-enabled/default-ssl.conf
  545. \end{minted}
  546. Add:
  547. \begin{minted}{sh}
  548. <IfModule mod_headers.c>
  549. Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
  550. </IfModule>
  551. \end{minted}
  552. Add stuff, and run:
  553. \begin{minted}{sh}
  554. vim /var/www/owncloud/config/config.php
  555. \end{minted}
  556. \begin{minted}{sh}
  557. 'defaultapp' => 'calendar',
  558. 'session_keepalive' => true,
  559. 'htaccess.RewriteBase' => '/owncloud',
  560. \end{minted}
  561. \begin{minted}{sh}
  562. sudo -u www-data /var/www/owncloud/occ maintenance:update:htaccess
  563. \end{minted}
  564. Drop /owncloud from the URL
  565. \begin{minted}{sh}
  566. vim /etc/apache2/conf-available/owncloud.conf
  567. \end{minted}
  568. \begin{minted}{sh}
  569. Alias / "/var/www/owncloud/"
  570. \end{minted}
  571. \begin{minted}{sh}
  572. vim /var/www/owncloud/config/config.php
  573. \end{minted}
  574. \begin{minted}{sh}
  575. 'overwrite.cli.url' => 'https://pwn.themoes.org',
  576. \end{minted}
  577. \subsection{Misc}
  578. \begin{minted}{sh}
  579. vim /var/www/owncloud/config/config.php
  580. \end{minted}
  581. \begin{minted}{sh}
  582. 'logtimezone' => 'MST',
  583. 'session_keepalive' => true,
  584. 'htaccess.RewriteBase' => '/',
  585. 'overwritewebroot' => '/',
  586. 'check_for_working_webdav' => true,
  587. 'check_for_working_wellknown_setup' => true,
  588. 'check_for_working_htaccess' => true,
  589. 'logfile' => '/var/log/owncloud.log',
  590. 'loglevel' => 2,
  591. 'enable_previews' => true,
  592. 'preview_max_x' => 2048,
  593. 'preview_max_y' => 2048,
  594. 'preview_max_scale_factor' => 10,
  595. 'preview_max_filesize_image' => 50,
  596. 'preview_office_cl_parameters' =>
  597. ' --headless --nologo --nofirststartwizard --invisible
  598. --norestore '.
  599. '-convert-to pdf -outdir ',
  600. 'enabledPreviewProviders' => array(
  601. 'OC\Preview\PNG',
  602. 'OC\Preview\JPEG',
  603. 'OC\Preview\GIF',
  604. 'OC\Preview\BMP',
  605. 'OC\Preview\XBitmap',
  606. 'OC\Preview\MP3',
  607. 'OC\Preview\TXT',
  608. 'OC\Preview\MarkDown',
  609. 'OC\Preview\PDF',
  610. 'OC\Preview\Postscript',
  611. 'OC\Preview\SVG',
  612. 'OC\Preview\Movie',
  613. 'OC\Preview\MSOfficeDoc',
  614. 'OC\Preview\MSOffice2003',
  615. 'OC\Preview\MSOffice2007',
  616. 'OC\Preview\OpenDocument',
  617. 'OC\Preview\StarOffice',
  618. ),
  619. 'maintenance' => false,
  620. 'singleuser' => false,
  621. 'asset-pipeline.enabled' => false,
  622. \end{minted}
  623. set up that temp dir:
  624. \begin{minted}{sh}
  625. mkdir /srv/owncloudtemp
  626. chown www-data:www-data /srv/owncloudtemp/
  627. chmod 770 /srv/owncloudtemp/
  628. vim /var/www/owncloud/config/config.php
  629. \end{minted}
  630. \begin{minted}{sh}
  631. 'tempdirectory' => '/srv/owncloudtemp',
  632. \end{minted}
  633. php.ini stuff
  634. \begin{minted}{sh}
  635. vim /etc/php5/apache2/php.ini
  636. \end{minted}
  637. \begin{minted}{sh}
  638. php_value upload_max_filesize = 5G
  639. php_value post_max_size = 5G
  640. php_value max_input_time 3600
  641. php_value max_execution_time 3600
  642. memory_limit = 512M
  643. \end{minted}
  644. for svg ?
  645. \begin{minted}{sh}
  646. apt-get install inkscape
  647. \end{minted}
  648. \begin{minted}{sh}
  649. \subsection{Solr / Nexant}
  650. \end{minted}
  651. \begin{minted}{sh}
  652. apt-get install php-solr solr-jetty
  653. \end{minted}
  654. \begin{minted}{sh}
  655. # enable nexant app in web interface
  656. # vim /etc/jetty9/jetty-http.xml
  657. # vim /etc/jetty9/jetty-https.xml
  658. # <Set name="host"><Property name="jetty.host" /></Set>
  659. # to
  660. # <Set name="host"><Property name="jetty.host" default="127.0.0.1" /></Set>
  661. \end{minted}
  662. \begin{minted}{sh}
  663. # nope
  664. #cd solr/
  665. #cp -fr configsets/basic_configs nextant
  666. # This:
  667. # https://github.com/nextcloud/nextant/wiki/Setup-your-local-standalone-Solr
  668. # see local git clone
  669. # Actually, do this install of solr...
  670. # https://github.com/nextcloud/nextant/wiki/Setup-your-local-Solr-as-a-Service
  671. # apt-get install tesseract-ocr tesseract-ocr-eng
  672. # apt-get install ocrmypdf # not needed, for other OCR thing
  673. \end{minted}
  674. \subsection{Spreed}
  675. \large{Spreed Nextcloud WebRTC}
  676. There is a Spreed.me module for Nextcloud, which points to a spreed
  677. webrtc server. If the spreed and nextcloud server use different
  678. hostnames (origins), screen-sharing won't be allowed due to browser
  679. restrictions. So spreed is getting installed straight onto the Nextcloud
  680. server, https://own.alephobjects.com .
  681. \subsection{Links}
  682. \begin{minted}{sh}
  683. * https://github.com/strukturag/spreed-webrtc
  684. * https://github.com/strukturag/nextcloud-spreedme
  685. * https://github.com/strukturag/nextcloud-spreedme#installation--setup-of-a-spreed-webrtc-server
  686. * https://hub.docker.com/r/spreed/webrtc/
  687. * https://docs.docker.com/engine/installation/linux/debian/
  688. \end{minted}
  689. We're going to use a \gls{docker} install... own.alephobjects.com is
  690. currently running Debian Stretch (testing, version 9). Unfortunately,
  691. \gls{docker}.io (as it is named in Debian) is available for jessie-backports
  692. and sid, but not for stretch... We'll use \gls{docker}'s apt repos to get
  693. \gls{docker} ....
  694. \subsection{Install Docker}
  695. \begin{minted}{sh}
  696. * https://docs.docker.com/engine/installation/linux/debian/
  697. \end{minted}
  698. \begin{minted}{sh}
  699. apt update
  700. apt install apt-transport-https ca-certificates gnupg2
  701. apt-key adv \
  702. --keyserver hkp://ha.pool.sks-keyservers.net:80 \
  703. --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  704. vim /etc/apt/sources.list.d/docker.list
  705. \end{minted}
  706. Add:
  707. \begin{minted}{sh}
  708. deb https://apt.dockerproject.org/repo debian-stretch main
  709. \end{minted}
  710. \begin{picture}(0,0)\put(-10000,0){
  711. \gls{docker}
  712. }\end{picture}
  713. \begin{minted}{sh}
  714. cd /etc ; git add . ; git commit -a -m 'Add docker repo to apt'
  715. \end{minted}
  716. save
  717. \begin{minted}{sh}
  718. apt update
  719. apt install -y docker-engine
  720. cd /etc ; git add . ; git commit -a -m 'Install docker'
  721. service docker start
  722. \end{minted}
  723. \subsection{Test docker}
  724. \begin{picture}(0,0)\put(-10000,0){
  725. \gls{docker}
  726. }\end{picture}
  727. \begin{minted}{sh}
  728. docker run hello-world
  729. \end{minted}
  730. \subsection{Set up spreed docker}
  731. \begin{minted}{sh}
  732. mkdir -p /srv/spreed/extra.d
  733. vim /etc/spreed-webrtc-nextcloud.conf
  734. \end{minted}
  735. make config like this:
  736. \begin{minted}{sh}
  737. [http]
  738. basePath = /webrtc/
  739. [app]
  740. authorizeRoomJoin = true
  741. extra.d = /srv/spreed/extra.d
  742. [users]
  743. enabled = true
  744. mode = sharedsecret
  745. \end{minted}
  746. \subsection{Run Spreed Docker}
  747. \begin{picture}(0,0)\put(-10000,0){
  748. \gls{docker}
  749. }\end{picture}
  750. \begin{minted}{sh}
  751. cd /srv/spreed
  752. docker run --name ao-spreed-webrtc -p 8080:8080 -p 8443:8443 \
  753. -v /srv/spreed -i -t spreed/webrtc -c /etc/spreed-webrtc-nextcloud.conf
  754. \end{minted}
  755. On first launch, it may hang forever because it doesn't have any
  756. entropy. So it will hang at "Creating new server secrets ..."
  757. Here is a workaround to generate entropy:
  758. \begin{minted}{sh}
  759. apt install -y rng-tools
  760. rngd -f -r /dev/urandom
  761. \end{minted}
  762. Run it thusly:
  763. \begin{picture}(0,0)\put(-10000,0){
  764. \gls{docker}
  765. }\end{picture}
  766. \begin{minted}{sh}
  767. docker run -d --name my-spreed-webrtc -p 8080:8080 -p 8443:8443 -v \
  768. /etc/spreed:/etc/spreed -v /var/log/spreed:/var/log/spreed -v \
  769. /var/www/owncloud/apps/spreedme/extra:/var/www/owncloud/apps/spreedme/extra \
  770. -i -t spreed/webrtc -c /etc/spreed/server.conf
  771. \end{minted}
  772. \large{Configure Apache}
  773. install needed apache modules:
  774. \begin{minted}{sh}
  775. a2enmod proxy proxy_http proxy_wstunnel headers
  776. vim /etc/apache2/sites-enabled/01-own.alephobjects.com.conf
  777. \end{minted}
  778. Add this inside the VirtualHost section:
  779. \begin{minted}{sh}
  780. # Spreed WebRTC
  781. ProxyPass http://127.0.0.1:8080/webrtc
  782. ProxyPassReverse /webrtc
  783. ProxyPass ws://127.0.0.1:8080/webrtc/ws
  784. ProxyVia On
  785. ProxyPreserveHost On
  786. RequestHeader set X-Forwarded-Proto 'https' env=HTTPS
  787. \end{minted}
  788. \subsection{Spreed Configuration}
  789. \begin{picture}(0,0)\put(-10000,0){
  790. \gls{docker}
  791. }\end{picture}
  792. \begin{minted}{sh}
  793. Get the config in own.alephobjects.com --> admin --> Additional
  794. Settings(?) --> Spreed.me
  795. # Generate that config, put it in /etc/spreed/spreed.conf
  796. # Restart docker.
  797. #cd /etc ; git add . ; git commit -a -m 'Configure'
  798. ##### HMM
  799. docker run --name ao-spreed-webrtc -p 8080:8080 -p 8443:8443 -v \
  800. /srv/spreed -i -t spreed/webrtc -c /etc/spreed/server.conf
  801. rngd -f -r /dev/urandom
  802. # 585 docker run --name my-spreed-webrtc -p 8080:8080 -p 8443:8443 -v \
  803. /etc/spreed:/etc/spreed -i -t spreed/webrtc -c /etc/spreed/server.conf
  804. # 587 docker run -d --name my-spreed-webrtc -p 8080:8080 -p 8443:8443 \
  805. -v /etc/spreed:/etc/spreed -v /var/log/spreed:/var/log/spreed -v \
  806. /var/www/owncloud/apps/spreedme/extra:/var/www/owncloud/apps/spreedme/extra \
  807. -i -t spreed/webrtc -c /etc/spreed/server.conf
  808. docker run -d --name my-spreed-webrtc -p 8080:8080 -p 8443:8443 -v \
  809. /etc/spreed:/etc/spreed -v /var/log/spreed:/var/log/spreed -v \
  810. /var/www/owncloud/apps/spreedme/extra:/var/www/owncloud/apps/spreedme/extra \
  811. -i -t spreed/webrtc -c /etc/spreed/server.conf
  812. # These two:
  813. rngd -f -r /dev/urandom
  814. docker run -d --restart unless-stopped --name my-spreed-webrtc -p \
  815. 8080:8080 -p 8443:8443 -v /etc/spreed:/etc/spreed -v \
  816. /var/log/spreed:/var/log/spreed -v \
  817. /var/www/owncloud/apps/spreedme/extra:/var/www/owncloud/apps/spreedme/extra \
  818. -i -t spreed/webrtc -c /etc/spreed/server.conf \
  819. \end{minted}
  820. \subsection{apache2}
  821. Install needed apache modules:
  822. \begin{minted}{sh}
  823. a2enmod proxy proxy_http proxy_wstunnel headers
  824. vim /etc/apache2/sites-enabled/pwn.themoes.org.conf
  825. \end{minted}
  826. Add this inside the VirtualHost section:
  827. \begin{minted}{sh}
  828. # Spreed WebRTC
  829. <Location /webrtc>
  830. ProxyPass http://127.0.0.1:8080/webrtc
  831. ProxyPassReverse /webrtc
  832. </Location>
  833. <Location /webrtc/ws>
  834. ProxyPass ws://127.0.0.1:8080/webrtc/ws
  835. </Location>
  836. ProxyVia On
  837. ProxyPreserveHost On
  838. RequestHeader set X-Forwarded-Proto 'https' env=HTTPS
  839. \end{minted}
  840. \section{\href{http://support.ntp.org/}{NTP}}
  841. Syncs time on every server and workstation.
  842. \section{\href{http://www.opendkim.org/}{OpenDKIM}}
  843. DKIM (Domain Keys Identified Mail) sender authentication system.
  844. \section{\href{http://www.openssh.com/}{OpenSSH}}
  845. Used to control every server, create encrypted tunnels (autossh),
  846. mount filesystems (sshfs), and remote file transfer (sftp).
  847. \section{\href{http://openvpn.net/}{OpenVPN}}
  848. Connects external resources, such as employee mobiles and laptops, to the internal network.
  849. \section{\href{https://www.piwiki.org/}{Piwik}}
  850. Application to analyze web site traffic.
  851. \href{http://www.mrunix.net/webalizer/}{Webalizer} is used occassionally.
  852. \section{\href{http://www.postfix.org/}{Postfix}}
  853. Main SMTP outgoing mail server.
  854. \section{\href{http://www.postgresql.org/}{Postgres}}
  855. Database server.
  856. \section{\href{http://www.qemu.org/}{QEMU}}
  857. Computer emulator, runs virtual servers. Uses \gls{kvm}.
  858. \section{\href{http://rsync.samba.org/}{rsync}}
  859. File server.
  860. \section{\href{http://www.rsyslog.com/}{rsyslog}}
  861. Logging on every server and workstation.
  862. \section{\href{http://www.spamassassin.org/}{spamassassin}}
  863. Spam filtering of email.
  864. \section{\href{http://fuse.sourceforge.net/sshfs.html}{sshfs}}
  865. Main internal fileserver.
  866. \section{\href{http://www.freedesktop.org/wiki/Software/systemd}{systemd}}
  867. System bootup and process manager.
  868. \section{\href{http://dnsmasq.org/}{TFTP}}
  869. Network install server.
  870. \section{\href{http://www.xinetd.org}{xinetd}}
  871. xinetd on Debian systems. inetd on OpenBSD. Misc network utils.
  872. \section{\href{http://www.ejabberd.im/}{XMPP/jabber}}
  873. ejabberd, Erlang XMPP (jabber) server.