Commit cb8fab23 authored by Waitman Gobble's avatar Waitman Gobble 🍓
Browse files

add remote follow

parent 4ae2525c
......@@ -22,9 +22,9 @@ $ret['icon'] = [
'type' => 'Image',
'mediaType' => 'image/jpeg',
'updated' => date('c'),
'url' => 'https://solopor.com/moi-300.jpg',
'height' => 300,
'width' => 300
'url' => 'https://solopor.com/SOLOPOR/moibh800.jpg',
'height' => 800,
'width' => 800
];
$ret['image'] = [
'type' => 'Image',
......@@ -65,7 +65,7 @@ $wf['links'] = [
0 => [
'rel' => 'http://webfinger.net/rel/avatar',
'type' => 'image/jpeg',
'href' => 'https://solopor.com/moi-300.jpg'
'href' => 'https://solopor.com/SOLOPOR/moibh800.jpg'
],
1 => [
'rel' => 'http://webfinger.net/rel/blog',
......@@ -83,7 +83,7 @@ $wf['links'] = [
],
4 => [
'rel' => 'http://ostatus.org/schema/1.0/subscribe',
'template' => 'https://solopor.com/follow/'
'template' => 'https://solopor.com/follow/{uri}'
]
];
......
......@@ -107,7 +107,15 @@ if (strstr($_SERVER['HTTP_ACCEPT'],'json'))
case '.well-known':
include('mod/well-known.php');
exit();
break;
break;
case 'makefollow':
include('mod/makefollow.php');
break;
case 'follow':
include('mod/follow.php');
break;
case 'authorize':
include('mod/authorize.php');
......
......@@ -35,8 +35,8 @@
"created_at": "2020-05-17T22:13:45.857Z",
"note": "<p></p>",
"url": "https://solorpor.com/@wago",
"avatar": "https://solopor.com/moi-300.jpg",
"avatar_static": "https://solopor.com/moi-300.jpg",
"avatar": "https://solopor.com/SOLOPOR/moibh800.jpg",
"avatar_static": "https://solopor.com/SOLOPOR/moibh800.jpg",
"header": "https://solopor.com/SOLOPOR/Landschaft_87.png",
"header_static": "https://solopor.com/SOLOPOR/Landschaft_87.png",
"followers_count": <!--FOLLOWERS-->,
......
<?php
barf();
if (!$authenticated)
{
mysqli_close($conn);
Header("Location: /login");
exit();
} else {
$target = substr(urldecode($page[2]),0,128);
$sql = "SELECT idx FROM profiles WHERE url='".
mysqli_real_escape_string($conn,$target)."' OR url='".
mysqli_real_escape_string($conn,str_replace('/@','/channel/',$target))."'";
$res = mysqli_query($conn,$sql);
if (mysqli_num_rows($res)>0)
{
$content = '<h3>OOPs</h3><p>The profile at url '.htmlentities($target).' is already in the database.</p>';
} else {
$content = '<h3>Follow Federated User</h3>
<p>URI: '.htmlentities($target).'</p>
<form method="post" action="/makefollow">
<input type="hidden" name="target" value="'.htmlentities($target).'">
<input type="checkbox" name="private" value="Y"> Private<br>
<input type="checkbox" name="shop" value="Y"> Shop<br>
<input type="checkbox" name="photo" value="Y"> Photo<br>
<button type="submit" class="btn btn-primary">Follow</button>
</form>
';
}
mysqli_free_result($res);
}
<?php
define('SIGNIT',false);
barf();
if (!$authenticated)
{
mysqli_close($conn);
Header("Location: /login");
exit();
} else {
$target = rs('target',128);
$sql = "SELECT idx FROM profiles WHERE url='".
mysqli_real_escape_string($conn,$target)."' OR url='".
mysqli_real_escape_string($conn,str_replace('/@','/channel/',$target))."'";
$res = mysqli_query($conn,$sql);
if (mysqli_num_rows($res)>0)
{
$content = '<h3>OOPs</h3><p>The profile at url '.htmlentities($target).' is already in the database.</p>';
} else {
$shop = 'N';
$photo = 'N';
$private ='N';
if ($_POST['photo']=='Y') $photo='Y';
if ($_POST['shop']=='Y') $shop='Y';
if ($_POST['private']=='Y') $private='Y';
$ch = curl_init($target);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: '.LDJSON_HEADER));
$result = curl_exec($ch);
$sql = "INSERT INTO profiles (idx,url,created,approved,pending,following,follower,updated,deleted,private,shop,photo,content,request) VALUES (NULL,'".
mysqli_real_escape_string($conn,$target)."','".
mysqli_real_escape_string($conn,time())."','0','0','N','N','0','0','".
mysqli_real_escape_string($conn,$private)."','".
mysqli_real_escape_string($conn,$shop)."','".
mysqli_real_escape_string($conn,$photo)."','".
mysqli_real_escape_string($conn,$result)."','')";
mysqli_query($conn,$sql) or die($sql);
$profile_idx = mysqli_insert_id($conn);
if ($profile_idx<1) exit('error insert profile');
require_once('LDSignatures.php');
$keys = json_decode(file_get_contents(KEYPATH),true);
$p = json_decode(file_get_contents(ACTORPATH),true);
$actor = $p['url'];
$channel=array();
$channel['prvkey']=$keys['prvkey'];
$channel['url']=$actor;
$jd = json_decode($result,true);
$inbox = $jd['inbox'];
$msg_id = 'https://solopor.com/msgid/'.bin2hex(random_bytes(16));
if (SIGNIT) {
$msg = array_merge(['@context' => [
ACTIVITYSTREAMS_JSONLD_REV,
'https://w3id.org/security/v1'
]],
[
'id' => $msg_id,
'type' => ACTIVITY_FOLLOW,
'actor' => $actor,
'object' => $target,
'to' => [ $addr ]
]);
$msg['signature'] = LDSignatures::sign($msg,$channel);
} else {
$msg = [
'@context' => ACTIVITYSTREAMS_JSONLD_REV,
'id' => $msg_id,
'type' => ACTIVITY_FOLLOW,
'actor' => $actor,
'object' => $target
];
}
$jmsg = json_encode($msg, JSON_UNESCAPED_SLASHES);
$sql = "INSERT INTO queue (idx,profile_idx,msg_id,posturl,created,delivered,scheduled,response,msg) VALUES (NULL,'".
mysqli_real_escape_string($conn,$profile_idx)."','".
mysqli_real_escape_string($conn,$msg_id)."','".
mysqli_real_escape_string($conn,$inbox)."','".time()."','0','".time()."','','".
mysqli_real_escape_string($conn,$jmsg)."')";
mysqli_query($conn,$sql) or die($sql);
$content = '<h3>Follow Request Queued</h3>
<p>Msg Id: '.htmlentities($msg_id).'</p>
';
}
mysqli_free_result($res);
}
......@@ -5,11 +5,11 @@ barf();
switch ($page[2])
{
case 'webfinger':
$out = file_get_contents(WEBFINGERPATH);
Header("Content-type: application/jrd+json");
Header("Content-length: ".strlen($out));
echo $out;
mysqli_close($conn);
$out = file_get_contents(WEBFINGERPATH);
Header("Content-type: application/jrd+json");
Header("Content-length: ".strlen($out));
echo $out;
mysqli_close($conn);
break;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment