gboolean cockpit_handler_resource (CockpitWebServer *server, const gchar *path, GHashTable *headers, CockpitWebResponse *response, CockpitHandlerData *ws) { CockpitWebService *service; if (g_str_has_prefix (path, "/cockpit/static/")) { cockpit_web_response_file (response, path + 16, TRUE, ws->static_roots); return TRUE; } service = cockpit_auth_check_cookie (ws->auth, headers); if (service) { cockpit_web_service_resource (service, headers, response); g_object_unref (service); } else if (g_str_equal (path, "/") || g_str_has_suffix (path, ".html")) { send_login_html (response, ws); } else { cockpit_web_response_error (response, 401, NULL, NULL); } return TRUE; }
static void handle_resource (CockpitHandlerData *data, CockpitWebService *service, const gchar *path, GHashTable *headers, CockpitWebResponse *response) { gchar *where; where = cockpit_web_response_pop_path (response); if (where && (where[0] == '@' || where[0] == '$') && where[1] != '\0') { if (service) { cockpit_channel_response_serve (service, headers, response, where, cockpit_web_response_get_path (response)); } else if (g_str_has_suffix (path, ".html")) { send_login_html (response, data); } else { cockpit_web_response_error (response, 401, NULL, NULL); } } else { cockpit_web_response_error (response, 404, NULL, NULL); } g_free (where); }
static void handle_shell (CockpitHandlerData *data, CockpitWebService *service, const gchar *path, GHashTable *headers, CockpitWebResponse *response) { gboolean valid; const gchar *shell_path; /* Check if a valid path for a shell to be served at */ valid = g_str_equal (path, "/") || g_str_has_prefix (path, "/@") || strspn (path + 1, COCKPIT_RESOURCE_PACKAGE_VALID) == strcspn (path + 1, "/"); if (g_str_has_prefix (path, "/@/") || g_str_has_prefix (path, "//")) valid = FALSE; if (!valid) { cockpit_web_response_error (response, 404, NULL, NULL); } else if (service) { shell_path = cockpit_conf_string ("WebService", "Shell"); cockpit_channel_response_serve (service, headers, response, NULL, shell_path ? shell_path : cockpit_ws_shell_component); } else { send_login_html (response, data); } }