Config handling

FossilOrigin-Name: 65d5f9e7c528992ed6d5dff66a1f8945d6a4fbc37aed5ee3e4999c469815ce61
This commit is contained in:
me@ow.nekobit.net 2022-04-01 14:56:30 +00:00
parent 216cf686f2
commit 064097c069
9 changed files with 130 additions and 23 deletions

View file

@ -18,11 +18,16 @@
#ifndef LOCAL_CONFIG_H
#define LOCAL_CONFIG_H
#include "query.h"
struct local_config
{
int changed;
char* theme;
int themeclr;
int jsactions;
int jsreply;
int jslive;
};
#endif // LOCAL_CONFIG_H

69
src/local_config_set.c Normal file
View file

@ -0,0 +1,69 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <fcgi_stdio.h>
#include <stdlib.h>
#include "local_config_set.h"
int set_config_str(char** ssn,
char* cookie_name,
char* value)
{
if (value && ssn)
{
*ssn = value;
printf("Set-Cookie: %s=%s; HttpOnly; Path=/; SameSite=Strict;\r\n",
cookie_name, value);
}
// If ssn isn't passed but value is set, then that means
// something has changed
return value != NULL;
}
int set_config_int(int* ssn,
char* cookie_name,
char* value)
{
if (!value) return 0;
char* err = NULL;
long str_l = strtol(value, &err, 0);
// Not a number
if (err == value)
return 0;
if (ssn)
{
*ssn = str_l;
printf("Set-Cookie: %s=%ld; HttpOnly; Path=/; SameSite=Strict;\r\n",
cookie_name, str_l);
}
return 1;
}
void load_config(struct session* ssn)
{
set_config_str(&(ssn->config.theme), "theme", ssn->post.theme);
set_config_int(&(ssn->config.themeclr), "themeclr", ssn->post.themeclr);
set_config_int(&(ssn->config.jsactions), "jsactions", ssn->post.jsactions);
set_config_int(&(ssn->config.jsreply), "jsreply", ssn->post.jsreply);
set_config_int(&(ssn->config.jslive), "jslive", ssn->post.jslive);
}

34
src/local_config_set.h Normal file
View file

@ -0,0 +1,34 @@
/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LOCAL_CONFIG_SET_H
#define LOCAL_CONFIG_SET_H
#include "local_config.h"
#include "session.h"
int set_config_str(char** ssn,
char* cookie_name,
char* value);
int set_config_int(int* ssn,
char* cookie_name,
char* value);
void load_config(struct session* ssn);
#endif // LOCAL_CONFIG_SET_H

View file

@ -26,7 +26,7 @@
#include "page_config.h"
#include "query.h"
#include "cookie.h"
#include "local_config.h"
#include "local_config_set.h"
#include "string_helpers.h"
#include "l10n.h"
@ -43,17 +43,6 @@ enum config_category
CONFIG_CAT_ACCOUNT
};
static void load_config(struct session* ssn)
{
if (ssn->post.theme)
{
ssn->config.theme = ssn->post.theme;
printf("Set-Cookie: %s=%s; HttpOnly; SameSite=Strict;",
"theme", ssn->post.theme);
ssn->config.changed = 1;
}
}
static char* construct_config_sidebar(enum config_category cat, size_t* size)
{
char* sidebar_html;

View file

@ -77,6 +77,10 @@ char* read_post_data(struct query_values* post)
{ "itype", &(post->itype) },
{ "id", &(post->id) },
{ "theme", &(post->theme) },
{ "themeclr", &(post->themeclr) },
{ "jsactions", &(post->jsactions) },
{ "jsreply", &(post->jsreply) },
{ "jslive", &(post->jslive) },
{ "username", &(post->username) },
{ "password", &(post->password) },
{ "replyid", &(post->replyid) },

View file

@ -29,7 +29,13 @@ struct http_query_info
struct query_values
{
// Config
char* theme;
char* themeclr;
char* jsactions;
char* jsreply;
char* jslive;
char* content;
char* itype;
char* id;

View file

@ -1,5 +1,5 @@
<div class="simple-page">
<form action="../config" method="post">
<form action="appearance" method="post">
<!-- Appearance -->
<h1>Appearance</h1>
<h3>Theme variant</h3>
@ -16,11 +16,11 @@
<h3>Color Scheme</h3>
<ul>
<li>
<input type="radio" id="cfglight" name="themeclr" value="light" checked>
<input type="radio" id="cfglight" name="themeclr" value="1" checked>
<label for="cfglight">Light</label>
</li>
<li>
<input type="radio" id="cfgdark" name="themeclr" value="dark">
<input type="radio" id="cfgdark" name="themeclr" value="2">
<label for="cfgdark">Dark</label>
</li>
</ul>

View file

@ -1,18 +1,18 @@
<div class="simple-page">
<form action="../config" method="post">
<form action="general" method="post">
<h1>General</h1>
<h3>JavaScript</h3>
<ul>
<li>
<input type="checkbox" id="cfgjsactions" name="jsactions">
<input type="checkbox" id="cfgjsactions" name="jsactions" value="1">
<label for="cfgjsactions">Quick actions - Likes, Boosts, etc done in background</label>
</li>
<li>
<input type="checkbox" id="cfgjsreply" name="jsreply">
<input type="checkbox" id="cfgjsreply" name="jsreply" value="1">
<label for="cfgjsreply">Quick reply - Replies don't require redirects</label>
</li>
<li>
<input type="checkbox" id="cfgjslive" name="jslive">
<input type="checkbox" id="cfgjslive" name="jslive" value="1">
<label for="cfgjslive">Live statuses - Statuses fetch on the fly</label>
</li>
</ul>

View file

@ -35,7 +35,7 @@
<label class="pointer">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 9l6 6-6 6"/><path d="M4 4v7a4 4 0 0 0 4 4h11"/></svg>
<span class="count">%s</span>
<input class="hidden" type="submit">
<input class="hidden" type="submit" value="Reply">
</label>
</form>
</td>
@ -45,7 +45,7 @@
<label class="pointer">
<svg class="repeat %s" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 2.1l4 4-4 4"/><path d="M3 12.2v-2a4 4 0 0 1 4-4h12.8M7 21.9l-4-4 4-4"/><path d="M21 11.8v2a4 4 0 0 1-4 4H4.2"/></svg>
<span class="count">%s</span>
<input class="hidden" type="submit">
<input class="hidden" type="submit" value="Repeat">
</label>
</form>
</td>
@ -55,7 +55,7 @@
<label class="pointer">
<svg class="like %s" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg>
<span class="count">%s</span>
<input class="hidden" type="submit">
<input class="hidden" type="submit" value="Like">
</label>
</form>
</td>
@ -63,7 +63,7 @@
<form action="%s/status/%s#id-%s" method="post">
<label class="pointer">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6M14 10l6.1-6.1M9 21H3v-6M10 14l-6.1 6.1"/></svg>
<input class="hidden" type="submit">
<input class="hidden" type="submit" >
</label>
</form>
</td>