# cpan-lib.pl # Functions for getting information about perl modules BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); use Config; $packages_file = "$module_config_directory/packages.txt.gz"; if (!-r $packages_file) { $packages_file = "$module_var_directory/packages.txt.gz"; } $available_packages_cache = "$module_config_directory/available-cache"; if (!-r $available_packages_cache) { $available_packages_cache = "$module_var_directory/available-cache"; } # Get the paths to perl and perldoc $perl_path = &get_perl_path(); if (&has_command("perldoc")) { $perl_doc = &has_command("perldoc"); } else { $perl_path =~ /^(.*)\/[^\/]+$/; if (-x "$1/perldoc") { $perl_doc = "$1/perldoc"; } } if ($perl_doc && $] >= 5.006) { $perl_doc = "$perl_path -T $perl_doc"; } # list_perl_modules([master-name]) # Returns a list of all installed perl modules, by reading .packlist files sub list_perl_modules { local ($limit) = @_; local (@rv, %done, $d, %donedir, %donemod); foreach $d (&expand_usr64($Config{'privlib'}), &expand_usr64($Config{'sitelib_stem'} ? $Config{'sitelib_stem'} : $Config{'sitelib'}), &expand_usr64($Config{'sitearch_stem'} ? $Config{'sitearch_stem'} : $Config{'sitearch'}), &expand_usr64($Config{'vendorlib_stem'} ? $Config{'vendorlib_stem'} : $Config{'vendorlib'}), &expand_usr64($Config{'installprivlib'})) { next if (!$d || !-d $d); next if ($donedir{$d}); local $f; open(FIND, "find ".quotemeta($d)." -name .packlist -print |"); while($f = <FIND>) { chop($f); local @st = stat($f); next if ($done{$st[0],$st[1]}++); local @st = stat($f); local $mod = { 'date' => scalar(localtime($st[9])), 'time' => $st[9], 'packfile' => $f, 'index' => scalar(@rv) }; $f =~ /\/(([A-Z][^\/]*\/)*[^\/]+)\/.packlist$/; $mod->{'name'} = $1; $mod->{'name'} =~ s/\//::/g; next if ($limit && $mod->{'name'} ne $limit); next if ($donemod{$mod->{'name'}}++); # Add the files in the .packlist local (%donefile, $l); open(FILE, "<".$f); while($l = <FILE>) { chop($l); $l =~ s/^\/tmp\/[^\/]+//; $l =~ s/^\/var\/tmp\/[^\/]+//; next if ($donefile{$l}++); if ($l =~ /\/((([A-Z][^\/]*\/)([^\/]+\/)?)?[^\/]+)\.pm$/) { local $mn = $1; $mn =~ s/\//::/g; push(@{$mod->{'mods'}}, $mn); push(@{$mod->{'files'}}, $l); } elsif ($l =~ /^([^\/]+)\.pm$/) { # Module name only, with no path! Damn redhat.. local @rpath; open(FIND2, "find ".quotemeta($d). " -name '$l' -print |"); while(<FIND2>) { chop; push(@rpath, $_); } close(FIND2); @rpath = sort { length($a) cmp length($b) } @rpath; if (@rpath) { $rpath[0] =~ /\/(([A-Z][^\/]*\/)*[^\/]+)\.pm$/; local $mn = $1; $mn =~ s/\//::/g; push(@{$mod->{'mods'}}, $mn); push(@{$mod->{'files'}}, $rpath[0]); $mod->{'noremove'} = 1; $mod->{'noupgrade'} = 1; } } push(@{$mod->{'packlist'}}, $l); } close(FILE); local $mi = &indexof($mod->{'name'}, @{$mod->{'mods'}}); $mod->{'master'} = $mi < 0 ? 0 : $mi; push(@rv, $mod) if (@{$mod->{'mods'}}); } close(FIND); } # Look for RPMs or Debs for Perl modules if (&foreign_check("software") && $config{'incpackages'}) { &foreign_require("software", "software-lib.pl"); if ($software::config{'package_system'} eq "rpm") { local $n = &software::list_packages(); local $i; for($i=0; $i<$n; $i++) { # Create the module object next if ($software::packages{$i,'name'} !~ /^perl-([A-Z].*)$/ && $software::packages{$i,'name'} !~ /^([A-Z].*)-[pP]erl$/i); local $mod = { 'index' => scalar(@rv), 'pkg' => $software::packages{$i,'name'}, 'pkgtype' => 'rpm', 'noupgrade' => 1, 'version' => $software::packages{$i,'version'} }; $mod->{'name'} = $1; $mod->{'name'} =~ s/\-/::/g; next if ($limit && $mod->{'name'} ne $limit); next if ($donemod{$mod->{'name'}}++); # Add the files in the RPM # XXX call rpm -ql only, avoid -V step # XXX same for Debian # XXX list_package_files function, returns an array foreach my $l (&software::package_files( $software::packages{$i,'name'}, $software::packages{$i,'version'})) { if ($l =~ /\/((([A-Z][^\/]*\/)([^\/]+\/)?)?[^\/]+)\.pm$/) { local $mn = $1; $mn =~ s/\//::/g; push(@{$mod->{'mods'}}, $mn); push(@{$mod->{'files'}}, $l); } push(@{$mod->{'packlist'}}, $l); if (!$mod->{'date'}) { local @st = stat($l); $mod->{'date'} = scalar(localtime($st[9])); $mod->{'time'} = $st[9]; } } local $mi = &indexof($mod->{'name'}, @{$mod->{'mods'}}); $mod->{'master'} = $mi < 0 ? 0 : $mi; push(@rv, $mod) if (@{$mod->{'mods'}}); } } elsif ($software::config{'package_system'} eq "debian") { # Look for Debian packages of Perl modules local $n = &software::list_packages(); local $i; for($i=0; $i<$n; $i++) { # Create the module object next if ($software::packages{$i,'name'} !~ /^lib(\S+)-perl$/); local $mod = { 'index' => scalar(@rv), 'pkg' => $software::packages{$i,'name'}, 'pkgtype' => 'debian', 'noupgrade' => 1, 'version' => $software::packages{$i,'version'} }; # Add the files in the RPM foreach my $l (&software::package_files( $software::packages{$i,'name'})) { if ($l =~ /\/((([A-Z][^\/]*\/)([^\/]+\/)?)?[^\/]+)\.pm$/) { local $mn = $1; $mn =~ s/\//::/g; push(@{$mod->{'mods'}}, $mn); push(@{$mod->{'files'}}, $l); } push(@{$mod->{'packlist'}}, $l); if (!$mod->{'date'}) { local @st = stat($l); $mod->{'date'} = scalar(localtime($st[9])); $mod->{'time'} = $st[9]; } } next if (!@{$mod->{'mods'}}); # Work out the name foreach my $m (@{$mod->{'mods'}}) { local $pn = lc($m); $pn =~ s/::/-/g; $pn = "lib".$pn."-perl"; if ($pn eq $mod->{'pkg'}) { $mod->{'name'} = $m; last; } } $mod->{'name'} ||= $mod->{'mods'}->[0]; next if ($limit && $mod->{'name'} ne $limit); next if ($donemod{$mod->{'name'}}++); local $mi = &indexof($mod->{'name'}, @{$mod->{'mods'}}); $mod->{'master'} = $mi < 0 ? 0 : $mi; push(@rv, $mod) if (@{$mod->{'mods'}}); } } } return @rv; } # expand_usr64(dir) # If a directory is like /usr/lib and /usr/lib64 exists, return them both sub expand_usr64 { if ($_[0] =~ /^(\/usr\/lib\/|\/usr\/local\/lib\/)(.*)$/) { local ($dir, $dir64, $rest) = ($1, $1, $2); $dir64 =~ s/\/lib\//\/lib64\//; return -d $dir64 ? ( $dir.$rest, $dir64.$rest ) : ( $dir.$rest ); } else { return ( $_[0] ); } } # module_desc(&mod, index) # Returns a one-line description for some module, and a version number sub module_desc { local ($in_name, $desc); local $f = $_[0]->{'files'}->[$_[1]]; local $pf = $f; local $ver = $_[0]->{'version'}; $pf =~ s/\.pm$/\.pod/; local ($got_version, $got_name); open(MOD, "<".$pf) || open(MOD, "<".$f); while(<MOD>) { if (/^=head1\s+name/i && !$got_name) { $in_name = 1; } elsif (/^=/ && $in_name) { $got_name++; $in_name = 0; } elsif ($in_name) { $desc .= $_; } if (/^\s*(our\s+)?\$VERSION\s*=\s*"([0-9\.]+)"/ || /^\s*(our\s+)?\$VERSION\s*=\s*'([0-9\.]+)'/ || /^\s*(our\s+)?\$VERSION\s*=\s*([0-9\.]+)/) { $ver = $2; $got_version++; } last if ($got_version && $got_name); } close(MOD); local $name = $_[0]->{'mods'}->[$_[1]]; $desc =~ s/^\s*$name\s+\-\s+// || $desc =~ s/^\s*\S*<$name>\s+\-\s+//; $desc =~ s/\$Id:.*\$//; return wantarray ? ($desc, $ver) : $desc; } # download_packages_file(&callback) sub download_packages_file { $config{'packages'} =~ /^http:\/\/([^\/]+)(\/.*)$/ || &error($text{'download_epackages'}); local ($host, $page, $port) = ($1, $2, 80); if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; } &http_download($host, $port, $page, $packages_file, undef, $_[0]); } # remove_module(&module) # Delete some perl module, and all sub-modules sub remove_module { local ($mod) = @_; if ($mod->{'pkg'}) { &foreign_require("software", "software-lib.pl"); return &software::delete_package($mod->{'pkg'}); } else { unlink(@{$mod->{'packlist'}}); unlink($mod->{'packfile'}); return undef; } } # get_recommended_modules() # Returns a list of Perl modules used by other Webmin modules sub get_recommended_modules { local (@rv, %done); foreach my $m (&get_all_module_infos()) { next if (!$m->{'cpan'}); next if (!&foreign_installed($m->{'dir'})); local $mdir = &module_root_directory($m->{'dir'}); next if (!-r "$mdir/cpan_modules.pl"); &foreign_require($m->{'dir'}, "cpan_modules.pl"); foreach my $c (&foreign_call($m->{'dir'}, "cpan_recommended")) { if (!$done{$c}++) { push(@rv, [ $c, $m ]); } } } return sort { $a->[0] cmp $b->[0] } @rv; } # can_list_packaged_modules() # Returns 1 if we can install Perl modules from APT or YUM sub can_list_packaged_modules { return 0 if (!&foreign_check("software") || !$config{'incpackages'}); &foreign_require("software", "software-lib.pl"); return 0 if (!$software::update_system); return 1; } # list_packaged_modules([refresh]) # Returns a list of Perl modules that can be installed from the system's # package update service (ie YUM or APT). sub list_packaged_modules { local ($refresh) = @_; return ( ) if (!&foreign_check("software") || !$config{'incpackages'}); &foreign_require("software", "software-lib.pl"); return ( ) if (!$software::update_system); local @avail; local @st = stat($available_packages_cache); if ($refresh || !@st || $st[9] < time()-24*60*60) { # Keep cache for a day # Need to refresh @avail = &software::update_system_available(); open(CACHE, ">$available_packages_cache"); print CACHE &serialise_variable(\@avail); close(CACHE); } else { # Can use cache local $avail = &unserialise_variable( &read_file_contents($available_packages_cache)); @avail = @$avail; } local @rv; foreach my $a (@avail) { if ($a->{'name'} =~ /^lib(\S+)-perl$/ || # Debian $a->{'name'} =~ /^perl-(\S+)$/ || # Redhat $a->{'name'} =~ /^p5-(\S+)$/) { # FreeBSD local $mod = $1; $mod =~ s/-/::/g; if ($mod eq "LDAP") { # Special case for redhat-ish systems $mod = "Net::LDAP"; } elsif ($mod eq "perl::ldap") { # Special case for FreeBSD $mod = "Net::LDAP"; } push(@rv, { 'mod' => $mod, 'package' => $a->{'name'}, 'version' => $a->{'version'}, }); } } return @rv; } # shared_perl_root() # Returns 1 if Perl is shared with the root zone, indicating that Perl modules # cannot be installed. sub shared_perl_root { return 0 if (!&running_in_zone()); local $pp = &get_perl_path(); if (&foreign_exists("mount")) { &foreign_require("mount", "mount-lib.pl"); local @rst = stat($pp); local $m; foreach $m (&mount::list_mounted()) { local @mst = stat($m->[0]); if ($mst[0] == $rst[0] && &is_under_directory($m->[0], $pp)) { # Found the mount! if ($m->[2] eq "lofs" || $m->[2] eq "nfs") { return 1; } } } } return 0; } # get_nice_perl_version() # Returns the Perl version is human-readable format sub get_nice_perl_version { local $ver = $^V; if ($ver =~ /^v/) { return $ver; } else { return join(".", map { ord($_) } split(//, $^V)); } } 1;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 1.88 KB | 0644 |
|
cgi_args.pl | File | 124 B | 0755 |
|
config | File | 153 B | 0644 |
|
config-solaris | File | 202 B | 0644 |
|
config.info | File | 442 B | 0644 |
|
config.info.ca | File | 539 B | 0644 |
|
config.info.cs | File | 494 B | 0644 |
|
config.info.de | File | 544 B | 0644 |
|
config.info.es | File | 351 B | 0644 |
|
config.info.fr | File | 504 B | 0644 |
|
config.info.hr | File | 0 B | 0644 |
|
config.info.hu | File | 72 B | 0644 |
|
config.info.it | File | 517 B | 0644 |
|
config.info.ja | File | 611 B | 0644 |
|
config.info.ko | File | 457 B | 0644 |
|
config.info.ms | File | 473 B | 0644 |
|
config.info.nl | File | 476 B | 0644 |
|
config.info.no | File | 459 B | 0644 |
|
config.info.pl | File | 505 B | 0644 |
|
config.info.ru | File | 292 B | 0644 |
|
config.info.sv | File | 76 B | 0644 |
|
config.info.uk | File | 305 B | 0644 |
|
config.info.zh | File | 244 B | 0644 |
|
config.info.zh_TW | File | 224 B | 0644 |
|
cpan-lib.pl | File | 11.04 KB | 0755 |
|
cpan.cgi | File | 3.36 KB | 0755 |
|
delete_file.cgi | File | 312 B | 0755 |
|
download.cgi | File | 10.56 KB | 0755 |
|
edit_mod.cgi | File | 2.35 KB | 0755 |
|
index.cgi | File | 4.28 KB | 0755 |
|
install.cgi | File | 3.61 KB | 0755 |
|
module.info | File | 160 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 127 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 178 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 185 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 201 B | 0644 |
|
module.info.ca | File | 124 B | 0644 |
|
module.info.ca.auto | File | 13 B | 0644 |
|
module.info.cs | File | 21 B | 0644 |
|
module.info.cs.auto | File | 122 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 129 B | 0644 |
|
module.info.de | File | 126 B | 0644 |
|
module.info.de.auto | File | 13 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 216 B | 0644 |
|
module.info.es | File | 32 B | 0644 |
|
module.info.es.auto | File | 104 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 134 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 224 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 114 B | 0644 |
|
module.info.fr | File | 28 B | 0644 |
|
module.info.fr.auto | File | 115 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 155 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 134 B | 0644 |
|
module.info.hu | File | 21 B | 0644 |
|
module.info.hu.auto | File | 121 B | 0644 |
|
module.info.it | File | 20 B | 0644 |
|
module.info.it.auto | File | 107 B | 0644 |
|
module.info.ja | File | 29 B | 0644 |
|
module.info.ja.auto | File | 171 B | 0644 |
|
module.info.ko | File | 20 B | 0644 |
|
module.info.ko.auto | File | 110 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 140 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 121 B | 0644 |
|
module.info.ms | File | 109 B | 0644 |
|
module.info.ms.auto | File | 13 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 126 B | 0644 |
|
module.info.nl | File | 28 B | 0644 |
|
module.info.nl.auto | File | 114 B | 0644 |
|
module.info.no | File | 21 B | 0644 |
|
module.info.no.auto | File | 109 B | 0644 |
|
module.info.pl | File | 111 B | 0644 |
|
module.info.pl.auto | File | 13 B | 0644 |
|
module.info.pt | File | 0 B | 0644 |
|
module.info.pt.auto | File | 132 B | 0644 |
|
module.info.pt_BR | File | 0 B | 0644 |
|
module.info.pt_BR.auto | File | 141 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 127 B | 0644 |
|
module.info.ru | File | 26 B | 0644 |
|
module.info.ru.auto | File | 165 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 149 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 112 B | 0644 |
|
module.info.sv | File | 21 B | 0644 |
|
module.info.sv.auto | File | 101 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 226 B | 0644 |
|
module.info.tr | File | 0 B | 0644 |
|
module.info.tr.auto | File | 139 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 185 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 214 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 164 B | 0644 |
|
module.info.zh | File | 20 B | 0644 |
|
module.info.zh.auto | File | 93 B | 0644 |
|
module.info.zh_TW | File | 22 B | 0644 |
|
module.info.zh_TW.auto | File | 99 B | 0644 |
|
postinstall.pl | File | 239 B | 0755 |
|
uninstall.cgi | File | 1.16 KB | 0755 |
|
uninstall_mods.cgi | File | 1.33 KB | 0755 |
|