diff --git a/.env.example b/.env.example index 89de920f8..e7b42d611 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/app/Console/Commands.php b/app/Console/Commands.php index 6af3de083..89ca6500c 100644 --- a/app/Console/Commands.php +++ b/app/Console/Commands.php @@ -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 { @@ -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]; @@ -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 { @@ -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; @@ -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; } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 204ccabf5..80c344403 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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); @@ -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') ] ]; diff --git a/app/Http/Controllers/Secretariat/SemesterEvaluationController.php b/app/Http/Controllers/Secretariat/SemesterEvaluationController.php index 227a6f4cb..757989588 100644 --- a/app/Http/Controllers/Secretariat/SemesterEvaluationController.php +++ b/app/Http/Controllers/Secretariat/SemesterEvaluationController.php @@ -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()); } /** diff --git a/app/Http/Controllers/StudentsCouncil/EpistolaController.php b/app/Http/Controllers/StudentsCouncil/EpistolaController.php index a35d4387e..4170dd813 100644 --- a/app/Http/Controllers/StudentsCouncil/EpistolaController.php +++ b/app/Http/Controllers/StudentsCouncil/EpistolaController.php @@ -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]); diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 6707c6103..999e0ed8a 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -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. * diff --git a/app/Jobs/PingRouter.php b/app/Jobs/PingRouter.php index ce3a1b43f..78da50c2a 100644 --- a/app/Jobs/PingRouter.php +++ b/app/Jobs/PingRouter.php @@ -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(); } diff --git a/app/Utils/Printer.php b/app/Utils/Printer.php index 575f40c75..cafaf7731 100644 --- a/app/Utils/Printer.php +++ b/app/Utils/Printer.php @@ -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]; diff --git a/config/app.php b/config/app.php index 0c6aa8bd6..6b450f734 100644 --- a/config/app.php +++ b/config/app.php @@ -283,4 +283,10 @@ 'View' => Illuminate\Support\Facades\View::class, ], + + /* + Trust proxies + */ + + 'trust_proxies' => explode(',', env('TRUST_PROXIES', '')), ]; diff --git a/config/commands.php b/config/commands.php new file mode 100644 index 000000000..c3ea4f12c --- /dev/null +++ b/config/commands.php @@ -0,0 +1,9 @@ + 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'), +]; diff --git a/config/contacts.php b/config/contacts.php new file mode 100644 index 000000000..5c9060628 --- /dev/null +++ b/config/contacts.php @@ -0,0 +1,24 @@ + 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', ''), +]; diff --git a/config/github.php b/config/github.php new file mode 100644 index 000000000..f5d092eae --- /dev/null +++ b/config/github.php @@ -0,0 +1,6 @@ + env('GITHUB_AUTH_TOKEN', ''), + 'repo' => env('GITHUB_REPO', ''), +]; diff --git a/config/print.php b/config/print.php index 3e5c9f1c6..0ded57983 100644 --- a/config/print.php +++ b/config/print.php @@ -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', ''), ]; diff --git a/resources/views/dormitory/print/print.blade.php b/resources/views/dormitory/print/print.blade.php index f50c5802d..8e61cb840 100644 --- a/resources/views/dormitory/print/print.blade.php +++ b/resources/views/dormitory/print/print.blade.php @@ -5,7 +5,7 @@

@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']])

@lang('print.available_money'): {{ user()->printAccount->balance }} HUF. @lang('print.upload_money') diff --git a/resources/views/emails/epistola.blade.php b/resources/views/emails/epistola.blade.php index 6fb09bf0d..114df6b56 100644 --- a/resources/views/emails/epistola.blade.php +++ b/resources/views/emails/epistola.blade.php @@ -132,8 +132,8 @@ Eötvös József Collegium

- {{env('MAIL_VALASZTMANY')}}
- {{env('MAIL_KOMMBIZ')}} + {{config('contacts.mail_valasztmany')}}
+ {{config('contacts.mail_kommbiz')}}

diff --git a/resources/views/emails/router_status_warning_resident.blade.php b/resources/views/emails/router_status_warning_resident.blade.php index 1f412fea8..c01da62bd 100644 --- a/resources/views/emails/router_status_warning_resident.blade.php +++ b/resources/views/emails/router_status_warning_resident.blade.php @@ -1,6 +1,6 @@ @component('mail::message')

@lang('mail.dear') {{ $recipient->name }}!

-@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')}}.

@endcomponent diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index edec51a09..86c249303 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -66,12 +66,12 @@ @if(isset($contacts[\App\Models\Role::STUDENT_COUNCIL]))
Választmány
- {{env('MAIL_VALASZTMANY')}}
+ {{config('contacts.mail_valasztmany')}}
@foreach($contacts[\App\Models\Role::STUDENT_COUNCIL] as $roleuser) @lang('role.'.$roleuser->object->name): {{$roleuser->user?->name}} @if($roleuser->object->name == \App\Models\Role::PRESIDENT) - {{env('MAIL_ELNOK')}} + {{config('contacts.mail_elnok')}} {{ $roleuser->user?->email }} {{ $roleuser->user?->personalInformation?->phone_number }} @endif @@ -139,7 +139,7 @@ @if(isset($contacts['admins']))
@lang('role.sys-admins')
- {{env('DEVELOPER_EMAIL')}}
+ {{config('contacts.developer_email')}}
@foreach($contacts['admins'] as $admin) @if(!$loop->first)|@endif {{$admin->name}}