summaryrefslogtreecommitdiffstats
path: root/modules/ipxe.inc.php
blob: d479bd15d5bb7c2f8f088b24c1ce2883b599cdfc (plain) (blame)
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
<?php

class Page_iPxe extends Page
{

	protected function doPreprocess()
	{
		User::load();

		if (!User::hasPermission('superadmin')) {
			Message::addError('no-permission');
			Util::redirect('?do=Main');
		}

		if (isset($_POST['action'])) {
			if ($_POST['action'] === 'compile') {
				if (!Util::verifyToken()) {
					Util::redirect('?do=Main');
				}
			}
		}
	}

	protected function doRender()
	{
		$ips = array();
		$current = CONFIG_IPXE_DIR . '/last-ip';
		if (file_exists($current)) $current = file_get_contents($current);
		exec('/bin/ip a', $retval);
		foreach ($retval as $ip) {
			if (preg_match('#inet (\d+\.\d+\.\d+\.\d+)/\d+.*scope#', $ip, $out) && $out[1] !== '127.0.0.1') {
				$ips[] = array(
					'ip'       => $out[1],
					'current'  => ($out[1] == $current)
				);
			}
		}
		Render::addTemplate('page-ipxe', array('ips' => $ips, 'token' => Session::get('token')));
	}
}