#include "xterminals.h" #include "xterminals.m" #include <../../libmodules/guruengine/guruengine.h> static HELP_FILE help_floppy ("xterminals","floppy"); static HELP_FILE help_kernel ("xterminals","kernel"); /* Check if an IP is valid */ static bool floppy_validip (const SSTRING &ip, int &nof, int field) { bool ret = true; const char *s = ip.get(); if (s[0] != '\0'){ if (!ipnum_validip(s,true)){ xconf_error (MSG_U(E_IVLDIPNUM,"Invalid IP number: %s"),s); nof = field; ret = false; } } return ret; } /* Check if a netmask is valid */ static bool floppy_validmask (const SSTRING &mask, int &nof, int field) { bool ret = true; const char *s = mask.get(); if (s[0] != '\0'){ if (!ipnum_validmask(s)){ xconf_error (MSG_U(E_IVLDMASK,"Invalid network mask: %s"),s); nof = field; ret = false; } } return ret; } /* Check that an IP number fits on a network */ static bool floppy_fitsonlocal ( const SSTRING &ip, const SSTRING &mask, const SSTRING &target) { bool ret = true; if (ip.is_filled()){ unsigned long b_ip = ipnum_aip2l (ip.get()); const char *pt = mask.get(); if (pt != NULL) pt = ipnum_getdefaultmask (ip.get()); unsigned b_mask = ipnum_aip2l (pt); unsigned long b_target = ipnum_aip2l (target.get()); ret = (b_ip & b_mask) == (b_target & b_mask); } return ret; } /* Check if a gateway fits on the local network */ static bool floppy_validgtw ( const SSTRING &ip, const SSTRING &mask, const SSTRING >w, int &nof, int field) { bool ret = true; const char *s = gtw.get(); if (s[0] != '\0'){ if (!ipnum_validip(s,true)){ xconf_error (MSG_U(E_IVLDGTW,"Invalid IP for the default gateway: %s"),s); nof = field; ret = false; }else{ // Now we check the gateway is on the same network if (!floppy_fitsonlocal(ip,mask,gtw)){ xconf_error (MSG_U(E_GTWMISMATCH ,"The gateway %s is not reachable from\n" "the station %s\n" "\n" "Use a different netmask\n" "or select a different gateway") ,gtw.get(),ip.get()); nof = field; ret = false; } } } return ret; } void xterminals_makeboot() { SSTRING termip,netmask,gateway; SSTRING nfsip; char kernel; char type; glocal.kernel = 255; glocal.type = 255; (MSG_U(T_MAKEBOOT,"Create a boot floppy") ,MSG_U(I_MAKEBOOT ,"We will create a boot floppy. This floppy will be used\n" "to start the X terminals. Once configured, a terminal\n" "can boot from its hard drive if available.\n" "\n" "The floppy will be either in DOS or Linux format.\n" "After entering several (optional) parameters\n" "you will be asked to insert a floppy") ,help_floppy); (mode,status); settitle (MSG_U(T_KERNELSELECTION,"Kernel selection")); status.is_filled = glocal.kernel!=255; setintro (MSG_U(I_KERNELSELECTION ,"For low end machine, use the small kernel (2.0)\n" " (386s/4 megs ram for example)\n" "The large kernel has more ethernet drivers\n" "The modular kernel has even more features and drivers")); char kernel = glocal.kernel == 255 ? 2 : glocal.kernel; dia.newf_radio (MSG_U(F_USE,"Use"),kernel,0 ,MSG_U(I_KERNEL_2_0,"Kernel 2.0")); dia.newline(); dia.newf_radio (MSG_R(F_USE),kernel,1 ,MSG_U(I_KERNEL_2_2,"kernel 2.2 (large)")); dia.newline(); dia.newf_radio (MSG_R(F_USE),kernel,2 ,MSG_U(I_KERNEL_2_4,"kernel 2.4 (modular)")); dia.newline(); if (edit (help_kernel)) glocal.kernel = kernel; settitle (MSG_U(T_PARAMETERS,"Boot parameters")); setintro (MSG_U(I_PARAMETERS ,"In general, the IP number of the terminal is allocated from\n" "a DHCP server. The DHCP server is also the default\n" "NFS server. Do not enter any IP number unless you have\n" "a non standard setup.\n")); int termip_nof = dia.getnb(); dia.newf_str (MSG_U(F_TERMIP,"IP number of the terminal") ,glocal.termip); dia.newline(); int netmask_nof = dia.getnb(); dia.newf_str (MSG_U(F_NETMASK,"Netmask of the terminal") ,glocal.netmask); dia.newline(); int gateway_nof = dia.getnb(); dia.newf_str (MSG_U(F_GATEWAY,"Default gateway") ,glocal.gateway); dia.newline(); int nfsip_nof = dia.getnb(); dia.newf_str (MSG_U(F_NFSIP,"IP number of the NFS server") ,glocal.nfsip); while (1){ if (!edit (help_floppy)){ break; }else{ int nof = 0; if (glocal.termip.is_empty() && (glocal.netmask.is_filled() || glocal.gateway.is_filled())){ xconf_error (MSG_U(E_MISSINGIP ,"You can't provide a netmask or gateway\n" "unless you provide the IP number of the terminal")); nof = termip_nof; }else if (floppy_validip(glocal.termip,nof,termip_nof) && floppy_validmask(glocal.netmask,nof,netmask_nof) && floppy_validgtw (glocal.termip,glocal.netmask ,glocal.gateway,nof,gateway_nof) && floppy_validip (glocal.nfsip,nof,nfsip_nof)){ // Ok, we have done various tests. // The IPs are valid (or not specified) // Now, either the nfsip fits on the local network // or the gateway has been supplied if (glocal.gateway.is_empty()){ if (floppy_fitsonlocal(glocal.termip,glocal.netmask ,glocal.nfsip)){ break; }else{ xconf_error (MSG_U(E_REACHNFS ,"The NFS server %s is not reachable\n" "from the IP %s\n" "\n" "The netmask is may invalid\n" "or specify a gateway") ,glocal.nfsip.get(),glocal.termip.get()); nof = nfsip_nof; } }else{ break; } } setcursor (nof); } } settitle (MSG_U(T_FLOPPYTYPE,"Floppy type")); status.is_filled = glocal.type != 255; setintro (MSG_U(I_FLOPPYTYPE ,"You can produce a Linux boot floppy or a DOS one.\n" "The Linux boot floppy only requires a blank floppy.\n" "The DOS floppy required a DOS formatted one with the\n" "operating system installed (format a: /s)")); char type = glocal.type == 255 ? 0 : glocal.type; dia.newf_radio ("",type,0,MSG_U(I_LINUXFLOPPY,"Linux floppy")); dia.newline(); dia.newf_radio ("",type,1,MSG_U(I_DOSFLOPPY,"DOS floppy")); if (edit (help_floppy)) glocal.type = type; settitle (MSG_U(T_PUTFLOPPY,"Insert floppy")); char lowlevel=0,dosformat=0; if (glocal.type == 0){ setintro (MSG_U(I_PUTBLANKLINUX ,"Insert a floppy and hit next.\n" "The content will be overwritten with a Linux\n" "bootable filesystem.")); }else{ setintro (MSG_U(I_PUTDOSFLOPPY ,"Insert a DOS formatted floppy.\n" "3 files will be copied on it:\n" "\tautoexec.bat\n" "\tloadlin.exe\n" "\tzimage\n" "\n" "You may copy those file onto a DOS hard drive\n" "to boot the terminal from a DOS C:\\")); dia.newf_chk (MSG_R(F_PERFORM),dosformat ,MSG_U(I_DOSFORMAT,"a DOS level format")); } dia.newline(); dia.newf_chk (MSG_U(F_PERFORM,"Perform"),lowlevel ,MSG_U(I_LOWLEVEL,"low level format of the floppy")); dia.newline(); if (edit()){ int ret = 0; if (lowlevel){ ret = netconf_system_if ("xterminals-fdformat","/dev/fd0H1440",200); dosformat = 1; } if (ret == 0){ if (glocal.type == 0){ SSTRING args; args.setfrom ("--noprompt"); args.appendf (" --kernel kernels/kernel-2.%d" ,glocal.kernel*2); if (glocal.termip.is_filled()){ args.appendf (" --termip %s",glocal.termip.get()); } if (glocal.nfsip.is_filled()){ args.appendf (" --nfsip %s",glocal.nfsip.get()); } if (glocal.netmask.is_filled()){ args.appendf (" --netmask %s",glocal.nfsip.get()); } if (glocal.gateway.is_filled()){ args.appendf (" --gateway %s",glocal.nfsip.get()); } ret |= netconf_system_if ("xterminals-makeboot.sh",args.get(),120); }else{ if (dosformat) ret |= netconf_system_if ("xterminals-mkdosfs","/dev/fd0",60); ret |= netconf_system_if ("xterminals-makeboot-dos.sh","--noprompt",60); } } if (ret == 0){ xconf_notice (MSG_U(N_DONE,"Floppy done")); }else{ xconf_error (MSG_U(E_NOTDONE,"Floppy not written properly")); } } }