简体   繁体   English

从PHP按钮运行bash代码

[英]running bash code from php button

I want to test 4 files in Linux server through PHP, and the display result should show in the text area. 我想通过PHP在Linux服务器中测试4个文件,并且显示结果应显示在文本区域中。 let me know whats the correct way to solve this. 让我知道解决此问题的正确方法。

Sh test_batch.sh sh test_batch.sh

$ {dict_file} $ {locale} $ {keyboard_layout} $ {golden_test_file} $ 
{auto_correction_file} (optional)

这些是带有复选框的四个文件

 if (isset($_POST['files'])) {
 foreach ($_POST['files'] as $value) {
 echo $dir . $value . '<br />';
 $result = shell_exec('sudo sh test_batch.sh $dir .$value. ');

  }
  }else {
  exit('No files selected');
  }
  }
   ?>
                            <br/>
                            <table>
                             <tr>
                    <td><b>Result to Display and Save:</b></td></tr>
            <tr>
                    <td colspan="3">
                    <textarea disabled id="inputTextToSave"  style="width:512px;height:256px" value = "'.$result.'"></textarea>`

First of all, you should refrain from ever using sudo in a web script to do anything. 首先,您应该避免在网络脚本中使用sudo做任何事情。 What if someone decided to feed your server the string "&& rm -rf /" in your $_POST and that got concatenated into your sudo sh test_batch.sh $dir .$value string? 如果有人决定在$ _POST中向服务器提供字符串“ && rm -rf /” ,并将其串联到sudo sh test_batch.sh $ dir。$ value字符串中怎么办? That would make for a very bad day. 那将是非常糟糕的一天。

Instead, consider implementing whatever test_batch.sh does into some kind of worker script that processes requests queued to it (you could do this in Perl, PHP, with Node.JS...there are a few ways. 相反,考虑将test_batch.sh所做的任何事情实现到某种工作脚本中,以处理排队到该请求的请求(您可以使用Node.JS在Perl,PHP中进行此操作...有几种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM