-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrainloopsync.php
88 lines (78 loc) · 2.69 KB
/
rainloopsync.php
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
<?php
// Load config file
require_once ('config.php');
// Build array to create http query
$uservars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => 'v-list-users',
'arg1' => 'json'
);
// Build query based on array
$userdata = http_build_query($uservars);
// Build curl query and execute
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $userdata);
$users = curl_exec($curl);
// Parse JSON output to array
$userout = json_decode($users, true);
// Loop through array of usernames to pull out domain names
foreach ($userout as $key => $value){
// Build array to create http query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => 'v-list-mail-domains',
'arg1' => $key,
'arg3' => 'json'
);
// Build query based on array
$postdata = http_build_query($postvars);
// Build curl query and execute
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
// Parse JSON output
$data = json_decode($answer, true);
//Loop through array to create configuration files
foreach (array_keys($data) as $domain){
// Define file contents
$configout = 'imap_host = "mail.'.$domain.'"
imap_port = 993
imap_secure = "SSL"
imap_short_login = Off
sieve_use = Off
sieve_allow_raw = Off
sieve_host = ""
sieve_port = 4190
sieve_secure = "None"
smtp_host = "mail.'$domain'."
smtp_port = 25
smtp_secure = "TLS"
smtp_short_login = Off
smtp_auth = On
smtp_php_mail = Off
white_list = ""';
// Check for existing files
if (!file_exists($rainloopdir.$domain.".ini")){
// If no file found, write configuration file to Rainloop domain configuration directory
file_put_contents($rainloopdir.$domain.".ini", $configout);
// Place entry in synclog.log
file_put_contents("synclog.log", date("Y/m/d")." ".date("h:i:sa")." ".$domain.".ini created\r\n", FILE_APPEND);
} else {
// If file found, do not write configuration file and place entry in synclog.log
file_put_contents("synclog.log", date("Y/m/d")." ".date("h:i:sa")." ".$domain.".ini exists, skipped\r\n", FILE_APPEND);
}
}
}
?>