]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/handlers_boot.py
5 import tornado
.httpserver
13 BASEDIR
= os
.path
.dirname(__file__
)
15 def word_wrap(s
, width
=45):
16 paragraphs
= s
.split('\n')
18 for paragraph
in paragraphs
:
19 while len(paragraph
) > width
:
20 pos
= paragraph
.rfind(' ', 0, width
)
23 lines
.append(paragraph
[:pos
])
24 paragraph
= paragraph
[pos
:]
25 lines
.append(paragraph
.lstrip())
26 return '\n'.join(lines
)
28 class BootBaseHandler(tornado
.web
.RequestHandler
):
31 return backend
.NetBoot()
34 class MenuGPXEHandler(BootBaseHandler
):
39 # Check if version of the bootloader is recent enough.
40 # Otherwise send the latest version of the PXE loader.
41 user_agent
= self
.request
.headers
.get("User-Agent", None)
44 client
, version
= user_agent
.split("/")
48 # We replaced gPXE by iPXE.
50 return self
.serve_update()
52 # Everything under version 1.0.0 should be
55 return self
.serve_update()
58 self
.set_header("Content-Type", "text/plain")
59 self
.write("#!gpxe\n")
61 self
.write("set 209:string premenu.cfg\n")
62 self
.write("set 210:string http://boot.ipfire.org/\n")
63 self
.write("chain pxelinux.0\n")
65 def serve_update(self
):
66 self
.set_header("Content-Type", "text/plain")
67 self
.write("#!gpxe\n")
70 self
.write("echo\necho Your copy of gPXE/iPXE is too old. ")
71 self
.write("Upgrade to avoid seeing this every boot!\n")
73 self
.write("chain http://mirror0.ipfire.org/releases/ipfire-boot/latest/ipxe.kpxe\n")
76 class MenuCfgHandler(BootBaseHandler
):
77 def _menu_string(self
, menu
, level
=0):
81 s
+= self
._menu
_entry
(entry
, level
=level
)
85 def _menu_entry(self
, entry
, level
=0):
90 if entry
.type == "seperator":
91 lines
.append(ident
+ "menu separator")
93 elif entry
.type == "header":
94 lines
.append(ident
+ "menu begin %d" % entry
.id)
95 lines
.append(ident
+ "\tmenu title %s" % entry
.title
)
98 lines
.append(ident
+ "\tlabel %d.back" % entry
.id)
99 lines
.append(ident
+ "\t\tmenu label Back...")
100 lines
.append(ident
+ "\t\tmenu exit")
101 lines
.append(ident
+ "\tmenu separator")
103 lines
.append("%s" % self
._menu
_string
(entry
.submenu
, level
=level
+1))
104 lines
.append(ident
+ "menu end")
106 elif entry
.type == "config":
107 lines
.append(ident
+ "label %d" % entry
.id)
108 lines
.append(ident
+ "\tmenu label %s" % entry
.title
)
109 if entry
.description
:
110 lines
.append(ident
+ "\ttext help")
111 lines
.append(word_wrap(entry
.description
))
112 lines
.append(ident
+ "\tendtext")
114 config
= self
.netboot
.get_config(entry
.item
)
115 if not config
: return ""
117 lines
.append(ident
+ "\tkernel %s" % config
.image1
)
119 lines
.append(ident
+ "\tinitrd %s" % config
.image2
)
121 lines
.append(ident
+ "\tappend %s" % config
.args
)
123 return "\n".join(lines
+ [""])
126 self
.set_header("Content-Type", "text/plain")
128 menu
= self
._menu
_string
(self
.netboot
.get_menu(1))
130 self
.render("netboot/menu.cfg", menu
=menu
)