Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
paramtamtam committed Aug 1, 2017
2 parents 21b5851 + 363cfbc commit be055a1
Show file tree
Hide file tree
Showing 122 changed files with 56,017 additions and 632 deletions.
8 changes: 8 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"directory": "public/components",
"color": true,
"save": true,
"scripts": {
"postinstall": ""
}
}
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
APP_ENV=local
APP_DEBUG=true
APP_TIMEZONE=UTC

#CACHE_DRIVER=memcached
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Homestead
Homestead.json
Homestead.yaml

# Environment deps.
/.env
composer.lock
/*ide*helper*.*

# IDEs
/nbproject
/.idea

# WIKIs
/wiki

# Vendors
/vendor

# Temp dirs & trash
/temp
/tmp
/legacy
.DS_Store
.php_cs.cache

# etc.
/processed
/output
/samples
/storage/testswhich/*
/storage/*.key
/public/hot
/public/storage
/.vagrant
npm-debug.log
/node_modules
24 changes: 24 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
preset: laravel

enabled:
- strict
- align_double_arrow
- dir_constant
- linebreak_after_opening_tag
- mb_str_functions
- no_short_echo_tag
- non_printable_character
- ordered_class_elements
- phpdoc_add_missing_param_annotation
- phpdoc_align
- phpdoc_annotation_without_dot
- phpdoc_order
- phpdoc_separation
- phpdoc_return_self_reference
- align_equals
- concat_with_spaces

disabled:
- unalign_equals
- concat_without_spaces

19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

15 changes: 0 additions & 15 deletions README.md

This file was deleted.

File renamed without changes.
30 changes: 30 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
protected function schedule(Schedule $schedule)
{
//
}
}
61 changes: 61 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
*
* @return void
*/
public function report(Exception $e)
{
parent::report($e);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof NotFoundHttpException) {
return response(view('errors.404'), 404);
}

if (env('APP_DEBUG')) {
return parent::render($request, $e);
} else {
return response(view('errors.500'), 500);
}
}
}
21 changes: 21 additions & 0 deletions app/Http/Controllers/AbstractController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller as BaseController;

/**
* Class AbstractController.
*/
abstract class AbstractController extends BaseController
{
/**
* @param $any
*
* @return string
*/
protected function getHash($any)
{
return md5(serialize($any));
}
}
85 changes: 85 additions & 0 deletions app/Http/Controllers/ScriptController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers;

use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Services\HostsParser\HostsParser;

/**
* Class ScriptController.
*/
class ScriptController extends AbstractController
{
/**
* @var \Illuminate\Cache\Repository
*/
protected $cache;

/**
* Response cache lifetime (in seconds);.
*
* @var int
*/
protected $cache_lifetime = 30;

/**
* ScriptController constructor.
*/
public function __construct()
{
$this->cache = app('cache');
}

/**
* Generate script source.
*
* @param Request $request
*
* @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory
*/
public function source(Request $request)
{
$cache_key = $this->getHash($request->all());

if ($this->cache->has($cache_key)) {
/** @var \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory $cached */
$cached = $this->cache->get($cache_key);

return $cached;
} else {
$this->validate($request, [
'sources_urls' => 'required|string|between:11,4096',
'format' => 'string|between:3,64',
'version' => 'string|between:1,8',
'excluded_hosts' => 'string|between:1,4096',
'limit' => 'integer|min:1',
'redirect_to' => 'ip',
]);

$format = $request->get('format', 'routeros');
$version = $request->get('version', config('app.version'));
$limit = $request->get('limit', (int) config('limits.result_entries', 0));
$cache = true;

$hosts_parser = (new HostsParser)
->setCacheEnabled($cache)
->addComment(sprintf(
'Sources cache state: %s, *response* cache lifetime: %s',
$cache ? 'enabled' : 'disabled',
$this->cache_lifetime
))
->addExcludedHosts($request->get('excluded_hosts', config('defaults.excluded_hosts')))
->addSource($request->get('sources_urls'))
->setRedirectToAddress($request->get('redirect_to', config('defaults.redirect_ip')))
->requestSourcesResources();

$result = response($hosts_parser->render($limit, config('defaults.script_ad_entries_comment'), $format))
->header('Content-Type', 'text/plain');

$this->cache->put($cache_key, $result, Carbon::now()->addSeconds($this->cache_lifetime));

return $result;
}
}
}
35 changes: 35 additions & 0 deletions app/Http/Controllers/WebController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Controllers;

/**
* Class WebController.
*/
class WebController extends AbstractController
{
/**
* @return \Illuminate\View\View
*/
public function index()
{
return view('index', [
'sources' => config('sources'),
'user_sources_limit' => config('limits.user_sources'),
'default_redirect_ip' => config('defaults.redirect_ip'),
'result_entries_limit' => config('limits.result_entries'),
'excluded_hosts' => implode("\n", config('defaults.excluded_hosts', [])),
'source_cache_lifetime' => config('limits.source.cache.lifetime'),
'source_uri_length' => config('limits.source_uri_length'),
'excluded_hosts_limit' => config('limits.excluded_hosts'),
'source_file_size_limit' => config('limits.source_file_size'),
'sources_protocols' => config('limits.sources_protocols'),

'js_vars' => [
'APP_VERSION' => config('app.version'),
'REPOSITORY_URI' => config('contacts.repository.uri'),
'SCRIPT_SOURCE_BASE_URI' => route('script.source'),
'SCRIPT_AD_ENTRIES_COMMENT' => config('defaults.script_ad_entries_comment'),
],
]);
}
}
46 changes: 46 additions & 0 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;

class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;

/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
*
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
*
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}

return $next($request);
}
}
Loading

0 comments on commit be055a1

Please sign in to comment.