perl 限制用户操作
发布时间:2020-12-15 23:52:18 所属栏目:大数据 来源:网络整理
导读:pre name="code" class="sql"#!/usr/bin/perluse strict;use Switch;use Sys::Hostname;use File::Basename;my $host = hostname;my $prompt = "$host ";my @allow_command=( "/bin/cat","/bin/pwd","/bin/date","/bin/df","/bin/dmesg","/bin/grep","/bin/h
<pre name="code" class="sql">#!/usr/bin/perl use strict; use Switch; use Sys::Hostname; use File::Basename; my $host = hostname; my $prompt = "$host >"; my @allow_command=( "/bin/cat","/bin/pwd","/bin/date","/bin/df","/bin/dmesg","/bin/grep","/bin/hostname","/bin/ls","/bin/netstat","/bin/ping","/bin/ps","/bin/rpm","/bin/sleep","/bin/sort","/bin/uname","/sbin/ifconfig","/usr/bin/clear","/usr/bin/du","/usr/bin/id","/usr/bin/vi","/bin/tar","/usr/kerberos/bin/ftp","export","/bin/echo","/bin/env","source","chdir",); my @allow_command2=map {basename("$_") } @allow_command; #print "@allow_command2n"; sub help() { print "Available commands:n"; print $_."n" foreach (@allow_command); } system("/usr/bin/clear"); while ("1") { my $command; print "$prompt " ; my $input_command=<STDIN>; chomp ($command=$input_command); next if $command eq ''; if ($command =~ /^(.|)/){print "Sorry,unknown command '$command',please run 'help' to show all the avaiable commands.n";}; exit if ($command =~ /^(quit|exit)$/); if ($command eq "help") { &help; next; } my ($binary,undef)=split /s+/,"$command"; if (grep m/$binary/,@allow_command or grep m/$binary/,@allow_command2 ) { system("$command"); } elsif ($binary eq "cd") {my $newdir=(split /s+/,"$command")[1]; chdir $newdir;} else{ print "Sorry,unknown command '$binary',please run 'help' to show all the avaiable commands.n";} } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |