#include /* memset */ #include "internal.h" #include "apache.m" #include "keyword.h" static APACHE_HELP_FILE help_apache ("apache"); static APACHE_HELP_FILE help_mod ("modules"); static APACHE_HELP_FILE help_perf ("performance"); static APACHE_HELP_FILE help_users ("users"); extern CONFIG_FILE httpd_conf; /* FIXME: Do the mapping like vhosts */ int HTTPD_USERS::cwrite() { int ret = -1; CONFIG_FILE conf (file.get(),help_nil,CONFIGF_OPTIONAL|CONFIGF_MANAGED); FILE_CFG *fp = conf.fopen("w"); if(fp != NULL) { int n = getnb(); for(int i=0;iuser.is_empty()) { fprintf(fp,"%s:%s\n",u->user.get(),u->pass.get()); } } ret = fclose(fp); } return ret; } int HTTPD_AUTHS::edit() { int ret = -1, nof = 0; while (1) { DIALOG dia; dia.newf_title ("",MSG_U(T_USERFILES,"Users configurations")); int n = getnb(); for(int i=0;ifile.is_empty()) dia.new_menuitem("",d->file); } MENU_STATUS code = dia.editmenu (MSG_U(T_USERS, "Users configurations") ,MSG_U(I_USERS,"You can configure Apache users/groups\n") ,help_users ,nof,0); nof--; if (code == MENU_ESCAPE || code == MENU_QUIT){ break; }else if(code == MENU_ADD) { }else if (nof < n && nof >= 0){ ret = editone(nof); } } return ret; } PUBLIC int HTTPD_USERS::edit () { int ret = 0, nof = 0; ret = parsehtpasswd((char *)file.get(),*this); if(ret == -1) return -1; while(1) { DIALOG dia; int usernum = getnb(); for(int i=0;iuser.get()); } dia.setbutinfo (MENU_USR1,MSG_U(B_CHANGEPASS,"Change Password"),""); MENU_STATUS code = dia.edit ( MSG_U(T_APAUSER,"User Configuration") ,MSG_U(I_APAUSER,"You can configure Apache Users") ,help_users ,nof,MENUBUT_ACCEPT|MENUBUT_USR1|MENUBUT_ADD|MENUBUT_DEL); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else if (code == MENU_ACCEPT){ ret = 0; break; }else if (code == MENU_ADD){ HTTPD_USER *u = new HTTPD_USER(); add(u); u->edit (*this); }else if(code == MENU_USR1){ if(getitem(nof)->edit(*this) == 2) cwrite(); }else if(code == MENU_ACCEPT) { cwrite(); }else if (code == MENU_DEL){ if (xconf_delok()){ remove_del(nof); ret = 1; cwrite(); break; } } } return 0; } PUBLIC int HTTPD_USER::edit (HTTPD_USERS &users) { int ret = -1, nof = 0; DIALOG dia; SSTRING repass, cpass; dia.newf_str(MSG_U(F_USER,"Username"),user); dia.newf_pass(MSG_U(F_PASS,"Password"),cpass); dia.newf_pass(MSG_U(F_REPASS,"Re-type password"),repass); while(1) { MENU_STATUS code = dia.edit ( MSG_U(T_APANAMEPASS,"User name/password") ,MSG_U(I_APANAMEPASS,"You can configure user name/password") ,help_users ,nof,MENUBUT_CANCEL|MENUBUT_ACCEPT); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else if (code == MENU_ACCEPT){ if(stricmp(cpass.get(),repass.get()) != 0) // FIXME: Translations xconf_error("Passwords dont match\n"); else { pass.setfrom(cryptit((char *)pass.get())); return 2; } } } return ret; } int parsehtpasswd (const char *file, HTTPD_USERS &users) { char line[100], username[60], password[40]; if(file == NULL) return -1; CONFIG_FILE conf (file,help_nil,CONFIGF_OPTIONAL); FILE_CFG *fp = conf.fopen("r"); if (fp == NULL) return -1; users.remove_all(); while(fgets(line,sizeof(line), fp) != NULL) { if(line[0] == '\n') break; int i = 0, a = 0; while(line[i] != ':') { username[i] = line[i]; i++; } username[i] = '\0'; i++; /* : */ while(line[i] != '\n') { password[a] = line[i]; i++, a++; } password[a] = '\0'; HTTPD_USER *c = new HTTPD_USER(); c->user.setfrom(username); c->pass.setfrom(password); users.add(c); memset(line,0,sizeof(line)); memset(username,0,sizeof(username)); memset(password,0,sizeof(password)); } return 0; } PUBLIC int HTTPD_CONFIG::perfedit() { VIEW_MAIN vmain (itemss); DIALOG dia; VIEWEDIT vedit (vmain,dia); int ret = -1; int nof = 0; dia.newf_title ("",MSG_U(T_NRPROC,"Number of Processes")); vedit.newf_num (MSG_U(F_STARTSERVERS,"Start servers"),K_STARTSERVERS); vedit.newf_num (MSG_U(F_MAXCLIENTS,"Max clients per servers"),K_MAXCLIENTS); vedit.newf_num (MSG_U(F_MAXREQUESTS,"Max requests per child") ,K_MAXREQUESTSPERCHILD); vedit.newf_num (MSG_U(F_MINSPARESERVERS,"Minimum of spare servers") ,K_MINSPARESERVERS); vedit.newf_num (MSG_U(F_MAXSPARESERVERS,"Maximum of spare servers") ,K_MAXSPARESERVERS); dia.newf_title ("",MSG_U(T_KEEPSALIVE,"Keeps Alive")); vedit.newf_chk ("",K_KEEPALIVE,MSG_U(I_KEEPALIVE,"Keep Alive")); vedit.newf_num (MSG_U(F_KEEPALIVET,"Keep Alive Timeout") ,K_KEEPALIVETIMEOUT); vedit.newf_num (MSG_U(F_MAXKEEPALIVEREQ,"Max Keep Alive Requests") ,K_MAXKEEPALIVEREQ); dia.newf_title ("",MSG_U(T_ADVTUNING,"Advanced Tuning")); vedit.newf_num (MSG_U(F_TIMEOUT,"Time out"),K_TIMEOUT); while(1) { MENU_STATUS code = dia.edit ( MSG_U(T_APAPERF,"Apache Performance Tuning") ,MSG_U(I_APAPERF,"You can configure Apache performance") ,help_perf ,nof); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else if (code == MENU_ACCEPT){ ret = 0; vedit.update(""); write(); break; } } return ret; } PUBLIC int HTTPD_CONFIG::modedit() { int ret = -1; DIALOG dia; int nof = 0; SSTRINGS s_mods; VIEWITEMS v_mods; v_mods.neverdelete(); itemss.reset_iter(); VIEWITEM *it; while ((it=itemss.getnext())!=NULL){ const char *s = it->line.get(); char word[200]; const char *pt = str_copyword (word,s,sizeof(word)-1); if (strcmp(word,K_LOADMODULE)==0){ pt = str_skip(pt); s_mods.add (new SSTRING(pt)); } } while (1){ int n = s_mods.getnb(); for(int i=0;i