Compare commits

...

5 commits

Author SHA1 Message Date
Fenris Wolf
54e27f2ad9 [int] 2024-11-14 19:57:13 +01:00
Fenris Wolf
b5b5dde9e3 [res] 2024-11-10 17:20:41 +01:00
Fenris Wolf
5de4728901 Merge remote-tracking branch 'origin/main' into task-192 2024-11-10 17:19:58 +01:00
Fenris Wolf
c9b882edbe [mod] date formatting [mod] caldav resource integration 2024-11-01 13:34:44 +01:00
Fenris Wolf
cde912392c [upd] plankton 2024-11-01 13:34:22 +01:00
17 changed files with 3172 additions and 2305 deletions

View file

@ -4,7 +4,8 @@
{
"kind": "stdout",
"data": {
"threshold": "info"
"threshold": "info",
"format": "human_readable"
}
}
],

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -9,8 +9,8 @@ namespace _zeitbild.api
) : void
{
register<
any,
any
null,
string
>(
rest_subject,
lib_plankton.caldav.enum_method.propfind,
@ -42,56 +42,82 @@ namespace _zeitbild.api
"nullable": false,
"type": "string",
}),
"response_body_mimetype": "application/xml",
"response_body_mimetype": "text/xml; charset=utf-8",
"response_body_encode": output => Buffer.from(output),
// "restriction": restriction_basic_auth,
"restriction": restriction_none,
/**
* @todo examine body
*/
"execution": async (stuff) => {
return Promise.resolve(
{
"status_code": 207,
"data": (
/*"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
+*/
lib_plankton.webdav.data_multistatus_encode(
{
"responses": [
const user_id : (null | type_user_id) = await _zeitbild.api.web_auth(
stuff.headers["Authorization"]
??
stuff.headers["authorization"]
??
null
);
if (user_id === null) {
return Promise.resolve(
{
"status_code": 401,
"data": "",
"extra_headers": {
"WWW-Authenticate": "Basic realm=Restricted",
}
}
);
}
else {
return (
_zeitbild.service.calendar.overview(user_id)
.then(
(data_raw) => Promise.resolve(
data_raw
.map(
(entry) => ({
"id": entry.id,
"name": entry.name,
"access_level": _zeitbild.value_object.access_level.to_string(entry.access_level),
})
)
)
)
.then(
(data) => Promise.resolve({
"status_code": 207,
"data": (
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+
lib_plankton.webdav.data_multistatus_encode(
{
"href": "/caldav/events",
"body": {
"propstats": [
{
"prop": [
{"name": "d:displayname", "value": "default"},
// {"name": "cs:getctag", "value": "47"}, // TODO correct value
// {"name": "current-user-privilege-set", "value": ""},
/*
"uid",
"dtstamp",
"dtstart",
"dtend",
"summary",
"description",
"url",
"location",
*/
],
"status": "HTTP/2.0 200 OK",
"description": null,
"responses": [
{
"href": "/caldav/events",
"body": {
"propstats": data.map(
(entry) => ({
"prop": [
{"name": "displayname", "value": entry.name},
// {"name": "cs:getctag", "value": "47"}, // TODO correct value
// {"name": "current-user-privilege-set", "value": ""},
],
"status": "HTTP/2.0 200 OK",
"description": entry.access_level,
})
),
},
]
},
"description": null,
}
],
"description": null,
}
],
"description": null,
}
)
),
}
);
)
),
})
)
);
}
}
}
);

View file

@ -0,0 +1,46 @@
namespace _zeitbild.api
{
/**
*/
export function register_caldav_sniff(
rest_subject : lib_plankton.rest_caldav.type_rest
) : void
{
register<
any,
null
>(
rest_subject,
lib_plankton.caldav.enum_method.options,
"/caldav",
{
"restriction": restriction_none,
"execution": async (stuff) => {
const permitted : boolean = await restriction_basic_auth(stuff);
if (! permitted) {
return Promise.resolve(
{
"status_code": 401,
"data": null,
"extra_headers": {
"WWW-Authenticate": "Basic realm=Restricted",
}
}
);
}
else {
return Promise.resolve(
{
"status_code": 200,
"data": null
}
);
}
}
}
);
}
}

View file

@ -33,6 +33,7 @@ namespace _zeitbild.api
data : {
url : string;
read_only : boolean;
from_fucked_up_wordpress : boolean;
};
}
);
@ -79,6 +80,7 @@ namespace _zeitbild.api
"data": {
"url": stuff.input.resource.data.url,
"read_only": stuff.input.resource.data.read_only,
"from_fucked_up_wordpress": stuff.input.resource.data.from_fucked_up_wordpress,
}
};
break;

View file

