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

📄 filemgr.pl

📁 filemgr
💻 PL
字号:
#!/usr/bin/perl 
#改成你的主机上的PERL解释器路径
$password = '123';
#改成你想使用的密码

####################
# 以下内容无须更改 #
####################
sub get_request {
    if ($ENV{'REQUEST_METHOD'} eq "POST") {
        read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
    } elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
        $request = $ENV{'QUERY_STRING'};
    } else {
        while (read (STDIN, $chunck, 10))
        {
            $request = $request . $chunck;
        }
    }

    %args = &url_decode(split(/[&=]/, $request));
}

sub url_decode {

    foreach (@_) {
        tr/+/ /;
        s/%(..)/pack("c",hex($1))/ge;
    }
    @_;
}

sub html_header {

    local($title) = @_;

    print "Content-type: text/html\n\n";
    print "<html><head>\n";
    print "<title>$title</title>\n";
    print "</head>\n<body background='nettext.gif' bgproperties='fixed'>\n";
}

sub small_html_header {

    # Subroutine html_header sends to Standard Output the necessary
    # material to form an HHTML header for the document to be
    # returned, the single argument is the TITLE field.

    local($title) = @_;

    print "<html><head>\n";
    print "<title>$title</title>\n";
    print "</head>\n<body background='nettext.gif' bgproperties='fixed'>\n";
}

sub html_trailer {

    # subroutine html_trailer sends the trailing material to the HTML
    # on STDOUT.

    local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
        = gmtime;

    local($mname) = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
                     "Aug", "Sep", "Oct", "Nov", "Dec")[$mon];
    local($dname) = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
                     "Sat")[$wday]; 

    print "<p>\n本程序汉化:小狼<br>\n";
    print "现在时间: $hour:$min:$sec UT on $dname $mday $mname $year.<p>\n";
    print "</body></html>\n";
}
1;


get_request();

# Removes <cr> from contents
$args{'contents'} =~ tr/\r//d;

html_header("WEB网页处理系统V1.1");
print "<h3>WEB网页处理系统V1.1</h3>\n";
print "要处理的文件:$args{'filename'}<br><br>\n";

#print "filename=$args{'filename'}<br>\n";
#print "action=$args{'action'}<br>\n";
#print "perm=$args{'perm'}<br>\n";
#print "type=$args{'type'}<br>\n";
#print "password=$args{'password'}<br>\n";
#print "contents=$args{'contents'}<br>\n";

# Verify password
if ($args{'password'} ne $password)
{
  print ("Invalid password!<br>\n");
  html_trailer ();
  exit;
}

# Go!
if ($args{'action'} eq 'create')
{
  # Create/Replace
  $err = create_append_file ('create');

  # Change permission
  if (!$err)
  {
    chmod_file();
  }
}
elsif ($args{'action'} eq 'append')
{
  # Append
  $err = create_append_file ('append');

  # Change permission
  if (!$err)
  {
    chmod_file();
  }
}
elsif ($args{'action'} eq 'remove')
{
  # Remove
  $err = remove_file ();
}
elsif ($args{'action'} eq 'perm')
{
  # Just change permission
  $err = chmod_file ();
}
elsif ($args{'action'} eq 'view')
{
  # Just change permission
  $err = view_file ();
}
else
{
  # Invalid action
  print ("Invalid Action!<br>\n");
  html_trailer ();
  exit 1;
}

if ($args{'action'} ne 'view')
{
  html_trailer ();
}
exit $err;



# Create/append to file
# usage: create_append_file (mode)
# where mode = 'create' or 'append'
sub create_append_file {
  # open file
  if (@_[0] eq 'create')
  {
    # create/replace file
    print ("打开文件... ");
    $err = open (FILE, ">$args{'filename'}");
  }
  elsif (@_[0] eq 'append')
  {
    # append to file
    # Append only text files
    if ($args{'type'} ne 'text')
    {
      print ("Can only append to text files!<br>\n");
      return 1;
    }
    print ("创建文件... ");
    $err = open (FILE, ">>$args{'filename'}");
  }
  else
  {
    printf "Invalid operation '@_[0]'!<br>\n";
    return 1;
  }
  if ($err == 1)
  {
    printf "ok.<br><br>\n";
  }
  else
  {
    printf "$!<br><br>\n";
    return 1;
  }
  
  # add contents
  if ($args{'type'} eq 'text')
  {
    # text files
    $data = $args{'contents'};
  }
  elsif ($args{'type'} eq 'bin')
  {
    # binary files
    # unpack line by line
    foreach $line (split (/\n/, $args{'contents'}))
    {
      $data = $data . unpack ('u', $line);
    }
  }
  else
  {
    printf "Invalid file type '$args{'type'}'!<br>\n";
    return 1;
  }

  # write data to file
  printf "写入文件... ";
  $err = print FILE $data;
  if ($err == 1)
  {
    printf "ok.<br><br>\n";
  }
  else
  {
    printf "$!<br><br>\n";
    close FILE;
    return 1;
  }

  # close file
  close FILE;
  
  # Ok.
  return 0;
}

# Remove file
sub remove_file {
  # Remove the file
  print ("删除文件... ");
  $err = unlink ($args{'filename'});
  if ($err == 1)
  {
    printf "ok.<br><br>\n";
  }
  else
  {
    printf "$!<br><br>\n";
    return 1;
  }

  # Ok.
  return 0;
}

# Change file permissions
sub chmod_file {
  if ($args{'perm'})
  {
    print "把文件属性改为 $args{'perm'}... ";
    $err = chmod oct($args{'perm'}), $args{'filename'};
    if ($err == 1)
    {
      printf "ok.<br><br>\n";
    }
    else
    {
      printf "$!<br><br>\n";
      return 1;
    }
  }

  # Ok.
  return 0;
}

# View file
sub view_file {
  # open file
  print ("打开文件... ");
  $err = open (FILE, "<$args{'filename'}");
  if ($err == 1)
  {
    printf "ok.<br><br>\n";
  }
  else
  {
    printf "$!<br><br>\n";
    return 1;
  }

  # File stats
  ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat (FILE);
  $moddate = localtime ($mtime);
  #print "Owner (uid:gid): $uid:$gid<br><br>\n";
  print "大小:$size 字节<br><br>\n";
  print "上次修改:$moddate<br><br>\n";
  print "模式:$mode<br><br>\n";
  print "属性:";
  print "可读" if -r _;
  print "、可写" if -w _;
  print "、可执行" if -x _;

  # Display file
  # Append only text files
  if ($args{'type'} eq 'text')
  {
    @lines = <FILE>;
    close (FILE);
    print <<EOF;
<form method="POST" action="filemgr.pl">
  <p>文件名: <input type="text" name="filename" size="65" maxlength="256"
  value="$args{'filename'}"><br><br>
  任务: <select name="action" size="1">
    <option selected value="create">修改</option>
    <option value="append">添加</option>
    <option value="remove">删除</option>
    <option value="perm">改变属性</option>
    <option value="view">查看</option>
  </select><br><br>
  属性: <input type="text" name="perm" size="4" maxlength="4"><br><br>
  文件类型: <select name="type" size="1">
    <option selected value="text">文本</option>
    <option value="bin">二进制</option>
  </select><br><br>
  密码: <input name="password" size="10" maxlength="10" value="$args{'password'}"
  type="password"><br><br>
  内容: <textarea name="contents" cols="80" rows="20" wrap="off">@lines
</textarea><br><br><input type="submit" value="执行"></p>
</form>
</body>
</html>

EOF
  }

  # Ok.
  return 0;
}



⌨️ 快捷键说明

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