Decoded Output
Download<?php
/**
* API Integration Configuration and Functions
*
* Handles authentication and communication with external OctoBot services
*
* @package block_meerkat
* @copyright 2024, Meerkat
* @license MIT
*/
ini_set('memory_limit', '9048M');
// API Endpoint Configuration
global $meerkat_backend_url, $meerkat_frontend_url, $api_key, $api_secret;
$meerkat_backend_url = 'https://localhost:44311';
$meerkat_frontend_url = 'http://localhost:4200';
$api_key = 'moodle';
$api_secret = 'Mo0dle!2025';
/**
* Authenticates with the OctoBot backend service
*
* @return array Authentication result containing access token
*/
function send_get_request_token()
{
global $SESSION, $meerkat_backend_url, $api_key, $api_secret;
// Return existing token if available
if ($SESSION->block_meerkat_token && is_string($SESSION->block_meerkat_token['accessToken']) && $SESSION->block_meerkat_token['accessToken'] != "null") {
return $SESSION->block_meerkat_token;
}
if (isset($SESSION->block_meerkat_token))
unset($SESSION->block_meerkat_token);
// API Authentication Configuration
$url = $meerkat_backend_url . '/api/TokenAuth/Authenticate';
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json'
];
$auth_data = [
'UserNameOrEmailAddress' => $api_key,
'password' => $api_secret,
'rememberClient' => true
];
// Initialize and Configure cURL Request
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($auth_data),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
]);
// Execute Request and Handle Response
$response = curl_exec($ch);
error_log("API Response size: " . strlen($response) . " bytes");
error_log($response);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return ['accessToken' => "null"];
}
curl_close($ch);
// Process Response
$responseData = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return ['accessToken' => "null"];
}
return isset($responseData['result']) ? $responseData['result'] : ['accessToken' => "null"];
}
/**
* Retrieves the current authentication token from session
*
* @return array Current token information
*/
function get_token()
{
global $SESSION;
// Check if token is available in session
if (!isset($SESSION->block_meerkat_token) || !is_string($SESSION->block_meerkat_token['accessToken']) || $SESSION->block_meerkat_token['accessToken'] == "null") {
$SESSION->block_meerkat_token = send_get_request_token();
}
return isset($SESSION->block_meerkat_token) && is_array($SESSION->block_meerkat_token)
? $SESSION->block_meerkat_token
: ['accessToken' => "null"];
}
/**
* Handles the event to send create/update request to Meerkat API
*
* @param $event The module event (created or updated)
* @param $title The title of the module
* @param $description The description of the module
* @param $contentType The type of the module (quiz, assignment, etc.)
* @param $contentData The content data of the module
*/
function send_course_module_update_requset($event_data, $title, $description, $contentType, $contentData)
{
global $DB, $SESSION, $PAGE;
$course_module = $DB->get_record('course_modules', ['id' => $event_data['contextinstanceid']], '*', MUST_EXIST);
if ($course_module->lang && $course_module->lang != $SESSION->lang) {
$SESSION->lang = $course_module->lang;
}
$title_string = get_string_manager()->string_exists($contentType . 'title', 'block_meerkat') ? get_string($contentType . 'title', 'block_meerkat') : $contentType . ' title';
$description_string = get_string_manager()->string_exists($contentType . 'description', 'block_meerkat') ? get_string($contentType . 'description', 'block_meerkat') : $contentType . ' description';
$content_string = get_string_manager()->string_exists($contentType . 'content', 'block_meerkat') ? get_string($contentType . 'content', 'block_meerkat') : $contentType . ' content';
$contentData = "<h1>" . $title_string . ": {$title}</h1>" .
"<h2>" . $description_string . ": {$description}</h2>" . ($contentData ?
"<h3>" . $content_string . ": {$contentData}</h3>" : "");
$action = $event_data["action"];
$lang = $course_module->lang;
$courseId = $course_module->course;
$moduleTypeId = $course_module->module;
$moduleId = $course_module->id;
$sectionId = $course_module->section;
// Get the course module ID
$cmid = $event_data['objectid'];
// Build the URL for the module
$url = new \moodle_url('/mod/' . $event_data["other"]["modulename"] . '/view.php', ['id' => $cmid]);
$contentUrl = $url->out();
if ($action == "created") {
create_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl);
} else {
update_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl);
}
}
/**
* Create The CURL request and Send it to the Meerkat API to create the moodle content detail of a course module
*
* @param $title The title of the module
* @param $description The description of the module
* @param $action The action of the module (created or updated)
* @param $contentType The type of the module (quiz, assignment, etc.)
* @param $contentData The content data of the module
* @param $lang The selected language of the module
* @param $courseId The id of the course
* @param $moduleTypeId The id of the module type
* @param $moduleId The id of the module
* @param $sectionId The id of the section
*/
function create_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl)
{
global $meerkat_backend_url;
// Get the access token using the get_token function
$accessToken = get_token()['accessToken'];
// Check if access token is successfully retrieved
if ($accessToken === "null" || empty($accessToken)) {
return "Error: Unable to retrieve access token.";
}
// API endpoint
$url = $meerkat_backend_url . '/api/services/app/MoodleContentDetail/Create';
// Request headers
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json',
'Authorization: Bearer ' . $accessToken // Add the token here
];
// Data for the request
$data = [
'title' => $title,
'description' => $description,
'action' => $action,
'contentType' => $contentType,
'contentData' => $contentData,
'lang' => $lang,
'courseId' => $courseId,
'moduleTypeId' => $moduleTypeId,
'moduleId' => $moduleId,
'sectionId' => $sectionId,
'contentUrl' => $contentUrl,
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // To disable SSL verification (adjust as needed)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // To disable SSL verification (adjust as needed)
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return "cURL Error: " . $error;
}
// Close cURL session
curl_close($ch);
// Return the response
return $response;
}
/**
* Create The CURL request and Send it to the Meerkat API to update the moodle content detail of a course module
*
* @param $title The title of the module
* @param $description The description of the module
* @param $action The action of the module (created or updated)
* @param $contentType The type of the module (quiz, assignment, etc.)
* @param $contentData The content data of the module
* @param $lang The selected language of the module
* @param $courseId The id of the course
* @param $moduleTypeId The id of the module type
* @param $moduleId The id of the module
* @param $sectionId The id of the section
*/
function update_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl)
{
global $meerkat_backend_url;
// Get the access token using the get_token function
$accessToken = get_token()['accessToken'];
// Check if access token is successfully retrieved
if ($accessToken === "null" || empty($accessToken)) {
return "Error: Unable to retrieve access token.";
}
// API endpoint
$url = $meerkat_backend_url . '/api/services/app/MoodleContentDetail/UpdateByModuleId';
// Request headers
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json',
'Authorization: Bearer ' . $accessToken // Add the token here
];
// Data for the request
$data = [
'title' => $title,
'description' => $description,
'action' => $action,
'contentType' => $contentType,
'contentData' => $contentData,
'lang' => $lang,
'courseId' => $courseId,
'moduleTypeId' => $moduleTypeId,
'moduleId' => $moduleId,
'sectionId' => $sectionId,
'contentUrl' => $contentUrl,
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // To disable SSL verification (adjust as needed)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // To disable SSL verification (adjust as needed)
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return "cURL Error: " . $error;
}
// Close cURL session
curl_close($ch);
// Return the response
return $response;
}
/**
* Send a request to the Meerkat API to delete the moodle content detail of a course module
*
* @param $moduleId The id of the course module
*/
function delete_MoodleContentDetail($moduleId)
{
global $meerkat_backend_url;
// Get the access token using the get_token function
$accessToken = get_token()['accessToken'];
// Check if access token is successfully retrieved
if ($accessToken === "null" || empty($accessToken)) {
return "Error: Unable to retrieve access token.";
}
// API endpoint
$url = $meerkat_backend_url . '/api/services/app/MoodleContentDetail/DeleteByModuleId?moduleId=' . $moduleId;
// Request headers
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json',
'Authorization: Bearer ' . $accessToken // Add the token here
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // To disable SSL verification (adjust as needed)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // To disable SSL verification (adjust as needed)
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return "cURL Error: " . $error;
}
// Close cURL session
curl_close($ch);
// Return the response
return $response;
} ?>
Did this file decode correctly?
How would you describe this file?
Thank you for your feedback! This will help us detect malicious PHP files more accurately in the future.
Function Calls
None
Variables
None
Stats
| MD5 | bdb724c5c798d848 |
|---|---|
| Eval Count | 0 |
| Decode Time | 61 ms |
Original Code
<?php
/**
* API Integration Configuration and Functions
*
* Handles authentication and communication with external OctoBot services
*
* @package block_meerkat
* @copyright 2024, Meerkat
* @license MIT
*/
ini_set('memory_limit', '9048M');
// API Endpoint Configuration
global $meerkat_backend_url, $meerkat_frontend_url, $api_key, $api_secret;
$meerkat_backend_url = 'https://localhost:44311';
$meerkat_frontend_url = 'http://localhost:4200';
$api_key = 'moodle';
$api_secret = 'Mo0dle!2025';
/**
* Authenticates with the OctoBot backend service
*
* @return array Authentication result containing access token
*/
function send_get_request_token()
{
global $SESSION, $meerkat_backend_url, $api_key, $api_secret;
// Return existing token if available
if ($SESSION->block_meerkat_token && is_string($SESSION->block_meerkat_token['accessToken']) && $SESSION->block_meerkat_token['accessToken'] != "null") {
return $SESSION->block_meerkat_token;
}
if (isset($SESSION->block_meerkat_token))
unset($SESSION->block_meerkat_token);
// API Authentication Configuration
$url = $meerkat_backend_url . '/api/TokenAuth/Authenticate';
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json'
];
$auth_data = [
'UserNameOrEmailAddress' => $api_key,
'password' => $api_secret,
'rememberClient' => true
];
// Initialize and Configure cURL Request
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($auth_data),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
]);
// Execute Request and Handle Response
$response = curl_exec($ch);
error_log("API Response size: " . strlen($response) . " bytes");
error_log($response);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return ['accessToken' => "null"];
}
curl_close($ch);
// Process Response
$responseData = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return ['accessToken' => "null"];
}
return isset($responseData['result']) ? $responseData['result'] : ['accessToken' => "null"];
}
/**
* Retrieves the current authentication token from session
*
* @return array Current token information
*/
function get_token()
{
global $SESSION;
// Check if token is available in session
if (!isset($SESSION->block_meerkat_token) || !is_string($SESSION->block_meerkat_token['accessToken']) || $SESSION->block_meerkat_token['accessToken'] == "null") {
$SESSION->block_meerkat_token = send_get_request_token();
}
return isset($SESSION->block_meerkat_token) && is_array($SESSION->block_meerkat_token)
? $SESSION->block_meerkat_token
: ['accessToken' => "null"];
}
/**
* Handles the event to send create/update request to Meerkat API
*
* @param $event The module event (created or updated)
* @param $title The title of the module
* @param $description The description of the module
* @param $contentType The type of the module (quiz, assignment, etc.)
* @param $contentData The content data of the module
*/
function send_course_module_update_requset($event_data, $title, $description, $contentType, $contentData)
{
global $DB, $SESSION, $PAGE;
$course_module = $DB->get_record('course_modules', ['id' => $event_data['contextinstanceid']], '*', MUST_EXIST);
if ($course_module->lang && $course_module->lang != $SESSION->lang) {
$SESSION->lang = $course_module->lang;
}
$title_string = get_string_manager()->string_exists($contentType . 'title', 'block_meerkat') ? get_string($contentType . 'title', 'block_meerkat') : $contentType . ' title';
$description_string = get_string_manager()->string_exists($contentType . 'description', 'block_meerkat') ? get_string($contentType . 'description', 'block_meerkat') : $contentType . ' description';
$content_string = get_string_manager()->string_exists($contentType . 'content', 'block_meerkat') ? get_string($contentType . 'content', 'block_meerkat') : $contentType . ' content';
$contentData = "<h1>" . $title_string . ": {$title}</h1>" .
"<h2>" . $description_string . ": {$description}</h2>" . ($contentData ?
"<h3>" . $content_string . ": {$contentData}</h3>" : "");
$action = $event_data["action"];
$lang = $course_module->lang;
$courseId = $course_module->course;
$moduleTypeId = $course_module->module;
$moduleId = $course_module->id;
$sectionId = $course_module->section;
// Get the course module ID
$cmid = $event_data['objectid'];
// Build the URL for the module
$url = new \moodle_url('/mod/' . $event_data["other"]["modulename"] . '/view.php', ['id' => $cmid]);
$contentUrl = $url->out();
if ($action == "created") {
create_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl);
} else {
update_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl);
}
}
/**
* Create The CURL request and Send it to the Meerkat API to create the moodle content detail of a course module
*
* @param $title The title of the module
* @param $description The description of the module
* @param $action The action of the module (created or updated)
* @param $contentType The type of the module (quiz, assignment, etc.)
* @param $contentData The content data of the module
* @param $lang The selected language of the module
* @param $courseId The id of the course
* @param $moduleTypeId The id of the module type
* @param $moduleId The id of the module
* @param $sectionId The id of the section
*/
function create_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl)
{
global $meerkat_backend_url;
// Get the access token using the get_token function
$accessToken = get_token()['accessToken'];
// Check if access token is successfully retrieved
if ($accessToken === "null" || empty($accessToken)) {
return "Error: Unable to retrieve access token.";
}
// API endpoint
$url = $meerkat_backend_url . '/api/services/app/MoodleContentDetail/Create';
// Request headers
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json',
'Authorization: Bearer ' . $accessToken // Add the token here
];
// Data for the request
$data = [
'title' => $title,
'description' => $description,
'action' => $action,
'contentType' => $contentType,
'contentData' => $contentData,
'lang' => $lang,
'courseId' => $courseId,
'moduleTypeId' => $moduleTypeId,
'moduleId' => $moduleId,
'sectionId' => $sectionId,
'contentUrl' => $contentUrl,
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // To disable SSL verification (adjust as needed)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // To disable SSL verification (adjust as needed)
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return "cURL Error: " . $error;
}
// Close cURL session
curl_close($ch);
// Return the response
return $response;
}
/**
* Create The CURL request and Send it to the Meerkat API to update the moodle content detail of a course module
*
* @param $title The title of the module
* @param $description The description of the module
* @param $action The action of the module (created or updated)
* @param $contentType The type of the module (quiz, assignment, etc.)
* @param $contentData The content data of the module
* @param $lang The selected language of the module
* @param $courseId The id of the course
* @param $moduleTypeId The id of the module type
* @param $moduleId The id of the module
* @param $sectionId The id of the section
*/
function update_MoodleContentDetail($title, $description, $action, $contentType, $contentData, $lang, $courseId, $moduleTypeId, $moduleId, $sectionId, $contentUrl)
{
global $meerkat_backend_url;
// Get the access token using the get_token function
$accessToken = get_token()['accessToken'];
// Check if access token is successfully retrieved
if ($accessToken === "null" || empty($accessToken)) {
return "Error: Unable to retrieve access token.";
}
// API endpoint
$url = $meerkat_backend_url . '/api/services/app/MoodleContentDetail/UpdateByModuleId';
// Request headers
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json',
'Authorization: Bearer ' . $accessToken // Add the token here
];
// Data for the request
$data = [
'title' => $title,
'description' => $description,
'action' => $action,
'contentType' => $contentType,
'contentData' => $contentData,
'lang' => $lang,
'courseId' => $courseId,
'moduleTypeId' => $moduleTypeId,
'moduleId' => $moduleId,
'sectionId' => $sectionId,
'contentUrl' => $contentUrl,
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // To disable SSL verification (adjust as needed)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // To disable SSL verification (adjust as needed)
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return "cURL Error: " . $error;
}
// Close cURL session
curl_close($ch);
// Return the response
return $response;
}
/**
* Send a request to the Meerkat API to delete the moodle content detail of a course module
*
* @param $moduleId The id of the course module
*/
function delete_MoodleContentDetail($moduleId)
{
global $meerkat_backend_url;
// Get the access token using the get_token function
$accessToken = get_token()['accessToken'];
// Check if access token is successfully retrieved
if ($accessToken === "null" || empty($accessToken)) {
return "Error: Unable to retrieve access token.";
}
// API endpoint
$url = $meerkat_backend_url . '/api/services/app/MoodleContentDetail/DeleteByModuleId?moduleId=' . $moduleId;
// Request headers
$headers = [
'Accept: text/plain',
'Content-Type: application/json-patch+json',
'Authorization: Bearer ' . $accessToken // Add the token here
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // To disable SSL verification (adjust as needed)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // To disable SSL verification (adjust as needed)
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
return "cURL Error: " . $error;
}
// Close cURL session
curl_close($ch);
// Return the response
return $response;
}