Javascript php代码中的shell脚本

Javascript php代码中的shell脚本,javascript,php,shell,post,Javascript,Php,Shell,Post,我有一个web界面,它可以帮助我在shell中使用命令创建概要文件,但实际上我的代码中有一些错误,因为我在web界面中输入的值在shell srcipt中无法识别。这是我的源代码: index.php: <div class="inputbox"> <form id="createProfile" name="createProfile"> <label for="channelName">Group Name</label> <br/>

我有一个web界面,它可以帮助我在shell中使用命令创建概要文件,但实际上我的代码中有一些错误,因为我在web界面中输入的值在shell srcipt中无法识别。这是我的源代码:

index.php:

<div class="inputbox">
<form id="createProfile" name="createProfile">
<label for="channelName">Group Name</label>
<br/>
<input type="text" id="groupName" name="groupName" />
<br/>
<label for="profileName">Profile Name</label>
<br/>
<input type="text" id="profileName" name="profileName" />
<input type="button" value="Create Profile" onclick="createUser()" />
</form>
</div>

组名


配置文件名
script.js

function createUser(){
        if ($('#groupName').val() != '' && $('#profileName').val() != ''){
                     $.ajax({
                                type:'post',
                                url: 'addProfile.php',
                                data:{group_name:$('#groupName').val()+'/'+$('#profileName').val()},
                                cache:false,
                                success: function(returndata){
                                                                $('#profilesList').append('<option value="'+ $('#groupName').val()+'/'+$('#profileName').val() +'">' + $('#groupName').val()+'/'+$('#profileName').val() + '</option>');
                                 alert('profile added');
                                }
                        });
        }
        else{
        alert('you must enter both group name and profile name');
        }
}
函数createUser(){
if($('#groupName').val()!=''&('#profileName').val()!=''){
$.ajax({
类型:'post',
url:'addProfile.php',
数据:{group_name:$('#groupName').val()+'/'+$('#profileName').val()},
cache:false,
成功:函数(返回数据){
$('#profilesList')。追加('+$('#groupName').val()+'/'+$('#profileName').val()+'');
警报(“添加配置文件”);
}
});
}
否则{
警报(“您必须同时输入组名和配置文件名”);
}
}
addprofile.php

<?php
$var='.$_POST['group_name'].';
$output1=shell_exec('/etc/init.d/nfsen --add-profile $var  expire=0 maxsize=0 shadow=1');
echo "<pre>$output1</pre>";
?>


你能告诉我我的代码出了什么问题吗?

在你的PHP代码中,你正在使用
来界定你的字符串。如果希望将
$var
扩展为它的值,则必须使用
作为字符串分隔符,或者终止字符串并按如下方式对其进行处理:
'string start.$var.'string end'

此外,如果此应用程序是公共的,请在这里非常小心安全性。提交可以执行任何shell命令的
组名称
将非常容易

编辑:
正如@Tool在您的问题的评论中指出的那样,
$var=
行需要出于同样的原因进行调整。

$var='.$\u POST['group\u name'.];这不应该是$var=“.$\u POST['group\u name'.]”?这个问题需要更多关于您尝试做什么以及实际发生什么的细节。