zoukankan      html  css  js  c++  java
  • perl 限制用户操作

    <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_command2
    ";
    sub help() {
        print "Available commands:
    ";
        print $_."
    " 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.
    ";};
        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.
    ";}
    }


    
    
    
                                        
    
  • 相关阅读:
    Docker 安装各种环境
    N级树形菜单封装
    一个周期算出所有高电平的个数
    DDR3新版(3):DDR3自动读写控制器
    DDR3_新版(2):IP核再封装
    数电(6):时序逻辑电路
    Vue表单那些事
    liunx环境修改minio默认端口和后台启动
    liunx 后台启动mongodb服务
    liunx安装和部署nacos配置中心
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352027.html
Copyright © 2011-2022 走看看