SFTPGo authentication

This commit is contained in:
Miraty 2022-05-19 16:59:32 +02:00
parent e7e6ae2b7f
commit e5c306c24b
6 changed files with 34 additions and 21 deletions

19
common/init.php Normal file
View File

@ -0,0 +1,19 @@
<?php
define("DOMAIN_EXAMPLE", "example"); // From RFC2606: Reserved Top Level DNS Names > 2. TLDs for Testing, & Documentation Examples
define("PREFIX", ""); // Prefix in URL, if any
define("ROOT_PATH", "/srv/php/niver"); // niver-php directory
define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1));
define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
define("DB_PATH", ROOT_PATH . "/db/niver.db"); // Niver's SQLite database
define("SUDO_PATH", "/usr/bin/sudo");
define("HT_PATH", "/srv/ht");
// Service-specific functions and constants
if (SERVICE === "reg" OR SERVICE === "ns")
require ROOT_PATH . "/dns.php";
if (SERVICE !== "")
require ROOT_PATH . "/" . SERVICE . ".php";
// Page titles definition
require "pages.php";

View File

@ -1,20 +1,6 @@
<?php
define("DOMAIN_EXAMPLE", "example"); // From RFC2606: Reserved Top Level DNS Names > 2. TLDs for Testing, & Documentation Examples
define("PREFIX", ""); // Prefix in URL, if any
define("ROOT_PATH", "/srv/php/niver"); // niver-php directory
define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1));
define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
define("DB_PATH", ROOT_PATH . "/db/niver.db"); // Niver's SQLite database
define("SUDO_PATH", "/usr/bin/sudo");
define("HT_PATH", "/srv/ht");
// Service-specific functions and constants
if (SERVICE !== "")
require ROOT_PATH . "/" . SERVICE . ".php";
// Page titles definition
require "pages.php";
require "init.php";
function antiCSRF() {
if (!isset($_SERVER['HTTP_SEC_FETCH_SITE']) OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== "same-origin")

View File

@ -1,7 +1,5 @@
<?php
// This file is used by 'ns' and 'reg'
// Example IP adresses (for placeholders)
define("IPV6_EXAMPLE", "2001:db8::3"); // See RFC3849: IPv6 Address Prefix Reserved for Documentation
define("IPV4_EXAMPLE", "203.0.113.42"); // See RFC5737: IPv4 Address Blocks Reserved for Documentation

2
ns.php
View File

@ -1,7 +1,5 @@
<?php
require "dns.php";
define("KNOT_ZONES_PATH", "/srv/ns");
function nsCommonRequirements() {

View File

@ -1,7 +1,5 @@
<?php
require "dns.php";
define("SUBDOMAIN_REGEX", "^[a-z]{4,63}$");
define("REGISTRY", "niver.test.");

14
sftpgo-auth.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require "common/init.php";
require "auth.php";
$authData = json_decode(file_get_contents("php://input"), true);
$user = json_decode($authData['user'], true);
if (checkPassword($authData['username'], $authData['password']) === true) {
echo '{"status":1,"username":"' . $authData['username'] . '","permissions":{"/":["*"]}}';
http_response_code(200);
} else {
http_response_code(403);
}