我如何得到+2字符串在php和awnser一个问题在shell脚本bash linux自动

yptwkmov  于 2023-02-28  发布在  PHP
关注(0)|答案(1)|浏览(130)

我需要一个与awnser一些代码一个问题与PHP代码在html的shell脚本:
Shell脚本

read -p nome: nome
read -p ramal: ramal
read -p passwd: passwd

echo " " >> sip.conf
echo [$nome] >> sip.conf
echo type=friend >> sip.conf
echo username=$nome >> sip.conf
echo callerid=$nome >> sip.conf
echo mailbox =$ramal >> sip.conf
echo secret=$passwd >> sip.conf
echo host=dynamic >> sip.conf
echo context=local-tmp >> sip.conf

echo " "  >> extensions.conf
echo "exten => $ramal,1,Dial(SIP/$ramal,10,t)" >> extensions.conf

在html的php代码,应该执行shell_exec和anwser:

nome
ramal
passwd
wbgh16ku

wbgh16ku1#

你不需要bash来将内容附加到文件中,你可以使用fopena标志,或者file_put_contentFILE_APPEND标志:

$nome = $_POST['nome'] ?? throw new Exception('nome not defined');
$ramal = $_POST['ramal'] ?? throw new Exception('ramal not defined');
$passwd = $_POST['passwd'] ?? throw new Exception('passwd not defined');

$newContent = <<< BASH

[$nome]
type=friend
username=$nome
callerid=$nome
mailbox =$ramal
secret=$passwd
host=dynamic
context=local-tmp

BASH;

$newExtensionsContent = PHP_EOL . "exten => $ramal,1,Dial(SIP/$ramal,10,t)";

file_put_contents('sip.conf', $newContent, FILE_APPEND);
file_put_contents('extensions.conf', $newExtensionsContent, FILE_APPEND);

相关问题