/* server_http.c Author: Pekka Riikonen Copyright (C) 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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 General Public License for more details. */ #include "serverincludes.h" #include "server_internal.h" /************************* Types and definitions ****************************/ #define HTTP_START1 \ "\n" \ "\n" \ "\n" \ "\n" \ "\n" #define HTTP_START2 \ "\n" \ "\n" \ "\n" #define HTTP_END \ "\n" \ "\n" #define HTTP_404 "404 Not Found" #define HTTP_404_B "

404 Not Found

The page you are looking for cannot be located" #define STAT_OUTPUT(fmt, stat) \ do { \ silc_snprintf(buf, sizeof(buf), fmt "
", (int)stat); \ silc_buffer_strformat(&page, buf, SILC_STRFMT_END); \ } while(0) /****************************** HTTP access *********************************/ /* HTTP server callback. We serve pages here. */ static void silc_server_http_callback(SilcHttpServer httpd, SilcHttpConnection conn, const char *uri, const char *method, SilcBuffer data, void *context) { SilcServer server = context; SilcBufferStruct page; unsigned char buf[128]; SILC_LOG_DEBUG(("HTTP callback: %s %s", method, uri)); memset(&page, 0, sizeof(page)); if (!strcasecmp(method, "GET")) { /* Index page */ if (!strcmp(uri, "/") || !strcmp(uri, "/index.html")) { SILC_LOG_DEBUG(("Index")); silc_buffer_strformat(&page, HTTP_START1, SILC_STRFMT_END); silc_buffer_strformat(&page, "SILC ", server->server_type == SILC_ROUTER ? "Router " : "Server ", server->server_name, SILC_STRFMT_END); silc_buffer_strformat(&page, HTTP_START2, SILC_STRFMT_END); silc_buffer_strformat(&page, "

SILC ", server->server_type == SILC_ROUTER ? "Router " : "Server ", server->server_name, "


", SILC_STRFMT_END); silc_buffer_strformat(&page, "Statistics:

", SILC_STRFMT_END); STAT_OUTPUT("Clients : %d", server->stat.my_clients); STAT_OUTPUT("Servers : %d", server->stat.my_servers); STAT_OUTPUT("Routers : %d", server->stat.my_routers); STAT_OUTPUT("Channels : %d", server->stat.my_channels); STAT_OUTPUT("Joined users : %d", server->stat.my_chanclients); STAT_OUTPUT("Aways : %d", server->stat.my_aways); STAT_OUTPUT("Detached clients : %d", server->stat.my_detached); STAT_OUTPUT("Server operators : %d", server->stat.my_server_ops); STAT_OUTPUT("Router operators : %d", server->stat.my_router_ops); silc_buffer_strformat(&page, "

Global Statistics:

", SILC_STRFMT_END); STAT_OUTPUT("Cell clients : %d", server->stat.cell_clients); STAT_OUTPUT("Cell servers : %d", server->stat.cell_servers); STAT_OUTPUT("Cell channels : %d", server->stat.cell_channels); STAT_OUTPUT("Cell joined users : %d", server->stat.cell_chanclients); STAT_OUTPUT("All clients : %d", server->stat.clients); STAT_OUTPUT("All servers : %d", server->stat.servers); STAT_OUTPUT("All routers : %d", server->stat.routers); STAT_OUTPUT("All channels : %d", server->stat.channels); STAT_OUTPUT("All joined users : %d", server->stat.chanclients); STAT_OUTPUT("All aways : %d", server->stat.aways); STAT_OUTPUT("All detached clients : %d", server->stat.detached); STAT_OUTPUT("All server operators : %d", server->stat.server_ops); STAT_OUTPUT("All router operators : %d", server->stat.router_ops); silc_buffer_strformat(&page, "

Internal Statistics:

", SILC_STRFMT_END); STAT_OUTPUT("Connection attempts : %d", server->stat.conn_attempts); STAT_OUTPUT("Connection failures : %d", server->stat.conn_failures); STAT_OUTPUT("Authentication attempts : %d", server->stat.auth_attempts); STAT_OUTPUT("Authentication failures : %d", server->stat.auth_failures); STAT_OUTPUT("Packets sent : %d", server->stat.packets_sent); STAT_OUTPUT("Packets received : %d", server->stat.packets_received); STAT_OUTPUT("Commands sent : %d", server->stat.commands_sent); STAT_OUTPUT("Commands received : %d", server->stat.commands_received); STAT_OUTPUT("Connections : %d", server->stat.conn_num); silc_buffer_strformat(&page, HTTP_END, SILC_STRFMT_END); silc_http_server_send(httpd, conn, &page); silc_buffer_purge(&page); return; } } silc_http_server_send_error(httpd, conn, HTTP_404, HTTP_404_B); } void silc_server_http_init(SilcServer server) { if (!server->config->httpd_ip) return; /* Allocate HTTP server */ server->httpd = silc_http_server_alloc(server->config->httpd_ip, server->config->httpd_port, server->schedule, silc_server_http_callback, server); } void silc_server_http_uninit(SilcServer server) { if (server->httpd) silc_http_server_free(server->httpd); }