1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
14 #define NULL ((void *) 0)
20 #include "passwords.h"
27 /* Global variables */
31 // Different network options
32 static char nonet
[] = "<n>etwork [none]";
33 static char dhcpnet
[] = "<n>etwork [dhcp]";
34 static char statnet
[] = "<n>etwork [static]";
36 static char loginstr
[] = "<L>ogin ";
37 static char logoutstr
[] = "<L>ogout ";
40 unsigned int baseurl
:1; // Do we need to specify by url
41 unsigned int mountcd
:1; // Should we mount the cd
42 unsigned int winrep
:1; // Want to repair windows?
43 unsigned int linrep
:1; // Want to repair linux?
47 t_menuitem
*baseurl
, *mountcd
, *network
, *runprep
, *winrep
, *linrep
;
48 t_menuitem
*stat
, *dhcp
, *none
, *prepopt
, *secret
;
50 // all the menus we are going to declare
51 unsigned char TESTING
, RESCUE
, MAIN
, PREPMENU
, NETMENU
, LONGMENU
, SECRETMENU
;
53 char username
[12]; // Name of user currently using the system
57 TIMEOUTCODE
ontimeout(void)
70 void keys_handler(t_menusystem
* ms
__attribute__ (( unused
)), t_menuitem
* mi
, int scancode
)
74 if ((scancode
) == KEY_F1
&& mi
->helpid
!= 0xFFFF) { // If scancode of F1
75 runhelpsystem(mi
->helpid
);
77 // If user hit TAB, and item is an "executable" item
78 // and user has privileges to edit it, edit it in place.
79 if ((scancode
== KEY_TAB
) && (mi
->action
== OPT_RUN
) &&
80 (isallowed(username
, "editcmd") || isallowed(username
, "root"))) {
81 if (getscreensize(1, &nr
, &nc
)) {
82 /* Unknown screen size? */
86 // User typed TAB and has permissions to edit command line
87 gotoxy(EDITPROMPT
, 1);
88 csprint("Command line:", 0x07);
89 editstring(mi
->data
, ACTIONLEN
);
90 gotoxy(EDITPROMPT
, 1);
95 t_handler_return
login_handler(t_menusystem
* ms
, t_menuitem
* mi
)
105 if (mi
->item
== loginstr
) { /* User wants to login */
106 if (getscreensize(1, &nr
, &nc
)) {
107 /* Unknown screen size? */
111 gotoxy(PWDPROMPT
, 1);
112 csprint("Enter Username: ", 0x07);
113 getstring(login
, sizeof username
);
114 gotoxy(PWDPROMPT
, 1);
116 csprint("Enter Password: ", 0x07);
117 getpwd(pwd
, sizeof pwd
);
118 gotoxy(PWDPROMPT
, 1);
121 if (authenticate_user(login
, pwd
)) {
122 strcpy(username
, login
);
123 mi
->item
= logoutstr
; // Change item to read "Logout"
125 strcpy(username
, GUEST_USER
);
126 } else // User needs to logout
128 strcpy(username
, GUEST_USER
);
132 if (strcmp(username
, GUEST_USER
) == 0) {
133 prepopt
->action
= OPT_INACTIVE
;
134 secret
->action
= OPT_INVISIBLE
;
136 prepopt
->action
= OPT_SUBMENU
;
137 prepopt
->itemdata
.radiomenunum
= PREPMENU
;
138 secret
->action
= OPT_SUBMENU
;
139 secret
->itemdata
.submenunum
= SECRETMENU
;
147 void msys_handler(t_menusystem
* ms
, t_menuitem
* mi
)
152 if (getscreensize(1, &nr
, &nc
)) {
153 /* Unknown screen size? */
157 gotoxy(PWDLINE
, PWDCOLUMN
);
158 csprint("User: ", PWDATTR
);
159 cprint(ms
->fillchar
, ms
->fillattr
, sizeof username
);
160 gotoxy(PWDLINE
, PWDCOLUMN
+ 6);
161 csprint(username
, PWDATTR
);
163 if (mi
->parindex
!= PREPMENU
) // If we are not in the PREP MENU
168 gotoxy(INFLINE
+ 1, 0);
172 strcpy(infoline
, " ");
174 strcat(infoline
, "baseurl=http://192.168.11.12/gui ");
176 strcat(infoline
, "mountcd=yes ");
177 v
= (void *)network
->data
;
178 if (v
!= NULL
) // Some network option specified
180 strcat(infoline
, "network=");
181 strcat(infoline
, (char *)(((t_menuitem
*) v
)->data
));
184 strcat(infoline
, "repair=win ");
186 strcat(infoline
, "repair=lin ");
191 gotoxy(INFLINE
+ 1, 0);
194 csprint("Kernel Arguments:", 0x07);
196 csprint(infoline
, 0x07);
199 t_handler_return
network_handler(t_menusystem
* ms
, t_menuitem
* mi
)
201 // mi=network since this is handler only for that.
204 if (mi
->data
== (void *)none
)
206 if (mi
->data
== (void *)stat
)
208 if (mi
->data
== (void *)dhcp
)
210 return ACTION_INVALID
; // VALID or INVALID does not matter
213 t_handler_return
checkbox_handler(t_menusystem
* ms
, t_menuitem
* mi
)
215 (void)ms
; /* Unused */
219 if (mi
->action
!= OPT_CHECKBOX
)
220 return ACTION_INVALID
;
222 if (strcmp(mi
->data
, "baseurl") == 0)
223 flags
.baseurl
= (mi
->itemdata
.checked
? 1 : 0);
224 if (strcmp(mi
->data
, "winrepair") == 0) {
225 if (mi
->itemdata
.checked
) {
227 linrep
->action
= OPT_INACTIVE
;
230 linrep
->action
= OPT_CHECKBOX
;
233 if (strcmp(mi
->data
, "linrepair") == 0) {
234 if (mi
->itemdata
.checked
) {
236 winrep
->action
= OPT_INACTIVE
;
239 winrep
->action
= OPT_CHECKBOX
;
242 if (strcmp(mi
->data
, "mountcd") == 0)
243 flags
.mountcd
= (mi
->itemdata
.checked
? 1 : 0);
257 // Set default username as guest
258 strcpy(username
, GUEST_USER
);
260 // Switch video mode here
261 // setvideomode(0x18); // or whatever mode you want
263 // Choose the default title and setup default values for all attributes....
264 init_passwords("/isolinux/password");
265 init_help("/isolinux/help");
266 init_menusystem(NULL
);
267 set_window_size(1, 1, 20, 78); // Leave some space around
269 // Choose the default values for all attributes and char's
270 // -1 means choose defaults (Actually the next 4 lines are not needed)
271 //set_normal_attr (-1,-1,-1,-1);
272 //set_status_info (-1,-1); // Display status on the last line
273 //set_title_info (-1,-1);
274 //set_misc_info(-1,-1,-1,-1);
276 // Register the menusystem handler
277 reg_handler(HDLR_SCREEN
, &msys_handler
);
278 reg_handler(HDLR_KEYS
, &keys_handler
);
279 // Register the ontimeout handler, with a time out of 10 seconds
280 reg_ontimeout(ontimeout
, 10, 0);
282 NETMENU
= add_menu(" Init Network ", -1);
283 none
= add_item("<N>one", "Dont start network", OPT_RADIOITEM
, "no ", 0);
284 dhcp
= add_item("<d>hcp", "Use DHCP", OPT_RADIOITEM
, "dhcp ", 0);
286 add_item("<s>tatic", "Use static IP I will specify later",
287 OPT_RADIOITEM
, "static ", 0);
289 TESTING
= add_menu(" Testing ", -1);
291 add_item("<M>emory Test", "Perform extensive memory testing", OPT_RUN
,
293 add_item("<I>nvisible", "You dont see this", OPT_INVISIBLE
, "junk", 0);
294 add_item("<E>xit this menu", "Go one level up", OPT_EXITMENU
, "exit", 0);
296 RESCUE
= add_menu(" Rescue Options ", -1);
297 add_item("<L>inux Rescue", "linresc", OPT_RUN
, "linresc", 0);
298 add_item("<D>os Rescue", "dosresc", OPT_RUN
, "dosresc", 0);
299 add_item("<W>indows Rescue", "winresc", OPT_RUN
, "winresc", 0);
300 add_item("<E>xit this menu", "Go one level up", OPT_EXITMENU
, "exit", 0);
302 PREPMENU
= add_menu(" Prep options ", -1);
304 add_item("<b>aseurl by IP?", "Specify gui baseurl by IP address",
305 OPT_CHECKBOX
, "baseurl", 0);
307 add_item("<m>ountcd?", "Mount the cdrom drive?", OPT_CHECKBOX
,
310 add_item(dhcpnet
, "How to initialise network device?", OPT_RADIOMENU
,
314 add_item("Reinstall <w>indows",
315 "Re-install the windows side of a dual boot setup",
316 OPT_CHECKBOX
, "winrepair", 0);
318 add_item("Reinstall <l>inux",
319 "Re-install the linux side of a dual boot setup", OPT_CHECKBOX
,
323 add_item("<R>un prep now", "Execute prep with the above options",
325 add_item("<E>xit this menu", "Go up one level", OPT_EXITMENU
, "exitmenu",
327 baseurl
->handler
= &checkbox_handler
;
328 mountcd
->handler
= &checkbox_handler
;
329 winrep
->handler
= &checkbox_handler
;
330 linrep
->handler
= &checkbox_handler
;
331 network
->handler
= &network_handler
;
337 SECRETMENU
= add_menu(" Secret Menu ", -1);
338 add_item("secret 1", "Secret", OPT_RUN
, "A", 0);
339 add_item("secret 2", "Secret", OPT_RUN
, "A", 0);
341 LONGMENU
= add_menu(" Long Menu ", 40); // Override default here
342 add_item("<A>a", "Aa", OPT_RUN
, "A", 0);
343 add_item("<B>b", "Ab", OPT_RUN
, "A", 0);
344 add_item("<C>", "A", OPT_RUN
, "A", 0);
345 add_item("<D>", "A", OPT_RUN
, "A", 0);
346 add_item("<E>", "A", OPT_RUN
, "A", 0);
347 add_item("<F>", "A", OPT_RUN
, "A", 0);
348 add_item("<G>", "A", OPT_RUN
, "A", 0);
349 add_item("<H>", "A", OPT_RUN
, "A", 0);
350 add_item("<I>", "A", OPT_RUN
, "A", 0);
351 add_item("<J>", "A", OPT_RUN
, "A", 0);
352 add_item("<K>", "A", OPT_RUN
, "A", 0);
353 add_item("<L>", "A", OPT_RUN
, "A", 0);
354 add_item("<J>", "A", OPT_RUN
, "A", 0);
355 add_item("<K>", "A", OPT_RUN
, "A", 0);
356 add_item("<L>", "A", OPT_RUN
, "A", 0);
357 add_item("<M>", "A", OPT_RUN
, "A", 0);
358 add_item("<N>", "A", OPT_RUN
, "A", 0);
359 add_item("<O>", "A", OPT_RUN
, "A", 0);
360 add_item("<P>", "A", OPT_RUN
, "A", 0);
361 add_item("<Q>", "A", OPT_RUN
, "A", 0);
362 add_item("<R>", "A", OPT_RUN
, "A", 0);
363 add_item("<S>", "A", OPT_RUN
, "A", 0);
364 add_item("<T>", "A", OPT_RUN
, "A", 0);
365 add_item("<U>", "A", OPT_RUN
, "A", 0);
366 add_item("<V>", "A", OPT_RUN
, "A", 0);
367 add_item("<W>", "A", OPT_RUN
, "A", 0);
368 add_item("<X>", "A", OPT_RUN
, "A", 0);
369 add_item("<Y>", "A", OPT_RUN
, "A", 0);
370 add_item("<Z>", "A", OPT_RUN
, "A", 0);
371 add_item("<1>", "A", OPT_RUN
, "A", 0);
372 add_item("<2>", "A", OPT_RUN
, "A", 0);
373 add_item("<3>", "A", OPT_RUN
, "A", 0);
374 add_item("<4>", "A", OPT_RUN
, "A", 0);
375 add_item("<5>", "A", OPT_RUN
, "A", 0);
376 add_item("<6>", "A", OPT_RUN
, "A", 0);
377 add_item("<7>", "A", OPT_RUN
, "A", 0);
378 add_item("<8>", "A", OPT_RUN
, "A", 0);
379 add_item("<9>", "A", OPT_RUN
, "A", 0);
381 MAIN
= add_menu(" Main Menu ", 8);
382 curr
= add_item(loginstr
, "Login as a privileged user", OPT_RUN
, NULL
, 0);
383 set_item_options(-1, 23);
384 curr
->handler
= &login_handler
;
386 add_item("<P>repare", "prep", OPT_RUN
, "prep", 0);
387 set_item_options(-1, 24);
389 add_item("<P>rep options...",
390 "Options for prep image: Requires authenticated user",
391 OPT_INACTIVE
, NULL
, PREPMENU
);
392 set_item_options(-1, 25);
394 add_item("<R>escue options...", "Troubleshoot a system", OPT_SUBMENU
, NULL
,
396 set_item_options(-1, 26);
397 add_item("<T>esting...", "Options to test hardware", OPT_SUBMENU
, NULL
,
399 set_item_options(-1, 27);
400 add_item("<L>ong Menu...", "test menu system", OPT_SUBMENU
, NULL
, LONGMENU
);
401 set_item_options(-1, 28);
403 add_item("<S>ecret Menu...", "Secret menu", OPT_INVISIBLE
, NULL
,
405 set_item_options(-1, 29);
406 add_item("<E>xit to prompt", "Exit the menu system", OPT_EXITMENU
, "exit",
408 set_item_options(-1, 30);
409 csprint("Press any key within 5 seconds to show menu...", 0x07);
410 if (get_key(stdin
, 50) == KEY_NONE
) // Granularity of 100 milliseconds
412 csprint("Sorry! Time's up.\r\n", 0x07);
415 curr
= showmenus(MAIN
);
417 if (curr
->action
== OPT_RUN
) {
418 strcpy(cmd
, curr
->data
);
419 if (curr
== runprep
) {
420 strcat(cmd
, infoline
);
421 if (network
->data
== (void *)stat
) // We want static
423 csprint("Enter IP address (last two octets only): ", 0x07);
425 editstring(ip
, sizeof ip
);
426 strcat(cmd
, "ipaddr=192.168.");
434 return 1; // Should not happen when run from SYSLINUX
437 // If user quits the menu system, control comes here
438 // If you want to execute some specific command uncomment the next two lines
440 // if (syslinux) runcommand(YOUR_COMMAND_HERE);
441 // else csprint(YOUR_COMMAND_HERE,0x07);
443 // Deallocate space used for these data structures