如何解决Python脚本未从PHP执行
当发布请求发送到apache网络服务器时,我正在尝试执行以下python文件。我提供了显示路径的屏幕截图以及其他可能有用的内容,例如权限(/ usr / bin / python&可执行文件)。 php和py文件都在var / www / html /文件夹中。预先感谢您的帮助。我将exec('load.py')更改为exec('/ usr / bin / python load.py')无效。
load.py
#!/usr/bin/python
import re
import paramiko
f = open('blocked.txt','r')
f = str(f.read())
#print(f)
s = f.find('epip="')
e = f.find(' epname="')
string = str(f[s:e])
string = re.findall(r'"([^"]*)"',string)
string = string[0]
print(string)
hostname = 'xxx'
username = 'xxx'
password = 'xxx'
ssh_client=paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=hostname,username=username,password=password)
stdin,stdout,stderr=ssh_client.exec_command('config firewall address \n ' + 'edit ' + string + '\n' + 'set subnet ' + string + '/32 \n ' + 'end \n' + 'config firewall addrgrp \n ' +'edit BlockedIPs \n ' + 'append member ' + string + '\n ' + 'end \n')
test = stdout.readlines()
print(string + ' has been added to the BlockedIPs group')
blocked.php
<html>
<body>
<?php
$file = 'blocked.txt';
$arr = $_POST;
$fp = fopen($file,'w') or die('Can not open!');
foreach ($arr as $key => $value) {
$toFile = "$value";
fwrite($fp,$toFile) or die('could not write to file');
}
fclose($fp);
$command = escapeshellcmd('load.py');
$output = shell_exec($command);
echo $output;?>
<br>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。