Adds some various php files

This commit is contained in:
zontreck 2024-05-15 04:17:50 -07:00
parent e73edafc99
commit f04ad028ae
9 changed files with 112 additions and 0 deletions

32
php/Common.php Normal file
View file

@ -0,0 +1,32 @@
<?php
if(defined("COMMON")) return;
define("COMMON", 1);
function get_DB() {
return mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
}
function getJsonizedInput() {
$js = file_get_contents("php://input");
return json_decode($js,true);
}
function rewrite_DB_conf($host, $user, $pass, $db)
{
$ptl = "<\?php\n"
. "define(\"DB_HOST\", \"$host\");\n"
. "define(\"DB_USER\", \"$user\");\n"
. "define(\"DB_PASS\", \"$pass\");\n"
. "define(\"DB_NAME\", \"$db\");\n"
. "\?>";
file_put_contents("Database.php", $ptl);
}
require("Database.php");
session_start();
?>

8
php/Database.php Normal file
View file

@ -0,0 +1,8 @@
<?php
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "changeme");
define("DB_NAME", "changeme");
?>

16
php/Login.php Normal file
View file

@ -0,0 +1,16 @@
<?php
if(!defined("COMMON"))
require("Common.php");
$js = getJsonizedInput();
// Read login parameters
$username = $js["username"];
$password = $js["password"];
// Password is hashed
// Compare against hash in database + : md5(salt)
$DB = get_DB();
?>

4
php/README.md Normal file
View file

@ -0,0 +1,4 @@
About
======
These files get copied to the API subdomain by default. This setup is intended to permit for multiple hosts.

17
php/SetupCheck.php Normal file
View file

@ -0,0 +1,17 @@
<?php
if(DB_NAME == "changeme" && DB_PASS == "changeme") {
$ret = array (
"done" => false
);
header("X-Zontreck-Setup-Completed", "FALSE");
die(json_encode($ret));
}else {
$ret = array (
"done" => true
);
header("X-Zontreck-Setup-Completed", "TRUE");
die(json_encode($ret));
}
?>