1 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
define (PROCESS_SYSINFO_SCRIPT, '/home/rodolico/wip/dd_tools/web/computer_asset_manager/modules/sysinfo/cli/process_sysinfo');
|
|
|
4 |
|
|
|
5 |
function processAFile( $filename ) {
|
|
|
6 |
$output = PROCESS_SYSINFO_SCRIPT . " < $filename\n";
|
|
|
7 |
$output .= shell_exec(PROCESS_SYSINFO_SCRIPT . " < $filename");
|
|
|
8 |
return $output;
|
|
|
9 |
}
|
|
|
10 |
|
|
|
11 |
function processFileContents( ) {
|
|
|
12 |
$filename = tempnam('/tmp', 'sysinfo');
|
|
|
13 |
$fh = fopen( $filename, "w" );
|
|
|
14 |
fwrite( $fh, $_POST['filecontents'] );
|
|
|
15 |
fclose( $fh );
|
|
|
16 |
$output = processAFile( $filename );
|
|
|
17 |
unlink ($filename);
|
|
|
18 |
return $output;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
function uploadFile() {
|
|
|
22 |
$filename = $_FILES['filename']['tmp_name'];
|
|
|
23 |
$output = "processing file $filename\n";
|
|
|
24 |
$output .= processAFile( $filename );
|
|
|
25 |
unlink ($filename);
|
|
|
26 |
return $output;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
function UnknownEntries () {
|
|
|
30 |
$data = queryDatabaseExtended( 'select count(*) num from unknown_entry where processed_date is null');
|
|
|
31 |
return $data['data'][0]['num'];
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
function processUnknownClients() {
|
|
|
35 |
$new = array();
|
|
|
36 |
$aliases = array();
|
|
|
37 |
$result = array();
|
|
|
38 |
foreach ( $_POST as $parameter => $value ) {
|
|
|
39 |
// look for all new and alias entries
|
|
|
40 |
if ( preg_match('/new_(\d+)/', $parameter, $id ) ) {
|
|
|
41 |
if ($value) {
|
|
|
42 |
$new[] = $id[1];
|
|
|
43 |
}
|
|
|
44 |
} elseif ( preg_match('/alias_for_(\d+)/', $parameter, $id ) ) {
|
|
|
45 |
if ($value) {
|
|
|
46 |
$aliases[] = $id[1];
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
foreach ( $new as $entryID ) {
|
|
|
51 |
$sql = "insert into client(name, added_date) select client_name, report_date from unknown_entry where unknown_entry_id = $entryID";
|
|
|
52 |
$data = queryDatabaseExtended( $sql );
|
|
|
53 |
$result[] = $sql;
|
|
|
54 |
$sql = "insert into site(client_id,name,added_date) select " . $data['insert_id'] . ", 'Default', report_date from unknown_entry where unknown_entry_id = $entryID";
|
|
|
55 |
queryDatabaseExtended( $sql );
|
|
|
56 |
$result[] = $sql;
|
|
|
57 |
}
|
|
|
58 |
foreach ( $aliases as $entryID ) {
|
|
|
59 |
$client_id = $_POST["alias_for_$entryID"];
|
|
|
60 |
$sql = "insert into client_alias(client_id,alias,added_date) select $client_id, client_name,report_date from unknown_entry where unknown_entry_id = $entryID";
|
|
|
61 |
$result[] = $sql;
|
|
|
62 |
queryDatabaseExtended( $sql );
|
|
|
63 |
}
|
|
|
64 |
return implode( "\n", $result );
|
|
|
65 |
} // function processUnknownClients
|
|
|
66 |
|
|
|
67 |
function processUnknownDevices() {
|
|
|
68 |
$new = array();
|
|
|
69 |
$aliases = array();
|
|
|
70 |
$result = array();
|
|
|
71 |
foreach ( $_POST as $parameter => $value ) {
|
|
|
72 |
// look for all new and alias entries
|
|
|
73 |
if ( preg_match('/new_(\d+)/', $parameter, $id ) ) {
|
|
|
74 |
if ($value) {
|
|
|
75 |
$new[] = $id[1];
|
|
|
76 |
}
|
|
|
77 |
} elseif ( preg_match('/alias_for_(\d+)/', $parameter, $id ) ) {
|
|
|
78 |
if ($value) {
|
|
|
79 |
$aliases[] = $id[1];
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
$whoami = $_SESSION['login_id'];
|
|
|
84 |
foreach ( $new as $entryID ) {
|
|
|
85 |
$sql ="insert into device (site_id, name, device_type_id, added_date)
|
|
|
86 |
select site_id, device_name, device_type_id, report_date
|
|
|
87 |
from unknown_entry join
|
|
|
88 |
(select min(site_id) site_id, client.name client
|
|
|
89 |
from site join client using (client_id)
|
|
|
90 |
group by client.name
|
|
|
91 |
union
|
|
|
92 |
select min(site_id) site_id, alias client
|
|
|
93 |
from site join client_alias using (client_id)
|
|
|
94 |
group by alias) site
|
|
|
95 |
on unknown_entry.client_name = site.client,
|
|
|
96 |
(select device_type_id from device_type where name = 'Computer') device_type
|
|
|
97 |
where unknown_entry.unknown_entry_id = $entryID";
|
|
|
98 |
$data = queryDatabaseExtended( $sql );
|
|
|
99 |
$result[] = $sql;
|
|
|
100 |
if ($data['insert_id']) {
|
|
|
101 |
$sql = "update unknown_entry set processed_date = now(), processed_by = $whoami where unknown_entry_id = $entryID";
|
|
|
102 |
$result[] = $sql;
|
|
|
103 |
queryDatabaseExtended( $sql );
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
foreach ( $aliases as $entryID ) {
|
|
|
107 |
$device_id = $_POST["alias_for_$entryID"];
|
|
|
108 |
$sql = "insert into device_alias(device_id,alias,added_date) select $device_id, device_name,report_date from unknown_entry where unknown_entry_id = $entryID";
|
|
|
109 |
$result[] = $sql;
|
|
|
110 |
$data = queryDatabaseExtended( $sql );
|
|
|
111 |
if ($data['insert_id']) {
|
|
|
112 |
$sql = "update unknown_entry set processed_date = now(), processed_by = $whoami where unknown_entry_id = $entryID";
|
|
|
113 |
$result[] = $sql;
|
|
|
114 |
queryDatabaseExtended( $sql );
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
// ensure device_alias contains the device.name also (this can be changed by manual entry)
|
|
|
118 |
$sql = "insert into device_alias (device_id,alias,added_date)
|
|
|
119 |
select device_id,device.name, now()
|
|
|
120 |
from device join device_type using (device_type_id)
|
|
|
121 |
where device_type.show_as_system = 'Y'
|
|
|
122 |
and device_id in (select device_id from sysinfo_report)
|
|
|
123 |
and concat(device.device_id,device.name) not in (
|
|
|
124 |
select concat(device_id,device_alias.alias) from device_alias order by device_id
|
|
|
125 |
)";
|
|
|
126 |
queryDatabaseExtended( $sql );
|
|
|
127 |
return implode( "\n", $result );
|
|
|
128 |
} // function processUnknownClients
|
|
|
129 |
?>
|