* License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ require_once sprintf('%s/vendor/autoload.php', dirname(__DIR__)); use SURFnet\VPN\Common\CliParser; use SURFnet\VPN\Common\Config; try { $p = new CliParser('Add a user to the portal', ['instance' => ['the VPN instance', true, false], 'user' => ['the username', true, true], 'pass' => ['the password', true, true]]); $opt = $p->parse($argv); if ($opt->e('help')) { echo $p->help(); exit(0); } $instanceId = $opt->e('instance') ? $opt->v('instance') : 'default'; $configFile = sprintf('%s/config/%s/config.yaml', dirname(__DIR__), $instanceId); $config = Config::fromFile($configFile); $configData = $config->v(); $passwordHash = password_hash($opt->v('pass'), PASSWORD_DEFAULT); $configData['FormAuthentication'][$opt->v('user')] = $passwordHash; Config::toFile($configFile, $configData, 0644); } catch (Exception $e) { echo sprintf('ERROR: %s', $e->getMessage()) . PHP_EOL; exit(1); }
use SURFnet\VPN\Common\HttpClient\GuzzleHttpClient; use SURFnet\VPN\Common\HttpClient\ServerClient; use SURFnet\VPN\Common\Logger; $logger = new Logger('vpn-admin-portal'); try { $request = new Request($_SERVER, $_GET, $_POST); if (false === ($instanceId = getenv('VPN_INSTANCE_ID'))) { $instanceId = $request->getServerName(); } $dataDir = sprintf('%s/data/%s', dirname(__DIR__), $instanceId); if (!file_exists($dataDir)) { if (false === @mkdir($dataDir, 0700, true)) { throw new RuntimeException(sprintf('unable to create folder "%s"', $dataDir)); } } $config = Config::fromFile(sprintf('%s/config/%s/config.yaml', dirname(__DIR__), $instanceId)); $templateDirs = [sprintf('%s/views', dirname(__DIR__)), sprintf('%s/config/%s/views', dirname(__DIR__), $instanceId)]; $templateCache = null; if ($config->v('enableTemplateCache')) { $templateCache = sprintf('%s/tpl', $dataDir); } $tpl = new TwigTpl($templateDirs, $templateCache); $tpl->addFilter(TwigFilters::sizeToHuman()); $tpl->setDefault(['requestUri' => $request->getUri(), 'requestRoot' => $request->getRoot(), 'requestRootUri' => $request->getRootUri()]); $service = new Service($tpl); $service->addBeforeHook('referrer_check', new ReferrerCheckHook()); $service->addAfterHook('no_cache', new NoCacheHook()); // Authentication $authMethod = $config->v('authMethod'); $tpl->addDefault(['authMethod' => $authMethod]); $session = new Session($request->getServerName(), $request->getRoot(), $config->v('secureCookie'));