added default image for all clients (known and unkown)
This commit is contained in:
parent
df17c93e76
commit
91811347d8
11
README.md
11
README.md
@ -29,6 +29,17 @@ db hosts setprop lab01 \
|
|||||||
|
|
||||||
By running the above command, the **memtest** image will be used for one boot only.
|
By running the above command, the **memtest** image will be used for one boot only.
|
||||||
|
|
||||||
|
## default image ##
|
||||||
|
|
||||||
|
When there's no specific setting for the host, the host is not in the hosts db, or the image specified for the host is not available, the *default image* is used.
|
||||||
|
|
||||||
|
To set the default image, you can use this command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
db configuration setprop pxeserver-httpd \
|
||||||
|
defaultimage memtest
|
||||||
|
```
|
||||||
|
|
||||||
## TODO / ideas ##
|
## TODO / ideas ##
|
||||||
|
|
||||||
* Create a menu, for interactive selection
|
* Create a menu, for interactive selection
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Summary: LibreSchool PXE server
|
Summary: LibreSchool PXE server
|
||||||
Name: libreschool-pxeserver
|
Name: libreschool-pxeserver
|
||||||
Version: 1.1.3
|
Version: 1.1.4
|
||||||
Release: 1.ns7
|
Release: 1.ns7
|
||||||
License: GPL
|
License: GPL
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
@ -112,6 +112,9 @@ if [ "$1" = 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Apr 28 2020 Paolo Asperti <paolo@asperti.com> - 1.1.4-1.ns7
|
||||||
|
- Added default image setting
|
||||||
|
|
||||||
* Sat Apr 25 2020 Paolo Asperti <paolo@asperti.com> - 1.1.3-1.ns7
|
* Sat Apr 25 2020 Paolo Asperti <paolo@asperti.com> - 1.1.3-1.ns7
|
||||||
- Added KUbuntu 20.04 (live only)
|
- Added KUbuntu 20.04 (live only)
|
||||||
- Added LUbuntu 20.04 (live only)
|
- Added LUbuntu 20.04 (live only)
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
localhd
|
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* This script manages the loading of the PXE image, based on specific
|
* This script manages the loading of the PXE image, based on specific
|
||||||
* host preferences.
|
* host preferences.
|
||||||
*
|
*
|
||||||
* php version 5.4.16
|
* php version 5.4.16
|
||||||
*
|
*
|
||||||
* @category Client_Management
|
* @category Client_Management
|
||||||
@ -21,15 +21,16 @@
|
|||||||
require_once "EsmithDatabase.php";
|
require_once "EsmithDatabase.php";
|
||||||
|
|
||||||
$hosts_db = new EsmithDatabase('hosts');
|
$hosts_db = new EsmithDatabase('hosts');
|
||||||
|
$config_db = new EsmithDatabase('configuration');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if specified mac address is valid
|
* Check if specified mac address is valid
|
||||||
*
|
*
|
||||||
* We should've used filter_var($mac, FILTER_VALIDATE_MAC) but it's available
|
* We should've used filter_var($mac, FILTER_VALIDATE_MAC) but it's available
|
||||||
* from PHP 5.5.0 and we have 5.4.16. Too bad.
|
* from PHP 5.5.0 and we have 5.4.16. Too bad.
|
||||||
*
|
*
|
||||||
* @param string $mac the mac address to examine
|
* @param string $mac the mac address to examine
|
||||||
*
|
*
|
||||||
* @return bool if the macaddress is valid or not
|
* @return bool if the macaddress is valid or not
|
||||||
*/
|
*/
|
||||||
function isValidMAC($mac) {
|
function isValidMAC($mac) {
|
||||||
@ -50,11 +51,11 @@ function isValidMAC($mac) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the client corresponding a specific mac address
|
* Get the client corresponding a specific mac address
|
||||||
*
|
*
|
||||||
* @param string $mac the mac address of the client
|
* @param string $mac the mac address of the client
|
||||||
*
|
*
|
||||||
* @return host||boolean client if found, false otherwise
|
* @return host||boolean client if found, false otherwise
|
||||||
*/
|
*/
|
||||||
function getClientFromMAC($mac=false) {
|
function getClientFromMAC($mac=false) {
|
||||||
@ -67,11 +68,11 @@ function getClientFromMAC($mac=false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default exit string
|
* Default exit string
|
||||||
* This string will instruct to reload the script
|
* This string will instruct to reload the script
|
||||||
* passing the mac address of the calling machine
|
* passing the mac address of the calling machine
|
||||||
*
|
*
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
function defaultExit() {
|
function defaultExit() {
|
||||||
@ -83,23 +84,43 @@ chain http://".$_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAME"]."?mac=\${mac}
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if specified PXE image exists
|
* Check if specified PXE image exists
|
||||||
*
|
*
|
||||||
* @param string $i image name
|
* @param string $i image name
|
||||||
*
|
*
|
||||||
* @return bool if the image exists or not
|
* @return bool if the image exists or not
|
||||||
*/
|
*/
|
||||||
function imageExists($i) {
|
function imageExists($i) {
|
||||||
$pwd = dirname(__FILE__);
|
$pwd = dirname(__FILE__);
|
||||||
$dir = $pwd . '/' . $i;
|
$dir = $pwd . '/' . $i;
|
||||||
$bootfile = $dir . '/boot';
|
$bootfile = $dir . '/boot';
|
||||||
$iso_is_mounted = $dir . '/iso_is_mounted';
|
$iso_is_mounted = $dir . '/iso_is_mounted';
|
||||||
$iso_ok = ! file_exists($iso_is_mounted) ||
|
$iso_ok = ! file_exists($iso_is_mounted) ||
|
||||||
(is_link($iso_is_mounted) && is_readable($iso_is_mounted));
|
(is_link($iso_is_mounted) && is_readable($iso_is_mounted));
|
||||||
return is_dir($dir) && is_readable($bootfile) && $iso_ok;
|
return is_dir($dir) && is_readable($bootfile) && $iso_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to boot the default PXE Image
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function try_defaultimage() {
|
||||||
|
global $config_db;
|
||||||
|
|
||||||
|
$defaultimage = $config_db->getProp('pxeserver-httpd','defaultimage');
|
||||||
|
if (imageExists($defaultimage)) {
|
||||||
|
print("#!ipxe
|
||||||
|
# Loading PXEImage
|
||||||
|
chain " . $defaultimage . "/boot
|
||||||
|
");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!isset($_REQUEST['mac'])) {
|
if (!isset($_REQUEST['mac'])) {
|
||||||
defaultExit();
|
defaultExit();
|
||||||
}
|
}
|
||||||
@ -112,7 +133,7 @@ if (!isValidMAC($_REQUEST['mac'])) {
|
|||||||
$mac = $_REQUEST['mac'];
|
$mac = $_REQUEST['mac'];
|
||||||
$client = getClientFromMAC($mac);
|
$client = getClientFromMAC($mac);
|
||||||
if (!$client) {
|
if (!$client) {
|
||||||
// TODO: make up a default for unknown clients
|
try_defaultimage();
|
||||||
defaultExit();
|
defaultExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user