forked from skunkie/ipxe-phpmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
91 lines (81 loc) · 2.53 KB
/
functions.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
<?php
function authenticated() {
global $username;
global $password;
global $access;
global $USERS;
$cred = "{$username}:{$password}";
switch($cred) {
case array_key_exists($cred, $USERS):
$authenticated = True;
$access = $USERS[$cred];
break;
default:
$authenticated = False;
break;
}
return $authenticated;
}
function title($name, $accesses) {
global $access;
if (strpos($accesses, $access) !== False) {
# the max number of characters for resolution 1024 x 768 is 107
$total_length = 107;
$name_length = strlen($name);
$start = intval(($total_length - $name_length) / 2);
$end = $total_length - $start - $name_length;
$title = str_repeat("-", $start) . $name . str_repeat("-", $end);
echo "item --gap -- {$title}\n";
}
}
function hotkey($item) {
global $index;
$index++;
$hotkey = (($index < 10) ? $index : sprintf("%c", $index + ord('A') - 10));
return $hotkey;
}
function item($item_name, $item, $ipxe_file, $accesses) {
global $entries;
global $url;
global $access;
if (strpos($accesses, $access) !== False) {
$i = hotkey($item);
echo "item --key {$i} {$item} ({$i}) {$item_name}\n";
$i = ":{$item}\nchain --replace --autofree {$url}{$ipxe_file}##params";
array_push($entries, $i);
}
}
function item_cmd($item_name, $item, $ipxe_cmd, $accesses) {
global $entries;
global $url;
global $access;
if (strpos($accesses, $access) !== False) {
$i = hotkey($item);
echo "item --key {$i} {$item} ({$i}) {$item_name}\n";
$i = ":{$item}\n{$ipxe_cmd} && chain --replace --autofree {$url}menu.php##params";
array_push($entries, $i);
}
}
function item_ks($item_name, $item, $ipxe_cmd, $accesses) {
global $entries;
global $url;
global $access;
if (strpos($accesses, $access) !== False) {
$i = hotkey($item);
echo "item --key {$i} {$item} ({$i}) {$item_name}\n";
$i = ":{$item}\n{$ipxe_cmd}";
array_push($entries, $i);
}
}
function ks_get_value($var) {
ob_start();
echo "echo \${{$var}}\n";
list(, $value) = split("echo ", ob_get_contents());
ob_end_clean();
return $value;
}
function ks_name_offset($name, $ks_var) {
global $offset;
return $name . str_repeat(".", ($offset - strlen($name))) . ks_get_value($ks_var);
}
?>