Initial commit

This commit is contained in:
Michael 2024-02-28 02:09:49 +00:00
parent bb91ab3643
commit f5af62ece2
3 changed files with 193 additions and 2 deletions

63
.gitignore vendored Normal file
View file

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

View file

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

107
index.php Normal file
View file

@ -0,0 +1,107 @@
<?php
$config = include 'config/local.config.php';
if (empty($config['config']['hostname'])) {
notFound();
}
$connection = connectDatabase($config);
if (empty($connection)) {
notFound();
}
if (!in_array($_REQUEST['pagename'], ['.well-known/atproto-did', ''])) {
notFound();
}
$server = '.' . trim($config['config']['hostname'], '.');
if (!strpos($_SERVER['SERVER_NAME'], $server)) {
notFound();
}
$nick = str_replace($server, '', $_SERVER['SERVER_NAME']);
$user = selectFirst($connection, "SELECT `uid` FROM `user` WHERE `nickname` = ?", [$nick]);
if (empty($user['uid'])) {
notFound();
}
if ($_REQUEST['pagename'] == '') {
header('Location: http://' . $config['config']['hostname'] . '/profile/' . $nick);
die();
}
$did = selectFirst($connection, "SELECT `v` FROM `pconfig` WHERE `uid` = ? AND `cat` = ? AND `k` = ?", [$user['uid'], 'bluesky', 'did']);
if (empty($did['v'])) {
notFound();
}
header('Content-Type: text/plain');
echo $did['v'];
function notFound()
{
header('HTTP/1.0 404 Not Found');
echo '<h1>404 - Page Not Found</h1>';
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;
}
?>