403Webshell
Server IP : 213.159.210.37  /  Your IP : 216.73.216.164
Web Server : nginx/1.18.0
System : Linux palich.ru 5.10.0-43-amd64 #1 SMP Debian 5.10.251-5 (2026-05-15) x86_64
User :  ( 600)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/custom-site/api.palich.ru/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/custom-site/api.palich.ru/index.php
<?php
//error_reporting(E_ALL ^ (E_NOTICE | E_WARNING | E_DEPRECATED));

error_reporting(E_ALL);
ini_set('display_errors', 1);

include_once('functions.php');

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
//use Slim\Psr7\Response;
use Slim\Factory\AppFactory;
use Middlewares\TrailingSlash;


define("API_DATA_PATH", '/var/www/custom-site/api-data');
define("API_LOGS_PATH", API_DATA_PATH.'/logs');

if (is_file(API_DATA_PATH.'/config.php'))
{
	include_once(API_DATA_PATH.'/config.php');
}


if (isset($_GET['IS_DEV']) && trim($_GET['IS_DEV'])=="YES")
{
	define("IS_DEV_API", true);
	define("CMS_DOCUMENT_ROOT", "/var/www/www-root/data/www/dev");
	$IS_DEV = true;
}
else
{
	define("IS_DEV_API", false);
	define("CMS_DOCUMENT_ROOT", "/var/www/www-root/data/www/ro-studio.ru");
	$IS_DEV = false;
}


require API_DATA_PATH.'/vendor/autoload.php';

$app = AppFactory::create();

$app->addErrorMiddleware(true, true, true); //false, true, true

$app->add(new TrailingSlash(true));

$apiKey = 'vK96V(Aj8*tzz#iP2%Af!fY7t';



$app->add(function (
    Request $slim_api_request,
    RequestHandler $handler
) use ($app, $apiKey): Response {

    $key = $slim_api_request->getHeaderLine('X-API-Key');

    $expectedKey = $apiKey;

    if (str_starts_with($slim_api_request->getUri()->getPath(), '/v1/messages/'))
    {
        $expectedKey = (defined("PUSH_CAMPAIGNS_API_KEY")?PUSH_CAMPAIGNS_API_KEY:'');
    }

    if (!$key || !$expectedKey || !hash_equals($expectedKey, $key)) {

        $slim_api_response = $app->getResponseFactory()->createResponse(401);

        $slim_api_response->getBody()->write(json_encode([
            'error' => 'Unauthorized'
        ]));

        return $slim_api_response->withHeader('Content-Type', 'application/json');
    }

    return $handler->handle($slim_api_request);
});



$app->get('/', function (Request $slim_api_request, Response $slim_api_response, $slim_api_args) {

		$slim_api_response->getBody()->write('PALICH.RU API SERVICE');
    return $slim_api_response;
		
});


$app->post('/v1/users/set/fb_token/', function (Request $slim_api_request, Response $slim_api_response, $slim_api_args) {
		
		$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'] = CMS_DOCUMENT_ROOT;
		require_once($DOCUMENT_ROOT."/bitrix/modules/main/include/prolog_before.php");
		
		if (!defined("BITRIX_LOADED"))
		{
			$slim_api_response->getBody()->write("CMS Temporarily Unavailable");
			return $slim_api_response->withHeader('Content-Type', 'application/json')->withStatus(503);			
		}		
		
		global $DB;
		
		
		$result = array('response'=>array("success" => false), 'status'=>200);
		
		$data = $slim_api_request->getBody()->getContents();
		
		api_log_write("set_token", $data, "REQUEST:\n", false);
		
    if ($data)
		{
			if (($json = json_decode(trim($data), true)) && (is_array($json)))
			{
				if (isset($json['userID']) && ($userID = intval($json['userID'])))
				{					
					$request_token_field = 'fbToken';
					$bitrix_user_field = 'UF_FIREBASE_TOKENS';
					
					if (isset($json['platform']) && ($json['platform'] == "ios"))
					{
						$request_token_field = 'pushToken';
						$bitrix_user_field = 'UF_FIREBASE_TOKENS_IOS';
					}
															
					if (isset($json[$request_token_field]) && ($fbToken = trim($json[$request_token_field])))
					{
						$arUser = Bitrix\Main\UserTable::getList([
								'select' => ['ID', $bitrix_user_field],
								'filter' => ['=ID' => $userID],
								'limit'  => 1,
						])->fetch();

						if ($arUser && isset($arUser['ID']) && ($arUser['ID']==$userID))
						{													
							$TOKENS = [];
							if (isset($arUser[$bitrix_user_field]) && ($s = trim($arUser[$bitrix_user_field])) && ($arr = json_decode($s, true)) && (is_array($arr) && sizeof($arr)))
							{
								$TOKENS = $arr;
							}
							$TOKENS[] = $fbToken;
							
							$TOKENS = array_unique($TOKENS);
							
							$UPDATE_ARR = [$bitrix_user_field => json_encode($TOKENS)];					
							
							$bx_user = new CUser();
							$bx_result = $bx_user->Update($userID, $UPDATE_ARR);

							if ($bx_result)
							{
								$result['response']["success"] = true;
							}
							else
							{
								if ($bx_error = trim((is_array($bx_user->LAST_ERROR)?current($bx_user->LAST_ERROR):$bx_user->LAST_ERROR)))
								{
									$result['response']['errorMsg'] = "Не удалось записать токен в базу данных сайта по причине следующей ошибки: ".$bx_error;																	
								}
								else
								{
									$result['response']['errorMsg'] = "Не удалось записать токен в базу данных сайта по причине неизвестной ошибки";
								}
								$result['status'] = 400;								
							}
						}
						else
						{
							$result['response']['errorMsg'] = "Указанный пользователь не найден на сайте";
							$result['status'] = 400;
						}						
					}
					else
					{
						$result['response']['errorMsg'] = "Не указан FireBase-токен";
						$result['status'] = 400;
					}					
				}
				else
				{
					$result['response']['errorMsg'] = "Не указан ID пользователя";
					$result['status'] = 400;
				}				
			}
			else
			{
				$result['response']['errorMsg'] = "Получены данные в некорректном формате";
				$result['status'] = 400;
			}			
		}
		else
		{
			$result['response']['errorMsg'] = "Получен пустой запрос";
			$result['status'] = 400;
		}
		
		api_log_write("set_token", $result, "RESULT:\n", true); 
		
		$slim_api_response->getBody()->write(json_encode($result['response']));

		return $slim_api_response->withHeader('Content-Type', 'application/json')->withStatus($result['status']);
});



