403Webshell
Server IP : 95.46.96.79  /  Your IP : 216.73.216.84
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux zaimer.uz 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : akslabs_uz_usr ( 1001)
PHP Version : 7.4.3-4ubuntu2.29
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/sugurtatrip__usr95/data/www/sugurtatrip.uz/apiv1/user/Api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/sugurtatrip__usr95/data/www/sugurtatrip.uz/apiv1/user/Api/LoginController.php
<?php

require_once __DIR__ . '/../Services/SMSConfirmationService.php';

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class LoginController {
    private $SMSConfirmationService;
    public function __construct() {
        $this->SMSConfirmationService = new SMSConfirmationService();
    }
    public function loginUser($username, $password) {
        return ($username === 'admin' && $password === 'password');
    }

    public function logoutUser() {}

    public function authenticate() {
        $headers = getallheaders();

        if (!isset($headers['Authorization'])) {
            http_response_code(401);
            echo json_encode(['error' => 'Unauthorized']);
            exit;
        }

        $authHeader = $headers['Authorization'];
        list($token) = sscanf($authHeader, 'Bearer %s');

        if (!$token) {
            http_response_code(401);
            echo json_encode(['error' => 'Token was not provided']);
            exit;
        }

        try {
            $decoded = $this->validateJWT($token);
            if (!$decoded) {
                http_response_code(401);
                echo json_encode(['error' => 'Token was not decoded']);
                exit;
            }
            return $decoded;
        } catch (Exception $e) {
            http_response_code(401);
            echo json_encode(['error' => 'Invalid token', 'message' => $e->getMessage()]);
            exit;
        }
    }

    public function requestCode($data) {
        return $this->SMSConfirmationService->request_code($data);
    }

    public function confirmCode($data) {
        $confirmation_result = $this->SMSConfirmationService->confirm_code($data);

        if ($confirmation_result['success']) {
            $token = $this->generateJWT($confirmation_result['user_id'], $confirmation_result['phone']);
            $confirmation_result['token'] = $token;
        }
        return $confirmation_result;
    }

    public function checkToken($data) {
        $token = $data['token'];
        $decoded = $this->validateJWT($token);
        if (!$decoded) {
            http_response_code(401);
            echo json_encode(['error' => 'Invalid token']);
            exit;
        }
        return [
            'success' => true,
            'data' => [
                'userId' => $decoded['userId'],
                'phone' => $decoded['phone']
            ]
        ];
    }

    private function generateJWT($userId, $phone) {
        $secretKey = $_ENV['JWT_SECRET'];
        $issuedAt = time();
        $expirationTime = $issuedAt + 3600 * 8;
        $payload = [
            'iat' => $issuedAt,
            'exp' => $expirationTime,
            'userId' => $userId,
            'phone' => $phone
        ];
    
        return JWT::encode($payload, $secretKey, 'HS256');
    }

    private function validateJWT($token) {
        $secretKey = $_ENV['JWT_SECRET'];
    
        try {
            $decoded = JWT::decode($token, new Key($secretKey, 'HS256'));
            return (array) $decoded;
        } catch (Exception $e) {
            return null;
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit