forked from phpLicenseWatcher/phpLicenseWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicense_alert.php
137 lines (90 loc) · 4.38 KB
/
license_alert.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
<?php
require_once(__DIR__."/common.php");
require_once(__DIR__.'/tools.php');
print_header("Licenses in Detail");
?>
<h1>License Alert</h1>
<?php
############################################################################
# Purpose: This script is used to e-mail alerts on licenses that are
# due to expire some time in the future. This script should
# be run out of cron preferably every day. Check config.php
# to configure e-mail address reports should be sent to
# as well as how much ahead should the user be warned about
# expiration ie. 10 days before license expires.
############################################################################
#########################################################
# Date when the licenses will expire
#########################################################
$expire_date = mktime (0,0,0,date("m"),date("d")+$lead_time, date("Y"));
$today = mktime (0,0,0,date("m"),date("d"), date("Y"));
for ( $i = 0 ; $i < sizeof($servers) ; $i++ ) {
#for ( $i = 0 ; $i < 1 ; $i++ ) {
build_license_expiration_array($lmutil_loc, $servers[$i], $expiration_array[$i]);
}
#print_r($expiration_array);
##############################################################
# We are using PHP Pear stuff ie. pear.php.net
##############################################################
require_once ("HTML/Table.php");
$table = new HTML_Table("class='table' style='width:100%;' ");
$colHeaders = array("Server", "Server description", "Feature expiring", "Expiration date",
"Days to expiration", "Number of license(s) expiring");
$table->addRow($colHeaders, "", "TH");
#######################################################
# Get names of different colors. These will be used to group visually
# licenses from the same license server
#######################################################
$color = explode(",", $colors);
# Now after the expiration has been built loop through all the fileservers
for ( $i = 0 ; $i < sizeof($expiration_array) ; $i++ ) {
if( isset($expiration_array[$i])){
foreach ( $expiration_array[$i] as $key => $myarray) {
for ( $j = 0 ; $j < sizeof($myarray) ; $j++ ) {
if ( (strcmp($myarray[$j]["days_to_expiration"],"permanent") != 0) && ($myarray[$j]["days_to_expiration"] <= $lead_time) ) {
if ( $myarray[$j]["days_to_expiration"] < 0 )
$myarray[$j]["days_to_expiration"] = "<b>Already expired</b>";
$table->addRow(array($servers[$i], $description[$i],
$key,$myarray[$j]["expiration_date"],
$myarray[$j]["days_to_expiration"],
$myarray[$j]["num_licenses"]),"bgcolor='" . $color[$i] ."'");
}
}
}
}
}
########################################################
# Center columns 2,4,5and 6. Columns start with 0 index
########################################################
$table->updateColAttributes(1,"align=center");
$table->updateColAttributes(4,"align=center");
$table->updateColAttributes(5,"align=center");
$table->updateColAttributes(3,"align=center");
########################################################
# Dump the table HTML into a variable
########################################################
$table_html = $table->toHTML();
#echo($table_html);
$message = "<HTML>\n<BODY>
These licenses will expire within " . $lead_time . " days. Licenses
will expire at 23:59 on the day of expiration.<p>";
$message .= $table_html;
$message .= "<?php echo footer(); ?>";
########################################################################
# If the table has more than one row (header row will be one) there
# are expiring licenses
########################################################################(
if ( $table->getRowCount() > 1 ) {
if ( $notify_address && ! isset($_GET['nomail']) ) {
echo("Emailing to $notify_address<p>\n");
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: [email protected]' ;
$headers[] ='Reply-To: [email protected]' ;
$headers[] ='X-Mailer: PHP/' . phpversion();
mail($notify_address, "ALERT: License expiration within " . $lead_time . " days", $message , implode("\r\n", $headers) );
}
}
echo($message);
echo footer();
?>