-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnviarRevendedorUser.php
72 lines (57 loc) · 1.91 KB
/
EnviarRevendedorUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
include("conexao.php");
include_once("functions.php");
if(ProtegePag() == true){
if($_SESSION['acesso'] == 1){
$CadUser = $_SESSION['id'];
$ArvoreAdminOnline = ArvoreUser($CadUser);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$id = (isset($_POST['id'])) ? $_POST['id'] : '';
if(empty($id)){
echo MensagemAlerta('Erro', 'Como você fez isso?', "danger");
}
elseif( (!in_array($id, $ArvoreAdminOnline)) ) {
echo MensagemAlerta('Erro', 'Este usuário não pertence a você!', "danger");
}
else{
$SQLUser = "SELECT login, operadora FROM login WHERE id = :id";
$SQLUser = $banco->prepare($SQLUser);
$SQLUser->bindParam(':id', $id, PDO::PARAM_INT);
$SQLUser->execute();
$Ln = $SQLUser->fetch();
//Seleciona o servidor
$SQLServer = "SELECT * FROM servidor WHERE nome = :nome";
$SQLServer = $banco->prepare($SQLServer);
$SQLServer->bindParam(':nome', $Ln['operadora'], PDO::PARAM_STR);
$SQLServer->execute();
$LnServer = $SQLServer->fetch();
$connection = ssh2_connect($LnServer['server'], $LnServer['porta']);
ssh2_auth_password($connection, $LnServer['user'], $LnServer['senha']);
$stream = ssh2_exec($connection, 'sudo pkill -KILL -u '.$Ln['login'].'');
$stream = ssh2_exec($connection, 'sudo userdel '.$Ln['login'].'');
stream_set_blocking($stream, true);
stream_set_timeout($stream, 15);
fclose($stream);
$acesso = 2;
$SQLU = "UPDATE login SET
acesso = :acesso
WHERE id = :id";
$SQLU = $banco->prepare($SQLU);
$SQLU->bindParam(':acesso', $acesso, PDO::PARAM_STR);
$SQLU->bindParam(':id', $id, PDO::PARAM_INT);
$SQLU->execute();
if(empty($SQLU)){
echo MensagemAlerta('Erro', 'Ocorreu um erro ao tornar o usuário revendedor.', "danger");
}
else{
echo MensagemAlerta('Sucesso', 'Usuário convertido revendedor com sucesso!', "success", "index.php?p=usuario");
}
}
}
}else{
echo Redirecionar('index.php');
}
}else{
echo Redirecionar('login.php');
}
?>