-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.php
205 lines (180 loc) · 5.5 KB
/
conf.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/* use PHPMailer\PHPMailer\PHPMailer; */
/* use PHPMailer\PHPMailer\Exception; */
date_default_timezone_set('Europe/Sofia');
setlocale(LC_ALL, 'bg_BG');
$minify_html=0;
$debug=0;
$debugIps= array('127.0.0.1');
$sitename = 'X'; //default, overwritten by .env
$defaulthashes = array('fqdn','main_ip_address','main_ip_gateway');
$tokens = array(
'tokenLKDJHFYUUHIEUIEJOIJOIJDDOJSHDK'
);
$app['site_name'] = $sitename; // but overwritable via env ?
$app['site_title'] = $app['site_name'];
$app['site_description'] = 'Next great thing';
$app['site_keywords'] = '';
//echo genPass('admin')."\n\n";
function authenticate($user, $pass) {
global $allowed_dept,$admins_dept,$admins,$ldapServer;
// check whether user is allowed and if credentials are OK
$user = clean($user,'@\.\-\_');
$pass = clean($pass,'\_\-\@\.\,\ \"\#\!\$\%\&\*');
$q = "select * from users where (username='$user' or email='$user') limit 1";
$qr = mql($q);
if(
(hashPass($qr['password'],$pass)) // check if the DB pass matches what we provided
){
return true;
}else{
return false;
}
return false;
}
function getAllUsers($userid=''){
if((isset($userid)) and (intval($userid>0))){
$user=" where u.id='".intval($userid)."' limit 1";
}
$q = "select * from users u $user";
$r = mql($q);
if((isset($userid)) and (intval($userid)>0)){ // single rec/user
switch ($r['status']){
case 0: $r['state']='<span class="label label-danger">No</span>'; $r['state_class']='danger'; break;
case 1: $r['state']='<span class="label label-success">Yes</span>'; $r['state_class']=''; break;
}
switch ($r['admin']){
case 0: $r['is-admin']='<span class="label label-danger">No</span>'; break;
case 1: $r['is-admin']='<span class="label label-success">Yes</span>'; break;
}
return $r;
}else{
$o = array();
foreach ($r as $r) {
switch ($r['status']){
case 0: $r['state']='<span class="label label-danger">No</span>'; $r['state_class']='danger'; break;
case 1: $r['state']='<span class="label label-success">Yes</span>'; $r['state_class']=''; break;
}
switch ($r['admin']){
case 0: $r['is-admin']='<span class="label label-danger">No</span>'; break;
case 1: $r['is-admin']='<span class="label label-success">Yes</span>'; break;
}
$o[]=$r;
}
return $o;
}
}
function allServersTabe(){
$q = "select * from servers";
$r = mql($q);
echo createTableFromArray($r,
/* $ignoredHeaders */
array(
'id',
'sys_cap',
'devices',
'mounts',
'full',
),
/* $renamedHeaders */
array(
'extend_days' => 'Extend days (Editable)',
'principals' => 'Principals (Editable)',
),
array(
)
);
}
function resetDbTableServers(){
$q = "drop table if exists servers;";
@mql($q);
$q = "
CREATE TABLE `servers` (
`id` INT NOT NULL AUTO_INCREMENT ,
`uuid` VARCHAR(40) NOT NULL ,
`os_family` VARCHAR(20) NULL ,
`distro` VARCHAR(40) NULL ,
`distro_release` VARCHAR(40) NULL ,
`distro_mver` INT(5) NULL ,
`distro_ver` VARCHAR(10) NULL ,
`kernel` VARCHAR(255) NULL ,
`product_name` VARCHAR(100) NULL ,
`product_serial` VARCHAR(100) NULL ,
`product_ver` VARCHAR(30) NULL ,
`arch` VARCHAR(10) NULL ,
`sys_vendor` VARCHAR(60) NULL ,
`virt_type` VARCHAR(60) NULL ,
`virt_role` VARCHAR(60) NULL ,
`uptime_sec` VARCHAR(20) NULL ,
`fqdn` VARCHAR(70) NULL ,
`hostname` VARCHAR(70) NULL ,
`nodename` VARCHAR(70) NULL ,
`is_chroot` VARCHAR(10) NULL ,
`iscsi_iqn` VARCHAR(100) NULL ,
`cpu_cores` VARCHAR(4) NULL ,
`cpu_count` VARCHAR(4) NULL ,
`cpu_threads_per_core` VARCHAR(4) NULL ,
`cpu_vcpus` VARCHAR(4) NULL ,
`system_capabilities_enforced` VARCHAR(1) NULL ,
`epoch_time` VARCHAR(50) NULL ,
`bios_ver` VARCHAR(20) NULL ,
`bios_date` VARCHAR(20) NULL ,
`boot_image` VARCHAR(255) NULL ,
`selinux_status` VARCHAR(50) NULL ,
`selinux_mode` VARCHAR(20) NULL ,
`selinux_type` VARCHAR(20) NULL ,
`service_mgr` VARCHAR(20) NULL ,
`python_ver` VARCHAR(10) NULL ,
`all_ipsv4` TEXT NULL ,
`all_ipsv6` TEXT NULL ,
main_ip_address VARCHAR(20) NULL ,
main_ip_netmask VARCHAR(20) NULL ,
main_ip_gateway VARCHAR(20) NULL ,
main_ip_interface VARCHAR(20) NULL ,
main_ip_mac VARCHAR(20) NULL ,
main_ip_network VARCHAR(20) NULL ,
main_ip_type VARCHAR(20) NULL ,
`domain` VARCHAR(100) NULL ,
`dns_ns` VARCHAR(255) NULL ,
`sys_cap` TEXT NULL ,
`memory_free` INT(10) NULL ,
`memory_total` INT(10) NULL ,
`memory_swap_free` INT(10) NULL ,
`memory_swap_total` INT(10) NULL ,
`devices` TEXT NULL ,
`mounts` TEXT NULL ,
`lvm` TEXT NULL ,
`ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`state` TEXT NULL ,
`full` JSON NULL ,
PRIMARY KEY (`id`), UNIQUE KEY `uuid` (`uuid`)) ENGINE = InnoDB;
";
@mql($q);
}
function dldCsv($data){
error_reporting(1);
$data = explode('|',$data);
$headers = array();
foreach($data as $header){
$headers[] = ucfirst(str_replace('_',' ',$header));
}
$qs = implode(',', $data);
$q = "select $qs from servers";
$r = mql($q);
$rfull = array_merge(array($headers),$r);
header('Content-Description: File Transfer');
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=ansibleBoy-report.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
$f = fopen('php://memory', 'w');
foreach ($rfull as $line) {
// generate csv lines from the inner arrays
fputcsv($f, $line, "\t");
}
// reset the file pointer to the start of the file
fseek($f, 0);
fpassthru($f);
}