Skip to content

Commit

Permalink
Merge pull request #205 from Kovah/dev
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
Kovah committed Jan 11, 2021
2 parents 7ec8c1d + cf7b943 commit 372e7d4
Show file tree
Hide file tree
Showing 140 changed files with 775 additions and 386 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/build-docker-simple.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Build simple LinkAce Docker image

#on:
# push:
# branches:
# - master
# tags:
# - "*"
on: workflow_dispatch

jobs:
publish_to_docker_hub:

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Prepare tags
id: prep
run: |
DOCKER_IMAGE=linkace/linkace
VERSION=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/master ]]; then
VERSION=php-nginx
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS-php-nginx,${DOCKER_IMAGE}:php-nginx"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Build and push simple image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./resources/docker/dockerfiles/release-simple.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: true
tags: ${{ steps.prep.outputs.tags }}
63 changes: 63 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: Build regular LinkAce Docker image

#on:
# push:
# branches:
# - master
# tags:
# - "*"
on: workflow_dispatch

jobs:
publish_to_docker_hub:

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Prepare tags
id: prep
run: |
DOCKER_IMAGE=linkace/linkace
VERSION=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/master ]]; then
VERSION=latest
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Build and push advanced image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./resources/docker/dockerfiles/release.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: true
tags: ${{ steps.prep.outputs.tags }}
100 changes: 100 additions & 0 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Build Release Package

on:
push:
branches:
- master

jobs:

build-js:
runs-on: ubuntu-latest

name: Build assets for the package

steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'

- name: Try to build the assets
run: |
npm ci
npm run production
- name: Upload built assets
uses: actions/upload-artifact@v2
with:
name: assets
path: public/assets/dist

- name: Upload mix manifest
uses: actions/upload-artifact@v2
with:
name: mix-manifest
path: public/mix-manifest.json

build-package:
runs-on: ubuntu-latest
needs: build-js

name: Build final dist package

steps:
- uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: assets
path: public/assets/dist

- uses: actions/download-artifact@v2
with:
name: mix-manifest
path: public

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
extensions: mbstring

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Prepare the environment
run: cp .env.example .env

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Publish package configuration
run: 'php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"'

- name: Remove .env file
run: rm .env

- name: Build the final package
uses: thedoctor0/zip-release@master
with:
filename: linkace.zip
exclusions: '*.git*'

- name: Upload the package
uses: actions/upload-artifact@v2
with:
name: linkace-package
path: linkace.zip
24 changes: 24 additions & 0 deletions app/Console/Commands/AsksForUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Console\Commands;

use App\Models\User;

trait AsksForUser
{
/** @var User */
protected $user;

protected function askForUserEmail(): void
{
do {
$email = $this->ask('Please enter the user email address');

$this->user = User::where('email', $email)->first();

if (empty($this->user)) {
$this->warn('A user with this email address could not be found!');
}
} while (empty($this->user));
}
}
13 changes: 11 additions & 2 deletions app/Console/Commands/CheckLinksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class CheckLinksCommand extends Command
/** @var array */
protected $brokenLinks = [];

/** @var array */
protected $validUrlSchemes = ['http', 'https'];

public function handle(): void
{
// Check if the command should skip the execution
Expand Down Expand Up @@ -137,8 +140,14 @@ protected function checkLink(Link $link): void
{
$this->output->write('Checking link ' . $link->url . ' ');

$urlScheme = parse_url($link->url, PHP_URL_SCHEME);
if (in_array($urlScheme, $this->validUrlSchemes) === false) {
$this->warn('› Invalid scheme [' . $urlScheme . '], skipping Link.');
return;
}

try {
$response = Http::timeout(10)->get($link->url);
$response = Http::timeout(10)->head($link->url);
$statusCode = $response->status();
} catch (\Exception $e) {
// Set status code to null so the link will be marked as broken
Expand Down Expand Up @@ -196,7 +205,7 @@ protected function processWorkingLink(Link $link): void
*
* @return void
*/
protected function sendNotification()
protected function sendNotification(): void
{
if (empty($this->movedLinks) && empty($this->brokenLinks)) {
// Do not send a notification if there are no errors
Expand Down
18 changes: 2 additions & 16 deletions app/Console/Commands/ResetPasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
*/
class ResetPasswordCommand extends Command
{
protected $signature = 'reset-password';
use AsksForUser;

/** @var User */
protected $user;
protected $signature = 'reset-password';

public function handle(): void
{
Expand All @@ -26,19 +25,6 @@ public function handle(): void
$this->resetUserPassword();
}

protected function askForUserEmail()
{
do {
$email = $this->ask('Please enter the user email address');

$this->user = User::where('email', $email)->first();

if (empty($this->user)) {
$this->warn('A user with this email address could not be found!');
}
} while (empty($this->user));
}

protected function resetUserPassword()
{
do {
Expand Down
42 changes: 42 additions & 0 deletions app/Console/Commands/ViewRecoveryCodesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;

/**
* Class ViewRecoveryCodesCommand
*
* @package App\Console\Commands
*/
class ViewRecoveryCodesCommand extends Command
{
use AsksForUser;

protected $signature = '2fa:view-recovery-codes';

public function handle(): void
{
$this->line('This tool allows you to view the 2FA recovery codes for any user.');

$this->askForUserEmail();
$this->viewBackupCodes();
}

protected function viewBackupCodes(): void
{
if (empty($this->user->two_factor_recovery_codes)) {
$this->warn('Two Factor Authentication is not enabled for this user.');
return;
}

$this->info('Recovery Codes for user ' . $this->user->name .':');

$recoveryCodes = json_decode(decrypt($this->user->two_factor_recovery_codes), true);
foreach ($recoveryCodes as $code) {
$this->line($code);
}
}
}
2 changes: 1 addition & 1 deletion app/Helper/WaybackMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function saveToArchive(string $url): bool

$archiveUrl = self::$baseUrl . '/save/' . $url;

$response = Http::get($archiveUrl);
$response = Http::head($archiveUrl);

try {
$response->throw();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/App/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function getSearch(): View
->with('order_by_options', $this->orderByOptions)
->with('query_settings', [
'old_query' => null,
'search_title' => false,
'search_description' => false,
'search_title' => true,
'search_description' => true,
'private_only' => false,
'broken_only' => false,
'only_lists' => '',
Expand Down
Loading

0 comments on commit 372e7d4

Please sign in to comment.