【问题标题】:check cpanel authorisation with perl script and write file使用 perl 脚本检查 cpanel 授权并写入文件
【发布时间】:2013-09-01 11:44:13
【问题描述】:

我正在编写一个 perl 脚本来检查多 cpanel 帐户的弱密码授权,就像服务器所有者可以检查他的用户是否使用弱密码,并且当连接到一个时,在 /public_html/ 目录中写入一个文件到通知用户。 我正在考虑使用cPanel::PublicAPI

my $cp = cPanel::PublicAPI->new(
       'user' => $username,
       'pass' => $password,
       'host' => $host,
     );

但我不知道如何检查是否已连接以及如何在其中写入文件 (i've looked here)

我找到了一个检查授权的脚本:

$authx = encode_base64($user.":".$passwd);
my $sock = IO::Socket::INET->new(Proto => "tcp",PeerAddr => "$host", PeerPort => "$port") || print " [-] Can not connect to the host";
print $sock "GET / HTTP/1.1";
print $sock "Authorization: Basic $authx";
print $sock "Connection: Close";
read $sock, $answer, 128;
close($sock);

if ($answer =~ /Moved/) {
print " passord is : $passwd\n";
}

但这太慢了,不能用它写文件。 对不起我的英语不好 :) 。问候

【问题讨论】:

  • 那个授权脚本是不必要的低级。我们有可用的 HTTP 库,例如 LWP::UserAgent 来完成这样的任务!

标签: perl cpanel


【解决方案1】:

我不知道如何检查是否连接

只需对 $cp 对象进行请求/方法调用。如果失败,则设置$cp->{error} attribute

如何写入文件

use autodie qw(:all);
open my $fh, '>', '/home/user/message_from_the_admin';
$fh->print('You made a boo-boo.');

参见第 9.3 章:文件 in Modern Perl

【讨论】:

  • 感谢您的帮助 :) 但是我如何调用 $cp 来检查它是否失败?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多