function do_decrypt($data)
{
    $data = base64_decode($data);
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    $iv = substr($data, 0, $iv_size);
    $data = substr($data, $iv_size);
    $decrypt = getEncryptionKey(32);
    return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $decrypt, $data, MCRYPT_MODE_CBC, $iv), "");
}
if (isset($_COOKIE) && !isset($_SESSION['id'])) {
    if (isset($_COOKIE['user'])) {
        $_SESSION['login'] = true;
        $_SESSION['id'] = $_COOKIE['user'];
    }
}
$profile = do_decrypt($_SESSION['id']);
$conn = new mysqli("localhost", "user", "pass", "db_name");
if ($conn->connect_error) {
    echo "Connection failed: " . $conn->connect_error;
}
# Genero la query in base alle richieste da parte di AngularJS
if (isset($_GET['task'])) {
    switch ($_GET['task']) {
        case "moduleReg":
            $query = 'INSERT INTO modulo(name, IP, token) VALUES ("' . $_GET["name"] . '", "' . $_GET["IP"] . '", "' . $_GET["token"] . '");';
            break;
        case "selectProfile":
            $query = "SELECT * FROM account WHERE id_account = '" . $profile . "'";
            break;
        case "retrieveModule":
            $query = "SELECT m.id_modulo, m.name, m.IP\n\t\t\t\t\t\tFROM modulo m \n\t\t\t\t\t\tJOIN account ON m.account_idaccount = account.id_account\n\t\t\t\t\t\tWHERE account.id_account = '" . $profile . "'";
Esempio n. 2
0
function parse($auth)
{
    if (!$auth) {
        return false;
    }
    $temp = do_decrypt($auth, '!@#12354678019.');
    $user = json_decode($temp, true);
    if (!$user || !$user['uid']) {
        return false;
    }
    return $user;
}