Explorar o código

SFTPGo authentication

Miraty %!s(int64=3) %!d(string=hai) anos
pai
achega
e5c306c24b
Modificáronse 6 ficheiros con 34 adicións e 21 borrados
  1. 19 0
      common/init.php
  2. 1 15
      common/top.php
  3. 0 2
      dns.php
  4. 0 2
      ns.php
  5. 0 2
      reg.php
  6. 14 0
      sftpgo-auth.php

+ 19 - 0
common/init.php

@@ -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";

+ 1 - 15
common/top.php

@@ -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")

+ 0 - 2
dns.php

@@ -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

+ 0 - 2
ns.php

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

+ 0 - 2
reg.php

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

+ 14 - 0
sftpgo-auth.php

@@ -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);
+}