在 Yii 2 中,基于 Hprose 实现 RPC 服务,报错:passthru() has been disabled for security reasons 的解决

1、在本地环境中,在 Postman 中 POST ,http://api.aims-api.localhost/v1/tasks?group_id=015ce30b116ce86058fa6ab4fea4ac63 ,响应成功

{
	"group_id":"015ce30b116ce86058fa6ab4fea4ac63",
	"title":"标题 - 20180809 - 1",
	"source":"xcontent",
	"media_path":"http://www.media_path.com",
	"type":"mc_vca",
	"callback_url":"http://www.callback_url.com",
	"dlurl":"http://www.dlurl.com"
}
{
    "code": 10000,
    "message": "提交任务成功",
    "data": {
        "id": 14,
        "group_id": "015ce30b116ce86058fa6ab4fea4ac63",
        "task_uuid": "B914E6E49B9F11E8872454EE75D2EBC1",
        "title": "标题 - 20180809 - 1",
        "source": "xcontent",
        "media_path": "http://www.media_path.com",
        "dlurl": "http://www.dlurl.com",
        "callback_url": "http://www.callback_url.com",
        "ai_task_type": "mc_vca",
        "ai_task_status": 0,
        "pri": 2,
        "pri_updated_at": 0,
        "status": 1,
        "created_at": 1533797093,
        "updated_at": 1533797093
    }
}

2、在开发环境中,在 Postman 中 POST ,http://wjdev2.chinamcloud.com:8659/v1/tasks?group_id=015ce30b116ce86058fa6ab4fea4ac63 ,响应失败,如图2

passthru() has been disabled for security reasons

图2

{
	"group_id":"015ce30b116ce86058fa6ab4fea4ac63",
	"title":"标题 - 20180809 - 1",
	"source":"xcontent",
	"media_path":"http://www.media_path.com",
	"type":"mc_vca",
	"callback_url":"http://www.callback_url.com",
	"dlurl":"http://www.dlurl.com"
}
{
{
    "name": "Exception",
    "message": "passthru() has been disabled for security reasons",
    "code": 0,
    "type": "Exception",
    "file": "/sobey/www/aims-api/vendor/hprose/hprose/src/Hprose/Client.php",
    "line": 383,
    "stack-trace": [
        "#0 /sobey/www/aims-api/vendor/hprose/hprose/src/Hprose/Client.php(477): Hprose//Client->decode('Es49/"passthru()...', Array, Object(stdClass))",
        "#1 /sobey/www/aims-api/vendor/hprose/hprose/src/Hprose/Client.php(489): Hprose//Client->syncInvokeHandler('task_create', Array, Object(stdClass))",
        "#2 /sobey/www/aims-api/vendor/hprose/hprose/src/Hprose/Client.php(103): Hprose//Client->invokeHandler('task_create', Array, Object(stdClass))",
        "#3 /sobey/www/aims-api/vendor/hprose/hprose/src/Hprose/Client.php(608): Hprose//Client->Hprose//{closure}('task_create', Array, Object(stdClass))",
        "#4 /sobey/www/aims-api/vendor/hprose/hprose/src/Hprose/Proxy.php(91): Hprose//Client->invoke('task_create', Array)",
        "#5 /sobey/www/aims-api/common/logics/rpc/Task.php(106): Hprose//Proxy->__call('task_create', Array)",
        "#6 /sobey/www/aims-api/common/services/TaskService.php(30): common//logics//rpc//Task->create(Array, '0.0', 'zh-CN')",
        "#7 /sobey/www/aims-api/api/rests/task/CreateAction.php(65): common//services//TaskService->create(Object(api//modules//v1//models//rpc//Task))",
        "#8 [internal function]: api//rests//task//CreateAction->run()",
        "#9 /sobey/www/aims-api/vendor/yiisoft/yii2/base/Action.php(94): call_user_func_array(Array, Array)",
        "#10 /sobey/www/aims-api/vendor/yiisoft/yii2/base/Controller.php(157): yii//base//Action->runWithParams(Array)",
        "#11 /sobey/www/aims-api/vendor/yiisoft/yii2/base/Module.php(528): yii//base//Controller->runAction('create', Array)",
        "#12 /sobey/www/aims-api/vendor/yiisoft/yii2/web/Application.php(103): yii//base//Module->runAction('v1/task/create', Array)",
        "#13 /sobey/www/aims-api/vendor/yiisoft/yii2/base/Application.php(386): yii//web//Application->handleRequest(Object(yii//web//Request))",
        "#14 /sobey/www/aims-api/api/web/index.php(17): yii//base//Application->run()",
        "#15 {main}"
    ]
}

3、编辑接口(RPC客户端)的 Dockerfile,在 disable_functions 中删除 passthru

FROM registry-vpc.cn-beijing.aliyuncs.com/cmc/centos-nginx112-php71:0.2.4

MAINTAINER wangqiang@chinamcloud.com

RUN sed -i 's/open_basedir = .//://sobey://tmp://data://webtv/;open_basedir = .//://sobey://tmp://data://webtv://usr//local//php/g' /usr/local/php/etc/php.ini && /
    sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && /
    sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini

COPY code /sobey/www/aims-api
COPY code/build/c_files/ /

RUN chown -R nginx:nginx /sobey/www/ && /
    rm -rf /etc/nginx/conf.d/status.conf && /
    chmod +x /usr/local/bin/composer && /
    cd /sobey/www/aims-api && /
    composer install

4、编辑RPC服务端的 Dockerfile,在 disable_functions 中删除 passthru

FROM registry-vpc.cn-beijing.aliyuncs.com/cmc/centos-nginx112-php71:0.2.4

MAINTAINER wangqiang@chinamcloud.com

RUN sed -i 's/open_basedir = .//://sobey://tmp://data://webtv/;open_basedir = .//://sobey://tmp://data://webtv://usr//local//php/g' /usr/local/php/etc/php.ini && /
    sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && /
    sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini

COPY code /sobey/www/aims-rpc
COPY code/build/c_files/ /

RUN chown -R nginx:nginx /sobey/www/ && /
    rm -rf /etc/nginx/conf.d/status.conf && /
    chmod +x /usr/local/bin/composer && /
    cd /sobey/www/aims-rpc && /
    composer install

5、在开发环境中,在 Postman 中 POST ,http://wjdev2.chinamcloud.com:8659/v1/tasks?group_id=015ce30b116ce86058fa6ab4fea4ac63 ,响应成功

{
	"group_id":"015ce30b116ce86058fa6ab4fea4ac63",
	"title":"标题 - 20180811 - 6",
	"source":"xContent",
	"media_path":"http://www.media_path.com",
	"type":"mc_vca",
	"callback_url":"http://www.callback_url.com",
	"dlurl":"http://www.dlurl.com"
}
{
    "code": 10000,
    "message": "提交任务成功",
    "data": {
        "id": 5,
        "group_id": "015ce30b116ce86058fa6ab4fea4ac63",
        "task_uuid": "D9C9092A9D4711E8AD5E54EE75D2EdC1",
        "title": "标题 - 20180811 - 5",
        "source": "xContent",
        "media_path": "http://www.media_path.com",
        "dlurl": "http://www.dlurl.com",
        "callback_url": "http://www.callback_url.com",
        "ai_task_type": "mc_vca",
        "ai_task_status": 0,
        "pri": 2,
        "pri_updated_at": 0,
        "status": 1,
        "created_at": 1533980458,
        "updated_at": 1533980458
    }
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/250426.html

(0)
上一篇 2022年4月29日 22:38
下一篇 2022年4月29日 22:38

相关推荐

发表回复

登录后才能评论