diff --git a/blue-theme/bsdfdisk/images/icon.gif b/blue-theme/bsdfdisk/images/icon.gif new file mode 100644 index 000000000..41d7ddaa4 Binary files /dev/null and b/blue-theme/bsdfdisk/images/icon.gif differ diff --git a/bsdfdisk/bsdfdisk-lib.pl b/bsdfdisk/bsdfdisk-lib.pl index a3bf84fa7..deb01670a 100644 --- a/bsdfdisk/bsdfdisk-lib.pl +++ b/bsdfdisk/bsdfdisk-lib.pl @@ -11,4 +11,119 @@ use WebminCore; &init_config(); &foreign_require("mount"); +sub check_fdisk +{ +if (!&has_command("fdisk")) { + return &text('index_ecmd', "fdisk"); + } +return undef; +} + +# list_disks_partitions() +# Returns a list of all disks, partitions and slices +sub list_disks_partitions +{ +my @rv; + +# Iterate over disk devices +foreach my $dev (glob("/dev/ada[0-9]"), + glob("/dev/ad[0-9]"), + glob("/dev/da[0-9]")) { + next if (!-r $dev || -l $dev); + my $disk = { 'device' => $dev, + 'prefix' => $dev, + 'parts' => [ ] }; + if ($dev =~ /^\/dev\/(.*)/) { + $disk->{'short'} = $1; + } + push(@rv, $disk); + + # Get size and partitions + my $out = &backquote_command("fdisk $dev"); + my @lines = split(/\r?\n/, $out); + my $part; + for(my $i=0; $i<@lines; $i++) { + if ($lines[$i] =~ /cylinders=(\d+)\s+heads=(\d+)\s+sectors\/tracks=(\d+)\s+\((\d+)/) { + # Disk information + # XXX model and size? + $disk->{'cylinders'} = $1; + $disk->{'heads'} = $2; + $disk->{'sectors'} = $3; + $disk->{'blksper'} = $4; + $disk->{'size'} = $disk->{'cylinders'} * + $disk->{'blksper'} * 512; + $disk->{'index'} = scalar(@rv); + } + elsif ($lines[$i] =~ /data\s+for\s+partition\s+(\d+)/ && + $lines[$i+1] !~ //) { + # Start of a partition + $part = { 'number' => $2, + 'device' => $dev."p".$2, + 'index' => scalar(@{$disk->{'parts'}}) }; + push(@{$disk->{'parts'}}, $part); + } + elsif ($lines[$i] =~ /sysid\s+(\d+)/ && $part) { + # Partition type + $part->{'type'} = $2; + } + elsif ($lines[$i] =~ /start\s+(\d+),\s+size\s+(\d+)\s+\((.*)\)/ && $part) { + # Partition start and size + $part->{'blocks'} = $2; + $part->{'size'} = &string_to_size("$3"); + } + elsif ($lines[$i] =~ /beg:\s+cyl\s+(\d+)/ && $part) { + # Partition start + $part->{'start'} = $1; + } + elsif ($lines[$i] =~ /end:\s+cyl\s+(\d+)/ && $part) { + # Partition end + $part->{'end'} = $1; + } + } + + # Get disk model from dmesg + open(DMESG, "/var/run/dmesg.boot"); + while() { + if (/^(\S+):\s+<(.*)>/ && $1 eq $disk->{'short'}) { + $disk->{'model'} = $2; + } + elsif (/^(\S+):\s+(\d+)(\S+)\s+\((\d+)\s+(\d+)\s+byte\s+sectors/ && + $1 eq $disk->{'short'}) { + $disk->{'sectorsize'} = $5; + $disk->{'size'} = &string_to_size("$2 $3"); + } + } + close(DMESG); + + # Get slices within partitions + # XXX + } + +return @rv; +} + +# string_to_size(str) +# Convert a string like 100 Meg to a number in bytes +sub string_to_size +{ +my ($str) = @_; +my ($n, $pfx) = split(/\s+/, $str); +if ($pfx =~ /^b/i) { + return $n; + } +if ($pfx =~ /^k/i) { + return $n * 1024; + } +if ($pfx =~ /^m/i) { + return $n * 1024 * 1024; + } +if ($pfx =~ /^g/i) { + return $n * 1024 * 1024 * 1024; + } +if ($pfx =~ /^t/i) { + return $n * 1024 * 1024 * 1024 * 1024; + } +return undef; +} + 1; diff --git a/bsdfdisk/index.cgi b/bsdfdisk/index.cgi new file mode 100644 index 000000000..9336135df --- /dev/null +++ b/bsdfdisk/index.cgi @@ -0,0 +1,38 @@ +#!/usr/local/bin/perl +# Show a list of disks + +use strict; +use warnings; +require './bsdfdisk-lib.pl'; +our (%in, %text, %config, $module_name); + +&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0); + +my $err = &check_fdisk(); +if ($err) { + &ui_print_endpage(&text('index_problem', $err)); + } + +my @disks = &list_disks_partitions(); +@disks = sort { $a->{'device'} cmp $b->{'device'} } @disks; +if (@disks) { + print &ui_columns_start([ $text{'index_dname'}, + $text{'index_dsize'}, + $text{'index_dmodel'}, + $text{'index_dparts'} ]); + foreach my $d (@disks) { + print &ui_columns_row([ + "".&html_escape($d->{'device'})."", + &nice_size($d->{'size'}), + $d->{'model'}, + scalar(@{$d->{'parts'}}), + ]); + } + print &ui_columns_end(); + } +else { + print "$text{'index_none'}

\n"; + } + +&ui_print_footer("/", $text{'index'}); diff --git a/bsdfdisk/lang/en b/bsdfdisk/lang/en index 62c24279f..01d963290 100644 --- a/bsdfdisk/lang/en +++ b/bsdfdisk/lang/en @@ -1 +1,8 @@ index_title=Partitions on Local Disks +index_ecmd=The required command $1 is missing +index_problem=This module cannot be used : $1 +index_none=No disks were found on this system! +index_dname=Disk name +index_dsize=Total size +index_dmodel=Make and model +index_dparts=Partitions diff --git a/gray-theme/bsdfdisk b/gray-theme/bsdfdisk new file mode 120000 index 000000000..7764e2b6b --- /dev/null +++ b/gray-theme/bsdfdisk @@ -0,0 +1 @@ +../blue-theme/bsdfdisk \ No newline at end of file diff --git a/software/ports-lib.pl b/software/ports-lib.pl index 761ab2a74..95e8eeb4a 100644 --- a/software/ports-lib.pl +++ b/software/ports-lib.pl @@ -111,6 +111,7 @@ return $name eq "apache" ? "apache22 ap22-mod_.*" : $name eq "openssh" ? "openssh-portable" : $name eq "postgresql" ? "postgresql-server" : $name eq "openldap" ? "openldap-server openldap-client" : + $name eq "samba" ? "samba36 samba36-nmblookup samba36-smbclient" : $name; }