Skip to content

Commit

Permalink
Pulling back new changes from deployment (#396)
Browse files Browse the repository at this point in the history
* Update TrustProxies.php

* Temporarly disable printer

* Added additional parameters for printers

* Added debug message

* Fixed order

* Reenable printer

* Added arguments for printer stats

* Use config instead of env for production #364

* Fix bugs

* Fix bugs

* .

* Fix typo

* Add logging

* Add logging

* Fix pdflatex path

* Change proxy IP

* Change proxy IP

* Added config for commands (#400)

* Added config for commands

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in f1d870d according to the output
from PHP CS Fixer.

Details: #400

* Fixed a bug and added some comments

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 6e41962 according to the output
from PHP CS Fixer.

Details: #400

* Fixed command name

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 6dfdd35 according to the output
from PHP CS Fixer.

Details: #400

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

* Add config options (#401)

* Added config for commands

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in f1d870d according to the output
from PHP CS Fixer.

Details: #400

* Fixed a bug and added some comments

* style: format code with PHP CS Fixer

This commit fixes the style issues introduced in 6e41962 according to the output
from PHP CS Fixer.

Details: #400

* Fixed command name

* fix typo

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

---------

Co-authored-by: horcsinbalint <51171286+horcsinbalint@users.noreply.github.com>
Co-authored-by: Bálint Horcsin <horcsinbalint@gmail.com>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Katkó Dominik <56202545+kdmnk@users.noreply.github.com>
  • Loading branch information
5 people authored Jan 21, 2024
1 parent c03f7dd commit 994264c
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 22 deletions.
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,20 @@ PREVENT_ACCESSING_MISSING_ATTRIBUTES=false
PRINT_COST_ONESIDED=8
PRINT_COST_TWOSIDED=12
PRINTER_NAME=NemUjBela
PRINTER_ADDITIONAL_ARGS=
PRINTER_STAT_ADDITIONAL_ARGS=

NETREG=1000
KKT=2000

TRUST_PROXIES=

LPSTAT_COMMAND=lpstat
CANCEL_COMMAND=cancel
PDFINFO_COMMAND=pdfinfo
PING_COMMAND=ping
PDFLATEX_COMMAND=/usr/bin/pdflatex

WORKSHOP_BALANCE_EXTERN=0.45
WORKSHOP_BALANCE_RESIDENT=0.6

Expand Down
11 changes: 6 additions & 5 deletions app/Console/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private static function isDebugMode()

public static function getCompletedPrintingJobs()
{
$command = "lpstat -W completed -o " . config('print.printer_name') . " | awk '{print $1}'";
$command = config('commands.lpstat') . " " . config('print.stat_additional_args') . " -W completed -o " . config('print.printer_name') . " | awk '{print $1}'";
if (self::isDebugMode()) {
$result = [0];
} else {
Expand All @@ -42,7 +42,7 @@ public static function print($command)

public static function cancelPrintJob(string $jobID)
{
$command = "cancel " . $jobID;
$command = config('commands.cancel') . " " . $jobID;
if (self::isDebugMode()) {
// cancel(1) exits with status code 0 if it succeeds
$result = ['output' => '', 'exit_code' => 0];
Expand All @@ -56,7 +56,7 @@ public static function cancelPrintJob(string $jobID)

public static function getPages($path)
{
$command = "pdfinfo " . $path . " | grep '^Pages' | awk '{print $2}' 2>&1";
$command = config('commands.pdfinfo') . " " . $path . " | grep '^Pages' | awk '{print $2}' 2>&1";
if (self::isDebugMode()) {
$result = rand(1, 10);
} else {
Expand All @@ -72,7 +72,7 @@ public static function pingRouter($router)
$result = rand(1, 10) > 9 ? "error" : '';
} else {
// This happens too often to log.
$command = "ping " . $router->ip . " -c 1 | grep 'error\|unreachable'";
$command = config('commands.ping') . " " . $router->ip . " -c 1 | grep 'error\|unreachable'";
$result = exec($command);
}
return $result;
Expand All @@ -83,9 +83,10 @@ public static function latexToPdf($path, $outputDir)
if (self::isDebugMode()) {
$result = "ok";
} else {
$command = "pdflatex " . "-interaction=nonstopmode -output-dir " . $outputDir . " " . $path . " 2>&1";
$command = config('commands.pdflatex') . " " . "-interaction=nonstopmode -output-dir " . $outputDir . " " . $path . " 2>&1";
Log::info($command);
$result = exec($command);
Log::info($result);
}
return $result;
}
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public function reportBug(Request $request)
$username = user()->name;

//personal auth token from your github.com account - see CONTRIBUTING.md
$token = env('GITHUB_AUTH_TOKEN');
$token = config('github.auth_token');

$url = "https://api.github.com/repos/" . env('GITHUB_REPO') . "/issues";
$url = "https://api.github.com/repos/" . config('github.repo') . "/issues";

//request details, removing slashes and sanitize content
$title = htmlspecialchars(stripslashes('Reported bug'), ENT_QUOTES);
Expand Down Expand Up @@ -196,11 +196,11 @@ private function getHomePageContacts(): array
'phone_number' => $staff?->personalInformation?->phone_number
],
'reception' => [
'phone_number' => env('PORTA_PHONE')
'phone_number' => config('contacts.porta_phone')
],
'doctor' => [
'name' => env('DOCTOR_NAME'),
'link' => env('DOCTOR_LINK')
'name' => config('contacts.doctor_name'),
'link' => config('contacts.doctor_link')
]
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function store(Request $request)
*/
public static function sendEvaluationAvailableMail()
{
Mail::to(env('MAIL_MEMBRA'))->queue(new \App\Mail\EvaluationFormAvailable());
Mail::to(config('contacts.mail_membra'))->queue(new \App\Mail\EvaluationFormAvailable());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function send()
{
$this->authorize('send', EpistolaNews::class);

Mail::to(env('MAIL_KOMMBIZ'))->send(new EpistolaCollegii(self::getActiveNews()));
Mail::to(config('contacts.mail_kommbiz'))->send(new EpistolaCollegii(self::getActiveNews()));

EpistolaNews::where('sent', false)->update(['sent' => true]);

Expand Down
8 changes: 8 additions & 0 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class TrustProxies extends Middleware
*/
protected $proxies;

/**
* Initiates the object with a configured proxy
*/
public function __construct()
{
$this->proxies = config('app.trust_proxies');
}

/**
* The headers that should be used to detect proxies.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/PingRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function handle()
$this->router->update([
'failed_for' => 0,
]);
} elseif (env('APP_DEBUG') == false) {
} elseif (config('app.debug') == false) {
$this->router->increment('failed_for');
$this->router->sendWarning();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Utils/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ private function printFile()
$printer_name = config('print.printer_name');
$state = PrintJob::QUEUED;
try {
$command = "lp -d " . $printer_name
$command = "lp " . config('print.additional_args') . " -d " . $printer_name
. ($this->is_two_sided ? " -o sides=two-sided-long-edge " : " ")
. "-n " . $this->number_of_copies . " "
. $this->path . " 2>&1";
$result = Commands::print($command);
if (!preg_match("/^request id is ([^\s]*) \\([0-9]* file\\(s\\)\\)$/", $result, $job)) {
Log::error("Printing error at line: " . __FILE__ . ":" . __LINE__ . " (in function " . __FUNCTION__ . "). result:"
. print_r($result, true));
. print_r($result, true) . ". Command: " . $command);
$state = PrintJob::ERROR;
}
$job_id = $job[1];
Expand Down
6 changes: 6 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,10 @@
'View' => Illuminate\Support\Facades\View::class,

],

/*
Trust proxies
*/

'trust_proxies' => explode(',', env('TRUST_PROXIES', '')),
];
9 changes: 9 additions & 0 deletions config/commands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [
'lpstat' => env('LPSTAT_COMMAND', 'lpstat'),
'cancel' => env('CANCEL_COMMAND', 'cancel'),
'pdfinfo' => env('PDFINFO_COMMAND', 'pdfinfo'),
'ping' => env('PING_COMMAND', 'ping'),
'pdflatex' => env('PDFLATEX_COMMAND', '/usr/bin/pdflatex'),
];
24 changes: 24 additions & 0 deletions config/contacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return [
'mail_test_admin' => env('MAIL_TEST_ADMIN', ''),
'mail_active' => env('MAIL_ACTIVE', ''),
'mail_driver' => env('MAIL_DRIVER', ''),
'mail_host' => env('MAIL_HOST', ''),
'mail_port' => env('MAIL_PORT', ''),
'mail_username' => env('MAIL_USERNAME', ''),
'mail_password' => env('MAIL_PASSWORD', ''),
'mail_encryption' => env('MAIL_ENCRYPTION', ''),
'mail_from_address' => env('MAIL_FROM_ADDRESS', ''),
'mail_replyto_address' => env('MAIL_REPLYTO_ADDRESS', ''),
'developer_email' => env('DEVELOPER_EMAIL', ''),
'mail_valasztmany' => env('MAIL_VALASZTMANY', ''),
'mail_elnok' => env('MAIL_ELNOK', ''),
'mail_kommbiz' => env('MAIL_KOMMBIZ', ''),
'mail_membra' => env('MAIL_MEMBRA', ''),
'mail_sysadmin' => env('MAIL_SYSADMIN', ''),
'mail_secretary' => env('MAIL_SECRETARY', ''),
'porta_phone' => env('PORTA_PHONE', ''),
'doctor_name' => env('DOCTOR_NAME', ''),
'doctor_link' => env('DOCTOR_LINK', ''),
];
6 changes: 6 additions & 0 deletions config/github.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'auth_token' => env('GITHUB_AUTH_TOKEN', ''),
'repo' => env('GITHUB_REPO', ''),
];
3 changes: 3 additions & 0 deletions config/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
'pdf_size_limit' => env('PRINT_MAX_FILE_SIZE', 5000000),

'printer_name' => env('PRINTER_NAME', 'ujbela'),

'stat_additional_args' => env('PRINTER_STAT_ADDITIONAL_ARGS', ''),
'additional_args' => env('PRINTER_ADDITIONAL_ARGS', ''),
];
2 changes: 1 addition & 1 deletion resources/views/dormitory/print/print.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p>
@lang('print.pdf_description')
@lang("print.pdf_maxsize", ['maxsize' => config('print.pdf_size_limit')/1000/1000])
@lang('print.costs',['one_sided'=>App\Models\PrintAccount::$COST['one_sided'], "two_sided" => env('PRINT_COST_TWOSIDED')])
@lang('print.costs',['one_sided'=>App\Models\PrintAccount::$COST['one_sided'], "two_sided" => App\Models\PrintAccount::$COST['two_sided']])
</p><p>
@lang('print.available_money'): <b class="coli-text text-orange"> {{ user()->printAccount->balance }}</b> HUF.
@lang('print.upload_money')
Expand Down
4 changes: 2 additions & 2 deletions resources/views/emails/epistola.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
<a href="https://eotvos.elte.hu" target="_blank" rel="noopener">Eötvös József Collegium</a><br>
<img src="{{ asset('img/valasztmany_logo.png') }}" width="120" alt=""><br>
<p>
<a href="mailto:{{env('MAIL_VALASZTMANY')}}">{{env('MAIL_VALASZTMANY')}}</a><br>
<a href="mailto:{{env('MAIL_KOMMBIZ')}}">{{env('MAIL_KOMMBIZ')}}</a>
<a href="mailto:{{config('contacts.mail_valasztmany')}}">{{config('contacts.mail_valasztmany')}}</a><br>
<a href="mailto:{{config('contacts.mail_kommbiz')}}">{{config('contacts.mail_kommbiz')}}</a>
</p>
<div class="subcopy">
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@component('mail::message')
<h1>@lang('mail.dear') {{ $recipient->name }}!</h1>
<p>
@lang('router.router_is_down_warning_resident', ['room' => $router->room]) {{ env('MAIL_REPLYTO_ADDRESS')}}.
@lang('router.router_is_down_warning_resident', ['room' => $router->room]) {{ config('contacts.mail_replyto_address')}}.
</p>
@endcomponent
6 changes: 3 additions & 3 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
<!-- Student Council -->
@if(isset($contacts[\App\Models\Role::STUDENT_COUNCIL]))
<h5>Választmány</h5>
<i><a href="mailto:{{ env('MAIL_VALASZTMANY') }}">{{env('MAIL_VALASZTMANY')}}</a></i><br>
<i><a href="mailto:{{ config('contacts.mail_valasztmany') }}">{{config('contacts.mail_valasztmany')}}</a></i><br>
@foreach($contacts[\App\Models\Role::STUDENT_COUNCIL] as $roleuser)
<b>@lang('role.'.$roleuser->object->name)</b>:
<i>{{$roleuser->user?->name}}</i>
@if($roleuser->object->name == \App\Models\Role::PRESIDENT)
<a href="mailto:{{ env('MAIL_ELNOK') }}">{{env('MAIL_ELNOK')}}</a>
<a href="mailto:{{ config('contacts.mail_elnok') }}">{{config('contacts.mail_elnok')}}</a>
<a href="mailto:{{ $roleuser->user?->email }}">{{ $roleuser->user?->email }}</a>
{{ $roleuser->user?->personalInformation?->phone_number }}
@endif
Expand Down Expand Up @@ -139,7 +139,7 @@
<!-- Admins -->
@if(isset($contacts['admins']))
<h5>@lang('role.sys-admins')</h5>
<i><a href="mailto:{{ env('DEVELOPER_EMAIL') }}">{{env('DEVELOPER_EMAIL')}}</a></i><br>
<i><a href="mailto:{{ config('contacts.developer_email') }}">{{config('contacts.developer_email')}}</a></i><br>
@foreach($contacts['admins'] as $admin)
@if(!$loop->first)|@endif
<i>{{$admin->name}}</i>
Expand Down

0 comments on commit 994264c

Please sign in to comment.