$app->post('/v1/messages/send/', function (Request $slim_api_request, Response $slim_api_response, $slim_api_args) {

		@set_time_limit(0);

		$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'] = CMS_DOCUMENT_ROOT;
		require_once($DOCUMENT_ROOT."/bitrix/modules/main/include/prolog_before.php");

		if (!defined("BITRIX_LOADED"))
		{
			$slim_api_response->getBody()->write("CMS Temporarily Unavailable");
			return $slim_api_response->withHeader('Content-Type', 'application/json')->withStatus(503);
		}

		require_once($DOCUMENT_ROOT."/local/modules/push_campaigns/init.php");

		$result = array('response'=>array("result" => false, "message" => ""), 'status'=>200);

		$data = $slim_api_request->getBody()->getContents();

		api_log_write("messages", $data, "REQUEST:\n", false);

		$json = false;

		if (!$data)
		{
			$result['response']['message'] = "Получен пустой запрос";
			$result['status'] = 400;
		}
		elseif (!($json = json_decode(trim($data), true, 512, JSON_BIGINT_AS_STRING)) || !is_array($json))
		{
			$result['response']['message'] = "Получены данные в некорректном формате";
			$result['status'] = 400;
		}
		elseif (!isset($json['message']) || !is_array($json['message']))
		{
			$result['response']['message'] = "Не передан блок message с текстом сообщения";
			$result['status'] = 400;
		}
		elseif (!isset($json['phones']) || !is_array($json['phones']))
		{
			$result['response']['message'] = "Не передан список номеров телефонов phones";
			$result['status'] = 400;
		}
		else
		{
			$IP_ADDR = '';

			foreach(array('HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR') as $server_key)
			{
				if (!$IP_ADDR && isset($_SERVER[$server_key]))
				{
					$IP_ADDR = trim($_SERVER[$server_key]);
				}
			}

			$res = array();
			$fatal = '';

			try {

				$res = push_campaigns_run($json['message'], $json['phones'], $IP_ADDR);

			} catch (\Throwable $e) {

				$fatal = $e->getMessage()." (".$e->getFile().":".$e->getLine().")";
			}

			if ($fatal)
			{
				$result['response']['message'] = "Внутренняя ошибка сайта: ".$fatal;
				$result['status'] = 500;
			}
			else
			{
				if (isset($res['CAMPAIGN']['ID']) && intval($res['CAMPAIGN']['ID']))
				{
					$result['response']['campaign_id'] = intval($res['CAMPAIGN']['ID']);
				}

				$result['response']['status'] = $res['STATUS'];
				$result['response']['stat'] = $res['STAT'];

				if ($res['ERROR'])
				{
					$result['response']['message'] = $res['ERROR'];
					$result['status'] = 400;
				}
				else
				{
					$result['response']['result'] = true;
				}
			}
		}

		api_log_write("messages", $result, "RESULT:\n", true);

		$slim_api_response->getBody()->write(json_encode($result['response'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));

		return $slim_api_response->withHeader('Content-Type', 'application/json')->withStatus($result['status']);
});



$app->get('/v1/messages/status/{id}/', function (Request $slim_api_request, Response $slim_api_response, $slim_api_args) {

		$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'] = CMS_DOCUMENT_ROOT;
		require_once($DOCUMENT_ROOT."/bitrix/modules/main/include/prolog_before.php");

		if (!defined("BITRIX_LOADED"))
		{
			$slim_api_response->getBody()->write("CMS Temporarily Unavailable");
			return $slim_api_response->withHeader('Content-Type', 'application/json')->withStatus(503);
		}

		require_once($DOCUMENT_ROOT."/local/modules/push_campaigns/init.php");

		$result = array('response'=>array("result" => false, "message" => ""), 'status'=>200);

		$res = push_campaigns_status((isset($slim_api_args['id'])?intval($slim_api_args['id']):0));

		if ($res['ERROR'])
		{
			$result['response']['message'] = $res['ERROR'];
			$result['status'] = 404;

			api_log_write("messages", $result, "STATUS RESULT:\n", false, "status_errors.log");
		}
		else
		{
			$result['response']['result'] = true;

			foreach($res['DATA'] as $key => $value)
			{
				$result['response'][$key] = $value;
			}
		}

		$slim_api_response->getBody()->write(json_encode($result['response'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));

		return $slim_api_response->withHeader('Content-Type', 'application/json')->withStatus($result['status']);
});




$app->run();

?>

Youez - 2016 - github.com/yon3zu
LinuXploit