📄 install_mod.cgi
字号:
#!/usr/local/bin/perl# install_mod.cgi# Download and install a webmin modulerequire './webmin-lib.pl';if ($ENV{REQUEST_METHOD} eq "POST") { &ReadParseMime(); }else { &ReadParse(); $no_upload = 1; }if ($in{'source'} == 0) { # from local file &error_setup(&text('install_err1', $in{'file'})); $file = $in{'file'}; if (!(-r $file)) { &inst_error($text{'install_efile'}); } }elsif ($in{'source'} == 1) { # from uploaded file &error_setup($text{'install_err2'}); $file = &tempname(); $need_unlink = 1; if ($no_upload) { &inst_error($text{'install_ebrowser'}); } open(MOD, "> $file"); print MOD $in{'upload'}; close(MOD); }elsif ($in{'source'} == 2) { # from ftp or http url &error_setup(&text('install_err3', $in{'url'})); $file = &tempname(); $need_unlink = 1; if ($in{'url'} =~ /^http:\/\/([^\/]+)(\/.*)$/) { $host = $1; $page = $2; $port = 80; if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; } &http_download($host, $port, $page, $file); } elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)\/(.*)$/) { $host = $1; $file = $2; &ftp_download($host, $file, $pfile); } else { &inst_error($text{'install_eurl'}); } }# Check if this is a valid module (a tar file of multiple module dirs)$tar = `tar tf $file 2>&1`;if ($?) { &inst_error(&text('install_etar', $tar)); }foreach $f (split(/\n/, $tar)) { if ($f =~ /^([^\/]+)\/(.*)$/) { $mods{$1}++; $hasfile{$1,$2}++; } }foreach $m (keys %mods) { $hasfile{$m,"module.info"} || &inst_error(&text('install_einfo', "<tt>$m</tt>")); }if (!%mods) { &inst_error($text{'install_enone'}); }# Get the module.info files to check dependancies$ver = &get_webmin_version();$tmpdir = &tempname();mkdir($tmpdir, 0700);foreach $m (keys %mods) { local %minfo; system("cd $tmpdir ; tar xf $file $m/module.info"); if (!&read_file("$tmpdir/$m/module.info", \%minfo)) { $err = &text('install_einfo', "<tt>$m</tt>"); } elsif (!&check_os_support(\%minfo)) { $err = &text('install_eos', "<tt>$m</tt>", $gconfig{'real_os_type'}, $gconfig{'real_os_version'}); } else { foreach $dep (split(/\s+/, $minfo{'depends'})) { if ($dep =~ /^[0-9\.]+$/) { if ($dep > $ver) { $err = &text('install_ever', "<tt>$m</tt>", "<tt>$dep</tt>"); } } elsif (!-r "../$dep/module.info") { $err = &text('install_edep', "<tt>$m</tt>", "<tt>$dep</tt>"); } } } last if ($err); }system("rm -rf $tmpdir >/dev/null 2>&1");&inst_error($err) if ($err);# Delete modules being replacedforeach $m (keys %mods) { system("rm -rf ../$m 2>&1 >/dev/null"); }# Extract all the modules and update perl path and ownership$out = `cd .. ; tar xf $file 2>&1 >/dev/null`;if ($?) { &inst_error(&text('install_eextract', $out)); }if ($need_unlink) { unlink($file); }open(PERL, $0);<PERL> =~ /^#!(\S+)/; $perl = $1;close(PERL);@st = stat($0);foreach $moddir (keys %mods) { chdir("../$moddir"); %minfo = &get_module_info($moddir); push(@mdescs, $minfo{'desc'}); chop($pwd = `pwd`); push(@mdirs, $pwd); `du -sk .` =~ /(\d+)/; push(@msizes, $1); system("(find . -name '*.cgi' ; find .-name '*.pl') | xargs $perl ../perlpath.pl $perl"); system("chown -R $st[4]:$st[5] ."); }# Copy appropriate config file from module to /etc/webminsystem("$perl ../copyconfig.pl $gconfig{'os_type'} $gconfig{'os_version'} .. $config_directory ".join(' ', keys %mods));# Update ACL for this user so they can access the new modules&read_acl(undef, \%acl);open(ACL, "> ".&acl_filename());foreach $u (keys %acl) { @mods = @{$acl{$u}}; if ($u eq $ENV{'REMOTE_USER'}) { push(@mods, keys %mods); @mods = &unique(@mods); } print ACL "$u: ",join(' ', @mods),"\n"; }close(ACL);# Display something nice for the user&header($text{'install_title'}, "");print "<hr>\n";print "$text{'install_desc'} <p>\n";print "<ul>\n";for($i=0; $i<@mdescs; $i++) { print &text('install_line', "<b>$mdescs[$i]</b>", "<tt>$mdirs[$i]</tt>", $msizes[$i]),"<p>\n"; }print "</ul><p>\n";print "<hr>\n";&footer("", $text{'index_return'});sub inst_error{if ($need_unlink) { unlink($file); }&error(@_);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -