forked from phpLicenseWatcher/phpLicenseWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicense_cache.php
More file actions
66 lines (46 loc) · 1.76 KB
/
license_cache.php
File metadata and controls
66 lines (46 loc) · 1.76 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
<?php
if ( ! is_readable(__DIR__.'/config.php') ) {
echo("<H2>Error: Configuration file config.php does not exist. Please
notify your system administrator.</H2>");
exit;
} else
include_once(__DIR__.'/config.php');
require_once(__DIR__."/common.php");
###################################################
# We are using PEAR's DB abstraction library
###################################################
require_once("DB.php");
################################################################
# Connect to the database
# Use persistent connections
################################################################
$db = DB::connect($dsn, true);
if (DB::isError($db)) {
die ($db->getMessage());
}
$today = date("Y-m-d");
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 (.*)Total /i", $line ) ) {
$out = explode(" ", $line);
# Remove the : in the end of the string
$feature = str_replace(":", "", $out[2]);
# Return the number
$sql = "INSERT INTO licenses_available (flmavailable_server,flmavailable_date,flmavailable_product,flmavailable_num_licenses) VALUES ('$servers[$i]','" .
$today . "','" . $feature . "'," . $out[6] . ")";
if ( isset($debug) && $debug == 1 )
print_sql ($sql);
$recordset = $db->query($sql);
if (DB::isError($recordset)) {
die ($recordset->getMessage());
}
}
}
pclose($fp);
}
$db->disconnect();
?>