forked from proche-rainmaker/phplicensewatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlmremove.php
118 lines (97 loc) · 3.94 KB
/
lmremove.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
<?php
require_once("common.php");
require_once("tools.php");
include_once('auth.php');
print_header("Remove user license");
# grab server info
if (isset($_GET['server'])) {
$host = $server[$_GET['server']];
$hostno = $_GET['server'];
} else {
die('no server defined');
}
?>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body role="document">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">phpLicenseWatcher</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li><a href="details.php?listing=0&server=<?php echo($hostno);?>">Server Details</a></li>
<li class="active"><a href="#">Remove license</a></li>
<!--li><a href="#about">About</a></li-->
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container" role="main">
<h1>Remove user license</h1>
<div id="msg" style="visibility:hidden;"></div>
<?php
if ( isset($disable_license_removal) && $disable_license_removal == 1 ) {
die("Sorry this feature is not enabled. If you need it talk to the maintainer of this
page on how to enable it.");
}
$args=preg_split("/ /i", $_GET['arg']);
#echo("<p>Host: " . $host['hostname'] . "</p>");
#echo("<p>Args: " . $args[0] . " " . $args[1] . " " . $args[2] . "</p>");
######################################################################
# Due to laziness feature contains colon (:) at the end. We need
# to strip it
######################################################################
$featurename = $_GET['feature'];
if ( preg_match('/^[a-zA-Z0-9\-_]+$/i', $featurename) ) {
echo("<p>Looking up feature " . $featurename . " on " . $host['hostname'] . "</p>");
} else {
die("Security Alert: Feature name you supplied has illegal characters that could possibly be used for security compromise.");
}
######################################################################
# For security purposes and other reasons before we remove a license
# we'll try to make sure whether it is actually used
######################################################################
$fp = popen($lmutil_loc . " lmstat -f " . $featurename . " -c " . $host['hostname'] , "r");
$featureFound = false;
while ( !feof ($fp) ) {
$line = fgets ($fp, 1024);
if ( preg_match ("/$args[0] $args[1] $args[2] /i", $line, $matchedline ) ) {
$featureFound = true;
break;
}
}
if ( $featureFound ) {
echo("<p>Feature " . $featurename . " found, trying to remove license</p>");
# checked out feature found
$commandline = ($lmutil_loc . " lmremove -c " . $host['hostname'] . " " . $featurename . " " . $matchedline[0] );
echo("<p>Output of your removal command<p><PRE>");
$fp2 = popen($commandline , "r");
while ( !feof ($fp2) ) {
$line = fgets ($fp2, 1024);
echo($line);
}
echo("</p>");
break;
} else {
echo("<p>No checkouts for feature " . $featurename . " found " . $host['hostname'] . " for specified user</p>");
}
# Close pipes
fclose($fp);
fclose($fp2);
?>