forked from phpLicenseWatcher/phpLicenseWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense_util.php
More file actions
98 lines (65 loc) · 2.64 KB
/
license_util.php
File metadata and controls
98 lines (65 loc) · 2.64 KB
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
<?php
include_once(__DIR__.'/tools.php');
require_once(__DIR__."/common.php");
##################################################
# Load PEAR DB abstraction library
##################################################
require_once("DB.php");
################################################################
# If DB settings set up - Connect to the database
################################################################
if ( isset($db_hostname) && isset($db_username) && isset($db_password) ) {
$db = DB::connect($dsn, true);
if (DB::isError($db)) {
die ($db->getMessage());
}
}
################################################################
# Get current date and time
################################################################
$date = date('Y-m-d');
$time = date('H:i') . ":00";
for ( $i = 0 ; $i < sizeof($servers) ; $i++ ) {
$fp = popen($lmutil_loc . " lmstat -a -c " . $servers[$i], "r");
while ( !feof ($fp) ) {
$line = fgets ($fp, 1024);
# Look for features in the output. You will see stuff like
# Users of Allegro_Viewer: (Total of 5 licenses available
if ( preg_match("/^(Users of) (.*)/i",$line, $out ) ) {
if ( preg_match("/(Total of) (.*) (license[s]? issued; Total of) (.*) (license[s]? in use)/i", $line, $items ) ) {
$license_array[] = array (
"feature" => substr($out[2],0,strpos($out[2],":")),
"licenses_used" => $items[4] ) ;
unset($out);
unset($items);
}
}
}
pclose($fp);
# $conn->debug=true;
if ( isset($license_array) && is_array ($license_array) ) {
for ( $j = 0 ; $j < sizeof($license_array) ; $j++ ) {
############################################################################
# Only insert into the database if DB settings are set
############################################################################
if ( isset($db_hostname) && isset($db_username) && isset($db_password) ) {
$sql = "INSERT INTO license_usage (flmusage_server,flmusage_product,flmusage_date,flmusage_time,flmusage_users) VALUES ('$servers[$i]','" .
$license_array[$j]["feature"] . "', '$date', '$time'," . $license_array[$j]["licenses_used"] . ")";
if ( isset($debug) && $debug == 1 )
print_sql ($sql);
$recordset = $db->query($sql);
if (DB::isError($recordset)) {
die ($recordset->getMessage());
}
}
}
unset($license_array);
}
}
##########################################################################
# Disconnect connection if using DB
##########################################################################
if ( isset($db_hostname) && isset($db_username) && isset($db_password) ) {
$db->disconnect();
}
?>