dourenzhou8740 2016-11-29 10:56
浏览 348
已采纳

通过php脚本选择OpenVPN配置文件

I am using openvpn on my own dedicated cloud server (ubuntu). Therefor I created an interface by doing all steps written in this tutorial. Everything works when I am using the terminal as described in the tutorial. Also when I am trying to connect to the interface via curl curl_setopt($ch, CURLOPT_INTERFACE, "tun0"); it works fine. But therefor I have to execute the following statement in the terminal before I run the php script:

openvpn "path/to/my/file.ovpn"

When I want to change the IP address I have to execute the statement above again but with another file.ovpn.

But I want to change the file.ovpn in my php script like:

exec('sudo openvpn path/to/my/file.ovpn');

But this isn't working. I always get the error curl error: Could not resolve host: tun0. So what am I doing wrong? Is this even possible?

For now the configuration files are living in the root folder. So may be it is an authorization / access issue?

  • 写回答

1条回答 默认 最新

  • drxkx6149 2016-11-29 14:19
    关注

    most likely, sudo fails, it tries to ask for a password and you're not giving it any, OR the user that PHP runs as is not in the sudo file and it errors out. in which case, shame on you for ignoring stderr and not noticing it.

    in any case, if php runs as the user "www-data", add this to /etc/sudoers

    www-data ALL=(ALL) NOPASSWD: /usr/bin/openvpn path/to/my/file.ovpn
    

    just replace www-data with whatever user php runs as (in linux, most commonly, its a user called www-data), and /usr/bin/openvpn with wherever your openvpn binary is located and warning, this allows the user to run the exact command /usr/bin/openvpn path/to/my/file.ovpn as root without a password. which i believe would solve your problem here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改