OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
facebook
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
11/28/2024 11:03:35 AM
rwxrwxr-x
📄
accessTest copy.php
657 bytes
10/10/2024 10:19:25 AM
rw-r--r--
📄
accessTest.php
657 bytes
10/10/2024 10:19:25 AM
rw-r--r--
📄
back_fb_post_handler.php
9.41 KB
10/10/2024 10:19:25 AM
rw-r--r--
📁
backup
-
10/10/2024 10:19:31 AM
rwxr-xr-x
📄
composer-setup.php
57.07 KB
10/10/2024 10:19:25 AM
rw-r--r--
📄
composer.json
64 bytes
10/10/2024 10:19:25 AM
rw-r--r--
📄
composer.lock
2.81 KB
10/10/2024 10:19:25 AM
rw-r--r--
📄
composer.phar
2.86 MB
10/10/2024 10:19:29 AM
rw-r--r--
📄
configuration.txt
79 bytes
10/10/2024 10:19:26 AM
rw-r--r--
📁
cream
-
10/10/2024 10:19:32 AM
rwxr-xr-x
📄
credential copy.json
556 bytes
10/10/2024 10:19:29 AM
rw-r--r--
📄
credential.json
556 bytes
10/10/2024 10:19:29 AM
rw-r--r--
📄
db_connect.php
341 bytes
10/10/2024 10:19:29 AM
rw-r--r--
📄
facebook_setup.php
10.45 KB
10/14/2024 07:50:50 AM
rw-r--r--
📄
facebook_setup_handler.php
1.23 KB
10/16/2024 07:25:53 AM
rw-r--r--
📄
fb_post_handler copy.php
6.55 KB
10/10/2024 10:19:29 AM
rw-r--r--
📄
fb_post_handler.php
12.35 KB
10/10/2024 11:44:18 AM
rw-r--r--
📄
fb_share.php
8.94 KB
10/10/2024 10:19:29 AM
rw-r--r--
📄
function.php
18.91 KB
10/16/2024 07:22:46 AM
rw-r--r--
📄
index.php
476 bytes
10/10/2024 10:19:29 AM
rw-r--r--
📄
navbar.php
1.63 KB
10/10/2024 10:19:29 AM
rw-r--r--
📁
new_folder
-
10/10/2024 10:19:37 AM
rwxr-xr-x
📄
new_index.php
10.18 KB
10/10/2024 10:19:29 AM
rw-r--r--
📄
new_table.php
13.36 KB
10/10/2024 10:19:29 AM
rw-r--r--
📄
postTest.php
3.43 KB
10/10/2024 10:19:29 AM
rw-r--r--
📄
sample_data.txt
7.07 KB
10/10/2024 10:19:30 AM
rw-r--r--
📄
share_facebook.php
2.01 KB
10/10/2024 10:19:30 AM
rw-r--r--
📄
sidebar.php
3.49 KB
10/10/2024 12:07:41 PM
rw-r--r--
📄
test.php
1.72 KB
10/10/2024 10:19:30 AM
rw-r--r--
📄
update_fb_pages.php
347 bytes
10/10/2024 10:19:30 AM
rw-r--r--
📁
vendor
-
10/10/2024 10:19:39 AM
rwxr-xr-x
Editing: back_fb_post_handler.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); class AttributeException extends Exception {} function postNow($db, $userId, $pages, $title, $link) { $returnData = []; $errorData = []; try { foreach ($pages as $page) { $response = facebook_post_to_page($db, $userId, $page, $title, $link); // Check if the response indicates success if (isset($response['success']) && $response['success'] === true) { $returnData[] = [ 'page_id' => $page, 'status' => 'success', 'message' => $response['message'], ]; } else { $errorData[] = [ 'page_id' => $page, 'status' => 'error', 'error_message' => $response['error'] ?? 'An unknown error occurred.', ]; } } // Check if there were any errors if (!empty($errorData)) { throw new Exception(json_encode($errorData)); } return [ 'status' => 'success', 'message' => 'Post(s) sent successfully!', 'title' => $title, 'link' => $link, 'details' => $returnData, ]; } catch (Exception $e) { return [ 'status' => 'error', 'error_message' => 'An error occurred while posting.', 'error' => $e->getMessage(), ]; } } 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 { $tokenResponse = fetch_long_live_access_token($db, $userId, $pageId); // Check if the token was successfully retrieved if (!$tokenResponse['success']) { throw new RuntimeException($tokenResponse['error']); } $pageAccessToken = $tokenResponse['token']; $postUrl = 'https://graph.facebook.com/v20.0/' . $pageId . '/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 as an associative array return [ 'success' => true, 'message' => 'Message posted successfully!', 'page_id' => $pageId, 'response_data' => $responseData, // Include API response data if needed ]; } catch (RuntimeException $e) { return [ 'success' => false, 'error' => $e->getMessage(), ]; } catch (Exception $e) { return [ '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]; try { // 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 { throw new RuntimeException('Error executing statement: ' . mysqli_stmt_error($stmt)); } // Close the statement mysqli_stmt_close($stmt); } else { throw new RuntimeException('Error preparing statement: ' . mysqli_error($db)); } } catch (RuntimeException $e) { $response['error'] = $e->getMessage(); } catch (Exception $e) { $response['error'] = 'An unexpected error occurred: ' . $e->getMessage(); } return $response; // Return the response as an associative array } function sendResponse($response, $data) { if ($response == "error") { echo json_encode(['status' => 'error', 'error_data' => $data]); } elseif ($response == "success") { echo json_encode(['status' => 'success', 'data' => $data]); // echo json_encode(array_merge(['message' => $message], $data)); } } try { // Check for required parameters if (!isset($data['action'])) { throw new AttributeException('Action is not set.'); } if (!isset($data['pages']) || !is_array($data['pages'])) { throw new AttributeException('Pages are not set or not an array.'); } if (!isset($data['title'])) { throw new AttributeException('Title is not set.'); } if (!isset($data['link'])) { throw new AttributeException('Link is not set.'); } switch ($data['action']) { case 'postNow': $responseData = postNow($db, $gUserId, $data['pages'], $data['title'], $data['link']); break; case 'schedulePost': if (!isset($data['schedule'])) { throw new AttributeException('Schedule time is not provided.'); } $responseData = schedulePost($db, $gUserId, $data['pages'], $data['title'], $data['link'], $data['schedule']); break; default: throw new Exception('Invalid action provided.'); } if ($responseData['status'] === "success") { $response = json_encode([ 'message' => $responseData['message'], 'data' => $responseData ]); sendResponse("success", $response); } else { $errorResponse = json_encode([ 'error_message' => $responseData['error_message'] ?? 'An error occurred.', 'error_data' => $responseData ]); sendResponse("error", $errorResponse); } } catch (AttributeException $e) { $errorResponse = json_encode([ 'error_message' => 'Attribute is missing.', 'error_data' => $e->getMessage() ]); sendResponse('error', $errorResponse); } catch (Exception $e) { $errorResponse = json_encode([ 'error_message' => 'An unexpected error occurred.', 'error_data' => $e->getMessage() ]); sendResponse('error', $errorResponse); }