📄 core.pl
字号:
# core.pl# Defines the core module directives# core_directives(version)# Returns ar array of references to associative arrays, each containing# information about some directive. The keys of each array are:# name - The name of this directive# type - What kind of directive this in. Possible values are# 0 - Processes and limits# 1 - Networking and addresses# 2 - Apache Modules# 3 - Log files# 4 - Access control# 5 - document options# 6 - MIME types# 7 - Error handling# 8 - Users and Groups# 9 - Miscellaneous# 10- Aliases and redirects# 11- CGI programs# 12- Directory indexing# 13- Proxying# 14- SSL# 15- Perl# 16- PHP# multiple - Can this directive appear multiple times# global - Can be used in the global server context# virtual - Can be used in a VirtualHost section or in the global section# directory - Can be used in a Directory section context# htaccess - Can be used in a .htaccess filesub core_directives{local($rv);$rv = [ [ 'AccessFileName', 0, 5, 'virtual', undef, 5 ], [ 'ClearModuleList AddModule', 1, 2, 'global' ], [ 'AllowOverride', 0, 5, 'directory' ], [ 'AuthName', 0, 4, 'directory htaccess', undef, 10 ], [ 'AuthType', 0, 4, 'directory htaccess', undef, 8 ], [ 'BindAddress Listen Port', 1, 1, 'global' ], [ 'ContentDigest', 0, 5, 'virtual directory htaccess' ], [ 'CoreDumpDirectory', 0, 9, 'global', 1.3 ], [ 'DefaultType', 0, 6, 'virtual directory htaccess' ], [ 'DocumentRoot', 0, 5, 'virtual', undef, 10 ], [ 'ErrorDocument', 1, 7, 'virtual directory htaccess' ], [ 'ErrorLog', 0, 3, 'virtual' ], [ 'Group', 0, 8, 'virtual' ], [ 'HostNameLookups', 0, 1, 'virtual directory htaccess' ], [ 'IdentityCheck', 0, 1, 'virtual directory htaccess' ], [ 'KeepAlive MaxKeepAliveRequests', 0, 1, 'global' ], [ 'KeepAliveTimeout', 0, 1, 'global' ], [ 'ListenBacklog', 0, 1, 'global', 1.2 ], [ 'LockFile', 0, 9, 'global' ], [ 'LimitRequestBody', 0, 0, 'virtual directory htaccess', 1.32 ], [ 'LimitRequestFields', 0, 0, 'global', 1.32 ], [ 'LimitRequestFieldsize', 0, 0, 'global', 1.32 ], [ 'LimitRequestLine', 0, 0, 'global', 1.32 ], [ 'MaxClients', 0, 0, 'global' ], [ 'MaxRequestsPerChild', 0, 0, 'global' ], [ 'StartServers', 0, 0, 'global' ], [ 'MinSpareServers', 0, 0, 'global' ], [ 'MaxSpareServers', 0, 0, 'global' ], [ 'NameVirtualHost', 1, 1, 'global', 1.3 ], [ 'Options', 0, 5, 'virtual directory htaccess', undef, 3 ], [ 'PidFile', 0, 9, 'global' ], [ 'require', 0, 4, 'directory htaccess', undef, 6 ], [ 'RLimitCPU', 0, 0, 'virtual', 1.2 ], [ 'RLimitMEM', 0, 0, 'virtual', 1.2 ], [ 'RLimitNPROC', 0, 0, 'virtual', 1.2 ], [ 'Satisfy', 0, 4, 'directory htaccess', 1.2, 4 ], [ 'ScoreBoardFile', 0, 9, 'global', 1.2 ], [ 'SendBufferSize', 0, 1, 'global' ], [ 'ServerAdmin', 0, 1, 'virtual' ], [ 'ServerAlias', 1, 1, 'virtual', 1.2 ], [ 'ServerName', 0, 1, 'virtual' ], [ 'ServerPath', 0, 5, 'virtual' ], [ 'ServerType', 0, 9, 'global' ], [ 'ServerTokens', 0, 9, 'global', 1.3 ], [ 'ServerSignature', 0, 5, 'virtual directory htaccess', 1.3 ], [ 'TimeOut', 0, 1, 'global' ], [ 'UseCanonicalName', 0, 1, 'virtual directory htaccess', 1.3 ], [ 'User', 0, 8, 'virtual', undef, 10 ] ];return &make_directives($rv, $_[0], "core");}# core_handlers(config, version)# Returns an array of all available handlerssub core_handlers{return ();}########################################################################## Process and limit directivessub edit_MaxClients{return (1, "Maximum concurrent requests", &opt_input($_[0]->{'value'}, "MaxClients", "Default", 4));}sub save_MaxClients{return &parse_opt("MaxClients", '^\d+$', "Maximum concurrent requests must be an integer");}sub edit_MaxKeepAliveRequests{return (1, "Maximum keepalives per connection", &opt_input($_[0]->{'value'}, "MaxKeepAliveRequests", "Default", 4));}sub save_MaxKeepAliveRequests{return &parse_opt("MaxKeepAliveRequests", '^\d+$', "Maximum keepalives per connection must be an integer");}sub edit_MaxRequestsPerChild{return (1, "Maximum requests per server process", &opt_input($_[0]->{'value'}, "MaxRequestsPerChild", "Default", 5));}sub save_MaxRequestsPerChild{return &parse_opt("MaxRequestsPerChild", '^\d+$', "Maximum requests per server process must be an integer");}sub edit_MinSpareServers{return (1, "Minimum spare server processes", &opt_input($_[0]->{'value'},"MinSpareServers","Default", 4));}sub save_MinSpareServers{return &parse_opt("MinSpareServers", '^\d+$', "Minimum spare server processes must be an integer");}sub edit_MaxSpareServers{return (1, "Maximum spare server processes", &opt_input($_[0]->{'value'},"MaxSpareServers","Default", 4));}sub save_MaxSpareServers{return &parse_opt("MaxSpareServers", '^\d+$', "Maximum spare server processes must be an integer");}sub edit_StartServers{return (1, "Initial server processes", &opt_input($_[0]->{'value'}, "StartServers", "Default", 4));}sub save_StartServers{return &parse_opt("StartServers", '^\d+$', "Initial server processes must be an integer");}sub edit_RLimitCPU{return &rlimit_input("RLimitCPU", "CPU resource limit", $_[0]);}sub save_RLimitCPU{return &parse_rlimit("RLimitCPU", "CPU resource limit");}sub edit_RLimitMEM{return &rlimit_input("RLimitMEM", "Memory resource limit", $_[0]);}sub save_RLimitMEM{return &parse_rlimit("RLimitMEM", "memory resource limit");}sub edit_RLimitNPROC{return &rlimit_input("RLimitNPROC", "Process limit", $_[0]);}sub save_RLimitNPROC{return &parse_rlimit("RLimitNPROC", "process limit");}# rlimit_input(name, desc, value)sub rlimit_input{local(@v, $rv);@v = split(/\s+/, $_[2]->{'value'});$rv = sprintf "<input type=radio name=$_[0]_mode value=0 %s> Default<br>\n", @v ? "" : "checked";$rv .= sprintf "<input type=radio name=$_[0]_mode value=1 %s>\n", @v == 1 ? "checked" : "";$rv .= sprintf "Soft limit <input name=$_[0]_soft1 size=5 value=\"%s\"><br>\n", @v == 1 ? $v[0] : "";$rv .= sprintf "<input type=radio name=$_[0]_mode value=2 %s>\n", @v == 2 ? "checked" : "";$rv .= sprintf "Soft limit <input name=$_[0]_soft2 size=5 value=\"%s\">\n", @v == 2 ? $v[0] : "";$rv .= sprintf "Hard limit <input name=$_[0]_hard2 size=5 value=\"%s\"><br>\n", @v == 2 ? $v[1] : "";return (1, $_[1], $rv);}# parse_rlimit(name, desc)sub parse_rlimit{if ($in{"$_[0]_mode"} == 0) { return ( [ ] ); }elsif ($in{"$_[0]_mode"} == 1) { $in{"$_[0]_soft1"} =~ /^(\d+|max)$/ || &error($in{"$_[0]_soft1"}." is not a valid soft $_[1]"); return ( [ $in{"$_[0]_soft1"} ] ); }elsif ($in{"$_[0]_mode"} == 2) { $in{"$_[0]_soft2"} =~ /^(\d+|max)$/ || &error($in{"$_[0]_soft2"}." is not a valid soft $_[1]"); $in{"$_[0]_hard2"} =~ /^(\d+|max)$/ || &error($in{"$_[0]_hard2"}." is not a valid hard $_[1]"); return ( [ $in{"$_[0]_soft2"}." ".$in{"$_[0]_hard2"} ] ); }}########################################################################## Networking and address directivessub edit_BindAddress_Listen_Port{local($bref, $lref, $pref, @blist, @plist, $inp);$bref = $_[0]; $lref = $_[1]; $pref = $_[2];if (@$lref) { # listen directives in use.. so BindAddress and Port are unused foreach $l (@$lref) { if ($l->{'value'} =~ /^(\S+):(\d+)$/) { push(@blist, $1); push(@plist, $2); } elsif ($l->{'value'} =~ /^(\d+)$/) { push(@blist, "*"); push(@plist, $1); } elsif ($l->{'value'} =~ /^(\S+)$/) { push(@blist, $1); push(@plist, undef); } } }else { # no listen directives... check for BindAddress if (@$bref) { push(@blist, $bref->[@$bref-1]->{'value'}); } else { push(@blist, "*"); } push(@plist, undef); }$port = @$pref ? $pref->[@$pref-1]->{'value'} : 80;$inp = "<b>Default port:</b> <input name=Port size=6 value=\"$port\"><br>\n";$inp .= "<table border>\n". "<tr $tb> <td><b>Address</b></td> <td><b>Port</b></td> </tr>\n";for($i=0; $i<@blist+1; $i++) { $inp .= sprintf "<tr><td><input type=radio name=BindAddress_def_$i value=2 %s>". " None <input type=radio name=BindAddress_def_$i value=1 %s>". " All <input type=radio name=BindAddress_def_$i value=0 %s> ". "<input name=BindAddress_$i size=20 value=\"%s\"></td>", $blist[$i] ? "" : "checked", $blist[$i] eq "*" ? "checked" : "", $blist[$i] && $blist[$i] ne "*" ? "checked" : "", $blist[$i] eq "*" ? "" : $blist[$i]; $inp .= "<td>".&opt_input($plist[$i], "Port_$i", "Default", 5)."</td>"; }$inp .= "</table>\n";return (2, "Listen on addresses and ports", $inp);}sub save_BindAddress_Listen_Port{local(@blist, @plist, $bdef, $b, $p);# build list of addresses and portsfor($i=0; defined($in{"Port_$i"}); $i++) { $bdef = $in{"BindAddress_def_$i"}; $b = $in{"BindAddress_$i"}; $pdef = $in{"Port_${i}_def"}; $p = $in{"Port_$i"}; if ($bdef == 2) { next; } if ($bdef) { push(@blist, "*"); } elsif ($b =~ /^\S+$/ && gethostbyname($b)) { push(@blist, $b); } else { &error("'$b' is not a valid address"); } if ($pdef) { push(@plist, undef); } elsif ($p =~ /^\d+$/) { push(@plist, $p); } else { &error("'$p' is not a valid port"); } }if (!@blist) { &error("You must specify at least one address to listen on"); }# Return directives$in{'Port'} =~ /^\d+$/ || &error("Invalid default port");if (@blist == 1 && !$plist[0]) { # Only one address, and the default port return ( $blist[0] eq "*" ? [ ] : [ $blist[0] ], [ ], [ $in{'Port'} ] ); }else { # More than one address, or a non-default port. Must use Listens for($i=0; $i<@blist; $i++) { if ($blist[$i] ne "*" && $plist[$i]) { push(@l, "$blist[$i]:$plist[$i]"); } elsif ($blist[$i] ne "*") { push(@l, $blist[$i]); } elsif ($plist[$i]) { push(@l, "*:$plist[$i]"); } else { push(@l, $in{'Port'}); } } return ( [], \@l, [ $in{'Port'} ] ); }}sub edit_KeepAlive_MaxKeepAliveRequests{$kref = $_[0]; $mref = $_[1];if ($_[2]->{'version'} >= 1.2) { # two separate directives for keep-alives $inp = sprintf "<input type=radio name=KeepAlive_def value=0 %s> None\n". "<input type=radio name=KeepAlive_def value=1 %s> Default\n". "<input type=radio name=KeepAlive_def value=2 %s> ". "<input name=KeepAlive size=5 value=\"%s\">", $kref->{'value'} =~ /off/i ? "checked" : "", $kref->{'value'} !~ /off/i && !$mref ? "checked" : "", $mref ? "checked" : "", $mref ? $mref->{'value'} : ""; }else { # only one directive $inp = sprintf "<input type=radio name=KeepAlive_def value=0 %s> None\n". "<input type=radio name=KeepAlive_def value=1 %s> Default\n". "<input type=radio name=KeepAlive_def value=2 %s> ". "<input name=KeepAlive size=5 value=\"%s\">", $kref->{'value'} eq "0" ? "checked" : "", $kref ? "" : "checked" , $kref->{'value'} ? "checked" : "", $kref->{'value'} ? $kref->{'value'} : ""; }return (1, "Multiple requests per connection", $inp);}sub save_KeepAlive_MaxKeepAliveRequests{if ($_[0]->{'version'} >= 1.2) { # two separate directives if ($in{'KeepAlive_def'} == 0) { return ( [ "off" ], [ ] ); } elsif ($in{'KeepAlive_def'} == 1) { return ( [ "on" ], [ ] ); } elsif ($in{'KeepAlive'} !~ /^\d+$/) { &error("'$in{'KeepAlive'}' is not a valid number of keepalives"); } else { return ( [ "on" ], [ $in{'KeepAlive'} ] ); } }else { # only one directive if ($in{'KeepAlive_def'} == 0) { return ( [ 0 ], [ ] ); } elsif ($in{'KeepAlive_def'} == 1) { return ( [ ], [ ] ); } elsif ($in{'KeepAlive'} !~ /^\d+$/) { &error("'$in{'KeepAlive'}' is not a valid number of keepalives"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -