bash - 在订购和终止时收集产品的自定义字段数据
问题描述
我目前正在 WHMCS 中处理一些自动化的事情。我在 WHMCS 中提供了几种定制产品:
Linux 产品 1 Linux 产品 2 Windows 产品 1 Windows 产品 2
我想在订单接受和服务从 WHMCS 终止时执行 bash 脚本。该脚本需要一个参数(IP 地址),它是上述产品的自定义字段。脚本应该获取这个包含 IP 地址的自定义字段数据,并比较产品是 Linux 还是 Windows,然后将其传递给脚本,如下所示:
如果产品是 Linux 产品,那么脚本传递将类似于“autoaccept.sh linux [IP]”
如果产品是 Windows 产品,那么脚本调用将类似于“autoaccept.sh windows [IP]”
类似地,当包在 WHMCS 上终止时,我们必须使用“autoterminate.sh [IP]”再次调用脚本
我猜可以使用 WHMCS AcceptOrder 和 AfterModuleTerminate 挂钩。但不确定我们如何获取这些自定义字段数据并在那里比较钩子 PHP 代码中的产品。任何人都可以对此有所了解或帮助我们正确编码。
任何回应将不胜感激!
已经创建了 Bash 脚本,并且运行良好。我是 WHMCS 钩子和 PHP 的新手,所以被困在这里。
解决方案
使用产品模块:产品模块并实现方法_CreateAccount($params) ,您可以在$params变量中找到“CustomFields” 。这是执行python脚本的示例:
<?php
function my_proc_execute($cmd)
{
$output='';
try
{
$descriptorspec = array(
0 => array("pipe", "r"), //STDIN
1 => array("pipe", "w"), //STDOUT
2 => array("pipe", "w"), //STDERR
);
$cwd = getcwd(); $env = null; $proc = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
$buffer=array();
if(is_resource($proc))
{
fclose($pipes[0]);
stream_set_blocking($pipes[1], 1);
stream_set_blocking($pipes[2], 1);
stream_set_timeout($pipes[1],500);
stream_set_timeout($pipes[2],500);
while (!feof($pipes[1]))
{
$line = fread($pipes[1], 1024);
if(!strlen($line))continue;
$buffer[]=$line;
}
while(!feof($pipes[2]))
{
$line=fread($pipes[2], 1024);
if(!strlen($line))continue;
$buffer[]=$line;
}
$output=implode($buffer);
fclose($pipes[1]);fclose($pipes[2]);
$return_value = proc_close($proc);
}
else $output = "no resource; cannot open proc...";
}catch(Exception $e){$output = $e->getMessage();}
return $output;
}
function mymodule_CreateAccount($params)
{
$myData=$params['customfields']['the_name_of_field'];
$to_send_arr=array();
$to_send_arr['is_new']='0';
$to_send_arr['id']='xyz';
$to_send_arr['url']='my';
$to_send_arr['display_name']=$myData;
$exewin="c:/Python27/python.exe C:/xampp_my/htdocs/my/modules/servers/xxx/pyscripts/create_data.py";
$exelinux="/var/www/html/modules/servers/xxx/pyscripts/create_data.py";
$command=$exewin . ' ' . escapeshellcmd(base64_encode(json_encode($to_send_arr)));
$output=my_proc_execute($command);
$arr=json_decode($output,true);
}
?>
Python
import sys
import json
import time
import base64
if len(sys.argv) != 2:
print 'Error in the passed parameters for Python script.', '<br>'
sys.exit()
json_data = json.loads(base64.b64decode(sys.argv[1]))
id= json_data['id']
推荐阅读
- javafx - 将 HBox 设置为 TitledPane 的标题
- jquery - 如何更改底层元素的“src”属性
- mysql - Xampp MySQL 服务器未运行或被防火墙阻止
- c# - 使用 WEB API HttpClient 使用外部 API 然后以角度显示反序列化结果是否可以接受?
- xades4j - xades 的不同命名空间:QualifyingProperties
- testing - 测试完成并通过后,Windows 硬件实验室包选项卡不可用
- android - 将一个 byte[] 拆分为多个 byte[] 数组
- android - 为什么将值传递给其他活动时日期选择器的值不能改变
- android - 改造:传递多个 GET 参数
- angular - 如果创建了 ScrollMagic 控制器,Angular 将无法注册 Service Worker