1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 nee <nee-git@hidamari.blue>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu services telephony)
20 #:use-module (gnu services)
21 #:use-module (gnu services shepherd)
22 #:use-module (gnu system shadow)
23 #:use-module (gnu packages admin)
24 #:use-module (gnu packages telephony)
25 #:use-module (guix records)
26 #:use-module (guix gexp)
27 #:use-module (srfi srfi-1)
28 #:use-module (ice-9 match)
29 #:export (murmur-configuration
30 make-murmur-configuration
32 murmur-configuration-package
33 murmur-configuration-user
34 murmur-configuration-group
35 murmur-configuration-port
36 murmur-configuration-welcome-text
37 murmur-configuration-server-password
38 murmur-configuration-max-users
39 murmur-configuration-max-user-bandwidth
40 murmur-configuration-database-file
41 murmur-configuration-log-file
42 murmur-configuration-pid-file
43 murmur-configuration-autoban-attempts
44 murmur-configuration-autoban-timeframe
45 murmur-configuration-autoban-time
46 murmur-configuration-opus-threshold
47 murmur-configuration-channel-nesting-limit
48 murmur-configuration-channelname-regex
49 murmur-configuration-username-regex
50 murmur-configuration-text-message-length
51 murmur-configuration-image-message-length
52 murmur-configuration-cert-required?
53 murmur-configuration-remember-channel?
54 murmur-configuration-allow-html?
55 murmur-configuration-allow-ping?
56 murmur-configuration-bonjour?
57 murmur-configuration-send-version?
58 murmur-configuration-log-days
59 murmur-configuration-obfuscate-ips?
60 murmur-configuration-ssl-cert
61 murmur-configuration-ssl-key
62 murmur-configuration-ssl-dh-params
63 murmur-configuration-ssl-ciphers
64 murmur-configuration-public-registration
65 murmur-configuration-file
67 murmur-public-registration-configuration
68 make-murmur-public-registration-configuration
69 murmur-public-registration-configuration?
70 murmur-public-registration-configuration-name
71 murmur-public-registration-configuration-url
72 murmur-public-registration-configuration-password
73 murmur-public-registration-configuration-hostname
77 ;; https://github.com/mumble-voip/mumble/blob/master/scripts/murmur.ini
79 (define-record-type* <murmur-configuration> murmur-configuration
80 make-murmur-configuration
82 (package murmur-configuration-package ;<package>
84 (user murmur-configuration-user
86 (group murmur-configuration-group
88 (port murmur-configuration-port
90 (welcome-text murmur-configuration-welcome-text
92 (server-password murmur-configuration-server-password
94 (max-users murmur-configuration-max-users
96 (max-user-bandwidth murmur-configuration-max-user-bandwidth
98 (database-file murmur-configuration-database-file
99 (default "/var/lib/murmur/db.sqlite"))
100 (log-file murmur-configuration-log-file
101 (default "/var/log/murmur/murmur.log"))
102 (pid-file murmur-configuration-pid-file
103 (default "/var/run/murmur/murmur.pid"))
104 (autoban-attempts murmur-configuration-autoban-attempts
106 (autoban-timeframe murmur-configuration-autoban-timeframe
108 (autoban-time murmur-configuration-autoban-time
110 (opus-threshold murmur-configuration-opus-threshold
111 (default 100)) ; integer percent
112 (channel-nesting-limit murmur-configuration-channel-nesting-limit
114 (channelname-regex murmur-configuration-channelname-regex
116 (username-regex murmur-configuration-username-regex
118 (text-message-length murmur-configuration-text-message-length
120 (image-message-length murmur-configuration-image-message-length
121 (default (* 128 1024))) ; 128 Kilobytes
122 (cert-required? murmur-configuration-cert-required?
124 (remember-channel? murmur-configuration-remember-channel?
126 (allow-html? murmur-configuration-allow-html?
128 (allow-ping? murmur-configuration-allow-ping?
130 (bonjour? murmur-configuration-bonjour?
132 (send-version? murmur-configuration-send-version?
134 (log-days murmur-configuration-log-days
136 (obfuscate-ips? murmur-obfuscate-ips?
138 (ssl-cert murmur-configuration-ssl-cert
140 (ssl-key murmur-configuration-ssl-key
142 (ssl-dh-params murmur-configuration-ssl-dh-params
144 (ssl-ciphers murmur-configuration-ssl-ciphers
146 (public-registration murmur-configuration-public-registration
147 (default #f)) ; <murmur-public-registration-configuration>
148 (file murmur-configuration-file
151 (define-record-type* <murmur-public-registration-configuration>
152 murmur-public-registration-configuration
153 make-murmur-public-registration-configuration
154 murmur-public-registration-configuration?
155 (name murmur-public-registration-configuration-name)
156 (password murmur-public-registration-configuration-password)
157 (url murmur-public-registration-configuration-url)
158 (hostname murmur-public-registration-configuration-hostname
161 (define (flatten . lst)
162 "Return a list that recursively concatenates all sub-lists of LST."
163 (define (flatten1 head out)
165 (fold-right flatten1 out head)
167 (fold-right flatten1 '() lst))
169 (define (default-murmur-config config)
172 <murmur-configuration>
173 (user port welcome-text server-password max-users max-user-bandwidth
174 database-file log-file pid-file autoban-attempts autoban-timeframe
175 autoban-time opus-threshold channel-nesting-limit channelname-regex
176 username-regex text-message-length image-message-length cert-required?
177 remember-channel? allow-html? allow-ping? bonjour? send-version?
178 log-days obfuscate-ips? ssl-cert ssl-key ssl-dh-params ssl-ciphers
180 (apply mixed-text-file "murmur.ini"
182 "welcometext=" welcome-text "\n"
183 "port=" (number->string port) "\n"
184 (if server-password (list "serverpassword=" server-password "\n") '())
185 (if max-user-bandwidth (list "bandwidth=" (number->string max-user-bandwidth)) '())
186 "users=" (number->string max-users) "\n"
188 "database=" database-file "\n"
189 "logfile=" log-file "\n"
190 "pidfile=" pid-file "\n"
191 (if autoban-attempts (list "autobanAttempts=" (number->string autoban-attempts) "\n") '())
192 (if autoban-timeframe (list "autobanTimeframe=" (number->string autoban-timeframe) "\n") '())
193 (if autoban-time (list "autobanTime=" (number->string autoban-time) "\n") '())
194 (if opus-threshold (list "opusthreshold=" (number->string opus-threshold) "\n") '())
195 (if channel-nesting-limit (list "channelnestinglimit=" (number->string channel-nesting-limit) "\n") '())
196 (if channelname-regex (list "channelname=" channelname-regex "\n") '())
197 (if username-regex (list "username=" username-regex "\n") '())
198 (if text-message-length (list "textmessagelength=" (number->string text-message-length) "\n") '())
199 (if image-message-length (list "imagemessagelength=" (number->string image-message-length) "\n") '())
200 (if log-days (list "logdays=" (number->string log-days) "\n") '())
201 "obfuscate=" (if obfuscate-ips? "true" "false") "\n"
202 "certrequired=" (if cert-required? "true" "false") "\n"
203 "rememberchannel=" (if remember-channel? "true" "false") "\n"
204 "allowhtml=" (if allow-html? "true" "false") "\n"
205 "allowping=" (if allow-ping? "true" "false") "\n"
206 "bonjour=" (if bonjour? "true" "false") "\n"
207 "sendversion=" (if send-version? "true" "false") "\n"
208 (cond ((and ssl-cert ssl-key)
210 "sslCert=" ssl-cert "\n"
211 "sslKey=" ssl-key "\n"))
212 ((or ssl-cert ssl-key)
213 (error "ssl-cert and ssl-key must both be set"
216 (if ssl-dh-params (list "sslDHParams=" ssl-dh-params) '())
217 (if ssl-ciphers (list "sslCiphers=" ssl-ciphers) '())
219 (match public-registration
221 (($ <murmur-public-registration-configuration>
222 name password url hostname)
223 (if (and (or (not server-password) (string-null? server-password))
226 "registerName=" name "\n"
227 "registerPassword=" password "\n"
228 "registerUrl=" url "\n"
230 (string-append "registerHostname=" hostname "\n")
232 (error "To publicly register your murmur server your server must be publicy visible
233 and users must be able to join without a password. To fix this set:
235 (server-password \"\")
236 Or set public-registration to #f"))))))))
238 (define (murmur-activation config)
240 (use-modules (guix build utils))
241 (let* ((log-dir (dirname #$(murmur-configuration-log-file config)))
242 (pid-dir (dirname #$(murmur-configuration-pid-file config)))
243 (db-dir (dirname #$(murmur-configuration-database-file config)))
244 (user (getpwnam #$(murmur-configuration-user config)))
247 (format #t "creating murmur ~a directory '~a'\n" name dir)
249 (chown dir (passwd:uid user) (passwd:gid user))
251 (ini #$(or (murmur-configuration-file config)
252 (default-murmur-config config))))
253 (init-dir "log" log-dir)
254 (init-dir "pid" pid-dir)
255 (init-dir "database" db-dir)
257 (format #t "murmur: use config file: ~a~%\n" ini)
258 (format #t "murmur: to set the SuperUser password run:
259 `~a -ini ~a -readsupw`\n"
260 #$(file-append (murmur-configuration-package config)
264 (define murmur-accounts
266 (($ <murmur-configuration> _ user group)
275 (comment "Murmur Daemon")
276 (home-directory "/var/empty")
277 (shell (file-append shadow "/sbin/nologin")))))))
279 (define (murmur-shepherd-service config)
280 (list (shepherd-service
281 (provision '(murmur))
282 (documentation "Run the Murmur Mumble server.")
283 (requirement '(networking))
284 (start #~(make-forkexec-constructor
285 '(#$(file-append (murmur-configuration-package config)
288 #$(or (murmur-configuration-file config)
289 (default-murmur-config config)))
290 #:pid-file #$(murmur-configuration-pid-file config)))
291 (stop #~(make-kill-destructor)))))
293 (define murmur-service-type
294 (service-type (name 'murmur)
296 "Run the Murmur voice-over-IP (VoIP) server of the Mumble
299 (list (service-extension shepherd-root-service-type
300 murmur-shepherd-service)
301 (service-extension activation-service-type
303 (service-extension account-service-type
305 (default-value (murmur-configuration))))