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

📄 save_mount.cgi

📁 Unix下基于Web的管理工具
💻 CGI
字号:
#!/usr/local/bin/perl# save_mount.cgi# Save or create a mount. When saving an existing mount, at lot of different# things can happen. require './mount-lib.pl';$whatfailed = "Failed to save mount";&ReadParse;$| = 1;# check inputsif ($in{type} ne "swap") {	$in{directory} =~ /^\// ||		&error("$in{directory} is not a valid directory name");	if (-r $in{directory} && !(-d $in{directory})) {		&error("$in{directory} is not a directory");		}	# non-existant directories get created later	}else {	# for swap files, set the directory to 'swap'	$in{directory} = "swap";	}# Get user choices@mmodes = &mount_modes($in{type});$msave = ($mmodes[0]==0 ? 0 : $in{msave});$mnow = ($mmodes[1]==0 ? $msave : $in{mmount});if (defined($in{old})) {	# Get info about the old mount	if ($in{temp}) { @mlist = &list_mounted(); }	else { @mlist = &list_mounts(); }	@mold = @{$mlist[$in{old}]};	if (!$mnow && !$in{oldmnow} && !$msave) {		# Not mounted, so remove from fstab without checking		$dev = $mold[1];		}	else {		# Changing an existing mount		$dev = &check_location($in{'type'});		&parse_options($mold[2], $mold[3]);		$opts = &check_options($in{'type'}, $dev, $in{'directory'});		@minfo = ($in{'directory'}, $dev, $in{'type'}, $opts,			  $mmodes[2] ? $in{'order'} : "-",			  $in{'msave'}==2||$mmodes[0]==1 ? "yes" : "no");		}	# Check for change in device	if ($mold[1] ne $dev) {		# Device has changed..check it		if (!&multiple_mount($minfo[2]) && &get_mounted("*", $dev)>=0) {			error("'$dev' is already mounted");			}		if (!&multiple_mount($minfo[2]) && &get_mount("*", $dev) != -1){			&error("'$dev' is already assigned to be mounted");			}		$changed = 1;		}	# Check for change in directory	if ($in{type} ne "swap" && $mold[0] ne $in{directory}) {		# Directory has changed.. check it too		if (&get_mounted($in{directory}, "*")>=0) {			&error("The directory '$in{directory}' ".			       "is alread mounted");			}		if (&get_mount($in{directory}, "*") != -1) {			&error("The directory '$in{directory}' is already ".			       "assigned for mounting");			}		$changed = 1;		if (!(-d $in{directory})) {			# Create the new directory			mkdir($in{directory}, 0755) ||				&error("Failed to create directory ".				       "$in{directory} : $!");			$made_dir = 1;			}		}	# Check for change in current mount status	if ($in{'oldmnow'} && $mmodes[3] == 1) {		# Mounted, and cannot be unmounted		}	elsif ($in{'oldmnow'} && !$mnow) {		# Just been unmounted..		if ($error = &unmount_dir($mold[0], $mold[1], $in{type})) {			#if ($error =~ /busy/) {				# Mount is busy.. most likely because it is				# currently in use. Offer the user a choice				# to remove from the mount table only			#	}			#else { &error("Unmount failed : $error"); }			&error("Unmount failed : $error");			}		}	elsif ($mnow && !$in{oldmnow}) {		# Just been mounted..		if ($error = &mount_dir(@minfo)) {			&error("Mount failed : $error");			}		}	elsif (!$mnow && !$in{oldmnow}) {		# Not mounted, and doesn't need to be		}	elsif (($mold[0] ne $minfo[0] || $mold[1] ne $minfo[1] ||	       $mold[3] ne $minfo[3]) && !$in{'perm_only'}) {		# Need to unmount/mount to apply new options		if ($error = &unmount_dir($mold[0], $mold[1], $in{type})) {			if ($error =~ /busy|Invalid argument/ && $msave) {				# Mount is busy.. most likely because it is				# currently in use. Offer the user a choice				# to update only the fstab file, rather than				# the real mount				&header("Edit Mount", "");				print "<hr>\n";				print "The changes to the mount on\n";				print "<tt>$mold[0]</tt> could not be\n";				print "applied, as the mount is currently\n";				print "in use. To have your changes made to\n";				print "the permanent mount list only, click\n";				print "on the button below. <p>\n";				print "<form action=save_mount.cgi>\n";				print "<input type=hidden name=perm_only ",				      "value=1>\n";				foreach $k (keys %in) {					print "<input type=hidden name=$k ",					      "value=\"$in{$k}\">\n";					}				print "<center><input type=submit ",				      "value=\"Apply To Permanent List\">",				      "</center>\n";				print "</form>\n";				print "<hr>\n";				&footer("", "filesystems list");				exit;				}			else { &error("Remount failed : $error"); }			}		if ($error = &mount_dir(@minfo)) {			&error("Remount failed : $error");			}		}	# Check for change in permanence	if ($in{oldmsave} && !$msave) {		# Delete from mount table		&delete_mount($in{old});		}	elsif ($msave && !$in{oldmsave}) {		# Add to mount table		&create_mount(@minfo);		}	elsif (!$msave && !$in{oldmsave}) {		# Not in mount table		}	else {		# Apply any changes in mount options		&change_mount($in{old}, @minfo);		}	}else {	# Creating a new mount	$dev = &check_location($in{type});	&parse_options($minfo[3]);	$opts = &check_options($in{type}, $dev, $in{'directory'});	@minfo = ($in{directory}, $dev, $in{type}, $opts,		  $mmodes[2] ? $in{order} : "-",		  $in{msave}==2||$mmodes[0]==1 ? "yes" : "no");	# Check if anything is being done	if (!$msave && !$mnow) {		&error("You didn't choose to save or mount");		}	# Check if the device is in use	if (!&multiple_mount($minfo[2]) && &get_mounted("*", $dev)>=0) {		&error("'$dev' is already mounted");		}	if (!&multiple_mount($minfo[2]) && &get_mount("*", $dev) != -1) {		&error("'$dev' is already assigned to be mounted");		}	# Check if the directory is in use	if ($in{type} ne "swap") {		if (&get_mounted($in{directory}, "*")>=0) {			&error("The directory '$in{directory}' ".			       "is alread mounted");			}		if (&get_mount($in{directory}, "*") != -1) {			&error("The directory '$in{directory}' is already ".			       "assigned for mounting");			}		}	# Create the directory	if ($in{type} ne "swap" && !(-d $in{directory})) {		mkdir($in{directory}, 0755) ||		  &error("Failed to create directory $in{directory} : $!");		$made_dir = 1;		}	# If mounting now, attempt to do it	if ($mnow) {		# If the mount fails, give up totally		if ($error = &mount_dir($minfo[0], $minfo[1],					$minfo[2], $minfo[3])) {			if ($made_dir) { rmdir($in{directory}); }			&error("Failed to mount $in{directory} : $error");			}		}	# If saving, save now	if ($msave) {		&create_mount(@minfo);		}	}&redirect("");print "done redirect\n";# undo_changes# Put back any changes to the fstab filesub undo_changes{if ($in{temp} && $in{mboot}) {	# a mount was made permanent.. undo by deleting it	&delete_mount($idx);	}elsif (!$in{temp} && !$in{mboot}) {	# a permanent mount was made temporary.. undo by making it permanent	&create_mount(@mold);	}elsif ($in{mboot}) {	# some mount options were changed.. undo by changing back	&change_mount($in{old}, @mold);	}if ($made_dir) {	# A directory for mounting was created.. delete it	rmdir($in{directory});	}}

⌨️ 快捷键说明

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