#pragma implementation #include #include #include #include #include "xterminals.h" #include "xterminals.m" #include #include #include #include #include #include static HELP_FILE help_xterminals ("xterminals","xterminals"); static HELP_FILE help_confmode ("xterminals","confmode"); static HELP_FILE help_dupconfig ("xterminals","dupconfig"); static CONFIG_FILE f_confmode ("/xterminals/root/configuring" ,help_xterminals,CONFIGF_OPTIONAL|CONFIGF_MANAGED); MODULE_DEFINE_VERSION(xterminals); static const char *keymenu=NULL; static void xterminals_confmode() { char mode = f_confmode.exist() ? 1 : 0; { struct stat st; if (stat(f_confmode.getpath(),&st)!=-1 && st.st_size > 0){ // The file is not empty mode = 2; } } DIALOG dia; dia.settype (DIATYPE_POPUP); dia.newf_radio (MSG_U(F_CONFMODE,"Configuration mode"),mode,0 ,MSG_U(I_LOCKED,"Terminals configuration are frozen")); dia.newf_radio ("",mode,1 ,MSG_U(I_MAYCONFIG,"Configuration / Manual start")); dia.newf_radio ("",mode,2 ,MSG_U(I_CONFIGAUTOSTART,"Configuration / Auto start")); int nof = 0; while (1){ MENU_STATUS code = dia.edit (MSG_U(T_CONFMODE,"Configuration mode") ,MSG_U(I_CONFMODE ,"You control how the terminals boot.\n" "They can do one of:\n" "\tBoot in graphic mode without operator intervention\n" "\tPopup a menu and wait for instructions\n" "\tPopup a menu, go in graphic mode after a short delay") ,help_confmode ,nof); if (code == MENU_ESCAPE || code == MENU_CANCEL){ break; }else{ master_registry.start_session(); const char *s = master_registry.get ("nfs.readwrite./var/xterminals"); bool var_rw = s != NULL && s[0] == '1'; if (mode == 0){ f_confmode.unlink(); // Make sure NFS is read-only for /var/xterminals if (var_rw){ master_registry.set ("nfs.readwrite./var/xterminals","0"); xconf_notice (MSG_U(N_VARTERMINALRO ,"The NFS server has been reconfigured:\n" "/var/xterminals is now in read-only mode")); } }else{ if (!var_rw){ master_registry.set ("nfs.readwrite./var/xterminals","1"); xconf_notice (MSG_U(N_VARTERMINALRW ,"The NFS server has been reconfigured:\n" "/var/xterminals is now in read-write mode\n" "\n" "Make sure the NFS server is restarted\n")); } FILE_CFG *fout = f_confmode.fopen ("w"); if (fout != NULL){ if (mode == 2) fputs ("10\n",fout); fclose (fout); } } master_registry.end_session(); break; } } } #if 0 static int xterminals_copydirs ( const char *src, const char *dst) { const char *dst; glocal.dst = dst; int ret = file_mkdir (dst,"root","root",0755); if (ret != -1){ (src); struct stat st; if (lstat(path,&st)!=-1){ char dst[PATH_MAX]; snprintf (dst,sizeof(dst)-1,"%s/%s",glocal.dst,relpath); if (S_ISREG(st.st_mode)){ file_copy (path,dst); }else if (S_ISDIR(st.st_mode)){ mkdir (dst,st.st_mode); }else if (S_ISLNK(st.st_mode)){ }else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)){ mknod (dst,st.st_mode,st.st_dev); } chmod (dst,st.st_mode); chown (dst,st.st_uid,st.st_gid); } } return ret; } static int xterminals_dupgo ( const char *refpath, const char *basedir, const char *startip, const char *lastip) { int ret = -1; IP_ADDR from,to; from.setfrom (startip); to.setfrom (lastip); if (from.cmp(&to)> 0){ xconf_error (MSG_U(E_RANGE,"The last IP number %s is lower than %s") ,startip,lastip); }else{ ret = 0; do { char path[PATH_MAX]; snprintf (path,sizeof(path)-1,"%s/%s",basedir,from.get()); if (xterminals_copydirs (refpath,path) == -1){ ret = -1; break; } from.increm(); } while (from.cmp(&to)<=0); } return ret; } static void xterminals_dupconfig() { SSTRING ref; SSTRING startip; SSTRING lastip; const char *basedir; bool found; glocal.basedir = configf_lookuppath("/var/xterminals"); DIALOG dia; dia.newf_str (MSG_U(F_REFTERM,"Reference terminal"),glocal.ref); dia.last_noempty(); dia.newf_str (MSG_U(F_STARTIP0,"First IP number"),glocal.startip); dia.last_noempty(); dia.newf_str (MSG_U(F_ENDIP0,"Last IP number"),glocal.lastip); dia.last_noempty(); int nof = 0; while (1){ MENU_STATUS code = dia.edit (MSG_U(T_DUPCONFIG ,"Duplicate configurations") ,MSG_U(I_DUPCONFIG,"You can duplicate the configuration\n" "of one working X terminals for a complete range\n" "of IP number") ,help_dupconfig ,nof); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else if (ipnum_validip(glocal.startip.get(),true)){ xconf_error (MSG_U(E_IVLDIP,"Invalid IP number: %s") ,glocal.startip.get()); nof = 1; }else if (ipnum_validip(glocal.lastip.get(),true)){ xconf_error (MSG_R(E_IVLDIP),glocal.lastip.get()); nof = 2; }else{ glocal.found = false; (glocal.basedir); if (file_type (path)==1){ if (glocal.ref.cmp(basename)==0){ // Ok, this is the directory we want glocal.found = true; }else{ // Maybe this is the name of the terminal SSTRING name; name.setfromf ("%s/sysconfig/TERMNAME",path); FILE *fin = fopen (name.get(),"r"); if (fin != NULL){ char s[1000]; if (fscanf(fin,"%s",s)==1 && glocal.ref.cmp(s)==0){ glocal.found = true; } } } if (glocal.found){ if (xterminals_dupgo (path,glocal.basedir ,glocal.startip.get() ,glocal.lastip.get()) != -1){ // Ok, some error, we continue in this // dialog by faking we have not found // the ref name. glocal.found = false; } end(); } } return false; if (glocal.found) break; } } } #endif static void xterminals_edit() { static const char *menuopt[]={ MSG_U(M_INSTALL,"Install"),MSG_U(M_XTERMENV,"the xterminals runtime"), MSG_U(M_REVIEW,"Review"), MSG_U(M_CONFIG,"server configuration"), MSG_R(M_REVIEW), MSG_U(M_USERDEF,"user account defaults"), MSG_U(M_CONTROL,"Control"), MSG_U(M_CONFMODE,"configuration mode (locked)"), MSG_U(M_MAKE,"Make"),MSG_U(M_BOOTFLOPPY,"A boot floppy"), MSG_U(M_CONFIGURE,"Configure"),MSG_U(M_XTERMDEF,"the default X terminals"), MSG_R(M_CONFIGURE),MSG_U(M_XTERMINALS,"X terminals"), MSG_U(M_EXPORT,"Export"),MSG_U(M_TERMCONF,"terminal configurations"), MSG_U(M_IMPORT,"Import"),MSG_R(M_TERMCONF), MSG_U(M_DELETE,"Delete"),MSG_R(M_TERMCONF), // MSG_U(M_DUPLICATE,"Duplicate"),MSG_R(M_TERMCONF), NULL,NULL }; (MSG_R(M_xterminals) ,MSG_U(I_xterminals ,"You control from here the configuration and operation\n" "of the linux based X terminals") ,help_xterminals ,menuopt); if (perm_rootaccess (MSG_U(P_xterminals,"configure X terminals"))){ if (no == 0){ xterminals_install(); }else if (no == 1){ xterminals_review(); }else if (no == 2){ users_review(); }else if (no == 3){ xterminals_confmode(); }else if (no == 4){ xterminals_makeboot (); }else if (no == 5){ xtermadmin_setdefault (); }else if (no == 6){ xtermadmin (); }else if (no == 7){ xtermadmin_export (); }else if (no == 8){ xtermadmin_import (); }else if (no == 9){ xtermadmin_clean (); } } } ("xterminals",PACKAGE_REV); tb.add (new SSTRING(MSG_U(T_USAGE ,"linuxconf --modulemain xterminals usage\n" "\n" " --floppy\n" " --import\n" " --review\n" " --default\n" ))); if (context == MENU_MISCSERV){ keymenu = MSG_U(M_xterminals,"Linux based X terminals"); dia.new_menuitem ("xterminals","",keymenu); } if (context == MENU_MISCSERV){ if (key == keymenu){ CONTEXT_LOCK lk ("xterminals"); if (lk.isok()) xterminals_edit(); } } return 0; int ret = LNCF_NOT_APPLICABLE; #if 0 // ### Check the variable key to provide your own html hook ret = 0; #endif return ret; int ret = -1; if (argc == 1){ xterminals_edit(); }else if (argc == 2){ if (perm_rootaccess (MSG_R(P_xterminals))){ CONTEXT_LOCK lk ("xterminals"); if (lk.isok()){ if (strcmp(argv[1],"--review")==0){ xterminals_review(); users_review(); }else if (strcmp(argv[1],"--floppy")==0){ xterminals_makeboot (); }else if (strcmp(argv[1],"--import")==0){ xtermadmin_import (); }else if (strcmp(argv[1],"--default")==0){ xtermadmin_setdefault(); }else if (strcmp(argv[1],"--help")==0){ printusage(); } ret = 0; } } }else{ printusage(); } return ret;