@ -160,27 +160,31 @@ namespace _zeitbild.api
user_id
)
.then(
(data) => Promise.resolve({
"status_code": 200,
"data": (
data
.map(
(entry) => ({
"calendar_id": entry.calendar_id,
"calendar_name": entry.calendar_name,
"access_level": _zeitbild.api.access_level_encode(entry.access_level),
"event_id": entry.event_id,
"event_object": entry.event_object,
})
)
),
})
(data) => Promise.resolve(
{
"status_code": 200,
"data": (
data
.map(
(entry) => ({
"calendar_id": entry.calendar_id,
"calendar_name": entry.calendar_name,
"access_level": _zeitbild.api.access_level_encode(entry.access_level),
"event_id": entry.event_id,
"event_object": entry.event_object,
})
)
),
}
)
)
.catch(
(reason) => Promise.resolve({
"status_code": 403,
"data": String(reason),
})
(reason) => Promise.resolve(
{
"status_code": 403,
"data": String(reason),
}
)
)
);
}

View file

@ -25,6 +25,77 @@ namespace _zeitbild.api
}
/**
* @todo outsource?
*/
export async function web_auth(
authorization_string : (null | string)
) : Promise<(null | _zeitbild.type_user_id)>
{
if (authorization_string === null) {
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
}
else {
const parts : Array<string> = authorization_string.split(" ");
const strategy : string = parts[0];
const data_raw : string = parts.slice(1).join(" ");
switch (strategy) {
default: {
lib_plankton.log.notice(
"zeitbild.web_auth.unhandled_strategy",
{
"strategy": strategy,
}
);
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
break;
}
case "Basic": {
const data_raw_decoded : string = lib_plankton.base64.decode(data_raw);
const parts_ : Array<string> = data_raw_decoded.split(":");
const username : string = parts_[0];
const password_is : string = parts_.slice(1).join(":");
const {"value": user_id, "error": error} = await lib_plankton.call.try_catch_wrap_async<_zeitbild.type_user_id>(
() => _zeitbild.service.user.identify(username)
);
if (error !== null) {
lib_plankton.log.notice(
"zeitbild.web_auth.unknown_user",
{
"username": username,
}
);
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
}
else {
const password_shall : string = lib_plankton.sha256.get(
username,
_zeitbild.conf.get()["misc"]["auth_salt"]
);
if (! (password_is === password_shall)) {
/**
* @todo remove
*/
lib_plankton.log.notice(
"zeitbild.web_auth.wrong_pasword",
{
"shall": password_shall,
"is": password_is,
}
);
return Promise.resolve<(null | _zeitbild.type_user_id)>(null);
}
else {
return Promise.resolve<(null | _zeitbild.type_user_id)>(user_id);
}
}
break;
}
}
}
}
/**
*/
export const restriction_logged_in : lib_plankton.rest_caldav.type_restriction<any> = (
@ -36,6 +107,26 @@ namespace _zeitbild.api
);
/**
*/
export const restriction_basic_auth : lib_plankton.rest_caldav.type_restriction<any> = (
(stuff) => (
web_auth(
stuff.headers["Authorization"]
??
stuff.headers["authorization"]
??
null
)
.then<boolean>(
(user_id) => Promise.resolve<boolean>(
(user_id !== null)
)
)
)
);
/**
*/
export const restriction_none : lib_plankton.rest_caldav.type_restriction<any> = (

View file

@ -52,6 +52,7 @@ namespace _zeitbild.api
}
// caldav
{
_zeitbild.api.register_caldav_sniff(rest_subject);
_zeitbild.api.register_caldav_probe(rest_subject);
_zeitbild.api.register_caldav_get(rest_subject);
}

View file

@ -41,7 +41,17 @@ namespace _zeitbild.conf
"error"
],
"default": "info"
}
},
"format": {
"nullable": false,
"type": "string",
"enum": [
"human_readable",
"jsonl",
"jsonl_structured",
],
"default": "human_readable",
},
},
"required": [
]

View file

@ -5,7 +5,7 @@ namespace _zeitbild.database
/**
*/
const _compatible_revisions : Array<string> = [
"r3",
"r4",
];

View file

