403Webshell
Server IP : 10.200.247.200  /  Your IP : 216.73.217.19
Web Server : Apache
System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64
User : jeremy ( 1001)
PHP Version : 8.4.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/usa_sites/governmentgrants.us/vx/usa/ai-overviews/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/usa_sites/governmentgrants.us/vx/usa/ai-overviews/update.php
<?php
        session_start();
        include_once($_SERVER['DOCUMENT_ROOT'].'/vx/lib/ua.php');
        include_once($_SERVER['DOCUMENT_ROOT'].'/vx/lib/func.php');
        include_once($_SERVER['DOCUMENT_ROOT'].'/vx_/site_info.php');
        include_once($_SERVER['DOCUMENT_ROOT'].'/vx/lib/mysql.php');
        $user = $_SESSION['user'];

        header('Content-Type: application/json');

        // Must be a VIP subscriber
        if(empty($_SESSION['subscriptions']['2'])) {
                echo json_encode(['success' => false, 'error' => 'VIP subscription required.']);
                exit;
        }

        // Must be POST
        if($_SERVER['REQUEST_METHOD'] !== 'POST') {
                echo json_encode(['success' => false, 'error' => 'Invalid request method.']);
                exit;
        }

        // Get lead ID and verify it belongs to this user
        $lead_id = (int)($_POST['lead_id'] ?? 0);
        if($lead_id <= 0) {
                echo json_encode(['success' => false, 'error' => 'Invalid profile.']);
                exit;
        }

        $siteDb = "lc2{$siteCode}_lc";
        $verify = $db->query("SELECT id FROM {$siteDb}.lc_leads WHERE id = {$lead_id} AND customerID = '".$db->clean($user)."'");
        if(empty($verify)) {
                echo json_encode(['success' => false, 'error' => 'Profile not found.']);
                exit;
        }

        // Sanitize inputs
        $city = $db->clean(trim($_POST['city'] ?? ''));
        $state = $db->clean(trim($_POST['state'] ?? ''));
        $zip = $db->clean(trim($_POST['zip'] ?? ''));
        $profile_category_id = (int)($_POST['profile_category_id'] ?? 0);
        $gender = $db->clean(trim($_POST['gender'] ?? ''));
        $age = $db->clean(trim($_POST['age'] ?? ''));
        $citizenship = $db->clean(trim($_POST['citizenship'] ?? ''));
        $money = $db->clean(trim($_POST['money'] ?? ''));
        $ethnicity = $db->clean(trim($_POST['ethnicity'] ?? ''));
        $employment_status = $db->clean(trim($_POST['employment_status'] ?? ''));
        $description = $db->clean(trim($_POST['description'] ?? ''));
        $uniqueness = $db->clean(trim($_POST['uniqueness'] ?? ''));

        // Update lc_leads (city, state, zip)
        $db->query("UPDATE {$siteDb}.lc_leads SET city = '{$city}', state = '{$state}', zip = '{$zip}' WHERE id = {$lead_id}");

        // Check if lead_profile exists
        $profile_exists = $db->query("SELECT lead_id FROM {$siteDb}.lead_profile WHERE lead_id = {$lead_id}");
        if(!empty($profile_exists)) {
                $db->query("UPDATE {$siteDb}.lead_profile SET
                        profile_category_id = " . ($profile_category_id > 0 ? $profile_category_id : 'NULL') . ",
                        gender = '{$gender}',
                        age = '{$age}',
                        citizenship = '{$citizenship}',
                        money = '{$money}',
                        ethnicity = '{$ethnicity}',
                        employment_status = '{$employment_status}',
                        description = '{$description}',
                        uniqueness = '{$uniqueness}'
                        WHERE lead_id = {$lead_id}
                ");
        } else {
                $db->query("INSERT INTO {$siteDb}.lead_profile (lead_id, profile_category_id, gender, age, citizenship, money, ethnicity, employment_status, description, uniqueness)
                        VALUES ({$lead_id}, " . ($profile_category_id > 0 ? $profile_category_id : 'NULL') . ", '{$gender}', '{$age}', '{$citizenship}', '{$money}', '{$ethnicity}', '{$employment_status}', '{$description}', '{$uniqueness}')
                ");
        }

        // Check monthly update limit (max 10 per month)
        $month_start = date('Y-m-01 00:00:00');
        $update_count_res = $db->query("SELECT COUNT(*) as cnt FROM grdb.ai_overviews_updated WHERE site_code = '".$db->clean($siteCode)."' AND lead_id = {$lead_id} AND ts >= '{$month_start}'");
        $update_count = (int)($update_count_res[0]['cnt'] ?? 0);
        if($update_count >= 10) {
                echo json_encode(['success' => false, 'error' => 'You have reached your limit of 10 profile updates this month. Your updates will reset next month.']);
                exit;
        }
		
		//Clear the recommendations for this client
		$db->query("DELETE FROM grdb.ai_overviews WHERE site_code='".$db->clean($siteCode)."' AND lead_id='".$db->clean($lead_id)."'");
		$db->query("DELETE FROM grdb.profile_recommendation_feed WHERE site_code='".$db->clean($siteCode)."' AND lead_id='".$db->clean($lead_id)."'");

        // Call the recommendation API to regenerate matches
        $api_url = "https://surfcrm.com/lcapi/ai/grants_new/api_recommend.php?site=" . urlencode($siteCode) . "&lead_id=" . $lead_id;
        $ch = curl_init($api_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 120);
        $api_response = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curl_error = curl_error($ch);
        curl_close($ch);

        // Log the update
        $client_id = (int)($db->query("SELECT customerID FROM lc2{$siteCode}_lc.lc_leads WHERE id = {$lead_id}")[0]['customerID'] ?? 0);
        $db->query("INSERT INTO grdb.ai_overviews_updated (site_code, client_id, lead_id) VALUES ('".$db->clean($siteCode)."', {$client_id}, {$lead_id})");

        $updates_remaining = 10 - ($update_count + 1);

        if($http_code === 200) {
                $api_data = json_decode($api_response, true);
                if(!empty($api_data['success'])) {
                        echo json_encode(['success' => true, 'message' => 'Profile updated and grant matches generated! You have ' . $updates_remaining . ' update(s) remaining this month.']);
                } else {
                        echo json_encode(['success' => true, 'message' => 'Profile updated. Grant matching completed with warnings. You have ' . $updates_remaining . ' update(s) remaining this month.']);
                }
        } else {
                // Profile was saved but API call failed
                echo json_encode(['success' => true, 'message' => 'Profile updated. Grant matching is processing — check back shortly. You have ' . $updates_remaining . ' update(s) remaining this month.']);
        }

Youez - 2016 - github.com/yon3zu
LinuXploit