From f5af62ece2cf60f36a5e87d097ffdcc8133670da Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 28 Feb 2024 02:09:49 +0000 Subject: [PATCH] Initial commit --- .gitignore | 63 +++++++++++++++++++++++++++++++ README.md | 25 ++++++++++++- index.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6d0c48 --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +favicon.* +\#* +*.log +*.out +*.version* +*~ +robots.txt + +#ignore local config +!/config/local-sample.config.php +/config/*.config.php + +#ignore config files from eclipse, we don't want IDE files in our repository +.project +.buildpath +.externalToolBuilders +.settings + +#ignore OSX .DS_Store files +.DS_Store + +#ignore NetBeans IDE's private files (at least) +/nbproject/private/ + +#Ignore config files from VSCode +/.vscode/ + +#ignore cache folders +nbproject + +#ignore local folder +/local/ + +#ignore config files from Visual Studio +/.vs/ +/php_friendica.phpproj +/php_friendica.sln +/php_friendica.phpproj.user + +#ignore config files from JetBrains +/.idea + +#ignore base .htaccess +/.htaccess + +#Ignore log folder +/log + +#Ignore temporary installed phpunit +/bin/phpunit + +#Ignore cache files +.php_cs.cache +.php-cs-fixer.cache + +#Ignore autotest results +autotest-results.xml + +#ignore phpunit result cache +tests/.phpunit.result.cache + +#ignore .php_cs (local copy) +.php_cs diff --git a/README.md b/README.md index ef07f26..1b6a1ee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ -# bluesky-handles +Bluesky handle registration for Friendica +========================================= -With this tool you enable your Friendica users to use a subdomains of your Friendica hostname as their Bluesky handle. \ No newline at end of file +This tool enables your Friendica users to rename their existing Bluesky handles to a subdomain of your Friendica system. +So for example user "nickname" on your server "myfriendica.tld" can then use "nickname.myfriendica.tld" as their Bluesky handle. + +## Installation + +### Webserver + +You need an additional configuration for your webserver to serve wildcard requests. +Best way is to copy your Friendica configuration and to simply change the following parameters and the directory: + + ServerName atproto.myfriendica.tld + ServerAlias *.myfriendica.tld + +Please be aware, that no SSL certificate is needed, serving HTTP only is completely okay. + +### Configuration + +Please copy the sample file local-sample.config.php to local.config.php and set the database configuration parameters like in ypur Friendica configuration. +Also don't forget to enter your Friendica hostname, that's all. +You can check your installation by visiting the page "nickname.myfriendica.tld" (with an existing handle and your real Friendica hostname). +If everything is configured correctly, this subdomain will then redirect you to the profile page of this user. \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..6f3bab9 --- /dev/null +++ b/index.php @@ -0,0 +1,107 @@ +404 - Page Not Found'; + echo 'The requested resource could not be found but may be available in the future.'; + die(); +} + +function connectDatabase(array $config): PDO +{ + if (!empty($config['database']['socket'])) { + $connect = 'mysql:unix_socket=' . $config['database']['socket']; + } else { + $connect = 'mysql:host=' . $config['database']['hostname']; + if (!empty($config['database']['port'])) { + $connect .= ';port=' . $config['database']['port']; + } + } + + if (!empty($config['database']['charset'])) { + $connect .= ';charset=' . $config['database']['charset']; + } + + $connect .= ';dbname=' . $config['database']['database']; + + try { + $connection = @new PDO($connect, $config['database']['username'], $config['database']['password'], [PDO::ATTR_PERSISTENT => false]); + $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); + } catch (PDOException $e) { + $connection = null; + } + return $connection; +} + +function selectFirst(PDO $connection, $query, $parameters = []): ?array +{ + if (!$stmt = $connection->prepare($query)) { + return null; + } + + foreach (array_keys($parameters) as $param) { + $data_type = PDO::PARAM_STR; + if (is_int($parameters[$param])) { + $data_type = PDO::PARAM_INT; + } elseif ($parameters[$param] !== null) { + $parameters[$param] = (string)$parameters[$param]; + } + + $stmt->bindParam($param + 1, $parameters[$param], $data_type); + } + + if (!$stmt->execute()) { + return null; + } + + $columns = $stmt->fetch(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + if (!is_array($columns)) { + return null; + } + + return $columns; +} +?>