summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_http.c64
-rw-r--r--ot_mutex.h1
-rw-r--r--ot_stats.c37
3 files changed, 100 insertions, 2 deletions
diff --git a/ot_http.c b/ot_http.c
index 7334609..849e396 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -16,6 +16,7 @@
16#include "array.h" 16#include "array.h"
17#include "iob.h" 17#include "iob.h"
18#include "ip6.h" 18#include "ip6.h"
19#include "scan.h"
19 20
20/* Opentracker */ 21/* Opentracker */
21#include "trackerlogic.h" 22#include "trackerlogic.h"
@@ -168,7 +169,7 @@ static const ot_keywords keywords_mode[] =
168 { "busy", TASK_STATS_BUSY_NETWORKS }, { "torr", TASK_STATS_TORRENTS }, { "fscr", TASK_STATS_FULLSCRAPE }, 169 { "busy", TASK_STATS_BUSY_NETWORKS }, { "torr", TASK_STATS_TORRENTS }, { "fscr", TASK_STATS_FULLSCRAPE },
169 { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "completed", TASK_STATS_COMPLETED }, 170 { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "completed", TASK_STATS_COMPLETED },
170 { "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION }, 171 { "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION },
171 { "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TRACKERSTATE }, { NULL, -3 } }; 172 { "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TRACKERSTATE }, { "fulllog", TASK_STATS_FULLLOG }, { NULL, -3 } };
172static const ot_keywords keywords_format[] = 173static const ot_keywords keywords_format[] =
173 { { "bin", TASK_FULLSCRAPE_TPB_BINARY }, { "ben", TASK_FULLSCRAPE }, { "url", TASK_FULLSCRAPE_TPB_URLENCODED }, 174 { { "bin", TASK_FULLSCRAPE_TPB_BINARY }, { "ben", TASK_FULLSCRAPE }, { "url", TASK_FULLSCRAPE_TPB_URLENCODED },
174 { "txt", TASK_FULLSCRAPE_TPB_ASCII }, { NULL, -3 } }; 175 { "txt", TASK_FULLSCRAPE_TPB_ASCII }, { NULL, -3 } };
@@ -306,6 +307,9 @@ static ot_keywords keywords_announce[] = { { "port", 1 }, { "left", 2 }, { "even
306#ifdef WANT_IP_FROM_QUERY_STRING 307#ifdef WANT_IP_FROM_QUERY_STRING
307{ "ip", 7 }, 308{ "ip", 7 },
308#endif 309#endif
310#ifdef WANT_FULLLOG_NETWORKS
311{ "lognet", 8 },
312#endif
309{ NULL, -3 } }; 313{ NULL, -3 } };
310static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } }; 314static ot_keywords keywords_announce_event[] = { { "completed", 1 }, { "stopped", 2 }, { NULL, -3 } };
311static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) { 315static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws, char *read_ptr ) {
@@ -412,6 +416,37 @@ static ssize_t http_handle_announce( const int64 sock, struct ot_workstruct *ws,
412 } 416 }
413 break; 417 break;
414#endif 418#endif
419#ifdef WANT_FULLLOG_NETWORKS
420 case 8: /* matched "lognet" */
421 {
422 //if( accesslist_isblessed( cookie->ip, OT_PERMISSION_MAY_STAT ) ) {
423 char *tmp_buf = ws->reply;
424 ot_net net;
425 signed short parsed, bits;
426
427 len = scan_urlencoded_query( &read_ptr, tmp_buf, SCAN_SEARCHPATH_VALUE );
428 tmp_buf[len] = 0;
429 if( len <= 0 ) HTTPERROR_400_PARAM;
430 if( *tmp_buf == '-' ) {
431 loglist_reset( );
432 return ws->reply_size = sprintf( ws->reply, "Successfully removed.\n" );
433 }
434 parsed = scan_ip6( tmp_buf, net.address );
435 if( !parsed ) HTTPERROR_400_PARAM;
436 if( tmp_buf[parsed++] != '/' )
437 bits = 128;
438 else {
439 parsed = scan_short( tmp_buf + parsed, &bits );
440 if( !parsed ) HTTPERROR_400_PARAM;
441 if( ip6_isv4mapped( net.address ) )
442 bits += 96;
443 }
444 net.bits = bits;
445 loglist_add_network( &net );
446 return ws->reply_size = sprintf( ws->reply, "Successfully added.\n" );
447 //}
448 }
449#endif
415 } 450 }
416 } 451 }
417 452
@@ -437,6 +472,31 @@ ssize_t http_handle_request( const int64 sock, struct ot_workstruct *ws ) {
437 ssize_t reply_off, len; 472 ssize_t reply_off, len;
438 char *read_ptr = ws->request, *write_ptr; 473 char *read_ptr = ws->request, *write_ptr;
439 474
475#ifdef WANT_FULLLOG_NETWORKS
476 struct http_data *cookie = io_getcookie( sock );
477 if( loglist_check_address( cookie->ip ) ) {
478 ot_log *log = malloc( sizeof( ot_log ) );
479 printf( "Hello World\n" );
480 if( log ) {
481 log->size = ws->request_size;
482 log->data = malloc( ws->request_size );
483 log->next = 0;
484 log->time = g_now_seconds;
485 memcpy( log->ip, cookie->ip, sizeof(ot_ip6));
486 if( log->data ) {
487 memcpy( log->data, ws->request, ws->request_size );
488 if( !g_logchain_first )
489 g_logchain_first = g_logchain_last = log;
490 else {
491 g_logchain_last->next = log;
492 g_logchain_last = log;
493 }
494 } else
495 free( log );
496 }
497 }
498#endif
499
440#ifdef _DEBUG_HTTPERROR 500#ifdef _DEBUG_HTTPERROR
441 reply_off = ws->request_size; 501 reply_off = ws->request_size;
442 if( ws->request_size >= G_DEBUGBUF_SIZE ) 502 if( ws->request_size >= G_DEBUGBUF_SIZE )
@@ -444,7 +504,7 @@ ssize_t http_handle_request( const int64 sock, struct ot_workstruct *ws ) {
444 memcpy( ws->debugbuf, ws->request, reply_off ); 504 memcpy( ws->debugbuf, ws->request, reply_off );
445 ws->debugbuf[ reply_off ] = 0; 505 ws->debugbuf[ reply_off ] = 0;
446#endif 506#endif
447 507
448 /* Tell subroutines where to put reply data */ 508 /* Tell subroutines where to put reply data */
449 ws->reply = ws->outbuf + SUCCESS_HTTP_HEADER_LENGTH; 509 ws->reply = ws->outbuf + SUCCESS_HTTP_HEADER_LENGTH;
450 510
diff --git a/ot_mutex.h b/ot_mutex.h
index 183fe2b..47d9abf 100644
--- a/ot_mutex.h
+++ b/ot_mutex.h
@@ -39,6 +39,7 @@ typedef enum {
39 TASK_STATS_SLASH24S = 0x0103, 39 TASK_STATS_SLASH24S = 0x0103,
40 TASK_STATS_TOP10 = 0x0104, 40 TASK_STATS_TOP10 = 0x0104,
41 TASK_STATS_EVERYTHING = 0x0105, 41 TASK_STATS_EVERYTHING = 0x0105,
42 TASK_STATS_FULLLOG = 0x0106,
42 43
43 TASK_FULLSCRAPE = 0x0200, /* Default mode */ 44 TASK_FULLSCRAPE = 0x0200, /* Default mode */
44 TASK_FULLSCRAPE_TPB_BINARY = 0x0201, 45 TASK_FULLSCRAPE_TPB_BINARY = 0x0201,
diff --git a/ot_stats.c b/ot_stats.c
index 8b36323..46fc961 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -26,6 +26,7 @@
26#include "ot_mutex.h" 26#include "ot_mutex.h"
27#include "ot_iovec.h" 27#include "ot_iovec.h"
28#include "ot_stats.h" 28#include "ot_stats.h"
29#include "ot_accesslist.h"
29 30
30#ifndef NO_FULLSCRAPE_LOGGING 31#ifndef NO_FULLSCRAPE_LOGGING
31#define LOG_TO_STDERR( ... ) fprintf( stderr, __VA_ARGS__ ) 32#define LOG_TO_STDERR( ... ) fprintf( stderr, __VA_ARGS__ )
@@ -477,6 +478,38 @@ static size_t stats_return_completed_mrtg( char * reply ) {
477 ); 478 );
478} 479}
479 480
481#ifdef WANT_FULLLOG_NETWORKS
482static void stats_return_fulllog( int *iovec_entries, struct iovec **iovector, char *r ) {
483 ot_log *loglist = g_logchain_first, *llnext;
484 char * re = r + OT_STATS_TMPSIZE;
485
486 g_logchain_first = g_logchain_last = 0;
487
488 while( loglist ) {
489 if( r + ( loglist->size + 64 ) >= re ) {
490 r = iovec_fix_increase_or_free( iovec_entries, iovector, r, 32 * OT_STATS_TMPSIZE );
491 if( !r ) return;
492 re = r + 32 * OT_STATS_TMPSIZE;
493 }
494 r += sprintf( r, "%08ld: ", loglist->time );
495 r += fmt_ip6c( r, loglist->ip );
496 *r++ = '\n';
497 memcpy( r, loglist->data, loglist->size );
498 r += loglist->size;
499 *r++ = '\n';
500 *r++ = '*';
501 *r++ = '\n';
502 *r++ = '\n';
503
504 llnext = loglist->next;
505 free( loglist->data );
506 free( loglist );
507 loglist = llnext;
508 }
509 iovec_fixlast( iovec_entries, iovector, r );
510}
511#endif
512
480static size_t stats_return_everything( char * reply ) { 513static size_t stats_return_everything( char * reply ) {
481 torrent_stats stats = {0,0,0}; 514 torrent_stats stats = {0,0,0};
482 int i; 515 int i;
@@ -570,6 +603,10 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype
570 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break; 603 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 128 ); break;
571 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break; 604 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break;
572 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break; 605 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break;
606#ifdef WANT_FULLLOG_NETWORKS
607 case TASK_STATS_FULLLOG: stats_return_fulllog( iovec_entries, iovector, r );
608 return;
609#endif
573 default: 610 default:
574 iovec_free(iovec_entries, iovector); 611 iovec_free(iovec_entries, iovector);
575 return; 612 return;