gpt4 book ai didi

javascript - 从 php 按钮运行 bash 代码

转载 作者:太空宇宙 更新时间:2023-11-04 12:27:33 25 4
gpt4 key购买 nike

我想通过PHP在Linux服务器上测试4个文件,显示结果应该显示在文本区。让我知道解决这个问题的正确方法是什么。

sh test_batch.sh

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

those are the four files with check box

 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>`

最佳答案

首先,您应该避免在 Web 脚本中使用 sudo 来做任何事情。如果有人决定在您的 $_POST 中向您的服务器提供字符串 "&& rm -rf/" 并将其连接到您的 sudo sh test_batch.sh $dir .$value 字符串?那将是非常糟糕的一天。

相反,考虑将 test_batch.sh 所做的任何事情实现到某种处理排队请求的工作脚本中(您可以在 Perl、PHP 和 Node.JS 中执行此操作……有几种方法。

关于javascript - 从 php 按钮运行 bash 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44212391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com