forked from kselkowitz/smash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smash.php
129 lines (89 loc) · 3.83 KB
/
smash.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
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
#!/usr/bin/php
<?php
// WELCOME TO SMASH
// Selkowitz Multifactor Authentication Snitch and Hound
// this script emails admin UI and Portal Users (chosen scopes) to remind them to set up MFA, as well as emailing the list of users to an admin
// fill out the info below
define("SERVER", "localhost");
define("MYSQLUSER", "user");
define("MYSQLPASS", "password");
define("PORTALSCOPES","Super User,Reseller"); //comma separated list of portal scopes to check for MFA
define("EMAILTO","user@domain.tld"); // will receive list of users with MFA not enabled
define("EMAILFROM","user@domain.tld");
$headers = "From: " . EMAILFROM . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
///////////////////////////////
// check Admin UI Users
$localDb['server'] = SERVER;
$localDb['user'] = MYSQLUSER;
$localDb['password'] = MYSQLPASS;
$localDb['db'] = 'SiPbxDomain';
$sql = "SELECT firstname, lastname, email FROM level1_access WHERE two_step!='google'";
# Get the data
$data = get_data($localDb, $sql);
// email body to admin
$body_details = "";
foreach ( $data as $key => $login ) {
// $current_logins_arr[$login['login']] = $login;
$body_details .= "The Admin UI User " .$login['firstname'] ." " . $login['lastname'] . "does not have MFA enabled.<br>\n";
// email user
If ($login['email'])
{
mail($login['email'],'MFA is not enabled','You do not have MFA enabled on your SNAPsolution Admin UI login. Please add MFA by:<br>logging into your Admin UI <br>going to System>User Accounts and Editing your User <br>Select Google as the Multi Factor Authentication type <br>scan the 2D barcode using your authenticator app (e.g. Google Authenticator) <br>Then enter the 6 digit code and click Modify', $headers);
}
}
//mail admin the list
if ($body_details!="")
{
mail(EMAILTO,"Admin UI Users without MFA enabled!", $body_details,$headers);
}
///////////////////////////////
// check Portal Users
$scopearray=explode(',', PORTALSCOPES);
$scopequery="";
foreach ($scopearray as $scope)
{
$scopequery .= "Scope='" . $scope . "' OR ";
}
$scopequery=substr($scopequery,0,-4); //strip last OR
$sql = "SELECT CONCAT(aor_user,'@',aor_host) as subscriber_id, firstname,lastname, email_address FROM SiPbxDomain.subscriber_config LEFT JOIN NsApi.multifactor_auth ON CONCAT(aor_user,'@',aor_host) = ns_id WHERE ns_id IS NULL AND " . $scopequery;
# Get the data
$data = get_data($localDb, $sql);
// email body to admin
$body_details = "";
foreach ( $data as $key => $login ) {
$body_details .= "The Portal User " . $login['firstname'] . " " . $login['lastname'] . " " . $login['subscriber_id'] . " does not have MFA enabled.<br>\n";
// email user
If ($login['email_address'])
{
mail($login['email_address'],'MFA is not enabled','You do not have MFA enabled on your SNAPsolution Portal login. Please add MFA by:<br>logging into the Portal <br>Edit your Profile <br>Click Set Up Google Authenticator<br>scan the 2D barcode using your authenticator app (e.g. Google Authenticator) <br>Then enter the 6 digit code and password and click Save',$headers);
}
}
//mail admin the list
if ($body_details!="")
{
mail(EMAILTO,"Portal Users without MFA enabled!", $body_details, $headers);
}
function get_data($db_data, $sql) {
$returner = [];
$link = mysqli_connect($db_data['server'], $db_data['user'], $db_data['password'], $db_data['db']);
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = mysqli_query($link, $sql) or die(mysqli_error($link)." Q=".$sql);
if ( $result ) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
$returner[] = $row;
}
/* free result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
return $returner;
}
?>