Compare commits
No commits in common. "main" and "0.1.10" have entirely different histories.
164
README.md
164
README.md
|
@ -1,115 +1,5 @@
|
|||
# gnuboard5-activitypub
|
||||
GNUBOARD5-ActivityPub: ActivityPub (Fediverse) implementation for GNUBOARD5
|
||||
|
||||
* https://sir.kr/g5_plugin/10381
|
||||
* https://codeberg.org/fediverse/delightful-activitypub-development
|
||||
|
||||
## 사용 전 설정
|
||||
* `apstreams` 게시판 추가
|
||||
* `apstreams` 사용자 추가
|
||||
|
||||
## 지원현황
|
||||
- [x] WebFinger
|
||||
- [x] User
|
||||
- [x] Inbox
|
||||
- [x] Outbox
|
||||
- [x] Followers
|
||||
- [x] Following
|
||||
- [x] Liked
|
||||
- [ ] ~~Shares~~ (Altered to inbound/outbound)
|
||||
- [x] Geolocation
|
||||
- [x] File attachment
|
||||
- [ ] File attachment - Automatically download a remote file to the local server
|
||||
- [x] Digest/Signature - Outbound
|
||||
- [ ] ~~Digest/Signature - Inbound~~ (No required)
|
||||
- [x] w3id.org (e.g. the `publicKey` field of an actor)
|
||||
- [ ] OAuth 2.0
|
||||
- [ ] Message Queue Compatible (e.g. Redis, RebbitMQ, Kafka)
|
||||
|
||||
## 부가기능 (옵션)
|
||||
- [x] 아바타 (gravatar.com)
|
||||
- [x] 날씨 (openweathermap.org)
|
||||
- [x] 환율 (koreaexim.go.kr)
|
||||
- [x] 국내 Geolocation (Naver Cloud)
|
||||
- [x] 국외 Geolocation (IP2Location)
|
||||
|
||||
## 전문(메시지) 예시
|
||||
|
||||
```json
|
||||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"type": "Create",
|
||||
"id": "http://example.org/bbs/board.php?bo_table=apstreams&wr_id=235",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public", "http://example.org/?route=activitypub.user&mb_id=admin"],
|
||||
"actor": "http://example.org/?route=activitypub.user&mb_id=admin",
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"generator": "GNUBOARD5 ActivityPub Plugin (INSTANCE_ID: 4d6076784cbd864ade7c746690d37051, INSTANCE_VERSION: 0.1.11-dev)",
|
||||
"id": "http://example.org/bbs/board.php?bo_table=free&wr_id=1",
|
||||
"attributedTo": "http://example.org/?route=activitypub.user&mb_id=admin",
|
||||
"content": "안녕하세요 @admin@example.org",
|
||||
"icon": "https://www.gravatar.com/avatar/bdbd5eb70305f1eaaa0340687758676a",
|
||||
"location": {
|
||||
"name": "xxx.xxx.xxx.xxx, 서울특별시 금천구 가산동 (Korea Telecom), Seoul, Seoul-teukbyeolsi, Korea (Republic of), KR, 06030, +09:00",
|
||||
"type": "Place",
|
||||
"longitude": 126.8917326,
|
||||
"latitude": 37.4769094,
|
||||
"units": "m",
|
||||
"_weather": {
|
||||
"dt": 1657163472,
|
||||
"sunrise": 1657138663,
|
||||
"sunset": 1657191385,
|
||||
"temp": 305.42,
|
||||
"feels_like": 309.65,
|
||||
"pressure": 1005,
|
||||
"humidity": 56,
|
||||
"dew_point": 295.52,
|
||||
"uvi": 8.53,
|
||||
"clouds": 100,
|
||||
"visibility": 10000,
|
||||
"wind_speed": 5.72,
|
||||
"wind_deg": 186,
|
||||
"wind_gust": 10.14,
|
||||
"weather": [{
|
||||
"id": 804,
|
||||
"main": "Clouds",
|
||||
"description": "overcast clouds",
|
||||
"icon": "04d"
|
||||
}]
|
||||
},
|
||||
"_exchange": {
|
||||
"KRW": {
|
||||
"AED": 355.94,
|
||||
"AUD": 887.07,
|
||||
"BHD": 3467.72,
|
||||
"BND": 930.73,
|
||||
"CAD": 1003.15,
|
||||
"CHF": 1346.86,
|
||||
"CNH": 194.76,
|
||||
"DKK": 178.9,
|
||||
"EUR": 1331.33,
|
||||
"GBP": 1558.81,
|
||||
"HKD": 166.61,
|
||||
"IDR(100)": 8.72,
|
||||
"JPY(100)": 960.93,
|
||||
"KRW": 0,
|
||||
"KWD": 4253.09,
|
||||
"MYR": 295.49,
|
||||
"NOK": 128.98,
|
||||
"NZD": 804.44,
|
||||
"SAR": 348.27,
|
||||
"SEK": 124.02,
|
||||
"SGD": 930.73,
|
||||
"THB": 36.12,
|
||||
"USD": 1307.4
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"published": "2022-07-07T03:11:12Z",
|
||||
"updated": "2022-07-07T03:11:12Z"
|
||||
}
|
||||
```
|
||||
ActivityPub implementation for GNUBOARD 5
|
||||
|
||||
## References
|
||||
* https://www.w3.org/TR/activitypub/
|
||||
|
@ -120,12 +10,50 @@ GNUBOARD5-ActivityPub: ActivityPub (Fediverse) implementation for GNUBOARD5
|
|||
* https://organicdesign.nz/ActivityPub_Code
|
||||
* https://socialhub.activitypub.rocks/t/posting-to-pleroma-inbox/1184
|
||||
* https://github.com/broidHQ/integrations/tree/master/broid-schemas#readme
|
||||
* https://github.com/autogestion/pubgate-telegram
|
||||
* https://docs.joinmastodon.org/spec/security/
|
||||
* https://chat.openai.com/share/4fda7974-cc0b-439a-b0f2-dc828f8acfef
|
||||
* https://codeberg.org/mro/activitypub/src/commit/4b1319d5363f4a836f23c784ef780b81bc674013/like.sh#L101
|
||||
* https://socialhub.activitypub.rocks/t/problems-posting-to-mastodon-inbox/801/10
|
||||
|
||||
## 사용 전 설정
|
||||
* `apstreams` 게시판 추가
|
||||
* `apstreams` 사용자 추가
|
||||
|
||||
## 작업진행
|
||||
- [x] WebFinger
|
||||
- [x] User
|
||||
- [x] Inbox
|
||||
- [x] Outbox
|
||||
- [x] Followers
|
||||
- [x] Following
|
||||
- [x] Liked
|
||||
- [x] (Added) Geolocation
|
||||
- [ ] (Added) File attachment
|
||||
|
||||
## 전문 예시
|
||||
|
||||
```json
|
||||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"type": "Create",
|
||||
"id": "http://website.local/bbs/board.php?bo_table=apstreams#Draft",
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public", "http://website.local/?route=activitypub.user&mb_id=admin"],
|
||||
"actor": "http://website.local/?route=activitypub.user&mb_id=admin",
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"generator": "GNUBOARD5 ActivityPub Plugin (INSTANCE_ID: 4d6076784cbd864ade7c746690d37051, INSTANCE_VERSION: 0.1.10-dev)",
|
||||
"id": "http://website.local/bbs/board.php?bo_table=apstreams&wr_id=156",
|
||||
"attributedTo": "http://website.local/?route=activitypub.user&mb_id=admin",
|
||||
"content": "hello world @admin@website.local",
|
||||
"icon": "https://www.gravatar.com/avatar/bdbd5eb70305f1eaaa0340687758676a",
|
||||
"location": {
|
||||
"name": "xxx.xxx.xxx.xxx, Seoul, Seoul-teukbyeolsi, Korea (Republic of), KR, 06030, +09:00",
|
||||
"type": "Place",
|
||||
"longitude": 126.977943,
|
||||
"latitude": 37.566311,
|
||||
"units": "m"
|
||||
}
|
||||
},
|
||||
"published": "2022-07-05T09:37:06Z",
|
||||
"updated": "2022-07-05T09:37:06Z"
|
||||
}
|
||||
```
|
||||
|
||||
## 문의
|
||||
* abuse@catswords.net
|
||||
* ActivityPub [@gnh1201@catswords.social](https://catswords.social/@gnh1201)
|
||||
* gnh1201@gmail.com
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
// GhatGPT-ActivityPub implementation for GNUBOARD 5
|
||||
// Go Namhyeon <abuse@catswords.net>
|
||||
// MIT License
|
||||
// 2023-02-16
|
||||
|
||||
if (!defined('_GNUBOARD_') || !defined("ACTIVITYPUB_INSTANCE_ID")) exit; // 개별 페이지 접근 불가
|
||||
|
||||
// ChatGPT API 키 발급: https://platform.openai.com/account/api-keys
|
||||
define("CHATGPT_API_KEY", "YOUR_API_KEY"); // API 키 입력
|
||||
define("CHATGPT_API_URL", "https://api.openai.com/v1/completions"); // GhatGPT API 주소 입력
|
||||
define("LINGVA_API_URL", "https://lingva.ml/api/v1"); // Lingva Translate (구글 번역기 프론트엔드) API 주소 입력
|
||||
|
||||
function lingva_translate($content, $source = 'ko', $target = 'en') {
|
||||
$handle = curl_init();
|
||||
curl_setopt($handle, CURLOPT_URL, LINGVA_API_URL . '/' . $source . '/' . $target . '/' . urlencode($content));
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$response = json_decode(curl_exec($handle), true);
|
||||
curl_close($handle);
|
||||
return $response['translation'];
|
||||
}
|
||||
|
||||
function lingva_ko2en($content) {
|
||||
return lingva_translate($content, 'ko', 'en');
|
||||
}
|
||||
|
||||
function lingva_en2ko($content) {
|
||||
return lingva_translate($content, 'en', 'ko');
|
||||
}
|
||||
|
||||
function chatgpt_request($content, $mb) {
|
||||
// "What is the capital of France?"
|
||||
$prompt = lingva_ko2en(filter_var($content, FILTER_SANITIZE_STRING));
|
||||
$prompt = filter_var($content, FILTER_SANITIZE_STRING);
|
||||
|
||||
$data = array(
|
||||
"model" => "text-davinci-003",
|
||||
"prompt" => $prompt,
|
||||
"max_tokens" => 3000,
|
||||
"temperature" => 0.5,
|
||||
);
|
||||
|
||||
$data_string = json_encode($data);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, CHATGPT_API_URL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . CHATGPT_API_KEY,
|
||||
"Content-Length: " . strlen($data_string))
|
||||
);
|
||||
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
// print_r($output);
|
||||
|
||||
$output_json = json_decode($output, true);
|
||||
$response = $output_json["choices"][0]["text"];
|
||||
// echo $response;
|
||||
|
||||
return lingva_en2ko($response);
|
||||
}
|
||||
|
||||
function chatgpt_send_conversation($content) {
|
||||
global $member;
|
||||
|
||||
// 로그인 상태인 경우 해당 회원, 아닌 경우 ActivityPub 공통 계정
|
||||
$mb = isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME);
|
||||
|
||||
// 수신자 목록
|
||||
$to = array();
|
||||
|
||||
// 참고: 아래에 기술된 역할은 외부 프로그램이 담당하게 할 수도 있음 (service:chatgpt)
|
||||
if (!empty(CHATGPT_API_KEY)) {
|
||||
$response = chatgpt_request($content, $mb);
|
||||
$to[] = "service:chatgpt";
|
||||
}
|
||||
|
||||
// Activity 발행 (발신: 그누보드5 -> ChatGPT)
|
||||
activitypub_publish_content(
|
||||
$content,
|
||||
activitypub_get_url("user", array("mb_id" => $mb['mb_id'])),
|
||||
get_member(ACTIVITYPUB_G5_USERNAME),
|
||||
array(),
|
||||
$to
|
||||
);
|
||||
|
||||
// Activity 발행 (수신: ChatGPT -> 그누보드5)
|
||||
activitypub_publish_content(
|
||||
$response,
|
||||
"service:chatgpt",
|
||||
get_member(ACTIVITYPUB_G5_USERNAME),
|
||||
array(),
|
||||
array(
|
||||
activitypub_get_url("user", array("mb_id" => $mb['mb_id']))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function _chatgpt_memo_form_update_after($member_list, $str_nick_list, $redirect_url, $me_memo) {
|
||||
// 수신자에 'apstreams' 계정이 있는지 확인
|
||||
if (!in_array(ACTIVITYPUB_G5_USERNAME, $member_list['id'])) return;
|
||||
|
||||
// ChatGPT에게 대화 걸기
|
||||
chatgpt_send_conversation($me_memo);
|
||||
}
|
||||
|
||||
add_event("memo_form_update_after", "_chatgpt_memo_form_update_after", 1, 4);
|
|
@ -1,167 +0,0 @@
|
|||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
// ActivityPub/WebHook implementation for GNUBOARD 5
|
||||
// Go Namhyeon <abuse@catswords.net>
|
||||
// MIT License
|
||||
// 2022-07-07
|
||||
|
||||
// [Reference]
|
||||
// * https://github.com/gnh1201/reasonableframework/blob/master/helper/webhooktool.php
|
||||
|
||||
// `NateOn` is trademark of SK Communications Co Ltd., SK Planet Co Ltd.
|
||||
// `Discord' is trademark of Discord Inc. (Former, Hammer And Chisel)
|
||||
// `Slack` is trademark of Slack Technologies Inc.
|
||||
|
||||
// 내려받기: https://sir.kr/g5_plugin/10381
|
||||
if (!defined("ACTIVITYPUB_INSTANCE_ID")) return;
|
||||
|
||||
define("NATEON_WEBHOOK_URL", "");
|
||||
define("DISCORD_WEBHOOK_URL", "");
|
||||
define("SLACK_WEBHOOK_URL", "");
|
||||
define("SLACK_WEBHOOK_CHANNEL", "#webhook");
|
||||
|
||||
function nateon_send_webhook($content, $mb) {
|
||||
$headers = array(
|
||||
"Content-Type" => "application/x-www-form-urlencoded",
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => NATEON_WEBHOOK_URL,
|
||||
CURLOPT_HTTPHEADER => activitypub_build_http_headers($headers),
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => "content=" . urlencode($content),
|
||||
CURLOPT_POST => true
|
||||
));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return array("status" => $status);
|
||||
}
|
||||
|
||||
function discord_send_webhook($content, $mb) {
|
||||
$headers = array(
|
||||
"Content-Type" => "application/json",
|
||||
);
|
||||
|
||||
$rawdata = activitypub_json_encode(array(
|
||||
"content" => $content,
|
||||
"username" => $mb['mb_nick']
|
||||
));
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => DISCORD_WEBHOOK_URL,
|
||||
CURLOPT_HTTPHEADER => activitypub_build_http_headers($headers),
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => $rawdata,
|
||||
CURLOPT_POST => true
|
||||
));
|
||||
$response = curl_exec($ch);
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return array("status" => $status);
|
||||
}
|
||||
|
||||
function slack_send_webhook($content, $mb) {
|
||||
$headers = array(
|
||||
"Content-Type" => "application/json",
|
||||
);
|
||||
|
||||
$rawdata = activitypub_json_encode(array(
|
||||
"channel" => SLACK_WEBHOOK_CHANNEL,
|
||||
"username" => $mb['mb_nick'],
|
||||
"text" => $content,
|
||||
"icon_emoji" => ":ghost:"
|
||||
));
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => SLACK_WEBHOOK_URL,
|
||||
CURLOPT_HTTPHEADER => activitypub_build_http_headers($headers),
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => $rawdata,
|
||||
CURLOPT_POST => true
|
||||
));
|
||||
$response = curl_exec($ch);
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return array("status" => $status);
|
||||
}
|
||||
|
||||
function send_webhooks($content) {
|
||||
global $member;
|
||||
|
||||
// 로그인 상태인 경우 해당 회원, 아닌 경우 ActivityPub 공통 계정
|
||||
$mb = isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME);
|
||||
|
||||
// 수신자 목록
|
||||
$to = array();
|
||||
|
||||
// 참고: 아래 함수의 역할은 외부 프로그램이 담당하게 할 수도 있음 (ActivityPub Outbox로부터 데이터 받은 후 처리 가능)
|
||||
// nateon_send_webhook, discord_send_webhook, slack_send_webhook
|
||||
|
||||
if (!empty(NATEON_WEBHOOK_URL))
|
||||
nateon_send_webhook($content, $mb);
|
||||
$to[] = "webhook:nateon";
|
||||
|
||||
if (!empty(DISCORD_WEBHOOK_URL))
|
||||
discord_send_webhook($content, $mb);
|
||||
$to[] = "webhook:discord";
|
||||
|
||||
if (!empty(SLACK_WEBHOOK_URL))
|
||||
slack_send_webhook($content, $mb);
|
||||
$to[] = "webhook:slack";
|
||||
|
||||
// Activity로 발행
|
||||
activitypub_publish_content(
|
||||
$content,
|
||||
activitypub_get_url("user", array("mb_id" => $mb['mb_id'])),
|
||||
get_member(ACTIVITYPUB_G5_USERNAME),
|
||||
array(),
|
||||
$to
|
||||
);
|
||||
}
|
||||
|
||||
function _webhook_memo_form_update_after($member_list, $str_nick_list, $redirect_url, $me_memo) {
|
||||
send_webhooks($me_memo); // 웹훅 보내기
|
||||
}
|
||||
|
||||
function _webhook_write_update_after($board, $wr_id, $w, $qstr, $redirect_url) {
|
||||
global $g5;
|
||||
|
||||
// 본문 가져오기
|
||||
$sql = "select wr_id, wr_content from {$g5['write_prefix']}{$board['bo_table']} where wr_id = '{$wr_id}'";
|
||||
$row = sql_fetch($sql);
|
||||
if (empty($row['wr_id'])) return;
|
||||
|
||||
// 웹훅 보내기
|
||||
send_webhooks($row['wr_content']);
|
||||
}
|
||||
|
||||
function _webhook_comment_update_after($board, $wr_id, $w, $qstr, $redirect_url, $comment_id, $reply_array) {
|
||||
global $g5;
|
||||
|
||||
// 본문(댓글) 가져오기
|
||||
$sql = "select wr_id, wr_parent, wr_content from {$g5['write_prefix']}{$board['bo_table']} where wr_id = '{$comment_id}'";
|
||||
$row = sql_fetch($sql);
|
||||
if (empty($row['wr_id'])) return;
|
||||
|
||||
// 웹훅 보내기
|
||||
send_webhooks($row['wr_content']);
|
||||
}
|
||||
|
||||
add_event("write_update_after", "_webhook_write_update_after", 1, 5);
|
||||
add_event("comment_update_after", "_webhook_comment_update_after", 1, 7);
|
||||
add_event("memo_form_update_after", "_webhook_memo_form_update_after", 1, 4);
|
Loading…
Reference in New Issue
Block a user