forked from sorvani/freepbx-helper-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext_test.php
More file actions
124 lines (95 loc) · 2.8 KB
/
Copy pathext_test.php
File metadata and controls
124 lines (95 loc) · 2.8 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EXT TEST</title>
<!-- <link rel="stylesheet" type="text/css" href="style.css"> -->
</head>
<body>
<?php
//Set the minumim and maxium extensions to display
$f_ext = 100;
$l_ext = 199;
//including the future php file that processes the form
include "ext_test_form_processor.php";
//File to use... may work with $wrets, I can't test that.
$txt_file = 'ext_test.txt';
//Check if file exists, if not
if (file_exists($txt_file)) {
echo "<br><br><br>";
// echo "<center>The file <strong>$txt_file</strong> exists and is readable.</center>";
echo "<br>";
}
else {
echo "The file $txt_file does not exist.";
}
//grabs contents of the text file.
$contents = file_get_contents($txt_file);
//regex pattern to use -- matches any number after a "/"
$pattern = '/\/([0-9]+)/';
//opens file in read-only mode to use.
$handle = fopen($txt_file, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
preg_match_all($pattern,$contents,$matches);
}
//closes open file
fclose($handle);
} else {
echo "Can't open file.";
}
?>
<!-- Start of form, uses built-in htmlspecialchars security function as added precaution:
http://php.net/manual/en/function.htmlspecialchars.php -->
<form enctype="multipart/form-data" method="post" action=<?php print htmlspecialchars($_SERVER["PHP_SELF"]); ?>>
<?php
if (!($_SERVER["REQUEST_METHOD"] == "POST")) {
?>
<center>
<fieldset style="width:270px"><legend class="legendtitle">Select extension(s) to reboot:</legend>
<!-- begin table -->
<center>
<table border="1" cellspacing="3" cellpadding="3">
<thead>
<tr>
<th><center><h4>Reboot?</h4></center></th>
<th><center><h4>Extension</h4></center></th>
</tr>
</thead>
<tbody>
<?php } ?>
<?php
// print default table using file
if (!($_SERVER["REQUEST_METHOD"] == "POST")) {
foreach($matches[1] as $item => $value) {
if($value >= $f_ext && $value <= $l_ext) {
echo "\t\t<tr>\n\t\t\t<td align=\"center\"><input type=\"checkbox\" name=\"extension\" value=\"$value\"></td>\n";
echo "\t\t\t<td align=\"center\"><strong>$value</strong></td>\n";
}
}
print "</tbody>\n";
print "</table>\n"; // end table
print "<br>\n";
print "<p align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Reboot\"></p>";
echo "</fieldset>";
} else {
?>
<center>
<table border="1" cellspacing="3" cellpadding="3">
<thead>
<tr>
<th><center><h4>Submision Results:</h4></th>
</tr>
</thead>
<tbody>
<?php
// Submission results
print "\t\t<tr>\n\t\t\t<td>Placeholder for later...</td>\n\t\t</tr>\n";
print "</tbody>\n";
echo "</table>";
}
?>
</center>
</form>
</body>
</html>