ios: Add a EULA to try to appease Apple's Guideline 1.2 - Safety - User-Generated Content.

This commit is contained in:
2025-11-02 14:30:25 -05:00
parent 24f0cdb398
commit 7879ab1d50
12 changed files with 305 additions and 82 deletions

View File

@@ -1,5 +1,6 @@
#include "httpd.js.h"
#include "eula.h"
#include "file.js.h"
#include "http.h"
#include "log.h"
@@ -13,6 +14,11 @@
#include "sodium/crypto_sign.h"
#include "sodium/utils.h"
#include "zlib.h"
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#define CYAN "\e[1;36m"
#define MAGENTA "\e[1;35m"
@@ -616,28 +622,99 @@ tf_httpd_user_app_t* tf_httpd_parse_user_app_from_path(const char* path, const c
return result;
}
static void _httpd_endpoint_root_callback(const char* path, void* user_data)
typedef struct _root_t
{
tf_http_request_t* request = user_data;
const char* headers[] = {
"Location",
path ? path : "/~core/apps/",
};
tf_http_respond(request, 303, headers, tf_countof(headers) / 2, NULL, 0);
tf_http_request_unref(request);
}
tf_http_request_t* request;
const char* path;
} root_t;
static void _httpd_endpoint_root(tf_http_request_t* request)
static void _httpd_root_work(tf_ssb_t* ssb, void* user_data)
{
root_t* root = user_data;
tf_http_request_t* request = root->request;
const char* host = tf_http_request_get_header(request, "x-forwarded-host");
if (!host)
{
host = tf_http_request_get_header(request, "host");
}
bool require_eula =
#if TARGET_OS_IPHONE
true;
#else
false;
#endif
int64_t accepted_eula_crc = 0;
uint32_t eula_crc = crc32(crc32(0, NULL, 0), k_eula, k_eula_len);
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
tf_ssb_db_get_global_setting_int64(db, "accepted_eula_crc", &accepted_eula_crc);
if (require_eula && accepted_eula_crc != eula_crc)
{
root->path = tf_strdup("/static/eula.html");
}
else
{
root->path = tf_ssb_db_resolve_index(db, host);
}
tf_ssb_release_db_reader(ssb, db);
}
static void _httpd_root_after_work(tf_ssb_t* ssb, int status, void* user_data)
{
root_t* root = user_data;
tf_http_request_t* request = root->request;
const char* headers[] = {
"Location",
root->path ? root->path : "/~core/apps/",
};
tf_http_respond(request, 303, headers, tf_countof(headers) / 2, NULL, 0);
tf_http_request_unref(request);
tf_free((void*)root->path);
tf_free(root);
}
static void _httpd_endpoint_root(tf_http_request_t* request)
{
root_t* root = tf_malloc(sizeof(root_t));
*root = (root_t) {
.request = request,
};
tf_http_request_ref(request);
tf_task_t* task = request->user_data;
tf_ssb_t* ssb = tf_task_get_ssb(task);
tf_ssb_run_work(ssb, _httpd_root_work, _httpd_root_after_work, root);
}
static void _httpd_accept_eula_work(tf_ssb_t* ssb, void* user_data)
{
uint32_t eula_crc = crc32(crc32(0, NULL, 0), k_eula, k_eula_len);
char buffer[64];
snprintf(buffer, sizeof(buffer), "%u", eula_crc);
sqlite3* db = tf_ssb_acquire_db_writer(ssb);
tf_ssb_db_set_global_setting_from_string(db, "accepted_eula_crc", buffer);
tf_ssb_release_db_writer(ssb, db);
}
static void _httpd_accept_eula_after_work(tf_ssb_t* ssb, int status, void* user_data)
{
tf_http_request_t* request = user_data;
const char* headers[] = {
"Location",
"/",
};
tf_http_respond(request, 303, headers, tf_countof(headers) / 2, NULL, 0);
tf_http_request_unref(request);
}
static void _httpd_endpoint_accept_eula(tf_http_request_t* request)
{
tf_http_request_ref(request);
tf_ssb_db_resolve_index_async(ssb, host, _httpd_endpoint_root_callback, request);
tf_task_t* task = request->user_data;
tf_ssb_t* ssb = tf_task_get_ssb(task);
tf_ssb_run_work(ssb, _httpd_accept_eula_work, _httpd_accept_eula_after_work, request);
}
static void _httpd_endpoint_robots_txt(tf_http_request_t* request)
@@ -913,6 +990,7 @@ tf_http_t* tf_httpd_create(JSContext* context)
tf_http_add_handler(http, "/login/logout", tf_httpd_endpoint_logout, NULL, task);
tf_http_add_handler(http, "/login/auto", tf_httpd_endpoint_login_auto, NULL, task);
tf_http_add_handler(http, "/login", tf_httpd_endpoint_login, NULL, task);
tf_http_add_handler(http, "/eula/accept", _httpd_endpoint_accept_eula, NULL, task);
tf_http_add_handler(http, "/app/socket", tf_httpd_endpoint_app_socket, NULL, task);