<?php require_once __DIR__ . '/../../../requirements/config.php'; session_start(); header('Content-Type: application/json'); try { parse_str(file_get_contents("php://input"), $request_params); $server = new \AHContentBlockerServer\OAuth\Server(); $server->checkUserAuthentication(true, $request_params); $user = $server->getCurrentUser(); if (!is_null($user)) { $userID = $user->getUserID(); } else { $userID = 0; } $rule = new \AHContentBlockerServer\Rules\Rule($request_params); $rule->save($userID); } catch (Exception $e) { die(json_encode(['error' => ['message' => $e->getMessage()]])); } echo json_encode(['success' => true]);
<?php require_once __DIR__ . '/../../../requirements/config.php'; session_start(); header('Content-Type: application/json'); try { $server = new \AHContentBlockerServer\OAuth\Server(); $server->checkUserAuthentication(true); $user = $server->getCurrentUser(); $whitelisted = $user->getWhitelistedDomains(); } catch (Exception $e) { die(json_encode(['error' => ['message' => $e->getMessage()]])); } echo json_encode(['domains' => $whitelisted]);
<?php require_once __DIR__ . '/../../../requirements/config.php'; session_start(); header('Content-Type: application/json'); try { $server = new \AHContentBlockerServer\OAuth\Server(); $server->checkUserAuthentication(false); $user = $server->getCurrentUser(); if (!is_null($user)) { $userID = $user->getUserID(); } else { $userID = 0; } } catch (Exception $e) { die(json_encode(['error' => ['message' => $e->getMessage()]])); } $requestedCategories = isset($_REQUEST['category']) ? $_REQUEST['category'] : null; $targetType = isset($_REQUEST['targetType']) ? (int) $_REQUEST['targetType'] : 0; $query = sprintf("SELECT * FROM rules WHERE active=1 AND (userID=%d OR (accepted IS NOT NULL AND public=1))", $userID); if ($targetType != \AHContentBlockerServer\RULE_DEVICES_TARGET_ALL) { //No default, if it is unknown, simply return all. switch ($targetType) { case \AHContentBlockerServer\RULE_DEVICES_TARGET_MOBILE: $query .= sprintf(" AND (targetType=%d OR targetType=%d OR targetType=%d OR targetType=%d)", \AHContentBlockerServer\RULE_DEVICES_TARGET_ALL, \AHContentBlockerServer\RULE_DEVICES_TARGET_MOBILE, \AHContentBlockerServer\RULE_DEVICES_TARGET_SMARTPHONE, \AHContentBlockerServer\RULE_DEVICES_TARGET_TABLET); break; case \AHContentBlockerServer\RULE_DEVICES_TARGET_SMARTPHONE: case \AHContentBlockerServer\RULE_DEVICES_TARGET_TABLET: case \AHContentBlockerServer\RULE_DEVICES_TARGET_COMPUTER: $query .= sprintf(" AND (targetType=%d OR targetType=%d)", $targetType, \AHContentBlockerServer\RULE_DEVICES_TARGET_ALL); break;