creator.js
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const moment = require('moment');
const config = require('komodo-sdk/config');
const { orderBy } = require('natural-orderby');
const smstoolsConfig = require('./config-file');
const queuesAndProviders = require('./queues-and-providers');
function modemNames() {
const modems = [];
// eslint-disable-next-line no-restricted-syntax
for (const [key, value] of Object.entries(smstoolsConfig.modems || {})) {
if (value && !value.disabled) modems.push(key);
}
return modems;
}
function modemEntries() {
const modems = orderBy(modemNames());
const retval = [];
modems.forEach((modemName) => {
const modem = smstoolsConfig.modems[modemName];
let queuesLine = '';
if (queuesAndProviders.hasQueues()) {
const queues = queuesAndProviders.getModemQueueName(modemName);
queuesLine = `queues = ${(queues || []).join(', ') || 'other'}`;
}
const modemEntry = `
[${modemName}]
device = ${modem.device}
outgoing = ${modem.outgoing ? 'yes' : 'no'}
${queuesLine}
`.trim();
retval.push(modemEntry);
});
return retval;
}
module.exports = async () => {
const queuesAndProvidersStr = queuesAndProviders.hasQueues() ? (await queuesAndProviders.dump(true)) : '';
const newContent = `
# Generated by komodo-center-smstools based on config timestamp ${moment(smstoolsConfig.ts).format('YYYY-MM-DD HH:mm:ss')}
# Do not edit this file manually
devices = ${orderBy(modemNames()).join(',')}
logfile = ${config.smstools_logfile || config.smstools_log_file || '/var/log/smsd/smsd.log'}
loglevel = ${smstoolsConfig.loglevel || 5}
errorsleeptime = ${config.smstools_errorsleeptime || 10}
blockafter = ${config.smstools_blockafter || 3}
blocktime = ${config.smstools_blocktime || 3600}
smart_logging = yes
autosplit = ${(config.smstools_autosplit !== undefined && config.smstools_autosplit !== null) ? config.smstools_autosplit : 1}
user = ${smstoolsConfig.user || 'smstools'}
group = ${smstoolsConfig.group || 'smstools'}
eventhandler = ${config.smstools_eventhandler || '/var/lib/smstools/centers/smstools/bin/smstools-eventhandler.js'}
stats_interval = ${config.smstools_stats_interval || 60}
stats = ${config.smstools_stats || '/var/log/smsd/smsd_stats'}
sent = /var/spool/sms/sent
failed = /var/spool/sms/failed
${smstoolsConfig.customConfig || ''}
${queuesAndProvidersStr}
[default]
sentsleeptime = ${config.smstools_sentsleeptime || 0}
send_delay = ${config.smstools_send_delay || 0}
send_retries = ${config.smstools_send_retry || 2}
incoming = yes
regular_run_interval = 60
regular_run_cmd = AT+CGSN
regular_run_cmd = AT+CIMI
regular_run_cmd = AT+COPS?
regular_run_statfile = /var/spool/sms/regular_run/modemname
message_limit = ${config.smstools_message_limit || 5}
message_count_clear = ${config.smstools_message_count_clear || 1}
${modemEntries().join('\n\n')}
# end of configuration file
`;
return `${newContent.trim()}\n`;
};