Setup script created

This commit is contained in:
Mal 2020-08-19 23:45:39 +02:00
parent 5df0a1f8c2
commit 3a1a026e2f
4 changed files with 120 additions and 19 deletions

View File

@ -1,6 +1,8 @@
setup:
php backend/scripts/setup.php
build:
php data/scripts/generate.php
php backend/scripts/generate.php
clean:
rm -rf data/cache/* data/tmp/*
rm -rf backend/cache/* backend/tmp/*

View File

@ -1,19 +1,21 @@
# Ringfinger
A restfull keyring API with web UI to share your jabber fingerprints with the people you want.
Create an account, store your jabber fingerprints and share it with your friends. There is no need to type in your 64 chars long fingerprint for each of your friends. Just enter it once and decide which people you want to share your keyring with.
# Ringfinger
A restfull keyring API with web UI to share your jabber fingerprints with the people you want.
Create an account, store your jabber fingerprints and share it with your friends. There is no need to type in your 64 chars long fingerprint for each of your friends. Just enter it once and decide which people you want to share your keyring with.
# Setup
Clone or copy the ringfinger folder to the location folder of your webserver. Move into the ringfinger folder an generate the cache:
> make build
## Webserver configuration
Despite your basic setup with PHP and MySQL/MariaDB your webserver has to to rewrite all requests that access the path `/ringfinger/api/v1/...` to `/ringfinger/api/v1/index.php` to make the API working.
### NGINX
Add the following line to your nginx.conf or to a separate file that will be included by the nginx.conf:
> rewrite /ringfinger/api/v1/.* /ringfinger/api/v1/index.php;
**Also make sure you deny the access to /ringfinger/data for all!**
Before you start setting up make sure you have an empty MySQL database created. You also need a database user that has full access to the newly created database!
Then clone or copy the ringfinger folder to the location folder of your webserver. Move into the ringfinger folder and start the setup process
> make setup
## Webserver configuration
Despite your basic setup with PHP and MySQL/MariaDB your webserver has to to rewrite all requests that access the path `/ringfinger/api/v1/...` to `/ringfinger/api/v1/index.php` to make the API working.
### NGINX
Add the following line to your nginx.conf or to a separate file that will be included by the nginx.conf:
> rewrite /ringfinger/api/v1/.* /ringfinger/api/v1/index.php;
**Also make sure you deny the access to /ringfinger/backend for all!**

59
backend/scripts/setup.php Normal file
View File

@ -0,0 +1,59 @@
<?php
function getUserInput(string $label): string
{
echo $label;
return str_replace("\n", '', fgets(STDIN));
}
const TEMPLATE_SETTINGS = '<?php
/*
* This file was auto generated on :DATETIME
*/
declare(strict_types=1);
final class Setting
{
public const MYSQL_HOST = \':HOST\';
public const MYSQL_USER = \':USER\';
public const MYSQL_PASSWORD = \':PASSWORD\';
public const MYSQL_DATABASE = \':DATABASE\';
public const PATH_ROOT = \':ROOT_PATH/\';
public const PATH_QR_CODES = self::PATH_ROOT . \'backend/qr/\';
public const PATH_TMP = self::PATH_ROOT . \'backend/tmp/\';
}
';
$hostname = getUserInput('MySQL host address (default "localhost"): ');
$username = getUserInput('MySQL user: ');
$password = getUserInput('MySQL password (shown!): ');
$database = getUserInput('MySQL database: ');
$settings = str_replace(
[':HOST', ':USER', ':PASSWORD', ':DATABASE', ':ROOT_PATH', ':DATETIME'],
[$hostname, $username, $password, $database, getcwd(), (new DateTime())->format('Y-m-d H:i:s')],
TEMPLATE_SETTINGS
);
$file = fopen(getcwd() . '/backend/classes/Setting.php', 'w');
fwrite($file, $settings);
fclose($file);
require 'backend/classes/core/Autoloader.php';
Autoloader::BuildCache();
$autoloader = new Autoloader();
$file = fopen('backend/scripts/setup.sql', 'r');
$setupSql = fread($file, filesize('backend/scripts/setup.sql'));
fclose($file);
$db = new MySqlDatabase($hostname, $username, $password, $database);
$db->Query($setupSql);
echo 'Ringfinger setup has successfully finished.' . PHP_EOL;

38
backend/scripts/setup.sql Normal file
View File

@ -0,0 +1,38 @@
START TRANSACTION;
USE ringfinger;
CREATE TABLE User (
UserId int(10) unsigned NOT NULL AUTO_INCREMENT,
Username varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
Password varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
Email varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
JabberAddress varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (UserId),
UNIQUE KEY Username (Username),
UNIQUE KEY Email (Email),
UNIQUE KEY JabberAddress (JabberAddress)
);
CREATE TABLE Fingerprint (
FingerprintId int(10) unsigned NOT NULL AUTO_INCREMENT,
Fingerprint varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
UserId int(10) unsigned NOT NULL,
PRIMARY KEY (FingerprintId),
UNIQUE KEY Fingerprint (Fingerprint),
KEY User (UserId),
CONSTRAINT User FOREIGN KEY (UserId) REFERENCES User (UserId)
);
CREATE TABLE Sharing (
SharingId int(10) unsigned NOT NULL AUTO_INCREMENT,
User int(10) unsigned NOT NULL,
UserShared int(10) unsigned NOT NULL,
PRIMARY KEY (SharingId),
UNIQUE KEY User (User, UserShared),
KEY UserSharedId (UserShared),
CONSTRAINT UserId FOREIGN KEY (User) REFERENCES User (UserId),
CONSTRAINT UserSharedId FOREIGN KEY (UserShared) REFERENCES User (UserId)
);
COMMIT;