Esempio n. 1
0
 */
use DevAAC\Models\IpBan;
$meta = array('name' => 'IP Ban', 'description' => 'Disallows access to users who are IP banned. APC user cache is recommended for performance.', 'version' => '0.1', 'author' => 'Don Daniello', 'link' => 'https://github.com/DevelopersPL/DevAAC');
/*
 * This plugin strongly benefits from APC user cache!
 */
if (!in_array(basename(__FILE__), $DevAAC->enabled_plugins)) {
    return array_merge($meta, array('enabled' => false));
}
// http://docs.slimframework.com/#How-to-Use-Hooks
$DevAAC->hook('slim.before', function () use($DevAAC) {
    $req = $DevAAC->request;
    $apc = false;
    if (extension_loaded('apc') && ini_get('apc.enabled')) {
        $apc = true;
        $objname = 'ipban_' . $req->getIp();
    }
    if ($apc && apc_fetch($objname)) {
        $DevAAC->halt(403, 'Your IP address is banned.');
    } else {
        $ipban = IpBan::find(ip2long($req->getIp()));
        if ($ipban) {
            $DevAAC->halt(403, 'Your IP address is banned.');
            if ($apc) {
                apc_store($objname, true, 10 * 60);
            }
            // THE INFORMATION WILL BE IN CACHE FOR 10 MINUTES SO WE CAN REJECT REQUESTS WITHOUT RUNNING ANY SQL QUERIES
        }
    }
});
return array_merge($meta, array('enabled' => true));
Esempio n. 2
0
 *      @SWG\Parameter( name="ip",
 *                      description="IP to lift ban",
 *                      paramType="path",
 *                      required=true,
 *                      type="string"),
 *      @SWG\ResponseMessage(code=403, message="Permission denied"),
 *      @SWG\ResponseMessage(code=404, message="IP is not banned")
 *   )
 *  )
 * )
 */
$DevAAC->delete(ROUTES_API_PREFIX . '/server/ipBans/:ip', function ($ip) use($DevAAC) {
    if (!$DevAAC->auth_account || !$DevAAC->auth_account->isGod()) {
        throw new InputErrorException('You are not an admin', 403);
    }
    $ipban = IpBan::find(ip2long($ip));
    if (!$ipban) {
        throw new InputErrorException('This IP is not banned.', 404);
    }
    $ipban->delete();
    $DevAAC->response->headers->set('Content-Type', 'application/json');
    $DevAAC->response->setBody(json_encode(null, JSON_PRETTY_PRINT));
});
/**
 * @SWG\Resource(
 *  basePath="/api/v1",
 *  resourcePath="/server",
 *  @SWG\Api(
 *    path="/server/info",
 *    description="Operations on server",
 *    @SWG\Operation(