1#!/usr/local/bin/perl 2# Show user and login options 3 4require './dovecot-lib.pl'; 5&ui_print_header(undef, $text{'login_title'}, ""); 6$conf = &get_config(); 7 8print &ui_form_start("save_login.cgi", "post"); 9print &ui_table_start($text{'login_header'}, "width=100%", 4); 10 11# SASL authentication realms 12$realms = &find_value("auth_realms", $conf); 13print &ui_table_row($text{'login_realms'}, 14 &ui_opt_textbox("realms", $realms, 40, $text{'login_none'}), 3); 15 16# Default authentication realm 17$realm = &find_value("auth_default_realm", $conf); 18print &ui_table_row($text{'login_realm'}, 19 &ui_opt_textbox("realm", $realm, 10, $text{'default'})); 20 21# Authentication mechanisms (MD5, etc..) 22if (&find("auth_mechanisms", $conf, 2)) { 23 # Version 0.99 and 2.0 format 24 @mechs = split(/\s+/, &find_value("auth_mechanisms", $conf)); 25 } 26else { 27 # version 1.0 format 28 @mechs = split(/\s+/, &find_value("mechanisms", $conf, undef, 29 "auth", "default")); 30 } 31print &ui_table_row($text{'login_mechs'}, 32 &ui_select("mechs", \@mechs, 33 [ map { [ $_, $text{'login_'.$_} ] } @supported_auths ], 34 4, 1, 1)); 35 36print &ui_table_hr(); 37 38# User database, for mapping usernames to UIDs and homes 39if (&find("auth_userdb", $conf, 2)) { 40 # Version 0.99 format 41 $userdb = &find_value("auth_userdb", $conf); 42 } 43elsif ($usec = &find_section("userdb", $conf, undef, "auth", "default")) { 44 # Version 1.0.alpha format 45 $userdb = $usec->{'value'}; 46 $args = &find_value("args", $conf, undef, "userdb", $usec->{'value'}); 47 $userdb .= " $args" if ($args); 48 } 49elsif (&find_value("driver", $conf, 2, "userdb")) { 50 # Version 2.0 format 51 $userdb = &find_value("driver", $conf, undef, "userdb"); 52 $args = &find_value("args", $conf, undef, "userdb"); 53 $userdb .= " ".$args if ($args); 54 } 55else { 56 # Version 1.0 format 57 $userdb = &find_value("userdb", $conf, undef, "auth", "default"); 58 } 59if ($userdb eq "passwd") { 60 $usermode = "passwd"; 61 } 62elsif ($userdb =~ /^passwd-file\s+(.*)/) { 63 $usermode = "passwd-file"; 64 $passwdfile = $1; 65 } 66elsif ($userdb =~ /^static\s+uid=(\d+)\s+gid=(\d+)\s+home=(.*)/) { 67 $usermode = "static"; 68 $uid = $1; 69 $gid = $2; 70 $home = $3; 71 } 72elsif ($userdb eq "vpopmail") { 73 $usermode = "vpopmail"; 74 } 75elsif ($userdb =~ /^ldap\s+(.*)/) { 76 $usermode = "ldap"; 77 $ldap = $1; 78 } 79elsif ($userdb =~ /^pgsql\s+(.*)/) { 80 $usermode = "pgsql"; 81 $pgsql = $1; 82 } 83elsif ($userdb =~ /^sql\s+(.*)/) { 84 $usermode = "sql"; 85 $sql = $1; 86 } 87else { 88 $other = $userdb; 89 } 90print &ui_table_row($text{'login_userdb'}, 91 &ui_radio("usermode", $usermode, 92 [ [ "passwd", $text{'login_passwd'}."<br>" ], 93 [ "passwd-file", &text('login_passwdfile', 94 &ui_textbox("passwdfile", $passwdfile, 30))."<br>" ], 95 [ "static", &text('login_static', 96 &ui_textbox("uid", $uid, 6), 97 &ui_textbox("gid", $gid, 6), 98 &ui_textbox("home", $home, 20))."<br>" ], 99 [ "vpopmail", $text{'login_vpopmail'}."<br>" ], 100 [ "ldap", &text('login_ldap', 101 &ui_textbox("ldap", $ldap, 30))."<br>" ], 102 [ "pgsql", &text('login_pgsql', 103 &ui_textbox("pgsql", $pgsql, 30))."<br>" ], 104 [ "sql", &text('login_sql', 105 &ui_textbox("sql", $sql, 30))."<br>" ], 106 [ "", &text('login_other', 107 &ui_textbox("other", $other, 30))."<br>" ], 108 ]), 3); 109 110# Password authentication system 111if (&find("auth_passdb", $conf, 2)) { 112 # Version 0.99 format 113 $passdb = &find_value("auth_passdb", $conf); 114 } 115elsif ($psec = &find_section("passdb", $conf, undef, "auth", "default")) { 116 # Version 1.0.alpha format 117 $passdb = $psec->{'value'}; 118 $args = &find_value("args", $conf, undef, "passdb", $psec->{'value'}); 119 $passdb .= " $args" if ($args); 120 $alpha_opts = 1; 121 } 122elsif (&find_value("driver", $conf, 2, "passdb")) { 123 # Version 2.0 format 124 $passdb = &find_value("driver", $conf, undef, "passdb"); 125 $args = &find_value("args", $conf, undef, "passdb"); 126 $passdb .= " ".$args if ($args); 127 } 128else { 129 # Version 1.0 format 130 $passdb = &find_value("passdb", $conf, undef, "auth", "default"); 131 } 132if ($passdb eq "passwd") { 133 $passmode = "passwd"; 134 } 135elsif ($passdb eq "shadow") { 136 $passmode = "shadow"; 137 } 138elsif ($passdb eq "pam") { 139 $passmode = "dpam"; 140 } 141elsif ($passdb =~ /^pam(\s+\-session)?(\s+cache_key=(\S+))?\s+(\S*)$/) { 142 $passmode = "pam"; 143 $ppam = $4; 144 $psession = $1 ? 1 : 0; 145 $pckey = $3; 146 } 147elsif ($passdb =~ /^passwd-file\s+(.*)/) { 148 $passmode = "passwd-file"; 149 $ppasswdfile = $1; 150 } 151elsif ($passdb eq "vpopmail") { 152 $passmode = "vpopmail"; 153 } 154elsif ($passdb =~ /^ldap\s+(.*)/) { 155 $passmode = "ldap"; 156 $pldap = $1; 157 } 158elsif ($passdb =~ /^pgsql\s+(.*)/) { 159 $passmode = "pgsql"; 160 $ppgsql = $1; 161 } 162elsif ($passdb =~ /^sql\s+(.*)/) { 163 $passmode = "sql"; 164 $psql = $1; 165 } 166elsif ($passdb =~ /^bsdauth(\s+cache_key=(\S+))?$/) { 167 $passmode = "bsdauth"; 168 $pbckey = $2; 169 } 170elsif ($passdb =~ /^checkpassword\s+(.*)$/) { 171 $passmode = "checkpassword"; 172 $checkpassword = $1; 173 } 174else { 175 $pother = $passdb; 176 } 177print &ui_table_row($text{'login_passdb'}, 178 &ui_radio("passmode", $passmode, 179 [ [ "passwd", $text{'login_passwd2'}."<br>" ], 180 [ "shadow", $text{'login_shadow'}."<br>" ], 181 [ "dpam", &text('login_dpam')."<br>" ], 182 $alpha_opts ? 183 ( [ "pam", &text('login_pam2', 184 &ui_textbox("ppam", $ppam, 10), 185 &ui_checkbox("ppam_session", 1, 186 $text{'login_session'}, $psession), 187 &ui_opt_textbox("ppam_ckey", $pckey, 10, 188 $text{'login_none'}))."<br>" ] 189 ) : 190 ( [ "pam", &text('login_pam', 191 &ui_textbox("ppam", $ppam, 10))."<br>" ] 192 ), 193 [ "passwd-file", &text('login_passwdfile', 194 &ui_textbox("ppasswdfile", $ppasswdfile, 30))."<br>" ], 195 [ "vpopmail", $text{'login_vpopmail'}."<br>" ], 196 [ "ldap", &text('login_ldap', 197 &ui_textbox("pldap", $pldap, 30))."<br>" ], 198 [ "pgsql", &text('login_pgsql', 199 &ui_textbox("ppgsql", $ppgsql, 30))."<br>" ], 200 [ "sql", &text('login_sql', 201 &ui_textbox("psql", $psql, 30))."<br>" ], 202 $alpha_opts ? 203 ( [ "bsdauth", 204 &text('login_bsdauth', 205 &ui_opt_textbox("bsdauth_ckey", $pbckey, 10, 206 $text{'login_none'}))."<br>" ], 207 [ "checkpassword", 208 &text('login_checkpassword', 209 &ui_textbox("checkpassword", $checkpassword, 40))."<br>" ], 210 ) : 211 ( ), 212 [ "", &text('login_other', 213 &ui_textbox("pother", $pother, 30))."<br>" ], 214 ]), 3); 215 216print &ui_table_hr(); 217 218$fuid = &find_value("first_valid_uid", $conf); 219print &ui_table_row($text{'login_fuid'}, 220 &ui_opt_textbox("fuid", $fuid, 6, &getdef("first_valid_uid"))); 221 222$luid = &find_value("last_valid_uid", $conf); 223@mmap = ( [ 0, $text{'login_none'} ] ); 224print &ui_table_row($text{'login_luid'}, 225 &ui_opt_textbox("luid", $luid, 6, &getdef("last_valid_uid", \@mmap))); 226 227$fgid = &find_value("first_valid_gid", $conf); 228print &ui_table_row($text{'login_fgid'}, 229 &ui_opt_textbox("fgid", $fgid, 6, &getdef("first_valid_gid"))); 230 231$lgid = &find_value("last_valid_gid", $conf); 232print &ui_table_row($text{'login_lgid'}, 233 &ui_opt_textbox("lgid", $lgid, 6, &getdef("last_valid_gid", \@mmap))); 234 235$extra = &find_value("mail_extra_groups", $conf); 236print &ui_table_row($text{'login_extra'}, 237 &ui_opt_textbox("extra", $extra, 50, $text{'login_none'})."\n". 238 &group_chooser_button("extra", 1), 3); 239 240$chroot = &find_value("mail_chroot", $conf); 241print &ui_table_row($text{'login_chroot'}, 242 &ui_opt_textbox("chroot", $chroot, 40, $text{'login_none'})."\n". 243 &file_chooser_button("chroot", 1), 3); 244 245# Number of login processes 246if (&find("login_max_processes_count", $conf, 2)) { 247 print &ui_table_hr(); 248 $procs = &find_value("login_max_processes_count", $conf); 249 print &ui_table_row($text{'login_procs'}, 250 &ui_opt_textbox("procs", $procs, 6, 251 &getdef("login_max_processes_count")), 3); 252 } 253if (&find("login_processes_count", $conf, 2)) { 254 $count = &find_value("login_processes_count", $conf); 255 print &ui_table_row($text{'login_count'}, 256 &ui_opt_textbox("count", $count, 6, 257 &getdef("login_processes_count")), 3); 258 } 259 260 261print &ui_table_end(); 262print &ui_form_end([ [ "save", $text{'save'} ] ]); 263 264&ui_print_footer("", $text{'index_return'}); 265 266