⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux-lib.pl

📁 Unix下基于Web的管理工具
💻 PL
📖 第 1 页 / 共 4 页
字号:
		}	if ($?) { return "<pre>$out</pre>"; }	}elsif ($_[2] eq "auto") {	# Old automounter filesystem	$out = `amd $_[0] $_[1] >/dev/null 2>/dev/null`;	if ($?) { return "AMD failed"; }	}elsif ($_[2] eq "autofs") {	# New automounter filesystem	$opts = &autofs_args($_[3]);	$type = $_[1] !~ /^\// ? "yp" :		(-x $_[1]) ? "program" : "file";	$out = `automount $opts $_[0] $type $_[1] 2>&1`;	if ($?) { return "Automount failed : <pre>$out</pre>"; }	}elsif ($_[2] eq "smbfs") {	local $shar = $_[1];	$shar =~ s/\\/\//g;	if ($smbfs_support == 3) {		# SMB filesystem mounted with mount command		$opts = $_[3] eq "-" ? "" : "-o \"$_[3]\"";		$out = `mount -t $_[2] $opts $shar $_[0] 2>&1`;		if ($?) {			system("umount $_[0] >/dev/null 2>&1");			return "<pre>$out</pre>";			}		}	elsif ($smbfs_support == 2) {		# SMB filesystem mounted with version 2.x smbmount		&parse_options("smbfs", $_[3]);		$opts =		    ($options{'user'} ? "-U $options{'user'} " : "").		    ($options{'passwd'} ? "" : "-N ").		    ($options{'workgroup'} ? "-W $options{'workgroup'} " : "").		    ($options{'clientname'} ? "-n $options{'clientname'} " : "").		    ($options{'machinename'} ? "-I $options{'machinename'} " : "");		&foreign_require("proc", "proc-lib.pl");		local ($fh, $fpid) = &foreign_call("proc", "pty_process_exec",						   "sh", "-c", "smbmount $shar $_[0] -d 0 $opts");		if ($options{'passwd'}) {			local $w = &wait_for($fh, "word:");			if ($w < 0) {				system("umount $_[0] >/dev/null 2>&1");				return "Failed to connect to server";				}			local $p = "$options{'passwd'}\n";			syswrite($fh, $p, length($p));			}		local $got;		while(<$fh>) {			$got .= $_;			}		if ($got =~ /failed/) {			system("umount $_[0] >/dev/null 2>&1");			return "<pre>$got</pre>\n";			}		close($fh);		}	elsif ($smbfs_support == 1) {		# SMB filesystem mounted with older smbmount		&parse_options("smbfs", $_[3]);		$shortname = &get_system_hostname();		if ($shortname =~ /^([^\.]+)\.(.+)$/) { $shortname = $1; }		$opts =		   ($options{servername} ? "-s $options{servername} " : "").		   ($options{clientname} ? "-c $options{clientname} "					 : "-c $shortname ").		   ($options{machinename} ? "-I $options{machinename} " : "").		   ($options{user} ? "-U $options{user} " : "").		   ($options{passwd} ? "-P $options{passwd} " : "-n ").		   ($options{uid} ? "-u $options{uid} " : "").		   ($options{gid} ? "-g $options{gid} " : "").		   ($options{fmode} ? "-f $options{fmode} " : "").		   ($options{dmode} ? "-d $options{dmode} " : "");		$out = `smbmount $shar $_[0] $opts 2>&1`;		if ($out) {			system("umount $_[0] >/dev/null 2>&1");			return "<pre>$out</pre>";			}		}	&read_smbopts();	$smbopts{$_[0]} = $_[3] eq "-" ? "dummy=1" : $_[3];	&write_smbopts();	}else {	# some filesystem supported by mount	$opts = $_[3] eq "-" ? "" : "-o \"$_[3]\"";	$out = `mount -t $_[2] $opts $_[1] $_[0] 2>&1`;	if ($?) { return "<pre>$out</pre>"; }	}return 0;}# unmount_dir(directory, device, type)# Unmount a directory that is currently mounted. Returns 0 if ok,# or an error string if failedsub unmount_dir{local($out, %smbopts, $dir);if ($_[2] eq "swap") {	# Use swapoff to remove the swap space..	$out = `swapoff $_[1]`;	if ($?) { return "<pre>$out</pre>"; }	}elsif ($_[2] eq "auto") {	# Kill the amd process	$dir = $_[0];	if (`cat /etc/mtab` =~ /:\(pid([0-9]+)\)\s+$dir\s+(auto|nfs)\s+/) {		kill('TERM', $1) || return "Failed to kill AMD";		}	sleep(2);	}elsif ($_[2] eq "autofs") {	# Kill the automount process	$dir = $_[0];	`cat /etc/mtab` =~ /automount\(pid([0-9]+)\)\s+$dir\s+autofs\s+/;	kill('TERM', $1) || return "Failed to kill automount";	sleep(2);	}else {	$out = `umount $_[0] 2>&1`;	if ($?) { return "<pre>$out</pre>"; }	if ($_[2] eq "smbfs") {		# remove options from list		&read_smbopts();		delete($smbopts{$_[0]});		&write_smbopts();		}	}return 0;}# mount_modes(type)# Given a filesystem type, returns 4 numbers that determine how the file# system can be mounted, and whether it can be fsck'd#  0 - cannot be permanently recorded#	(smbfs under linux before 2.2)#  1 - can be permanently recorded, and is always mounted at boot#	(swap under linux)#  2 - can be permanently recorded, and may or may not be mounted at boot#	(most normal filesystems)# The second is:#  0 - mount is always permanent => mounted when saved#	(swap under linux before 2.2)#  1 - doesn't have to be permanent#	(normal fs types)# The third is:#  0 - cannot be fsck'd at boot time#  1 - can be be fsck'd at boot# The fourth is:#  0 - can be unmounted#  1 - cannot be unmountedsub mount_modes{if ($_[0] eq "swap")	{ return (1, $swaps_support ? 1 : 0, 0, 0); }elsif ($_[0] eq "auto" || $_[0] eq "autofs")	{ return (1, 1, 0, 0); }elsif ($_[0] eq "smbfs")	{ return ($smbfs_support == 3 ? 2 : 0, 1, 0, 0); }elsif ($_[0] eq "ext2" || $_[0] eq "minix" || $_[0] eq "xiafs")	{ return (2, 1, 1, 0); }else	{ return (2, 1, 0, 0); }}# disk_space(type, directory)# Returns the amount of total and free space for some filesystem, or an# empty array if not appropriate.sub disk_space{if (&get_mounted($_[1], "*") < 0) { return (); }if ($_[0] eq "proc" || $_[0] eq "swap" ||    $_[0] eq "auto" || $_[0] eq "autofs") { return (); }`df -k $_[1]` =~ /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/;return ($1, $2);}# list_fstypes()# Returns an array of all the supported filesystem types. If a filesystem is# found that is not one of the supported types, generate_location() and# generate_options() will not be called for it.sub list_fstypes{local @sup = ("ext2", "minix", "msdos", "nfs", "iso9660", "ext", "xiafs",	      "hpfs", "fat", "vfat", "umsdos", "sysv");push(@sup, "smbfs") if ($smbfs_support);push(@sup, "auto") if ($amd_support);push(@sup, "autofs") if ($autofs_support);push(@sup, "swap");return @sup;}# fstype_name(type)# Given a short filesystem type, return a human-readable name for itsub fstype_name{local(%fsmap);%fsmap = ("ext2","Linux Native Filesystem",	  "minix","Minix Filesystem",	  "msdos","MS-DOS Filesystem",	  "nfs","Network Filesystem",	  "smbfs","Windows Networking Filesystem",	  "iso9660","ISO9660 CD-ROM",	  "ext","Old EXT Linux Filesystem",	  "xiafs","Old XIAFS Linux Filesystem",	  "hpfs","OS/2 Filesystem",	  "fat","MS-DOS Filesystem",	  "vfat","Windows 95 Filesystem",	  "umsdos","Linux on top of MS-DOS Filesystem",	  "sysv","System V Filesystem",	  "swap","Virtual Memory",	  "proc","Kernel Filesystem",	  "devpts","PTS Filesystem",	  "auto",($autofs_support ? "Old " : "")."Automounter Filesystem",	  "autofs","New Automounter Filesystem");return $config{long_fstypes} && $fsmap{$_[0]} ? $fsmap{$_[0]} : uc($_[0]);}# multiple_mount(type)# Returns 1 if filesystems of this type can be mounted multiple times, 0 if notsub multiple_mount{return ($_[0] eq "nfs" || $_[0] eq "auto" || $_[0] eq "autofs");}# generate_location(type, location)# Output HTML for editing the mount location of some filesystem.sub generate_location{if ($_[0] eq "nfs") {	# NFS mount from some host and directory	$_[1] =~ /^([^:]+):(.*)$/;	print "<tr> <td><b>NFS Hostname</b></td>\n";	print "<td><input name=nfs_host size=20 value=\"$1\">\n";	&nfs_server_chooser_button("nfs_host");	print "&nbsp;<b>NFS Directory</b>\n";	print "<input name=nfs_dir size=20 value=\"$2\">\n";	&nfs_export_chooser_button("nfs_host", "nfs_dir");	print "</td> </tr>\n";	}elsif ($_[0] eq "auto") {	# Using some automounter map	print "<tr> <td><b>Automounter Map</b></td>\n";	print "<td><input name=auto_map size=20 value=\"$_[1]\">\n";	print &file_chooser_button("auto_map", 0);	print "</td> <td colspan=2></td> </tr>\n";	}elsif ($_[0] eq "autofs") {	# Using some kernel automounter map	print "<tr> <td><b>Automounter Map</b></td>\n";	print "<td><input name=autofs_map size=20 value=\"$_[1]\">\n";	print &file_chooser_button("autofs_map", 0);	print "</td> <td colspan=2></td> </tr>\n";	}elsif ($_[0] eq "swap") {	# Swap file or device	&foreign_require("fdisk", "fdisk-lib.pl");	printf "<tr> <td valign=top><b>Swap File</b></td>\n";	print "<td colspan=3>\n";	local $found;	local $sel = &foreign_call("fdisk", "partition_select", "lnx_disk",				   $_[1], 3, \$found);	printf "<input type=radio name=lnx_dev value=0 %s> Disk %s<br>\n",		$found ? "checked" : "", $sel;	printf "<input type=radio name=lnx_dev value=1 %s> Swap file\n",		$found ? "" : "checked";	printf "<input name=lnx_other size=35 value='%s'><br>\n",		$found ? "" : $_[1];	print "</td> </tr>\n";	}elsif ($_[0] eq "smbfs") {	# Windows filesystem	$_[1] =~ /^\\\\(.*)\\(.*)$/;	print "<tr> <td><b>Server Name</b></td>\n";	print "<td><input name=smbfs_server value=\"$1\" size=20>\n";	&smb_server_chooser_button("smbfs_server");	print "</td>\n";	print "<td><b>Share Name</b></td>\n";	print "<td><input name=smbfs_share value=\"$2\" size=20>\n";	&smb_share_chooser_button("smbfs_server", "smbfs_share");	print "</td> </tr>\n";	}else {	# This is some linux disk-based filesystem	&foreign_require("fdisk", "fdisk-lib.pl");	printf "<tr> <td valign=top><b>%s Disk</b></td>\n", &fstype_name($_[0]);	print "<td colspan=3>\n";	local $found;	local $sel = &foreign_call("fdisk", "partition_select", "lnx_disk",				   $_[1], 0, \$found);	printf "<input type=radio name=lnx_dev value=0 %s> Disk %s<br>\n",		$found ? "checked" : "", $sel;	printf "<input type=radio name=lnx_dev value=1 %s> Other device\n",		$found ? "" : "checked";	printf "<input name=lnx_other size=35 value='%s'><br>\n",		$found ? "" : $_[1];	print "</td> </tr>\n";	}}# generate_options(type, newmount)# Output HTML for editing mount options for a particular filesystem # under this OSsub generate_options{if ($_[0] ne "swap" && $_[0] ne "auto" &&    $_[0] ne "autofs" && $_[0] ne "smbfs") {	# Lots of options are common to all linux filesystems	print "<tr> <td><b>Read-only?</b></td>\n";	printf "<td nowrap><input type=radio name=lnx_ro value=1 %s> Yes\n",		defined($options{"ro"}) ? "checked" : "";	printf "<input type=radio name=lnx_ro value=0 %s> No</td>\n",		defined($options{"ro"}) ? "" : "checked";	print "<td><b>Buffer writes to filesystem?</b></td>\n";	printf"<td nowrap><input type=radio name=lnx_sync value=0 %s> Yes\n",		defined($options{"sync"}) ? "" : "checked";	printf "<input type=radio name=lnx_sync value=1 %s> No</td> </tr>\n",		defined($options{"sync"}) ? "checked" : "";	print "<tr> <td><b>Allow device files?</b></td>\n";	printf "<td nowrap><input type=radio name=lnx_nodev value=0 %s> Yes\n",		defined($options{"nodev"}) ? "" : "checked";	printf "<input type=radio name=lnx_nodev value=1 %s> No</td>\n",		defined($options{"nodev"}) ? "checked" : "";	print "<td><b>Allow execution of binaries?</b></td>\n";	printf"<td nowrap><input type=radio name=lnx_noexec value=0 %s> Yes\n",		defined($options{"noexec"}) ? "" : "checked";	printf "<input type=radio name=lnx_noexec value=1 %s> No</td> </tr>\n",		defined($options{"noexec"}) ? "checked" : "";	print "<tr> <td><b>Disallow setuid programs?</b></td>\n";	printf "<td nowrap><input type=radio name=lnx_nosuid value=1 %s> Yes\n",		defined($options{"nosuid"}) ? "checked" : "";	printf "<input type=radio name=lnx_nosuid value=0 %s> No</td>\n",		defined($options{"nosuid"}) ? "" : "checked";	print "<td><b>Allow users to mount this filesystem?</b></td>\n";	printf"<td nowrap><input type=radio name=lnx_user value=1 %s> Yes\n",		defined($options{"user"}) ? "checked" : "";	printf "<input type=radio name=lnx_user value=0 %s> No</td> </tr>\n",		defined($options{"user"}) ? "" : "checked";	}	if ($_[0] eq "ext2") {	# Ext2 has lots more options..	print "<tr> <td><b>Check mode</b></td>\n";	print "<td><select name=ext2_check>\n";	printf "<option value=normal %s> Normal\n",		$options{"check"} eq "" || $options{"check"} eq "normal" ?			"selected" : "";	printf "<option value=normal %s> Strict\n",		$options{"check"} eq "strict" ? "selected" : "";	printf "<option value=normal %s> None\n",		$options{"check"} eq "none" || defined($options{"nocheck"}) ?			"selected" : "";	print "</select></td>\n";	print "<td><b>Action on error</b></td>\n";	print "<td><select name=ext2_errors>\n";	printf "<option value=default %s> Default\n",		!defined($options{"errors"}) ? "selected" : "";	printf "<option value=continue %s> Continue\n",		$options{"error"} eq "continue" ? "selected" : "";	printf "<option value=remount-ro %s> Remount-ro\n",		$options{"error"} eq "remount-ro" ? "selected" : "";	printf "<option value=panic %s> Panic\n",		$options{"error"} eq "panic" ? "selected" : "";	print "</select></td> </tr>\n";	print "<tr> <td><b>Files inherit parent GID?</b></td>\n";	printf "<td nowrap><input type=radio name=ext2_grpid value=0 %s> Yes\n",		defined($options{"grpid"}) || defined($options{"bsdgroups"}) ?			"" : "checked";	printf "<input type=radio name=ext2_grpid value=1 %s> No</td>\n",		defined($options{"grpid"}) || defined($options{"bsdgroups"}) ?			"checked" : "";	print "<td><b>Use Quotas?</b></td>\n";	local $usrquota = defined($options{"usrquota"});	local $grpquota = defined($options{"grpquota"});	print "<td nowrap><select name=ext2_quota>\n";	printf "<option value=0 %s> No\n",		$usrquota || $grpquota ? "" : "selected";	printf "<option value=1 %s> User only\n",		$usrquota && !$grpquota ? "selected" : "";	printf "<option value=2 %s> Group only\n",		$grpquota && !$usrquota ? "selected" : "";	if (`uname -r` =~ /^2\.0\.(\d+)/ && $1 < 31) {		printf "<option value=3 %s> User and Group (UNSTABLE!)\n",			$usrquota && $grpquota ? "selected" : "";		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -