【问题标题】:shell cript in php codephp代码中的shell脚本
【发布时间】:2015-06-09 12:32:59
【问题描述】:

我有一个 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');
        }
}

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>";
?>

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

【问题讨论】:

  • $var='.$_POST['group_name'].';这不应该是 $var = "." . $_POST['group_name'] 。 "."; ?
  • 这个问题需要更多关于你想要做什么以及实际发生了什么的细节。

标签: javascript php shell post


【解决方案1】:

在您的 PHP 代码中,您使用 ' 来分隔字符串。如果你想将$var 扩展成它的值,你必须使用" 作为你的字符串分隔符或终止字符串并像这样连接它:'string start '.$var.' string end'

此外,如果此应用程序是公开的,请注意此处的安全性。提交可以执行任何 shell 命令的group_name 将非常容易。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 2019-12-29
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    相关资源
    最近更新 更多