diff --git a/Makefile b/Makefile index 99d1947..9b8e9d4 100644 --- a/Makefile +++ b/Makefile @@ -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/* diff --git a/README.md b/README.md index 4bd4534..16e353a 100644 --- a/README.md +++ b/README.md @@ -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!** diff --git a/backend/scripts/setup.php b/backend/scripts/setup.php new file mode 100644 index 0000000..65915f0 --- /dev/null +++ b/backend/scripts/setup.php @@ -0,0 +1,59 @@ +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; \ No newline at end of file diff --git a/backend/scripts/setup.sql b/backend/scripts/setup.sql new file mode 100644 index 0000000..26aad2b --- /dev/null +++ b/backend/scripts/setup.sql @@ -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; \ No newline at end of file