<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once("config.php");
require_once("includes/debug.php");
require_once("includes/functions.php");
require_once("includes/logincheck.php");
require_once("includes/settings.php");
//print_r($_GET);
//Array ( [login] => neto11 [id] => 1 )
if (!isset($_GET['login']) || !is_numeric($_GET['id'])) {
    exit();
}

if (isset($_POST['opc_kick']) && ($_POST['opc_kick'] == 1 || $_POST['opc_kick'] == 2)) {
    $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
    mysql_select_db($dbname);
    $SQL = "SELECT * FROM cmum_csp_config WHERE id='{$_GET['id']}'";
    $rs = mysql_query($SQL);
    $serv = mysql_fetch_assoc($rs);
//kick-user&name=
    $url = $serv["protocol_serv"] . "://" . $serv["ip_serv"] . ":" . $serv["porta_serv"] . "/xmlHandler?command=kick-user&name={$_GET['login']}";
//var_dump($url);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERPWD, $serv["user_serv"] . ":" . $serv["senha_serv"]);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); // TIME OUT is 5 seconds
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//var_dump($httpCode);
    curl_close($ch);
    $status_kick = 0;
    if ($httpCode == "200") {
        $status_kick = 1;
    }
}
if (isset($_POST['opc_kick']) && ($_POST['opc_kick'] == 2)) {
    $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
    mysql_select_db($dbname);
    $SQL = "UPDATE cmum_udb SET "
            . "enabled='false'"
            . " WHERE name='{$_GET['login']}'";
    $rs = mysql_query($SQL);
    $status_desativar = 0;
    if ($rs === true) {
        $status_desativar = 1;
    }
}
$msg_status = "";
if (isset($status_kick) && $status_kick == 1) {
    $msg_status = "<p>Login,<strong>{$_GET['login']}</strong> kickado com sucesso.</p>";
}
if (isset($status_desativar) && $status_desativar == 1) {
    $msg_status .= "<p>Login,<strong>{$_GET['login']}</strong> desativado com sucesso.</p>";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title><?php print($longtitle); ?></title>
            <link rel="shortcut icon" href="favicon.ico"/>
            <link rel="apple-touch-icon" href="favicon.png"/>
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
            <link href="css/main.css" rel="stylesheet" type="text/css" />
            <!--<script type="text/javascript" src="js/jquery.js"></script>-->
            <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
    </head>
    <body style="width: 350px; margin: auto;">
        <h4><?php print($longtitle); ?></h4>
        <p>Kickar/Desativar login:&nbsp;<span class="label label-danger"><strong><?php echo $_GET['login'] ?></strong></span></p>
        <?php if (isset($msg_status) && $msg_status != ""): ?>
            <div class="alert alert-success"><?php echo $msg_status; ?></div>
        <?php else: ?>
            <form method="post">
                <div class="form-group">
                    <label>Ação</label>
                    <select class="form-control" name="opc_kick" id="opc_kick">
                        <option value="2">Kickar</option>
                        <option value="1">Kickar & Desativar</option>                        

                    </select>
                </div>
                <div class="form-group">
                    <button class="btn btn-success">Executar</button>            
                </div>
            </form>
        <?php endif; ?>
    </body>
</html>
