我正在尝试创建一个使用 PHP 和 openSSL 生成自签名证书的站点。我很确定这是某种语法错误,但我似乎找不到它。
我已经在 linux 终端中尝试了该命令,它似乎有效,但仅在 PHP 文件中无效。
这是work.php,主要是功能:
<?php
function terminal($command)
{
//system
if(function_exists('system'))
{
ob_start();
system($command , $return_var);
$output = ob_get_contents();
ob_end_clean();
}
//passthru
else if(function_exists('passthru'))
{
ob_start();
passthru($command , $return_var);
$output = ob_get_contents();
ob_end_clean();
}
//exec
else if(function_exists('exec'))
{
exec($command , $output , $return_var);
$output = implode(n , $output);
}
//shell_exec
else if(function_exists('shell_exec'))
{
$output = shell_exec($command) ;
}
else
{
$output = 'Command execution not possible on this system';
$return_var = 1;
}
return array('output' => $output , 'status' => $return_var);
}
?>
这是 index.php 这是主文件
<form method="post">
<input type="text" placeholder="domain" name="name"></input>
<input type="submit" value="submit" name="submit"></input>
</form>
<?php
if(isset($_POST['submit']))
{
$name = $_POST["name"];
run();
}
function run() {
require "work.php";
$status = 0;
$name = $_POST["name"];
$command1 = "openssl req -x509 -newkey rsa:4096 -nodes -keyout " . $name . ".key -out " . $name . ".pem -days 3650 -subj '/CN=" . $name . "'";
$o = terminal($command1);
echo $o['output'];
echo "<br><br>";
echo "Your certificate >> <a href='" . $name . ".pem'>DOWNLOAD</a>";
echo "<br>";
echo "Your private key >> <a href='" . $name . ".key'>DOWNLOAD</a>";
}
?>