#include #include #include #include <../../libmodules/guruengine/guruengine.h> #include "xterminals.h" #include "xterminals.m" #include static const char K_NBTERM[]="nbterm"; static HELP_FILE help_proxy ("xterminals","proxys"); static HELP_FILE help_user ("xterminals","user"); static HELP_FILE help_virtualfs ("xterminals","virtualfs"); static CONFIG_FILE f_proxy_sh ("/etc/profile.d/http_proxy.sh",help_proxy ,CONFIGF_GENERATED|CONFIGF_OPTIONAL ,"root","root",0755); static CONFIG_FILE f_xsession ("/etc/X11/xdm/Xsession",help_virtualfs ,CONFIGF_GENERATED ,"root","root",0755); static CONFIG_FILE f_x11session ("/etc/X11/Xsession",help_virtualfs ,CONFIGF_GENERATED ,"root","root",0755); /* Read the file /etc/profile.d/http_proxy.sh and extract the servers and ports */ static void user_pickinfo( char *line, const char *keyword, SSTRING &server, SSTRING &port) { char *pt = strstr(line,keyword); if (pt != NULL){ pt += strlen(keyword); pt = strstr (pt,"//"); if (pt != NULL){ pt += 2; char *ptpt = strchr (pt,':'); if (ptpt != NULL){ *ptpt++ = '\0'; server.setfrom (pt); port.setfrom (ptpt); } } } } static void user_proxy( GURUPATH_MODE mode, GURUPATH_STATUS &status) { (mode,status); settitle (MSG_U(T_PROXYS,"HTTP and FTP proxys")); setterminal (MSG_R(T_PROXYS),""); status.is_possible = true; status.is_filled = f_proxy_sh.exist(); setintro (MSG_U(I_HTTPPROXY ,"We can set the HTTP proxy globally for every users.\n" "This is optional.\n" "Just fill the name or IP number of the proxy\n" "and the TCP port it is listening on.")); SSTRING httpserver,httpport,ftpserver,ftpport; { FILE_CFG *fin = f_proxy_sh.fopen ("r"); if (fin != NULL){ char buf[1000]; while (fgets_strip(buf,sizeof(buf)-1,fin,NULL)!=NULL){ user_pickinfo (buf,"http_proxy",httpserver,httpport); user_pickinfo (buf,"ftp_proxy",httpserver,httpport); } fclose (fin); } } dia.newf_info ("",MSG_U(F_SERVER,"Proxy server")); dia.newf_info (NULL,MSG_U(F_PORT,"TCP port")); dia.newline(); dia.newf_str (MSG_U(F_HTTPPROXYSERV,"HTTP"),httpserver); dia.newf_str (NULL,httpport,10); dia.newline(); dia.newf_str (MSG_U(F_FTPPROXYSERV,"FTP"),ftpserver); dia.newf_str (NULL,ftpport,10); dia.newline(); while (edit(help_proxy)){ if (httpserver.is_filled() && httpport.is_empty()){ xconf_error (MSG_U(E_NOPORT,"The TCP port is not optional")); setcursor (1); }else if (ftpserver.is_filled() && ftpport.is_empty()){ xconf_error (MSG_R(E_NOPORT)); setcursor (3); }else{ if (httpserver.is_filled() || ftpserver.is_filled()){ FILE_CFG *fout = f_proxy_sh.fopen ("w"); if (fout != NULL){ fprintf (fout,"#!/bin/sh\n"); if (httpserver.is_filled()) fprintf (fout,"export http_proxy=http://%s:%s\n",httpserver.get(),httpport.get()); if (ftpserver.is_filled()) fprintf (fout,"export ftp_proxy=http://%s:%s\n",ftpserver.get(),ftpport.get()); fclose (fout); } }else{ f_proxy_sh.unlink(); } break; } } } static int users_getnbterm(int defval) { return linuxconf_getvalnum (K_XTERMREVIEW,K_NBTERM,defval); } static int users_getreg (const char *key, const char *file) { int ret = 0; const char *s = master_registry.get (key); if (s != NULL) ret = atoi(s); if (ret == 0){ // This is not configured, so we check in the kernel FILE *fin = fopen (file,"r"); if (fin != NULL){ fscanf (fin,"%d\n",&ret); fclose (fin); } } return ret; } static void users_setreg (const char *key, int val) { char s[20]; sprintf (s,"%d",val); master_registry.set (key,s); } static bool users_kernelok(bool test) { bool ret = true; master_registry.start_session(); int nbterm = users_getnbterm(25); /* #Specification: kernel / suggested parameters We guess 400 files and 1600 inodes per terminals. */ int maxfile = users_getreg ("kernel.maxfile","/proc/sys/fs/file-max"); int maxfile_sug = nbterm * 400; int maxinode = users_getreg ("kernel.maxinode","/proc/sys/fs/inode-max"); int maxinode_sug = nbterm * 1600; if (maxfile_sug > maxfile){ ret = false; if (!test) users_setreg ("kernel.maxfile",maxfile_sug); } if (maxinode_sug > maxinode){ ret = false; if (!test) users_setreg ("kernel.maxinode",maxinode_sug); } master_registry.end_session(); return ret; } static void user_kernel ( GURUPATH_MODE mode, GURUPATH_STATUS &status) { (mode,status); status.some_errors = !users_kernelok(true); status.is_filled = true; settitle (MSG_U(T_KERNELTUNING,"Kernel tuning")); setterminal (MSG_R(T_KERNELTUNING),""); if (users_kernelok(true)){ allfine(); setintro (MSG_U(I_KERNELOK ,"The kernel parameters are properly configured")); edit(); }else{ attention(); setintro (MSG_U(I_KERNELNOTOK ,"The kernel parameters are not properly configured\n" "We will need to increase the number of open files\n" "and inodes descriptors")); if (edit()){ users_kernelok(false); } } } static bool user_checkvirtualfs (bool test, CONFIG_FILE &fcfg) { bool ret = false; FILE_CFG *fin = fcfg.fopen ("r"); if (fin != NULL){ char buf[1000]; while (fgets(buf,sizeof(buf),fin)!=NULL){ if (strstr(buf,"virtualfs")!=NULL){ ret = true; break; } } fclose (fin); if (!ret && !test){ char path[PATH_MAX]; snprintf (path,sizeof(path)-1,"%s.original",fcfg.getpath()); if (rename (fcfg.getpath(),path)!=-1){ FILE_CFG *fout = fcfg.fopen ("w"); if (fout != NULL){ fputs ("#!/bin/sh\n",fout); fprintf (fout,"exec virtualfs --session %s $*\n",path); fclose (fout); } } } } return ret; } /* Check if virtualfs is installed in either /etc/X11/Xsession or /etc/X11/xdm/Xsession */ static bool user_checkvirtualfs (bool test) { bool ret = false; if (f_x11session.exist()){ ret = user_checkvirtualfs (test,f_x11session); }else{ ret = user_checkvirtualfs (test,f_xsession); } return ret; } static void user_misc ( GURUPATH_MODE mode, GURUPATH_STATUS &status) { (mode,status); status.is_filled = user_checkvirtualfs(true); settitle (MSG_U(T_VIRTUALFS,"Virtualfs installation")); setterminal (MSG_U(T_MISC,"Miscellanenous services"),""); if (user_checkvirtualfs (true)){ allfine(); setintro (MSG_U(I_VIRTUALFSOK ,"Virtualfs is currently enabled for all user by default")); edit(help_virtualfs); }else{ attention(); setintro (MSG_U(I_VIRTUALFSNOTOK ,"Virtualfs is not active by default when the user log in\n" "It has to be installed in the X startup script\n" "\t/etc/X11/xdm/Xsession\n" "\n" "The original file will be renamed to /etc/X11/xdm/Xsesion.original\n" "and a small wrapper will be written")); char enable = 0; dia.newf_chk (MSG_U(F_VIRTUALFS,"Virtualfs"),enable ,MSG_U(I_VIRTUALFS,"must be enabled by default")); if (edit(help_virtualfs) && enable == 1){ user_checkvirtualfs(false); } } } void users_review() { (MSG_U(T_USERSERVICES,"User services") ,MSG_U(I_USERSERVICES ,"You will be presented with a set of dialog to ease\n" "user account default configuration.\n" "You will walk through the following configuration:\n" "\n" "\tProxys: default http and ftp proxys") ,help_user); (mode,status); status.is_filled = users_getnbterm(-1) != -1; settitle (MSG_U(T_HOWMANYTERM,"How many terminals connected")); setintro (MSG_U(I_HOWMANYTERM ,"To properly configure the server\n" "we must know how many terminals will\n" "connected at once")) ; int nbterm = users_getnbterm(25); dia.newf_num (MSG_U(F_HOWMANYTERM,"Terminals"),nbterm); if (edit()){ linuxconf_replace (K_XTERMREVIEW,K_NBTERM,nbterm); linuxconf_save(); } user_proxy(mode,status); user_kernel (mode,status); user_misc (mode,status); }