Commit 2b10800f95ab678dfb1a5faa09e7bc0f5c4b4262
1 parent
ceceec4da3
Exists in
master
orderby again
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
lib/smstools-config/creator.js
1 | const moment = require('moment'); | 1 | const moment = require('moment'); |
2 | const config = require('komodo-sdk/config'); | 2 | const config = require('komodo-sdk/config'); |
3 | const { orderBy } = require('natural-orderby'); | 3 | const { orderBy } = require('natural-orderby'); |
4 | const smstoolsConfig = require('./config-file'); | 4 | const smstoolsConfig = require('./config-file'); |
5 | 5 | ||
6 | function modemNames() { | 6 | function modemNames() { |
7 | const modems = []; | 7 | const modems = []; |
8 | 8 | ||
9 | // eslint-disable-next-line no-restricted-syntax | 9 | // eslint-disable-next-line no-restricted-syntax |
10 | for (const [key, value] of Object.entries(smstoolsConfig.modems || {})) { | 10 | for (const [key, value] of Object.entries(smstoolsConfig.modems || {})) { |
11 | if (value && !value.disabled) modems.push(key); | 11 | if (value && !value.disabled) modems.push(key); |
12 | } | 12 | } |
13 | 13 | ||
14 | return modems; | 14 | return modems; |
15 | } | 15 | } |
16 | 16 | ||
17 | function modemEntries() { | 17 | function modemEntries() { |
18 | const modems = orderBy(modemNames()); | 18 | const modems = orderBy(modemNames()); |
19 | const retval = []; | 19 | const retval = []; |
20 | 20 | ||
21 | modems.forEach((modemName) => { | 21 | modems.forEach((modemName) => { |
22 | const modem = smstoolsConfig.modems[modemName]; | 22 | const modem = smstoolsConfig.modems[modemName]; |
23 | 23 | ||
24 | const modemEntry = ` | 24 | const modemEntry = ` |
25 | [${modemName}] | 25 | [${modemName}] |
26 | device = ${modem.device} | 26 | device = ${modem.device} |
27 | outgoing = ${modem.outgoing ? 'yes' : 'no'} | 27 | outgoing = ${modem.outgoing ? 'yes' : 'no'} |
28 | `.trim(); | 28 | `.trim(); |
29 | 29 | ||
30 | retval.push(modemEntry); | 30 | retval.push(modemEntry); |
31 | }); | 31 | }); |
32 | 32 | ||
33 | return retval; | 33 | return retval; |
34 | } | 34 | } |
35 | 35 | ||
36 | module.exports = () => { | 36 | module.exports = () => { |
37 | const newContent = ` | 37 | const newContent = ` |
38 | # Generated by komodo-center-smstools based on config timestamp ${moment(smstoolsConfig.ts).format('YYYY-MM-DD HH:mm:ss')} | 38 | # Generated by komodo-center-smstools based on config timestamp ${moment(smstoolsConfig.ts).format('YYYY-MM-DD HH:mm:ss')} |
39 | # Do not edit this file manually | 39 | # Do not edit this file manually |
40 | 40 | ||
41 | devices = ${modemNames().join(',')} | 41 | devices = ${orderBy(modemNames()).join(',')} |
42 | logfile = ${config.smstools_logfile || config.smstools_log_file || '/var/log/smsd/smsd.log'} | 42 | logfile = ${config.smstools_logfile || config.smstools_log_file || '/var/log/smsd/smsd.log'} |
43 | loglevel = ${smstoolsConfig.loglevel || 5} | 43 | loglevel = ${smstoolsConfig.loglevel || 5} |
44 | smart_logging = yes | 44 | smart_logging = yes |
45 | autosplit = ${(config.smstools_autosplit !== undefined && config.smstools_autosplit !== null) ? config.smstools_autosplit : 1} | 45 | autosplit = ${(config.smstools_autosplit !== undefined && config.smstools_autosplit !== null) ? config.smstools_autosplit : 1} |
46 | user = ${smstoolsConfig.user || 'smstools'} | 46 | user = ${smstoolsConfig.user || 'smstools'} |
47 | group = ${smstoolsConfig.group || 'smstools'} | 47 | group = ${smstoolsConfig.group || 'smstools'} |
48 | eventhandler = ${config.smstools_eventhandler || '/var/lib/smstools/centers/smstools/bin/smstools-eventhandler.js'} | 48 | eventhandler = ${config.smstools_eventhandler || '/var/lib/smstools/centers/smstools/bin/smstools-eventhandler.js'} |
49 | stats_interval = ${config.smstools_stats_interval || 60} | 49 | stats_interval = ${config.smstools_stats_interval || 60} |
50 | stats = ${config.smstools_stats || '/var/log/smsd/smsd_stats'} | 50 | stats = ${config.smstools_stats || '/var/log/smsd/smsd_stats'} |
51 | sent = /var/spool/sms/sent | 51 | sent = /var/spool/sms/sent |
52 | ${smstoolsConfig.customConfig || ''} | 52 | ${smstoolsConfig.customConfig || ''} |
53 | 53 | ||
54 | [default] | 54 | [default] |
55 | incoming = yes | 55 | incoming = yes |
56 | regular_run_interval = 60 | 56 | regular_run_interval = 60 |
57 | regular_run_cmd = AT+CGSN | 57 | regular_run_cmd = AT+CGSN |
58 | regular_run_cmd = AT+CIMI | 58 | regular_run_cmd = AT+CIMI |
59 | regular_run_cmd = AT+COPS? | 59 | regular_run_cmd = AT+COPS? |
60 | regular_run_statfile = /var/spool/sms/regular_run/modemname | 60 | regular_run_statfile = /var/spool/sms/regular_run/modemname |
61 | 61 | ||
62 | ${modemEntries().join('\n\n')} | 62 | ${modemEntries().join('\n\n')} |
63 | 63 | ||
64 | # end of configuration file | 64 | # end of configuration file |
65 | `; | 65 | `; |
66 | return `${newContent.trim()}\n`; | 66 | return `${newContent.trim()}\n`; |
67 | }; | 67 | }; |
68 | 68 |