Compare commits

..

No commits in common. "54e27f2ad97bc0d5fc5ddd7f0f34ddf62f332d99" and "9d1fd0b55f68ea324113bfe64af700d7706c91ef" have entirely different histories.

17 changed files with 2275 additions and 3142 deletions

View file

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

View file

@ -1,46 +0,0 @@
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,7 +33,6 @@ namespace _zeitbild.api
data : { data : {
url : string; url : string;
read_only : boolean; read_only : boolean;
from_fucked_up_wordpress : boolean;
}; };
} }
); );
@ -80,7 +79,6 @@ namespace _zeitbild.api
"data": { "data": {
"url": stuff.input.resource.data.url, "url": stuff.input.resource.data.url,
"read_only": stuff.input.resource.data.read_only, "read_only": stuff.input.resource.data.read_only,
"from_fucked_up_wordpress": stuff.input.resource.data.from_fucked_up_wordpress,
} }
}; };
break; break;

View file

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

View file

@ -25,77 +25,6 @@ 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> = ( export const restriction_logged_in : lib_plankton.rest_caldav.type_restriction<any> = (
@ -107,26 +36,6 @@ 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> = ( export const restriction_none : lib_plankton.rest_caldav.type_restriction<any> = (

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -348,26 +348,11 @@ namespace _zeitbild.service.calendar
{ {
} }
); );
const ics_raw : string = ( const vcalendar : lib_plankton.ical.type_vcalendar = lib_plankton.ical.ics_decode(
(http_response.body === null) http_response.body.toString(),
?
""
:
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( return Promise.resolve(
vcalendar.vevents vcalendar.vevents
.map( .map(

View file

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

View file

@ -76,7 +76,6 @@ ${dir_temp}/zeitbild-unlinked.js: \
${dir_source}/api/actions/calendar_event_remove.ts \ ${dir_source}/api/actions/calendar_event_remove.ts \
${dir_source}/api/actions/events.ts \ ${dir_source}/api/actions/events.ts \
${dir_source}/api/actions/export_ical.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_probe.ts \
${dir_source}/api/actions/caldav_get.ts \ ${dir_source}/api/actions/caldav_get.ts \
${dir_source}/api/functions.ts \ ${dir_source}/api/functions.ts \

View file

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