@ -40,6 +40,7 @@ type type_data = {
data : {
url : string;
read_only : boolean;
from_fucked_up_wordpress ?: boolean;
};
}
);
@ -109,6 +110,7 @@ async function data_init(
"data": {
"url": calendar_raw.resource.data.url,
"read_only": calendar_raw.resource.data.read_only,
"from_fucked_up_wordpress": (calendar_raw.resource.data.from_fucked_up_wordpress ?? false),
}
};
resource_id = await _zeitbild.service.resource.add(
@ -157,11 +159,17 @@ async function main(
) : Promise<void>
{
// init1
lib_plankton.log.conf_push(
/*
lib_plankton.log.set_main_logger(
[
lib_plankton.log.channel_make({"kind": "stdout", "data": {"threshold": "info"}}),
{
"kind": "std",
"data": {
}
}
]
);
*/
// args
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler({
@ -244,20 +252,65 @@ async function main(
"name": "help",
}),
});
const args : Record<string, any> = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" "));
const args : Record<string, any> = arg_handler.read(
lib_plankton.args.enum_environment.cli,
args_raw.join(" ")
);
// init2
await _zeitbild.conf.init(
args["conf_path"]
);
lib_plankton.log.conf_push(
lib_plankton.log.set_main_logger(
_zeitbild.conf.get().log.map(
(log_output : any) => lib_plankton.log.channel_make(
{
"kind": log_output.kind,
"data": log_output.data
(log_output : any) => {
switch (log_output.kind) {
case "stdout": {
return {
"kind": "minlevel",
"data": {
"core": {
"kind": "std",
"data": {
"target": "stdout",
"format": lib_plankton.call.distinguish(
{
"kind": log_output.data.format,
"data": null,
},
{
"jsonl": () => ({
"kind": "jsonl",
"data": {
"structured": false,
}
}),
"jsonl_structured": () => ({
"kind": "jsonl",
"data": {
"structured": true,
}
}),
"human_readable": () => ({
"kind": "human_readable",
"data": {
}
}),
}
),
}
},
"threshold": log_output.data.threshold,
}
};
break;
}
default: {
throw (new Error("unhandled"));
break;
}
}
)
}
)
);
_zeitbild.cache = lib_plankton.cache.chest.implementation<any>(
@ -319,9 +372,8 @@ async function main(
break;
}
case "api-doc": {
lib_plankton.log.conf_push([]);
lib_plankton.log.set_main_logger([]);
const rest_subject : lib_plankton.rest_caldav.type_rest = _zeitbild.api.make();
lib_plankton.log.conf_pop();
process.stdout.write(
JSON.stringify(
lib_plankton.rest_caldav.to_oas(rest_subject),
@ -387,6 +439,7 @@ async function main(
"checklevel_restriction": lib_plankton.api.enum_checklevel.hard,
// "checklevel_input": lib_plankton.api.enum_checklevel.soft,
// "checklevel_output": lib_plankton.api.enum_checklevel.soft,
"set_content_length": false,
}
);
const output : string = lib_plankton.caldav.encode_response(http_response);
@ -416,6 +469,7 @@ async function main(
)
.catch(
(error) => {
// console.error(error);
process.stderr.write(String(error) + "\n");
}
)

View file

@ -366,6 +366,7 @@ namespace _zeitbild.repository.resource
"data": {
"url": dataset_extra_caldav["url"],
"read_only": dataset_extra_caldav["read_only"],
"from_fucked_up_wordpress": dataset_extra_caldav["from_fucked_up_wordpress"],
}
}
);
@ -409,6 +410,7 @@ namespace _zeitbild.repository.resource
{
"url": resource_object.data.url,
"read_only": resource_object.data.read_only,
"from_fucked_up_wordpress": resource_object.data.from_fucked_up_wordpress,
}
);
const resource_id : _zeitbild.type_resource_id = await get_resource_core_store().create(

View file

@ -348,11 +348,26 @@ namespace _zeitbild.service.calendar
{
}
);
const vcalendar : lib_plankton.ical.type_vcalendar = lib_plankton.ical.ics_decode(
http_response.body.toString(),
const ics_raw : string = (
(http_response.body === null)
?
""
:
http_response.body.toString()
);
const vcalendar_list : Array<lib_plankton.ical.type_vcalendar> = lib_plankton.ical.ics_decode_multi(
ics_raw,
{
"ignore_unhandled_instruction_keys": resource_object.data.from_fucked_up_wordpress,
"from_fucked_up_wordpress": resource_object.data.from_fucked_up_wordpress,
}
);
const vcalendar : lib_plankton.ical.type_vcalendar = {
// required
"version": vcalendar_list[0].version,
"prodid": vcalendar_list[0].prodid,
"vevents": vcalendar_list.map(x => x.vevents).reduce((x, y) => x.concat(y), []),
};
return Promise.resolve(
vcalendar.vevents
.map(

View file

@ -86,6 +86,7 @@ namespace _zeitbild
data : {
url : string;
read_only : boolean;
from_fucked_up_wordpress : boolean;
};
}
);

View file

@ -76,6 +76,7 @@ ${dir_temp}/zeitbild-unlinked.js: \
${dir_source}/api/actions/calendar_event_remove.ts \
${dir_source}/api/actions/events.ts \
${dir_source}/api/actions/export_ical.ts \
${dir_source}/api/actions/caldav_sniff.ts \
${dir_source}/api/actions/caldav_probe.ts \
${dir_source}/api/actions/caldav_get.ts \
${dir_source}/api/functions.ts \

View file

@ -24,9 +24,8 @@ modules="${modules} http"
modules="${modules} webdav"
modules="${modules} caldav"
modules="${modules} api"
modules="${modules} rest"
modules="${modules} rest_http"
modules="${modules} rest_webdav"
# modules="${modules} rest_http"
# modules="${modules} rest_webdav"
modules="${modules} rest_caldav"
modules="${modules} server"
modules="${modules} args"