OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
reader
/
facebook
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/04/2025 08:32:49 AM
rwxr-xr-x
📄
accessTest copy.php
601 bytes
05/19/2025 10:07:15 AM
rw-r--r--
📄
accessTest.php
601 bytes
05/19/2025 10:07:15 AM
rw-r--r--
📄
back_fb_post_handler.php
9.41 KB
05/19/2025 10:07:15 AM
rw-r--r--
📁
backup
-
05/19/2025 10:07:15 AM
rwxr-xr-x
📄
composer-setup.php
57.04 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
composer.json
64 bytes
03/03/2025 08:18:25 AM
rw-r--r--
📄
composer.lock
2.81 KB
03/03/2025 08:18:25 AM
rw-r--r--
📄
composer.phar
2.86 MB
03/03/2025 08:18:26 AM
rw-r--r--
📄
configuration.txt
79 bytes
03/03/2025 08:18:25 AM
rw-r--r--
📁
cream
-
05/19/2025 10:07:15 AM
rwxr-xr-x
📄
credential copy.json
556 bytes
03/03/2025 08:18:26 AM
rw-r--r--
📄
credential.json
556 bytes
03/03/2025 08:18:26 AM
rw-r--r--
📄
db_connect.php
341 bytes
05/19/2025 10:07:15 AM
rw-r--r--
📄
facebook_setup.php
10.39 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
facebook_setup_handler.php
1.17 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
fb_post_handler copy.php
6.55 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
fb_post_handler.php
12.35 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
fb_share.php
8.94 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
function.php
18.91 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
index.php
420 bytes
05/19/2025 10:07:15 AM
rw-r--r--
📄
navbar.php
1.63 KB
05/19/2025 10:07:15 AM
rw-r--r--
📁
new_folder
-
05/19/2025 10:07:15 AM
rwxr-xr-x
📄
new_index.php
10.12 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
new_table.php
13.36 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
postTest.php
3.38 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
sample_data.txt
7.07 KB
03/03/2025 08:18:26 AM
rw-r--r--
📄
share_facebook.php
1.95 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
sidebar.php
3.49 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
test.php
1.72 KB
05/19/2025 10:07:15 AM
rw-r--r--
📄
update_fb_pages.php
347 bytes
05/19/2025 10:07:15 AM
rw-r--r--
📁
vendor
-
05/19/2025 10:07:15 AM
rwxr-xr-x
Editing: fb_post_handler copy.php
Close
<?php // header('Content-Type: application/json'); include '../inc/validate.logged.php'; // include 'function.php'; include 'db_connect.php'; $data = json_decode(file_get_contents('php://input'), true); // Load credentials from the JSON file $credentials = json_decode(file_get_contents('credential.json'), true); if (!$credentials) { throw new RuntimeException('Invalid or missing credentials'); } function postNow($db, $userId, $pages, $title, $link) { $returnData = []; foreach ($pages as $page) { $response = facebook_post_to_page($db, $userId, $page, $title, $link); $returnData[] = $response; } return [ 'message' => 'Post(s) sent successfully now!', 'title' => $title, 'link' => $link, 'details' => $returnData ]; } function schedulePost($db, $userId, $pages, $title, $link, $schedule) { foreach ($pages as $page) { $response = facebook_schedule_post_to_page($db, $userId, $page, $title, $link, $schedule); $returnData[] = $response; } return [ 'message' => 'Post(s) scheduled successfully!', 'title' => $title, 'link' => $link, 'schedule' => $schedule, 'details' => $returnData ]; } function facebook_post_to_page($db, $userId, $pageId, $message, $link) { try { $pageAccessToken = fetch_long_live_access_token($db, $userId, $pageId); $postUrl = 'https://graph.facebook.com/v20.0/me/feed'; // Data to send $postData = [ 'link' => $link, 'message' => $message, 'access_token' => $pageAccessToken, ]; // Initialize cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $postUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute request $response = curl_exec($ch); // Check if there was an error with cURL if (curl_errno($ch)) { throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); // Decode the response $responseData = json_decode($response, true); // Check if there was an error in the API response if (isset($responseData['error'])) { throw new RuntimeException('Error: ' . $responseData['error']['message']); } // Return success response echo json_encode([ 'success' => true, 'message' => 'Message posted successfully!', 'page_id' => $pageId, ]); } catch (RuntimeException $e) { echo json_encode([ 'success' => false, 'error' => $e->getMessage(), ]); } catch (Exception $e) { echo json_encode([ 'success' => false, 'error' => 'An unexpected error occurred: ' . $e->getMessage(), ]); } } function facebook_schedule_post_to_page($db, $userId, $pageId, $message, $link, $schedule) { $pageAccessToken = fetch_long_live_access_token($db, $userId, $pageId); $postUrl = 'https://graph.facebook.com/v20.0/me/feed'; // Data to send $postData = [ 'link' => $link, 'message' => $message, 'access_token' => $pageAccessToken, ]; // Initialize cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $postUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute request $response = curl_exec($ch); // Check if there was an error with cURL if (curl_errno($ch)) { curl_close($ch); throw new RuntimeException('cURL error: ' . curl_error($ch)); } curl_close($ch); // Decode the response $responseData = json_decode($response, true); // echo "<pre>"; // print_r($responseData); // echo "</pre>"; // Check if there was an error in the API response if (isset($responseData['error'])) { throw new RuntimeException('Error: ' . $responseData['error']['message']); } return [ 'success' => true, 'message' => 'Message posted successfully!', 'page_id' => $pageId ]; } function fetch_long_live_access_token($db, $userId, $pageId) { $response = ['success' => false]; // Prepare the SQL statement $sql = "SELECT token FROM fb_long_lived_token WHERE pageId = ? AND userId = ?"; if ($stmt = mysqli_prepare($db, $sql)) { // Bind parameters mysqli_stmt_bind_param($stmt, "si", $pageId, $userId); // Execute the statement if (mysqli_stmt_execute($stmt)) { // Bind result mysqli_stmt_bind_result($stmt, $token); // Fetch the result if (mysqli_stmt_fetch($stmt)) { $response = [ 'success' => true, 'token' => $token, ]; } else { $response['error'] = 'No token found for userId: ' . $userId . ' and pageId: ' . $pageId; } } else { $response['error'] = 'Error executing statement: ' . mysqli_stmt_error($stmt); } // Close the statement mysqli_stmt_close($stmt); } else { $response['error'] = 'Error preparing statement: ' . mysqli_error($db); } // Close the database connection mysqli_close($db); return json_encode($response); } function sendResponse($message, $response = "error", $data = []) { echo json_encode(array_merge(['message' => $message], $data)); } if ( isset($data['action']) && isset($data['pages']) && is_array($data['pages']) && isset($data['title']) && isset($data['link']) ) { $action = $data['action']; if ($action === 'postNow') { $responseData = postNow($db, $gUserId, $data['pages'], $data['title'], $data['link']); sendResponse($responseData['message'], $responseData); } elseif ($action === 'schedulePost' && isset($data['schedule'])) { $responseData = schedulePost($db, $gUserId, $data['pages'], $data['title'], $data['link'], $data['schedule']); sendResponse($responseData['message'], $responseData); } else { sendResponse('Invalid action provided.'); } } else { sendResponse('Invalid data provided.'); } ?>