📄 create_virt.cgi
字号:
#!/usr/local/bin/perl# create_virt.cgi# Create a new virtual host.require './apache-lib.pl';&ReadParse();$access{'create'} || &error($text{'cvirt_ecannot'});&error_setup($text{'cvirt_err'});if ($in{'addr_def'}) { if ($httpd_modules{'core'} >= 1.2) { $addr = "_default_"; } else { $addr = "*"; } }elsif ($in{'addr'} !~ /\S/) { &error($text{'cvirt_eaddr1'}); }elsif (!gethostbyname($in{'addr'})) { &error(&text('cvirt_eaddr2', $in{'addr'})); }else { $addr = $in{'addr'}; }if ($in{'port_mode'} == 0) { $port = ""; }elsif ($in{'port_mode'} == 1) { $port = ":*"; }elsif ($in{'port'} !~ /^\d+$/) { &error(&text('cvirt_eport', $in{'port'})); }else { $port = ":$in{'port'}"; }if (!$in{'name_def'} && $in{'name'} !~ /^\S+$/) { &error(&text('cvirt_ename', $in{'name'})); }$in{'root'} =~ /\S/ || &error($text{'cvirt_eroot1'});if (!-d $in{'root'}) { # create the document root mkdir($in{'root'}, 0755) || &error(&text('cvirt_eroot2', $in{'root'}, $!)); $conf = &get_config(); $user = &find_directive("User", $conf); $group = &find_directive("Group", $conf); $uid = $user ? getpwnam($user) : 0; $gid = $group ? getgrnam($group) : 0; chown($uid, $gid, $in{'root'}); }# find file to add to$f = $config{'virt_file'};if (!$f) { # use the first file in config (usually httpd.conf) $vconf = &get_virtual_config(); $f = $vconf->[0]->{'file'}; for($j=0; $vconf->[$j]->{'file'} eq $f; $j++) { } $l = $vconf->[$j-1]->{'eline'}+1; }$lref = &read_file_lines($f);push(@$lref, "");push(@$lref, "<VirtualHost $addr$port>");push(@$lref, "DocumentRoot $in{'root'}");if (!$in{'name_def'}) { push(@$lref, "ServerName $in{'name'}"); }push(@$lref, "</VirtualHost>");&flush_file_lines();# add to aclif ($access{'virts'} ne '*') { $access{'virts'} .= " $addr$port"; &save_module_acl(\%access); }&redirect("");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -