1<?php 2/* 3 * vim:set softtabstop=4 shiftwidth=4 expandtab: 4 * 5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 6 * Copyright 2001 - 2020 Ampache.org 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 * 21 */ 22 23declare(strict_types=0); 24 25namespace Ampache\Module\Application\Test; 26 27use Ampache\Config\AmpConfig; 28use Ampache\Config\ConfigContainerInterface; 29use Ampache\Repository\Model\Preference; 30use Ampache\Module\Application\ApplicationActionInterface; 31use Ampache\Module\Authorization\GuiGatekeeperInterface; 32use Exception; 33use Psr\Http\Message\ResponseFactoryInterface; 34use Psr\Http\Message\ResponseInterface; 35use Psr\Http\Message\ServerRequestInterface; 36use Teapot\StatusCode; 37 38final class ShowAction implements ApplicationActionInterface 39{ 40 public const REQUEST_KEY = 'show'; 41 42 private ConfigContainerInterface $configContainer; 43 44 private ResponseFactoryInterface $responseFactory; 45 46 public function __construct( 47 ConfigContainerInterface $configContainer, 48 ResponseFactoryInterface $responseFactory 49 ) { 50 $this->configContainer = $configContainer; 51 $this->responseFactory = $responseFactory; 52 } 53 54 /** 55 * @param ServerRequestInterface $request 56 * @param GuiGatekeeperInterface $gatekeeper 57 * @return ResponseInterface|null 58 * @throws Exception 59 */ 60 public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface 61 { 62 $configfile = __DIR__ . '/../../../../config/ampache.cfg.php'; 63 64 // Load config from file 65 $results = array(); 66 if (!file_exists($configfile)) { 67 return $this->responseFactory 68 ->createResponse(StatusCode::FOUND) 69 ->withHeader( 70 'Location', 71 '/install.php' 72 ); 73 } else { 74 // Make sure the config file is set up and parsable 75 $results = @parse_ini_file($configfile); 76 77 if (empty($results)) { 78 $link = __DIR__ . '/../../public/test.php?action=config'; 79 } 80 } 81 /* Temp Fixes */ 82 $results = Preference::fix_preferences($results); 83 84 $this->configContainer->updateConfig($results); 85 unset($results); 86 87 // Try to load localization from cookie 88 $session_name = $this->configContainer->getSessionName(); 89 90 if (filter_has_var(INPUT_COOKIE, $session_name . '_lang')) { 91 AmpConfig::set('lang', $_COOKIE[$session_name . '_lang']); 92 } 93 if (!class_exists('Gettext\Translations')) { 94 require_once __DIR__ . '/../../../../public/templates/test_error_page.inc.php'; 95 throw new Exception('load_gettext()'); 96 } else { 97 load_gettext(); 98 // Load template 99 require_once __DIR__ . '/../../../../public/templates/show_test.inc.php'; 100 } 101 102 return null; 103 } 104} 105