This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconcore.js
148 lines (135 loc) · 3.84 KB
/
concore.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'use strict';
// Usage:
// node imap.js > account.mobileconfig
var mobileconfig = require('mobileconfig');
var fs = require('fs');
var prompt = require('prompt');
var colors = require('colors');
prompt.message = '';
prompt.delimiter = colors.cyan(':');
var schema = {
properties: {
name: {
pattern: /^[a-zA-Z\s\-]+$/,
description: colors.cyan('First- and surname'),
required: true
},
email_domain: {
message: colors.cyan('Enter email domain, eg example.com'),
default: 'coworkingplus.dk',
required: true
},
fullname: {
message: colors.cyan('Use default email alias? If no, then enter desired alias, eg example.'),
required: true,
default: 'yes'
},
password: {
required: true,
description: colors.cyan('Enter Password for the Email Account'),
hidden: true,
replace: '*'
},
imap: {
required: true,
description: colors.cyan('Enter IMAP host'),
default: 'mail16.123hotel.dk'
},
imap_port:{
required: true,
description: colors.cyan('Set the IMAP Port'),
default: '143'
},
imap_ssl:{
required: true,
description: colors.cyan('Use IMAP SSL?'),
default: false
},
smtp: {
required: true,
description: colors.cyan('Enter SMTP host'),
default: 'asmtp.curanet.dk'
},
smtp_port:{
required: true,
default: '587',
description: colors.cyan('Set the SMTP Port')
},
smtp_ssl:{
required: true,
default: false,
description: colors.cyan('Use SMTP SSL?')
},
key:{
required: true,
default: __dirname + '/keys/key.pem',
description: colors.cyan('Choose encryption key')
},
cert:{
required: true,
default: __dirname + '/keys/cert.pem',
description: colors.cyan('Choose encryption certificate')
}
}
};
prompt.start();
//
// Get two properties from the user: username and email
//
prompt.get(schema, function (err, result) {
//
// Log the results.
//
var initials = result.name.replace(/[^A-Z]/g, '').toLowerCase();
var email = '';
console.log(colors.cyan('--------------------'));
if(result.fullname.toLowerCase() == 'yes' || result.fullname.toLowerCase() == 'y'){
console.log(colors.magenta('Using ' + initials + ' as identifier'));
email = initials + '@' + result.email_domain;
} else {
initials = result.fullname;
console.log(colors.magenta('Using ' + result.fullname + ' as identifier'));
email = result.fullname + '@' + result.email_domain;
}
console.log(colors.cyan('Generating file for ') + colors.green(email));
mobileconfig.getSignedEmailConfig({
emailAddress: email,
organization: 'mail.' + initials + '.' + result.email_domain,
identifier: 'mail.' + initials + '.' + result.email_domain,
displayName: email + ' Config',
displayDescription: 'Install this profile to auto configure your Coworking Plus e-mail account',
accountName: 'IMAP Config',
accountDescription: email,
imap: {
hostname: result.imap,
port: result.imap_port,
secure: result.imap_ssl,
username: email,
password: result.password
},
smtp: {
hostname: result.smtp,
port: result.smtp_port,
secure: result.smtp_ssl,
username: email,
password: false // use the same password as for IMAP
},
keys: {
key: fs.readFileSync(result.key),
cert: fs.readFileSync(result.cert),
ca: []
}
}, function(err, data) {
var filename = email + '.mobileconfig';
if (err) {
process.stderr.write(colors.red(err.stack));
return process.exit(1);
}
fs.writeFile(__dirname + '/configs/' + filename, data, function(err) {
if(err) {
return console.log(colors.red(err));
}
console.log(colors.green("The file was saved, as /config/" + filename));
});
});
});