mirror of
https://github.com/cydrobolt/polr.git
synced 2024-11-09 19:52:28 +01:00
Merge branch 'ntoenk1186-master'
This commit is contained in:
commit
3afca8745d
22
.env.setup
22
.env.setup
@ -1,22 +0,0 @@
|
|||||||
APP_ENV=local
|
|
||||||
APP_DEBUG=true
|
|
||||||
APP_KEY=:_<uw?zyc`QQdO{):V?wd9J}%v9/m^bz
|
|
||||||
|
|
||||||
APP_LOCALE=en
|
|
||||||
APP_FALLBACK_LOCALE=en
|
|
||||||
|
|
||||||
# DB_CONNECTION=mysql
|
|
||||||
# DB_HOST=localhost
|
|
||||||
# DB_PORT=3306
|
|
||||||
# DB_DATABASE=homestead
|
|
||||||
# DB_USERNAME=homestead
|
|
||||||
# DB_PASSWORD=secret
|
|
||||||
|
|
||||||
CACHE_DRIVER=file
|
|
||||||
SESSION_DRIVER=file
|
|
||||||
QUEUE_DRIVER=file
|
|
||||||
|
|
||||||
VERSION=2.0.0rc1
|
|
||||||
VERSION_RELMONTH=August
|
|
||||||
VERSION_RELDAY=15
|
|
||||||
VERSION_RELYEAR=2016
|
|
@ -43,6 +43,11 @@ class Handler extends ExceptionHandler {
|
|||||||
if (env('APP_DEBUG') != true) {
|
if (env('APP_DEBUG') != true) {
|
||||||
// Render nice error pages if debug is off
|
// Render nice error pages if debug is off
|
||||||
if ($e instanceof NotFoundHttpException) {
|
if ($e instanceof NotFoundHttpException) {
|
||||||
|
if (env('SETTING_REDIRECT_404')) {
|
||||||
|
// Redirect 404s to SETTING_INDEX_REDIRECT
|
||||||
|
return redirect()->to(env('SETTING_INDEX_REDIRECT'));
|
||||||
|
}
|
||||||
|
// Otherwise, show a nice error page
|
||||||
return view('errors.404');
|
return view('errors.404');
|
||||||
}
|
}
|
||||||
if ($e instanceof HttpException) {
|
if ($e instanceof HttpException) {
|
||||||
@ -54,7 +59,7 @@ class Handler extends ExceptionHandler {
|
|||||||
return view('errors.500');
|
return view('errors.500');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If not 500, then render generic page
|
// If not 500, render generic page
|
||||||
return response(view('errors.generic', ['status_code' => $status_code, 'status_message' => $status_message]), $status_code);
|
return response(view('errors.generic', ['status_code' => $status_code, 'status_message' => $status_message]), $status_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,18 +48,25 @@ class LinkController extends Controller {
|
|||||||
$link = Link::where('short_url', $short_url)
|
$link = Link::where('short_url', $short_url)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
// Return 404 if link not found
|
||||||
if ($link == null) {
|
if ($link == null) {
|
||||||
return abort(404);
|
return abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$link_secret_key = $link->secret_key;
|
// Return an error if the link has been disabled
|
||||||
|
// or return a 404 if SETTING_REDIRECT_404 is set to true
|
||||||
if ($link->is_disabled == 1) {
|
if ($link->is_disabled == 1) {
|
||||||
|
if (env('SETTING_REDIRECT_404')) {
|
||||||
|
return abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
return view('error', [
|
return view('error', [
|
||||||
'message' => 'Sorry, but this link has been disabled by an administrator.'
|
'message' => 'Sorry, but this link has been disabled by an administrator.'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a 403 if the secret key is incorrect
|
||||||
|
$link_secret_key = $link->secret_key;
|
||||||
if ($link_secret_key) {
|
if ($link_secret_key) {
|
||||||
if (!$secret_key) {
|
if (!$secret_key) {
|
||||||
// if we do not receieve a secret key
|
// if we do not receieve a secret key
|
||||||
@ -72,22 +79,21 @@ class LinkController extends Controller {
|
|||||||
return abort(403);
|
return abort(403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment click count
|
||||||
$long_url = $link->long_url;
|
$long_url = $link->long_url;
|
||||||
$clicks = intval($link->clicks);
|
$clicks = intval($link->clicks);
|
||||||
|
|
||||||
if (is_int($clicks)) {
|
if (is_int($clicks)) {
|
||||||
$clicks += 1;
|
$clicks += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link->clicks = $clicks;
|
$link->clicks = $clicks;
|
||||||
|
|
||||||
$link->save();
|
$link->save();
|
||||||
|
|
||||||
|
// Redirect to final destination
|
||||||
LinkHelper::processPostClick($link);
|
LinkHelper::processPostClick($link);
|
||||||
|
|
||||||
return redirect()->to($long_url);
|
return redirect()->to($long_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@ class SetupController extends Controller {
|
|||||||
// if true, only logged in users can shorten
|
// if true, only logged in users can shorten
|
||||||
$st_shorten_permission = $request->input('setting:shorten_permission');
|
$st_shorten_permission = $request->input('setting:shorten_permission');
|
||||||
$st_index_redirect = $request->input('setting:index_redirect');
|
$st_index_redirect = $request->input('setting:index_redirect');
|
||||||
|
$st_redirect_404 = $request->input('setting:redirect_404');
|
||||||
$st_password_recov = $request->input('setting:password_recovery');
|
$st_password_recov = $request->input('setting:password_recovery');
|
||||||
|
|
||||||
$st_base = $request->input('setting:base');
|
$st_base = $request->input('setting:base');
|
||||||
@ -143,6 +144,7 @@ class SetupController extends Controller {
|
|||||||
'POLR_ACCT_ACTIVATION' => $polr_acct_activation,
|
'POLR_ACCT_ACTIVATION' => $polr_acct_activation,
|
||||||
'ST_SHORTEN_PERMISSION' => $st_shorten_permission,
|
'ST_SHORTEN_PERMISSION' => $st_shorten_permission,
|
||||||
'ST_INDEX_REDIRECT' => $st_index_redirect,
|
'ST_INDEX_REDIRECT' => $st_index_redirect,
|
||||||
|
'ST_REDIRECT_404' => $st_redirect_404,
|
||||||
'ST_PASSWORD_RECOV' => $st_password_recov,
|
'ST_PASSWORD_RECOV' => $st_password_recov,
|
||||||
|
|
||||||
'MAIL_ENABLED' => $mail_enabled,
|
'MAIL_ENABLED' => $mail_enabled,
|
||||||
|
@ -24,5 +24,7 @@
|
|||||||
<env name="CACHE_DRIVER" value="array"/>
|
<env name="CACHE_DRIVER" value="array"/>
|
||||||
<env name="SESSION_DRIVER" value="array"/>
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
<env name="QUEUE_DRIVER" value="sync"/>
|
<env name="QUEUE_DRIVER" value="sync"/>
|
||||||
|
<env name="SETTING_REDIRECT_URL_NOT_EXIST" value="true"/>
|
||||||
|
<env name="SETTING_INDEX_REDIRECT" value="http://redirect.polr.me/"/>
|
||||||
</php>
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 612 KiB After Width: | Height: | Size: 1.6 MiB |
@ -54,10 +54,14 @@ POLR_ACCT_ACTIVATION={{$POLR_ACCT_ACTIVATION}}
|
|||||||
# Set to true to require users to be logged in before shortening URLs
|
# Set to true to require users to be logged in before shortening URLs
|
||||||
SETTING_SHORTEN_PERMISSION={{$ST_SHORTEN_PERMISSION}}
|
SETTING_SHORTEN_PERMISSION={{$ST_SHORTEN_PERMISSION}}
|
||||||
|
|
||||||
# You must set SETTING_INDEX_REDIRETC if SETTING_PUBLIC_INTERFACE is false
|
# You must set SETTING_INDEX_REDIRECT if SETTING_PUBLIC_INTERFACE is false
|
||||||
# Polr will redirect logged off users to this URL
|
# Polr will redirect logged off users to this URL
|
||||||
SETTING_INDEX_REDIRECT={{$ST_INDEX_REDIRECT}}
|
SETTING_INDEX_REDIRECT={{$ST_INDEX_REDIRECT}}
|
||||||
|
|
||||||
|
# Set to true if you wish to redirect 404s to SETTING_INDEX_REDIRECT
|
||||||
|
# Otherwise, an error message will be shown
|
||||||
|
SETTING_REDIRECT_404={{$ST_REDIRECT_404}}
|
||||||
|
|
||||||
# Set to true to enable password recovery
|
# Set to true to enable password recovery
|
||||||
SETTING_PASSWORD_RECOV={{$ST_PASSWORD_RECOV}}
|
SETTING_PASSWORD_RECOV={{$ST_PASSWORD_RECOV}}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ Setup
|
|||||||
<p>Application protocol:</p>
|
<p>Application protocol:</p>
|
||||||
<input type='text' class='form-control' name='app:protocol' value='http://'>
|
<input type='text' class='form-control' name='app:protocol' value='http://'>
|
||||||
|
|
||||||
<p>Application URL (path to Polr, no http://, or trailing slash):</p>
|
<p>Application URL (path to Polr; do not include http:// or trailing slash):</p>
|
||||||
<input type='text' class='form-control' name='app:external_url' value='yoursite.com'>
|
<input type='text' class='form-control' name='app:external_url' value='yoursite.com'>
|
||||||
|
|
||||||
<p>Shortening Permissions:</p>
|
<p>Shortening Permissions:</p>
|
||||||
@ -61,15 +61,21 @@ Setup
|
|||||||
<option value='true'>Only logged in users may shorten URLs</option>
|
<option value='true'>Only logged in users may shorten URLs</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<p>Show Public Interface:</p>
|
<p>Public Interface:</p>
|
||||||
<select name='setting:public_interface' class='form-control'>
|
<select name='setting:public_interface' class='form-control'>
|
||||||
<option value='true' selected='selected'>Show public interface (default)</option>
|
<option value='true' selected='selected'>Show public interface (default)</option>
|
||||||
<option value='false'>Hide public interface (for private shorteners)</option>
|
<option value='false'>Redirect index page to redirect URL</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<p>404s and Disabled Short Links:</p>
|
||||||
|
<select name='setting:redirect_404' class='form-control'>
|
||||||
|
<option value='false' selected='selected'>Show an error message (default)</option>
|
||||||
|
<option value='true'>Redirect to redirect URL</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If public interface is hidden, redirect index page to:
|
Redirect URL:
|
||||||
<button data-content="Required if public interface is hidden. To use Polr, login by directly heading to yoursite.com/login first." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
|
<button data-content="Required if you wish to redirect the index page or 404s to a different website. To use Polr, login by directly heading to yoursite.com/login first." type="button" class="btn btn-xs btn-default setup-qmark" data-toggle="popover">?</button>
|
||||||
</p>
|
</p>
|
||||||
<input type='text' class='form-control' name='setting:index_redirect' placeholder='http://your-main-site.com'>
|
<input type='text' class='form-control' name='setting:index_redirect' placeholder='http://your-main-site.com'>
|
||||||
<p class='text-muted'>
|
<p class='text-muted'>
|
||||||
@ -181,7 +187,7 @@ Setup
|
|||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/simplex/bootstrap.min.css'>Crisp White</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/simplex/bootstrap.min.css'>Crisp White</option>
|
||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/darkly/bootstrap.min.css'>Cloudy Night</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/darkly/bootstrap.min.css'>Cloudy Night</option>
|
||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cerulean/bootstrap.min.css'>Calm Skies</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cerulean/bootstrap.min.css'>Calm Skies</option>
|
||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/paper/bootstrap.min.css'>Android Material Design</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/paper/bootstrap.min.css'>Google Material Design</option>
|
||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/superhero/bootstrap.min.css'>Blue Metro</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/superhero/bootstrap.min.css'>Blue Metro</option>
|
||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/sandstone/bootstrap.min.css'>Sandstone</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/sandstone/bootstrap.min.css'>Sandstone</option>
|
||||||
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cyborg/bootstrap.min.css'>Jet Black</option>
|
<option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cyborg/bootstrap.min.css'>Jet Black</option>
|
||||||
|
15
tests/LinkControllerTest.php
Normal file
15
tests/LinkControllerTest.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class LinkControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test LinkController
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testRequestGetNotExistShortUrl() {
|
||||||
|
$response = $this->call('GET', '/notexist');
|
||||||
|
$this->assertTrue($response->isRedirection());
|
||||||
|
$this->assertRedirectedTo(env('SETTING_INDEX_REDIRECT'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user