source: src-sh/pc-thinclient/resources/webui/functions.php @ 4023a66

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 4023a66 was 4023a66, checked in by Kris Moore <kris@…>, 15 months ago

Add the new pc-thinclient WebUI

Its very basic, but it lets you upload / edit pc-sysinstall
config files, as well as add MAC address links to the config you want
to install it with. Includes some basic PHP auth as well, to restrict
who can use it.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1<?php
2
3require("config.php");
4
5// Remove a mac address sym-link
6function rem_mac($mac)
7{
8  global $sdir;
9  chdir($sdir);
10  unlink($mac);
11}
12
13// Function to do the creation of the mac -> file symlink
14function doadd_mac()
15{
16  global $sdir;
17 
18  if ( ! isset($_POST['macaddress']) or ! isset($_POST['cfgfile']) )
19     die("Unset vars! Did you enter a mac address?");
20
21  $mac=$_POST['macaddress'];
22  $cfg=$_POST['cfgfile'];
23  chdir($sdir);
24  symlink($cfg, $mac . ".cfg");
25 
26}
27
28// Function to add a mac address sym-link -> config file
29function add_mac()
30{
31  global $sdir;
32
33  echo "<a href=\"?view=clients\">Back</a><br>";
34  echo "<br>";
35  echo "Please enter the MAC address, and select a config to install with:<br>";
36
37  echo "<form method=\"post\" action=\"?view=clients&doadd=true\">\n";
38  echo "Mac Address: <input type=\"text\" name=\"macaddress\" size=\"50\"><br>\n";
39  echo "Config File: <select name=cfgfile>\n";
40
41  chdir($sdir);
42  $dir_handle = @opendir($sdir) or die("Unable to open $sdir");
43
44  //running the while loop
45  while ($file = readdir($dir_handle))
46  {
47     if ( "$file" == ".." or "${file}" == "." or is_dir($file) or is_link($file))
48        continue;
49     echo "<option value=\"$file\">$file</option>";
50  }
51
52  echo "</select><br><br>\n";
53  echo "<input type=\"submit\" name=\"Save\" value=\"Add MAC\">";
54  echo "</form>\n";
55
56}
57
58// Function to list mac address sym-links in the scripts dir
59function list_mac()
60{
61  global $sdir;
62
63  // Display client MAC address scripts
64  chdir($sdir);
65  $dir_handle = @opendir($sdir) or die("Unable to open $sdir");
66
67  $bgcolor = "#BDBDBD";
68
69  echo "<a href=\"?view=clients&add=true\">Add a MAC address</a><br>";
70  echo "<table border=\"0\" cellspacing=\"0\"><tr bgcolor=\"#1A73CC\"><td><b>MAC Address</b></td><td></td><td><b>Config File</b></td><td></td></tr><br>";
71
72  //running the while loop
73  while ($file = readdir($dir_handle))
74  {
75     if ( "$file" == ".." or "${file}" == "." or is_dir($file) or ! is_link($file))
76        continue;
77
78     // Get the file sym-link target
79     $cfg = readlink($file);
80
81     $mac = strstr($file, '.cfg', true);
82
83     echo "<tr bgcolor=\"$bgcolor\" border=0><td>$mac</td><td>&nbsp;<b>></b>&nbsp;</td><td>$cfg</td><td>&nbsp; - <a href=\"?view=clients&del=$file\">Remove</a></td>";
84
85     if ( $bgcolor == "#BDBDBD" )
86       $bgcolor = "#FFFFFF";
87     else
88       $bgcolor = "#BDBDBD";
89  }
90
91  echo "</table>";
92
93} // End of list MAC addreses
94
95// Function to list cfg files
96function list_cfgs()
97{
98  global $sdir;
99
100  // Display cfg files
101  chdir($sdir);
102  $dir_handle = @opendir($sdir) or die("Unable to open $sdir");
103
104  $bgcolor = "#BDBDBD";
105
106  echo "<a href=\"?view=configs&add=true\">Add a Config</a><br>";
107  echo "<table border=\"0\" cellspacing=\"0\"><tr bgcolor=\"#1A73CC\"><td><b>Config File</b></td><td></td><td></td></tr><br>";
108
109  //running the while loop
110  while ($file = readdir($dir_handle))
111  {
112     if ( "$file" == ".." or "${file}" == "." or is_dir($file) or is_link($file))
113        continue;
114
115     // Get the file sym-link target
116     $config = strstr($file, '.cfg', true);
117
118     echo "<tr bgcolor=\"$bgcolor\" border=0><td>$config</td><td><a href=\"?view=configs&edit=$file\">Edit</a></td><td>&nbsp; - <a href=\"?view=configs&del=$file\">Remove</a></td>";
119
120     if ( $bgcolor == "#BDBDBD" )
121       $bgcolor = "#FFFFFF";
122     else
123       $bgcolor = "#BDBDBD";
124  }
125
126  echo "</table>";
127
128} // End of list config files
129
130// Function to add the new config file
131function doadd_cfg()
132{
133  global $sdir;
134
135  chdir($sdir);
136  $uploadfile = $sdir . "/" . basename($_FILES['usercfg']['name']);
137
138  if (! move_uploaded_file($_FILES['usercfg']['tmp_name'], $uploadfile))
139     die("Failed uploading config file");
140}
141
142
143function add_cfg()
144{
145  echo "<form enctype=\"multipart/form-data\" action=\"?view=configs&doadd=true\" method=\"POST\">";
146  echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />";
147  echo "Upload this config: <input name=\"usercfg\" type=\"file\" /><br>";
148  echo "<input type=\"submit\" value=\"Upload Config\" /><br>";
149  echo "</form>";
150}
151
152
153// Function to add a config file
154function edit_cfg($cfg)
155{
156  global $sdir;
157
158  // Get the file sym-link target
159  $confignick = strstr($cfg, '.cfg', true);
160
161  echo "<a href=\"?view=configs\">Back</a><br>";
162  echo "<br>";
163  echo "Editing the config: <b>$confignick</b><br>";
164
165  echo "<form method=\"post\" action=\"?view=configs&doedit=$cfg\">\n";
166  echo "<textarea name=\"script\" cols=\"100\" rows=\"25\">"; 
167  readfile($sdir . "/" .  $cfg);
168  echo "</textarea><br>\n";
169  echo "<input type=\"submit\" name=\"Save\" value=\"Save Config\">";
170  echo "</form>";
171
172}
173
174// Remove a mac address sym-link
175function rem_cfg($cfg)
176{
177  global $sdir;
178  chdir($sdir);
179  unlink($cfg);
180}
181
182// Function to edit the config file
183function doedit_cfg($cfg)
184{
185  global $sdir;
186 
187  if ( ! isset($_POST['script']) )
188     die("Unset vars! Did you not enter an install script?");
189
190  $contents=$_POST['script'];
191  $contents=str_replace("\r\n", "\n", $contents);
192  $handle = fopen($sdir . "/" . $cfg, "w");
193  fwrite($handle, $contents);
194}
195
196?>
Note: See TracBrowser for help on using the repository browser.