我已经在互联网上关注了很多这方面的教程,所以请不要让我先搜索,我已经这样做但仍然无法解决这个问题,这是我的完整代码:
<?php
include 'theme.php';
ceklogin();
$show=1;
if($_POST['delete']){
$file_config=$_POST['config'];
exec('rm -f /root/crt/'.$file_config);
header( "refresh:0;url=vpn.php" );
exit;
}
if($_POST['apply']){
exec('grep use_config /root/config |awk -F"\'" \'{print $2}\'',$y);
$use_config=$_POST['use_config'];
$file_config=$_POST['config'];
if ($use_config=='yes'){
exec('vpn use-config yes',$var);
exec('vpn file-config '.$file_config,$var);
header( "refresh:0;url=vpn.php" );
exit;
}
else{
exec('vpn use-config no',$var);
exec('vpn file-config '.$file_config,$var);
if($y[0]=='yes'){
header( "refresh:0;url=vpn.php" );
exit;
}else{
$server=$_POST['server'];
$user=$_POST['user'];
$pass=$_POST['pass'];
exec('vpn server '.$server,$var3);
exec('vpn user-pass '.$user.' '.$pass,$var3);
header( "refresh:0;url=vpn.php" );
exit;
}}}
css();
echo "
<form action=\"upload_crt.php\" method=\"post\"
enctype=\"multipart/form-data\">
<label for=\"file\">file:</label>
<input type=\"file\" name=\"file\" id=\"file\">
<input type=\"submit\" name=\"upload\" value=\"Upload\">
</form>";
exec('cat /root/user.txt',$out);
exec('vpn server show',$var1);
exec('vpn config-show',$h);
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "</br>";
exec('grep use_config /root/config |awk -F"\'" \'{print $2}\'',$y);
if ($y[0]=='yes'){
echo '<input type="checkbox" name="use_config" value="yes" checked>Use file Config<br><br>';
exec('ls /root/crt |grep -i -e .ovpn -e .txt',$list);
echo 'Config: <select name="config">';
$x=0;
while($x<count($list)){
if($list[$x]==$h[0]){
echo "<option value=\"/root/crt/$list[$x]\" selected>$list[$x]</option>";}
else{echo "<option value=\"/root/crt/$list[$x]\">$list[$x]</option>";}
$x++;
}
echo '<input name="edit" type="submit" value="Edit">';
echo "<input name=\"delete\" type=\"submit\" value=\"Delete\"/>";
}
else{echo '<input type="checkbox" name="use_config" value="yes" >Use file Config';
echo "<br><br>Server: <input type=\"text\" name=\"server\" value=\"$var1[0]\"/>";
echo " <br><br>";
echo "User--: <input type=\"text\" name=\"user\" value=\"$out[0]\"/>";
echo "<br><br>";
echo "Pass--: <input type=\"password\" name=\"pass\" value=\"$out[1]\"/>";}
echo "<br><br><input name=\"apply\" type=\"submit\" value=\"Apply Settings\"/>";
echo '</form>';
if($_POST['edit']){
$show=2;
}
if ( $show == 1 )
{
if(isset($_POST["update"])) {
file_put_contents($_POST['filename'], $_POST["akunvpn"]);
$show=1;
echo "<br><b><font color=\"green\">The file has been updated</font></b>";
}
echo '<br><div style="font-size: 13px; word-wrap: break-word; width:400px;height:70px;border:0px solid #000;text-align:left; overflow-y: scroll;">
<b>NOTICE:</b> If you want your internet to be automatically reconnected when OpenVPN gets disconnected, add these lines in your *.ovpn :<br>
script-security 2 <br>
up client-connect.sh';
}
else {
$filename = $_POST["config"];
$filecontent = file_get_contents($filename);
$nameonly = str_replace('/root/crt/', '', $filename);
echo '<br><b><font color="green">Now editing: '.$nameonly.'</font></b>
<br>
<form action="" method="post">
<textarea name="akunvpn" autofocus rows="12" cols="69" style="font-family: Arial;font-size: 9pt;">';
echo htmlentities($filecontent);
echo '</textarea><br><br>
<input type="hidden" name="filename" value="'.$filename.'">
<input name="update" type="submit" value="Update File">
</form>
'; //echos file content in textarea.
}
echo '
</div>
</div>';
foot();
echo '
</div>
</body>
</div>
</html>';
?>
我尝试按照互联网上的许多主题建议更改此部分:
if($_POST['edit']){
$show=2;
echo '<option value="/root/crt/'.$_POST["update"].' selected >'.$_POST["update"].'</option>';
}
但是当我单击编辑按钮时,所选值总是返回到下拉列表的顶部。帮助