#pragma implementation #include #include #include #include #include "inetdconf.h" #include "inetdconf.m" #include #include static void inetdconf_menu( void ); static const char *keymenu=NULL; static HELP_FILE help_inetdconf ("inetdconf","inetdconf"); MODULE_DEFINE_VERSION(inetdconf); PUBLIC MODULE_inetdconf::MODULE_inetdconf() : LINUXCONF_MODULE("inetdconf") { linuxconf_loadmsg ("inetdconf",PACKAGE_REV); module_register_api (SERVICECTL_API_KEY,SERVICECTL_API_REV ,inetdconf_servicectl_api_get, inetdconf_servicectl_api_release); module_register_api (INETDCONF_API_KEY,INETDCONF_API_REV ,inetdconf_api_get, inetdconf_api_release); } PUBLIC void MODULE_inetdconf::setmenu ( DIALOG &dia, MENU_CONTEXT context) { if (context == MENU_NETWORK_SERVER){ //fprintf(stderr,"setmenu\n"); keymenu = MSG_U(M_INETDCONFS,"Internet services"); // dia.new_menuitem ("inetdconf","",keymenu); dia.new_menuitem ("","",keymenu); } } PUBLIC int MODULE_inetdconf::domenu ( MENU_CONTEXT context, const char *key) { if (context == MENU_NETWORK_SERVER){ //fprintf(stderr,"domenu: key=%s\n", key); if (key == keymenu){ inetdconf_menu(); } } return 0; } PUBLIC int MODULE_inetdconf::dohtml (const char *key) { int ret = LNCF_NOT_APPLICABLE; if (strcmp(key,"inetdconf")==0){ // ### Insert any menu and dialog here ret = 0; } return ret; } PUBLIC int MODULE_inetdconf::message ( const char *msg, int argc, const char *argv[]) { int ret = LNCF_NOT_APPLICABLE; if (strcmp(msg,"about")==0){ ret = 0; SSTRINGS *tb = (SSTRINGS*)argv[0]; tb->add (new SSTRING(MSG_U(A_ABOUT1,"Module inetdconf was written by Torbjörn Gard (tgard@netg.se)"))); } return ret; } static void usage() { xconf_error (MSG_U(T_USAGE, "Module inetdconf\n" "linuxconf --modulemain inetdconf [ specific options ]\n" "\n" " --enable service [service ...]\n" " --disable service [service ...]\n" " --server-path --check\n" " --server-path --check-update\n" " --firewall --enable\n" " --firewall --disable\n" "\n" ) ); } PUBLIC void MODULE_inetdconf::usage (SSTRINGS &tb) { tb.add (new SSTRING (MSG_R(T_USAGE))); } PUBLIC int MODULE_inetdconf::execmain (int argc , char *argv[], bool) { int ret = LNCF_NOT_APPLICABLE; const char *pt = strrchr(argv[0],'/'); if (pt != NULL){ pt++; }else{ pt = argv[0]; } if (strcmp(pt,"inetdconf")==0){ ret = -1; if (argc == 1) { inetdconf_menu( ); } else { if ( argc > 2 ) { if ( strcmp( argv[1],"--enable" ) == 0 ) { argc -= 2; argv++; argv++; inetdconf_enable_service( argc, argv,1 ); } else if ( strcmp( argv[1],"--disable" ) == 0 ) { argc -= 2; argv++; argv++; inetdconf_enable_service( argc, argv,0 ); } else if ( strcmp( argv[1],"--server-path" ) == 0 ) { argc -= 2; argv++; argv++; if ( strcmp( argv[0], "--check-update" ) == 0 ) { inetdconf_server_path( 1 ); } else if ( strcmp( argv[0], "--check" ) == 0 ) { inetdconf_server_path( 0 ); } else { ::usage(); } } else if ( strcmp( argv[1],"--firewall" ) == 0 ) { if ( strcmp( argv[2],"--enable") == 0) { argc -= 3; argv++; argv++;argv++; firewall_enable( argc, argv ); } else if ( strcmp( argv[2],"--disable") == 0) { firewall_disable( ); } else { ::usage(); } } else { ::usage(); } } else { ::usage(); } } } return ret; } PUBLIC int MODULE_inetdconf::probe ( int level, // Current level being probed // Only service of this level should do something. int target, // target network runlevel of the probe // In which runlevel the machine is going to be // after the probe has completed bool simulation ) // simulation mode ? { //fprintf(stderr,"MODULE_inetdconf::probe level=%d target=%d %s\n", level, target, simulation?"simulation":"no simulation"); if (level == 2 && target == 2) { /* * Normal check of boot time daemon or after configuration * change. */ return( inetdconf_probe( level, target, simulation ) ); } return 0; } static MODULE_inetdconf inetdconf; static void inetdconf_menu( void ) { static const char *m_etcservice = MSG_U(M_ETCSERVICE,"Internet network services"); static const char *m_inetdconf = MSG_U(M_INETDCONFS_INETD,"Internet servers database"); static const char *m_firewall = MSG_U(M_FIREWALL,"Internet firewall and masquerade"); static const char *m_hostsallow = MSG_U(M_HOSTSALLOW,"Allowed server access"); static const char *m_hostsdeny = MSG_U(M_HOSTSDENY,"Denied server access"); static const char *menuopt[] = { "", m_etcservice, "", m_inetdconf, "", m_firewall, "", m_hostsallow, "", m_hostsdeny, NULL, }; DIALOG_MENU dia; dia.new_menuitems (menuopt); int choice=0; while( 1 ) { MENU_STATUS code = dia.editmenu (MSG_U(M_INETDCONFS_MENU, "Basic services") ,MSG_U(I_INETD, "This menu allows you to configure basic system services\n" "based on the internet super server inetd and do a\n" "simple firewall against the internet with internal\n" "masquerading of the local network.\n" "\n" "For servers which are started by inetd/tcpd it is also\n" "possible to allow or deny servers on a system basis." ) ,help_inetdconf ,choice,0); if ( code == MENU_QUIT || code == MENU_ESCAPE ) { break; } else { const char *key = menuopt[choice*2+1]; //fprintf(stderr,"inetdconf_menu key=%s code=%d choice=%d\n", key, code, choice); if (key == m_etcservice) { etcservice_edit( ); } else if (key == m_inetdconf) { inetdconf_edit( ); } else if (key == m_firewall) { firewall_edit( ); } else if (key == m_hostsallow) { hostsallow_edit( ); } else if (key == m_hostsdeny) { hostsdeny_edit( ); } } } } int inetdconf_probe( int level, int target, int simulation ) { //fprintf(stderr,"inetdconf.cc: inetdconf_probe() %s\n", simulation?"(simulation)":""); return( firewall_probe( level, target, simulation ) ); }