*** admin.c.orig Wed Oct 18 09:43:04 2000 --- admin.c Mon Dec 11 11:27:13 2000 *************** *** 22,39 **** #include "ntop.h" #include "globals-report.h" /* *******************************/ #ifdef HAVE_GDBM_H void showUsers(void) { u_int numUsers=0; ! char buf[BUF_SIZE]; datum key_data, return_data; ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

Registered ntop Users


\n"); #ifdef MULTITHREADED accessMutex(&gdbmMutex, "showUsers"); --- 22,46 ---- #include "ntop.h" #include "globals-report.h" + + /* Forward */ + #ifdef HAVE_GDBM_H + static void sendMenuFooter(int itm1Idx, int itm2Idx); + static void encodeWebFormURL(char *in, char *buf, int buflen); + static void decodeWebFormURL(char *buf); + static int readHTTPpostData(int len, char *buf, int buflen); + #endif + /* *******************************/ #ifdef HAVE_GDBM_H void showUsers(void) { u_int numUsers=0; ! char buf[BUF_SIZE], ebuf[128]; datum key_data, return_data; ! printHTMLheader("Registered ntop Users", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); #ifdef MULTITHREADED accessMutex(&gdbmMutex, "showUsers"); *************** *** 47,68 **** if(key_data.dptr[0] == '1') /* 1 = user */{ if(numUsers == 0) { ! sendString("

"TABLE_ON"\n"); sendString("\n"); } ! ! if(strcmp(key_data.dptr, "1admin") == 0) snprintf(buf, BUF_SIZE, "\n", &key_data.dptr[1], key_data.dptr); ! else snprintf(buf, BUF_SIZE, "\n", &key_data.dptr[1], key_data.dptr, ! key_data.dptr); sendString(buf); numUsers++; } --- 54,77 ---- if(key_data.dptr[0] == '1') /* 1 = user */{ if(numUsers == 0) { ! sendString("
\n" ! ""TABLE_ON"
UsersActions
" " %s" "" " 
" " %s" "" " " ! "
\n"); sendString("\n"); } ! ! if(strcmp(key_data.dptr, "1admin") == 0) { snprintf(buf, BUF_SIZE, "\n", &key_data.dptr[1], key_data.dptr); ! } else{ ! encodeWebFormURL(key_data.dptr, ebuf, sizeof(ebuf)); snprintf(buf, BUF_SIZE, "\n", &key_data.dptr[1], ebuf, ebuf); ! } sendString(buf); numUsers++; } *************** *** 76,247 **** #endif if(numUsers > 0) { ! sendString("
UsersActions
" " %s" "" " 
" " %s" "" " " ! "
"TABLE_OFF"\n"); } ! ! sendString("

[Add User] " ! "[Show URLs]\n"); } /* *******************************/ void addUser(char* user) { ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

Manage ntop Users


\n"); ! sendString("

\n"); ! if(user != NULL) { ! char tmpStr[128]; ! snprintf(tmpStr, sizeof(tmpStr), "User: " ! " %s \n", &user[1], &user[1]); ! sendString(tmpStr); ! } else ! sendString("User:  \n"); ! sendString("
Password:

\n"); ! if(user != NULL) ! sendString("

\n"); ! else ! sendString("\n"); ! ! sendString("

[Show Users] " ! "[Show URLs]

\n"); ! } ! /* *******************************/ ! static void redirectURL(char* destination) { ! sendString("HTTP/1.0 302 Found\n"); ! sendString("Content-type: text/html\n"); ! sendString("Location: /"); ! sendString(destination); ! sendString("\n\n"); } /* *******************************/ void deleteUser(char* user) { - datum key_data; if(user == NULL) { ! redirectURL("showUsers.html"); return; ! } ! key_data.dptr = user; ! key_data.dsize = strlen(user)+1; ! #ifdef MULTITHREADED ! accessMutex(&gdbmMutex, "redirectURL"); #endif ! ! if(gdbm_delete (pwFile, key_data) != 0) { ! sendHTTPProtoHeader(); sendString("Content-type: text/html\n\n"); ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

ntop user delete


\n"); ! sendString("FATAL ERROR: unable to delete specified user."); ! sendString("

[Add User]" ! " [Show URLs]

\n"); ! printHTTPtrailer(); ! } else { ! redirectURL("showUsers.html"); ! } ! #ifdef MULTITHREADED ! releaseMutex(&gdbmMutex); #endif - } /* *******************************/ ! void doAddUser(int _len) { ! char postData[256], tmpBuf[64], *user=NULL, *pw=NULL, *err=NULL; ! int i, rc, len = _len, idx=0; ! datum data_data, key_data; ! #ifdef HAVE_OPENSSL ! SSL* ssl = getSSLsocket(-newSock); ! #endif ! if(_len <= 0) { err = "ERROR: both user and password must be non empty fields."; } else { ! while(len > 0) ! { ! #ifdef HAVE_OPENSSL ! if(newSock < 0) ! rc = SSL_read(ssl, &postData[idx], len); ! else ! rc = recv(newSock, &postData[idx], len, 0); ! #else ! rc = recv(newSock, &postData[idx], len, 0); ! #endif ! if(rc < 0) { ! return; ! } ! idx += rc; ! len -= rc; } ! ! postData[idx] = '\0'; ! ! while(1) { ! fd_set mask; ! struct timeval wait_time; ! ! FD_ZERO(&mask); ! FD_SET((unsigned int)abs(newSock), &mask); ! ! /* select returns immediately */ ! wait_time.tv_sec = 0, wait_time.tv_usec = 0; ! if(select(newSock+1, &mask, 0, 0, &wait_time) == 1) { ! char aChar[8]; /* just in case */ ! ! #ifdef HAVE_OPENSSL ! if(newSock < 0) ! rc = SSL_read(ssl, aChar, 1); ! else ! rc = recv(newSock, aChar, 1, 0); ! #else ! rc = recv(newSock, aChar, 1, 0); ! #endif ! if(rc <= 0) break; ! } else ! break; } ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Data: '%s' (%d)\n", postData, idx); #endif ! for(i=0; i 0) { ! sendString(""TABLE_OFF"\n

\n"); ! sendString("\n"); } ! sendMenuFooter(1, 2); } /* *******************************/ void addUser(char* user) { ! char tmpStr[128]; ! printHTMLheader("Manage ntop Users", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); ! if((user != NULL) && ((strlen(user) < 2) || (user[0] != '1'))) { ! printFlagedWarning("The specified username is invalid."); ! } else { ! sendString("

\n"); ! sendString("
\n"); ! sendString("\n"); ! sendString("\n\n\n"); ! sendString("\n" ! "\n"); ! sendString("
User: "); ! if(user != NULL) { ! decodeWebFormURL(user); ! snprintf(tmpStr, sizeof(tmpStr), ! "%s\n", ! &user[1], &user[1]); ! sendString(tmpStr); ! } else ! sendString("\n"); ! sendString("
Password: 
\n"); ! ! snprintf(tmpStr, sizeof(tmpStr), ! "   \n", ! (user != NULL) ? "Modify User" : "Add User"); ! sendString(tmpStr); ! sendString("
\n"); ! sendString("
\n"); ! } ! sendMenuFooter(0, 2); } /* *******************************/ void deleteUser(char* user) { if(user == NULL) { ! returnHTTPredirect("showUsers.html"); return; ! } else if((strlen(user) < 2) || (user[0] != '1')) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Delete ntop User", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); ! printFlagedWarning("The specified username is invalid."); ! } else { ! int rc; ! datum key_data; ! decodeWebFormURL(user); ! key_data.dptr = user; ! key_data.dsize = strlen(user)+1; ! #ifdef MULTITHREADED ! accessMutex(&gdbmMutex, "deleteUser"); #endif ! rc = gdbm_delete (pwFile, key_data); #ifdef MULTITHREADED ! releaseMutex(&gdbmMutex); #endif + if(rc != 0) { + sendHTTPHeader(HTTP_TYPE_HTML, 0); + printHTMLheader("Delete ntop User", HTML_FLAG_NO_REFRESH); + sendString("


\n"); + printFlagedWarning("ERROR: unable to delete specified user."); + } else { + returnHTTPredirect("showUsers.html"); + return; + } + + } + sendMenuFooter(1, 2); + printHTMLtrailer(); + } /* *******************************/ ! void doAddUser(int len) { ! char *err=NULL; ! if(len <= 0) { err = "ERROR: both user and password must be non empty fields."; } else { + char postData[256], *key, *user=NULL, *pw=NULL, cpw[14]; + int i, idx, badChar=0; ! if((idx = readHTTPpostData(len, postData, sizeof(postData))) < 0) ! return; /* FIXME (DL): an HTTP error code should be sent here */ ! for(i=0,key=postData; i\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

ntop user add


\n"); ! sendString(err); ! sendString("

[Add User] " ! "[Show URLs]

\n"); ! printHTTPtrailer(); } else { ! redirectURL("showUsers.html"); } } --- 250,266 ---- releaseMutex(&gdbmMutex); #endif } } if(err != NULL) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("ntop user add", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); ! printFlagedWarning(err); ! sendMenuFooter(1, 2); ! printHTMLtrailer(); } else { ! returnHTTPredirect("showUsers.html"); } } *************** *** 284,296 **** void showURLs(void) { u_int numUsers=0; ! char buf[BUF_SIZE]; datum key_data, return_data; ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

Restricted ntop URLs


\n"); #ifdef MULTITHREADED accessMutex(&gdbmMutex, "showURLs"); --- 269,279 ---- void showURLs(void) { u_int numUsers=0; ! char buf[BUF_SIZE], ebuf[128]; datum key_data, return_data; ! printHTMLheader("Restricted ntop URLs", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); #ifdef MULTITHREADED accessMutex(&gdbmMutex, "showURLs"); *************** *** 302,318 **** key_data = return_data; if(key_data.dptr[0] == '2') { /* 2 = URL */ if(numUsers == 0) { ! sendString("

"TABLE_ON"\n"); sendString("\n"); } ! snprintf(buf, BUF_SIZE, "\n", &key_data.dptr[1], key_data.dptr, ! key_data.dptr); sendString(buf); numUsers++; } --- 285,303 ---- key_data = return_data; if(key_data.dptr[0] == '2') { /* 2 = URL */ + if(numUsers == 0) { ! sendString("
\n" ! ""TABLE_ON"
URLsActions
" " '%s*'" "" " " ! "
\n"); sendString("\n"); } ! ! encodeWebFormURL(key_data.dptr, ebuf, sizeof(ebuf)); snprintf(buf, BUF_SIZE, "\n", &key_data.dptr[1], ebuf, ebuf); sendString(buf); numUsers++; } *************** *** 325,526 **** releaseMutex(&gdbmMutex); #endif ! if(numUsers > 0) ! sendString("
URLsActions
" " '%s*'" "" " " ! "
"TABLE_OFF"\n"); ! ! sendString("

[Add URL]" ! " [Show Users]\n"); } /* *******************************/ void addURL(char* url) { datum key_data, return_data; ! char authorisedUsers[BUF_SIZE]; ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

Manage ntop URLs


\n"); ! sendString("

\n"); - if(url != NULL) { - char tmpStr[128]; - - snprintf(tmpStr, sizeof(tmpStr), "URL: http://<ntop host>:<ntop port>/" - "" - " %s * [Initial URL string]\n", &url[1], &url[1]); - sendString(tmpStr); ! key_data.dptr = url; ! key_data.dsize = strlen(url)+1; ! return_data = gdbm_fetch(pwFile, key_data); ! if(return_data.dptr != NULL) ! strncpy(authorisedUsers, return_data.dptr, BUF_SIZE); else ! authorisedUsers[0] = '\0'; ! } else { ! sendString("URL: http://<ntop host>:<ntop port>/" ! " * [Initial URL string]\n"); ! sendString("
Note: if you leave the above field empty then the access is restricted" ! "to all ntop pages!\n"); ! } #ifdef MULTITHREADED ! accessMutex(&gdbmMutex, "addURL"); #endif ! sendString("
Authorised Users:

\n"); ! if(url != NULL) ! sendString("

\n"); ! else ! sendString("\n"); ! ! sendString("

[Show Users] " ! "[Show URLs]

\n"); } /* *******************************/ ! void deleteURL(char* user) { ! datum key_data; ! ! key_data.dptr = user; ! key_data.dsize = strlen(user)+1; ! ! #ifdef MULTITHREADED ! accessMutex(&gdbmMutex, "deleteURL"); ! #endif ! if(gdbm_delete (pwFile, key_data) != 0) { ! sendHTTPProtoHeader(); sendString("Content-type: text/html\n\n"); ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

ntop URL delete


\n"); ! sendString("FATAL ERROR: unable to delete specified URL."); ! sendString("

[Add URL]" ! " [Show Users]

\n"); ! printHTTPtrailer(); } else { ! redirectURL("showURLs.html"); ! } #ifdef MULTITHREADED ! releaseMutex(&gdbmMutex); #endif } /* *******************************/ ! void doAddURL(int _len) { ! char postData[256], tmpBuf[64], *err=NULL; ! int rc, len = _len, idx=0; ! datum data_data, key_data; ! #ifdef HAVE_OPENSSL ! SSL* ssl = getSSLsocket(-newSock); ! #endif ! if(_len <= 0) { err = "ERROR: both url and users must be non empty fields."; } else { ! char *url, *users, *strtokState; ! while(len > 0) ! { ! #ifdef HAVE_OPENSSL ! if(newSock < 0) ! rc = SSL_read(ssl, &postData[idx], len); ! else ! rc = recv(newSock, &postData[idx], (size_t)len, 0); ! #else ! rc = recv(newSock, &postData[idx], (size_t)len, 0); ! #endif ! if(rc < 0) { ! return; ! } ! idx += rc; ! len -= rc; } ! ! postData[idx] = '\0'; ! ! while(1) { ! fd_set mask; ! struct timeval wait_time; ! ! FD_ZERO(&mask); ! FD_SET((unsigned int)abs(newSock), &mask); ! ! /* select returns immediately */ ! wait_time.tv_sec = 0, wait_time.tv_usec = 0; ! if(select(newSock+1, &mask, 0, 0, &wait_time) == 1) { ! char aChar[8]; /* just in case */ ! ! #ifdef HAVE_OPENSSL ! if(newSock < 0) ! rc = SSL_read(ssl, aChar, 1); ! else ! rc = recv(newSock, aChar, 1, 0); ! #else ! rc = recv(newSock, aChar, 1, 0); ! #endif ! if(rc <= 0) break; ! } else ! break; } ! /* traceEvent(TRACE_INFO, "Data: '%s' (%d)\n", postData, idx); */ ! ! url = strtok_r(postData, "&", &strtokState); ! url = &url[4 /* strlen("url=") */]; ! ! users = &url[strlen(url)+1]; ! ! /* traceEvent(TRACE_INFO, "URL: '%s' - users: '%s'\n", url, users); */ ! if(/* (url[0] == '\0') || */ (users[0] == '\0')) err = "ERROR: both url and users must be non empty fields."; ! else { snprintf(tmpBuf, sizeof(tmpBuf), "2%s", url); key_data.dptr = tmpBuf; key_data.dsize = strlen(tmpBuf)+1; ! data_data.dptr = users; ! data_data.dsize = strlen(users)+1; #ifdef MULTITHREADED accessMutex(&gdbmMutex, "doAddURL"); --- 310,546 ---- releaseMutex(&gdbmMutex); #endif ! if(numUsers > 0) { ! sendString(""TABLE_OFF"\n

\n"); ! sendString("\n"); ! } ! sendMenuFooter(3, 0); } /* *******************************/ void addURL(char* url) { + int i; datum key_data, return_data; ! char *aubuf=NULL, *authorisedUser[20]; ! char tmpStr[128]; ! printHTMLheader("Manage ntop URLs", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); ! if((url != NULL) && ((strlen(url) < 2) || (url[0] != '2'))) { ! printFlagedWarning("The specified URL is invalid."); ! } else { ! sendString("

\n"); ! sendString("
\n"); ! ! sendString("\n"); ! if(url != NULL) ! sendString("\n"); else ! sendString("\n"); ! sendString("\n\n"); ! sendString("\n" ! "\n"); ! sendString("
URL: 
URL: http://<ntop host>:<ntop port>/"); ! if(url != NULL) { ! decodeWebFormURL(url); ! snprintf(tmpStr, sizeof(tmpStr), ! "" ! "%s * [Initial URL string]", ! &url[1], &url[1]); ! sendString(tmpStr); ! } else { ! sendString(" *"); ! } ! sendString("
Authorised Users: \n
\n"); ! if(url == NULL) ! sendString("
\n
\n" ! "NOTE: if you leave the URL field empty then the " ! "access is restricted to all ntop pages, otherwise, this " ! "entry matches all the pages begining with the specified string.\n" ! "
\n
\n"); ! ! snprintf(tmpStr, sizeof(tmpStr), ! "   \n", ! (url != NULL) ? "Modify URL" : "Add URL"); ! sendString(tmpStr); ! ! sendString("
\n"); ! sendString("
\n"); ! ! } ! sendMenuFooter(0, 2); } /* *******************************/ ! void deleteURL(char* url) { ! if(url == NULL) { ! returnHTTPredirect("showURLs.html"); ! return; ! } else if((strlen(url) < 2) || (url[0] != '2')) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Delete ntop URL", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); ! printFlagedWarning("The specified URL is invalid."); } else { ! int rc; ! datum key_data; ! ! decodeWebFormURL(url); ! key_data.dptr = url; ! key_data.dsize = strlen(url)+1; #ifdef MULTITHREADED ! accessMutex(&gdbmMutex, "deleteURL"); #endif + rc = gdbm_delete (pwFile, key_data); + #ifdef MULTITHREADED + releaseMutex(&gdbmMutex); + #endif + + if(rc != 0) { + sendHTTPHeader(HTTP_TYPE_HTML, 0); + printHTMLheader("Delete ntop URL", HTML_FLAG_NO_REFRESH); + sendString("


\n"); + printFlagedWarning("ERROR: unable to delete specified URL."); + } else { + returnHTTPredirect("showURLs.html"); + return; + } + + } + sendMenuFooter(3, 0); + printHTMLtrailer(); } /* *******************************/ ! void doAddURL(int len) { ! char *err=NULL; ! if(len <= 0) { err = "ERROR: both url and users must be non empty fields."; } else { ! char postData[256], *key, *url=NULL, *users=NULL, authorizedUsers[256]; ! int i, idx, alen=0, badChar=0; ! if((idx = readHTTPpostData(len, postData, sizeof(postData))) < 0) ! return; /* FIXME (DL): an HTTP error code should be sent here */ ! memset(authorizedUsers, 0, sizeof(authorizedUsers)); ! for(i=0,key=postData; i<=idx; i++) { ! if((i==idx) || (postData[i] == '&')) { ! if(users != NULL) { ! decodeWebFormURL(users); ! snprintf(&authorizedUsers[alen], sizeof(authorizedUsers)-alen, ! "%susers=%s", (alen>0) ? "&" : "", users); ! alen = strlen(authorizedUsers); ! users = NULL; ! } ! if(i==idx) break; ! postData[i] = '\0'; ! key = &postData[i+1]; ! } else if((key != NULL) && (postData[i] == '=')) { ! postData[i] = '\0'; ! if(strcmp(key, "url") == 0) { ! url = &postData[i+1]; ! } else if(strcmp(key, "users") == 0) { ! users = &postData[i+1]; ! } ! key = NULL; } ! } ! if(url != NULL) { ! decodeWebFormURL(url); ! for(i=0; i0?authorizedUsers:"(not given)"); ! fflush(stdout); ! #endif ! if((url == NULL) || (url[0] == '\0') || (authorizedUsers[0] == '\0')) { err = "ERROR: both url and users must be non empty fields."; ! } else if(badChar) { ! err = "ERROR: the specified URL contains invalid characters."; ! } else { ! char tmpBuf[64]; ! datum data_data, key_data; ! snprintf(tmpBuf, sizeof(tmpBuf), "2%s", url); key_data.dptr = tmpBuf; key_data.dsize = strlen(tmpBuf)+1; ! data_data.dptr = authorizedUsers; ! data_data.dsize = strlen(authorizedUsers)+1; #ifdef MULTITHREADED accessMutex(&gdbmMutex, "doAddURL"); *************** *** 537,559 **** } if(err != NULL) { ! sendHTTPProtoHeader(); sendString("Content-type: text/html\n\n"); ! sendString("\n"); ! sendString("Welcome to ntop!\n"); ! sendString("\n"); ! sendString("

ntop URL add


\n"); ! sendString(err); ! sendString("

[Add URL]" ! " [Show Users]

\n"); ! printHTTPtrailer(); } else { ! redirectURL("showURLs.html"); } } /* *******************************/ static void addKeyIfMissing(char* key, char* value, int encryptValue) { datum key_data, return_data, data_data; /* Check existence of user 'admin' */ --- 557,577 ---- } if(err != NULL) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("ntop URL add", HTML_FLAG_NO_REFRESH); ! sendString("


\n"); ! printFlagedWarning(err); ! sendMenuFooter(3, 0); ! printHTMLtrailer(); } else { ! returnHTTPredirect("showURLs.html"); } } /* *******************************/ static void addKeyIfMissing(char* key, char* value, int encryptValue) { + char cpw[14]; datum key_data, return_data, data_data; /* Check existence of user 'admin' */ *************** *** 567,573 **** #ifdef WIN32 data_data.dptr = value; #else ! data_data.dptr = (char*)crypt(value, (const char*)CRYPT_SALT); #endif } else data_data.dptr = value; --- 585,593 ---- #ifdef WIN32 data_data.dptr = value; #else ! strncpy(cpw, (char*)crypt(value, (const char*)CRYPT_SALT), sizeof(cpw)); ! cpw[sizeof(cpw)-1] = '\0'; ! data_data.dptr = cpw; #endif } else data_data.dptr = value; *************** *** 578,584 **** data_data.dsize = strlen(data_data.dptr)+1; gdbm_store(pwFile, key_data, data_data, GDBM_REPLACE); ! } } /* *******************************/ --- 598,605 ---- data_data.dsize = strlen(data_data.dptr)+1; gdbm_store(pwFile, key_data, data_data, GDBM_REPLACE); ! } else ! free(return_data.dptr); } /* *******************************/ *************** *** 594,598 **** --- 615,757 ---- addKeyIfMissing("2shutdown", "users=1admin", 0); } + /* *******************************/ + + struct _menuData { + char *text, *anchor; + }; + + static struct _menuData menuItem[] = { + { "Show Users", "showUsers" }, + { "Add User", "addUser" }, + { "Show URLs", "showURLs" }, + { "Add URL", "addURL" } + }; + + /* *******************************/ + + static void sendMenuFooter(int itm1Idx, int itm2Idx) { + char buf[128]; + + sendString("

\n"); + sendString("

\n"); + snprintf(buf, sizeof(buf), + "[%s] [%s]\n", + menuItem[itm1Idx].anchor, menuItem[itm1Idx].text, + menuItem[itm2Idx].anchor, menuItem[itm2Idx].text); + sendString(buf); + sendString("

\n"); + sendString("
\n"); + + } + + /* *******************************/ + static void encodeWebFormURL(char *in, char *buf, int buflen) { + int i, j, c, d; + + for(i=j=0; (in[i]!='\0') && (j<(buflen-4)); i++) { + c = (unsigned int)in[i]; + if(isalpha(c) || isdigit(c)) { + buf[j++] = (char)c; + } else if (c == ' ') { + buf[j++] = '+'; + } else { + buf[j++] = '%'; + d = (c>>4) & 0x0f; + buf[j++] = (d < 10) ? '0'+d : 'A'+(d-10); + d = c & 0x0f; + buf[j++] = (d < 10) ? '0'+d : 'A'+(d-10); + } + } + buf[j] = '\0'; + } + + /* *******************************/ + static void decodeWebFormURL(char *buf) { + int i, j; + + for(i=j=0; buf[i]!='\0'; i++,j++) { + buf[j] = buf[i]; + if(buf[j] == '+') { + buf[j] = ' '; + } else if(buf[j] == '%') { + buf[j] = ((buf[i+1] >= 'A' ? ((buf[i+1] & 0xdf) - 'A')+10 : (buf[i+1] - '0')) & 0x0f) << 4 | + ((buf[i+2] >= 'A' ? ((buf[i+2] & 0xdf) - 'A')+10 : (buf[i+2] - '0')) & 0x0f); + i += 2; + } + } + buf[j] = '\0'; + } + + /* *******************************/ + static int readHTTPpostData(int len, char *buf, int buflen) { + int rc, idx=0; + + #ifdef HAVE_OPENSSL + SSL* ssl = getSSLsocket(-newSock); + #endif + + memset(buf, 0, buflen); + + if(len > (buflen-8)) { + traceEvent(TRACE_ERROR, "Too much HTTP POST data"); + return (-1); + } + + while(len > 0) { + #ifdef HAVE_OPENSSL + if(newSock < 0) + rc = SSL_read(ssl, &buf[idx], len); + else + rc = recv(newSock, &buf[idx], len, 0); + #else + rc = recv(newSock, &buf[idx], len, 0); + #endif + if(rc < 0) + return (-1); + + idx += rc; + len -= rc; + } + + buf[idx] = '\0'; + + while(1) { + fd_set mask; + struct timeval wait_time; + + FD_ZERO(&mask); + FD_SET((unsigned int)abs(newSock), &mask); + + /* select returns immediately */ + wait_time.tv_sec = 0, wait_time.tv_usec = 0; + if(select(newSock+1, &mask, 0, 0, &wait_time) == 1) { + char aChar[8]; /* just in case */ + + #ifdef HAVE_OPENSSL + if(newSock < 0) + rc = SSL_read(ssl, aChar, 1); + else + rc = recv(newSock, aChar, 1, 0); + #else + rc = recv(newSock, aChar, 1, 0); + #endif + if(rc <= 0) + break; + } else + break; + } + + #if 0 + printf("HTTP POST data: '%s' (%d)\n", buf, idx); + fflush(stdout); + #endif + + #ifdef DEBUG + traceEvent(TRACE_INFO, "Data: '%s' (%d)\n", buf, idx); + #endif + + return (idx); + } #endif /* HAVE_GDBM_H */ *** globals-core.h.orig Wed Oct 18 09:42:05 2000 --- globals-core.h Sat Dec 9 15:45:22 2000 *************** *** 231,244 **** /* http.c */ extern void sendStringLen(char *theString, unsigned int len); extern void sendString(char *theString); ! extern void printHTTPheader(void); ! extern void printHTTPtrailer(void); extern void initAccessLog(void); extern void termAccessLog(void); ! extern void sendHTTPHeaderType(void); ! extern void sendGIFHeaderType(void); ! extern void sendHTTPProtoHeader(void); extern void handleHTTPrequest(struct in_addr from); /* initialize.c */ extern void initIPServices(void); --- 231,243 ---- /* http.c */ extern void sendStringLen(char *theString, unsigned int len); extern void sendString(char *theString); ! extern void printHTMLheader(char *title, int headerFlags); ! extern void printHTMLtrailer(void); extern void initAccessLog(void); extern void termAccessLog(void); ! extern void sendHTTPHeader(int mimeType, int headerFlags); extern void handleHTTPrequest(struct in_addr from); + extern void returnHTTPredirect(char* destination); /* initialize.c */ extern void initIPServices(void); *** globals-report.h.orig Wed Oct 18 09:41:56 2000 --- globals-report.h Wed Dec 6 18:34:11 2000 *************** *** 77,82 **** --- 77,84 ---- char *label, char* label_1, char* label_2, float total, float percentage); + extern void printSectionTitle(char *text); + extern void printFlagedWarning(char *text); extern void printHeader(int reportType, int revertOrder, u_int column); extern char* getOSFlag(char* osName, int showOsName); extern int sortHostFctn(const void *_a, const void *_b); *** hash.c.orig Thu Oct 19 04:04:19 2000 --- hash.c Mon Dec 11 11:27:41 2000 *************** *** 80,88 **** ETHERNET_ADDRESS_LEN) == 0) { idx = broadcastEntryIdx; (*useIPAddressForSearching) = 0; ! } else if ((hostIpAddress == NULL) ! /* || (hostIpAddress->s_addr == 0x0) */ ! || isLocalAddress(hostIpAddress)) { memcpy(&idx, ðer_addr[ETHERNET_ADDRESS_LEN-sizeof(u_int)], sizeof(u_int)); (*useIPAddressForSearching) = 0; } else if ((hostIpAddress->s_addr == 0x0) --- 80,86 ---- ETHERNET_ADDRESS_LEN) == 0) { idx = broadcastEntryIdx; (*useIPAddressForSearching) = 0; ! } else if (hostIpAddress == NULL) { memcpy(&idx, ðer_addr[ETHERNET_ADDRESS_LEN-sizeof(u_int)], sizeof(u_int)); (*useIPAddressForSearching) = 0; } else if ((hostIpAddress->s_addr == 0x0) *************** *** 93,98 **** --- 91,99 ---- } else if(isBroadcastAddress(hostIpAddress)) { idx = broadcastEntryIdx; (*useIPAddressForSearching) = 1; + } else if (isLocalAddress(hostIpAddress)) { + memcpy(&idx, ðer_addr[ETHERNET_ADDRESS_LEN-sizeof(u_int)], sizeof(u_int)); + (*useIPAddressForSearching) = 0; } else { idx = 0; memcpy(&idx, &hostIpAddress->s_addr, 4); *************** *** 158,163 **** --- 159,165 ---- newSize = (int)(device[deviceToExtend].actualHashSize*multiplier); newSize = newSize - (newSize % 2); /* I want an even hash size */ + /* FIXME (DL): purgeIdleHosts() acts on actualDeviceId instead of deviceToExtend */ if(newSize > maxHashSize) /* Hard Limit */ { purgeIdleHosts(1); return; *************** *** 165,171 **** purgeIdleHosts(0); /* Delete only idle hosts */ #if defined(MULTITHREADED) ! if(device[actualDeviceId].hostsno < (device[deviceToExtend].actualHashSize*0.85)) { if(tryLockMutex(&hostsHashMutex, "resizeHostHash(processPacket)") != 0) { #ifdef DEBUG traceEvent(TRACE_INFO, "The table is already locked: let's try later"); --- 167,173 ---- purgeIdleHosts(0); /* Delete only idle hosts */ #if defined(MULTITHREADED) ! if(device[deviceToExtend].hostsno < (device[deviceToExtend].actualHashSize*0.85)) { if(tryLockMutex(&hostsHashMutex, "resizeHostHash(processPacket)") != 0) { #ifdef DEBUG traceEvent(TRACE_INFO, "The table is already locked: let's try later"); *************** *** 502,507 **** --- 504,510 ---- /* Delayed free */ void freeHostInfo(int theDevice, u_int hostIdx) { u_int idx, j, i; + /* FIXME (DL): checkSessionIdx() acts on actualDeviceId instead of theDevice */ HostTraffic *host = device[theDevice].hash_hostTraffic[checkSessionIdx(hostIdx)]; if(host == NULL) *** http.c.orig Thu Oct 19 04:15:18 2000 --- http.c Mon Dec 11 11:27:56 2000 *************** *** 22,27 **** --- 22,102 ---- #include "ntop.h" #include "globals-report.h" + struct _HTTPstatus { + int statusCode; + char *reasonPhrase; + char *longDescription; + }; + + /* + This is the complete list of "Status Codes" and suggested + "Reason Phrases" for HTTP responses, as stated in RFC 2068 + NOTE: the natural order is altered so "200 OK" results the + first item in the table (index = 0) + */ + struct _HTTPstatus HTTPstatus[] = { + { 200, "OK", NULL }, + { 100, "Continue", NULL }, + { 101, "Switching Protocols", NULL }, + { 201, "Created", NULL }, + { 202, "Accepted", NULL }, + { 203, "Non-Authoritative Information", NULL }, + { 204, "No Content", NULL }, + { 205, "Reset Content", NULL }, + { 206, "Partial Content", NULL }, + { 300, "Multiple Choices", NULL }, + { 301, "Moved Permanently", NULL }, + { 302, "Moved Temporarily", NULL }, + { 303, "See Other", NULL }, + { 304, "Not Modified", NULL }, + { 305, "Use Proxy", NULL }, + { 400, "Bad Request", "The specified request is invalid." }, + { 401, "Unauthorized", "Unauthorized to access the document." }, + { 402, "Payment Required", NULL }, + { 403, "Forbidden", "Server refused to fulfill your request." }, + { 404, "Not Found", "The server cannot found the requested page." }, + { 405, "Method Not Allowed", NULL }, + { 406, "Not Acceptable", NULL }, + { 407, "Proxy Authentication Required", NULL }, + { 408, "Request Time-out", "The request was timed-out." }, + { 409, "Conflict", NULL }, + { 410, "Gone", NULL }, + { 411, "Length Required", NULL }, + { 412, "Precondition Failed", NULL }, + { 413, "Request Entity Too Large", NULL }, + { 414, "Request-URI Too Large", NULL }, + { 415, "Unsupported Media Type", NULL }, + { 500, "Internal Server Error", NULL }, + { 501, "Not Implemented", "The requested method is not implemented by this server." }, + { 502, "Bad Gateway", NULL }, + { 503, "Service Unavailable", NULL }, + { 504, "Gateway Time-out", NULL }, + { 505, "HTTP Version not supported", "This server don't support the specified HTTP version." }, + }; + + /* + Note: the numbers below are offsets inside the HTTPstatus table, + they must be corrected every time the table is modified. + */ + #define HTTP_FLAG_STATUS_200 ( 0<<8) + #define HTTP_FLAG_STATUS_302 (11<<8) + #define HTTP_FLAG_STATUS_400 (15<<8) + #define HTTP_FLAG_STATUS_401 (16<<8) + #define HTTP_FLAG_STATUS_403 (18<<8) + #define HTTP_FLAG_STATUS_404 (19<<8) + #define HTTP_FLAG_STATUS_408 (23<<8) + #define HTTP_FLAG_STATUS_501 (32<<8) + #define HTTP_FLAG_STATUS_505 (36<<8) + + #define HTTP_INVALID_REQUEST -2 + #define HTTP_INVALID_METHOD -3 + #define HTTP_INVALID_VERSION -4 + #define HTTP_REQUEST_TIMEOUT -5 + #define HTTP_FORBIDDEN_PAGE -6 + #define HTTP_INVALID_PAGE -7 + + /* ************************* */ + static u_int httpBytesSent; static char httpRequestedURL[512], theUser[32]; static struct in_addr *requestFrom; *************** *** 30,35 **** --- 105,121 ---- /* ************************* */ + /* Forward */ + static int readHTTPheader(char* theRequestedURL, int theRequestedURLLen, char *thePw, int thePwLen); + static int decodeString(char *bufcoded, unsigned char *bufplain, int outbufsize); + static void logHTTPaccess(int rc); + static void returnHTTPspecialStatusCode(int statusIdx); + static int checkURLsecurity(char *url); + static int returnHTTPPage(char* pageName, int postLen); + static int checkHTTPpassword(char *theRequestedURL, int theRequestedURLLen _UNUSED_, char* thePw, int thePwLen); + + /* ************************* */ + static int readHTTPheader(char* theRequestedURL, int theRequestedURLLen, char *thePw, int thePwLen) { *************** *** 41,53 **** int rc, idxChar=0, contentLen=-1, numLine=0, topSock; fd_set mask; struct timeval wait_time; thePw[0] = '\0'; preLastChar = '\r'; lastChar = '\n'; theRequestedURL[0] = '\0'; ! ! wait_time.tv_sec = 10, wait_time.tv_usec = 0; #ifdef HAVE_OPENSSL topSock = abs(newSock); --- 127,140 ---- int rc, idxChar=0, contentLen=-1, numLine=0, topSock; fd_set mask; struct timeval wait_time; + int errorCode=0; + char *tmpStr; thePw[0] = '\0'; preLastChar = '\r'; lastChar = '\n'; theRequestedURL[0] = '\0'; ! memset(httpRequestedURL, 0, sizeof(httpRequestedURL)); #ifdef HAVE_OPENSSL topSock = abs(newSock); *************** *** 56,62 **** #endif for(;;) { - int goodCharType; FD_ZERO(&mask); FD_SET((unsigned int)topSock, &mask); --- 143,148 ---- *************** *** 64,71 **** /* printf("About to call select()\n"); fflush(stdout); */ /* select returns immediately */ ! if(select(newSock+1, &mask, 0, 0, &wait_time) == 0) ! return INVALID_HTTP_REQUEST; /* Timeout */ /* printf("About to call recv()\n"); fflush(stdout); */ /* printf("Rcvd %d bytes\n", recv(newSock, aChar, 1, MSG_PEEK)); fflush(stdout); */ --- 150,163 ---- /* printf("About to call select()\n"); fflush(stdout); */ /* select returns immediately */ ! wait_time.tv_sec = 10; wait_time.tv_usec = 0; ! if(select(newSock+1, &mask, 0, 0, &wait_time) == 0) { ! errorCode = HTTP_REQUEST_TIMEOUT; /* Timeout */ ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Timeout while reading from socket.\n"); ! #endif ! break; ! } /* printf("About to call recv()\n"); fflush(stdout); */ /* printf("Rcvd %d bytes\n", recv(newSock, aChar, 1, MSG_PEEK)); fflush(stdout); */ *************** *** 79,148 **** rc = recv(newSock, aChar, 1, 0); #endif - goodCharType = isprint(aChar[0]) || isspace(aChar[0]); - - if(!goodCharType) { - #ifdef DEBUG - traceEvent(TRACE_INFO, "Rcvd non expected char '%c' [%d]\n", - aChar[0], aChar[0]); - #endif - return INVALID_HTTP_REQUEST; - } - if(rc != 1) { ! idxChar=0; #ifdef DEBUG traceEvent(TRACE_INFO, "Socket read returned %d (errno=%d)\n", rc, errno); #endif break; /* Empty line */ } else { - /* traceEvent(TRACE_INFO, "%c", lastChar); */ ! if((aChar[0] == '\n') && (lastChar == '\r') && (preLastChar == '\n')) { ! idxChar=0; ! break; ! } else { ! if(aChar[0] == '\n') { ! numLine++; ! lineStr[(idxChar > 0) ? idxChar-1 : idxChar] = '\0'; ! /* traceEvent(TRACE_INFO, "%s [%d]\n", lineStr, idxChar); */ ! if(numLine == 1) ! strncpy(httpRequestedURL, lineStr, sizeof(httpRequestedURL)-1)[sizeof(httpRequestedURL)-1] = '\0'; ! ! if((idxChar >= 21) && (strncmp(lineStr, "Authorization: Basic ", 21) == 0)) ! strncpy(thePw, &lineStr[21], thePwLen-1)[thePwLen-1] = '\0'; ! else if((idxChar >= 16) && (strncasecmp(lineStr, "Content-length: ", 16) == 0)) { ! contentLen = atoi(&lineStr[16]); ! /* traceEvent(TRACE_INFO, "len=%d [%s/%s]\n", ! contentLen, lineStr, &lineStr[16]); */ ! } else if((numLine == 1) && (idxChar >= 3) && (strncmp(lineStr, "GET ", 4) == 0)) { ! strncpy(theRequestedURL, &lineStr[4], theRequestedURLLen-1)[theRequestedURLLen-1] = '\0'; ! } else if((numLine == 1) && (idxChar >= 3) && (strncmp(lineStr, "POST ", 5) == 0)) { ! strncpy(theRequestedURL, &lineStr[5], theRequestedURLLen-1)[theRequestedURLLen-1] = '\0'; ! } else if(numLine == 1) { ! return(INVALID_HTTP_REQUEST); ! } ! idxChar=0; ! } else { ! if(idxChar < 512) ! lineStr[idxChar++] = aChar[0]; ! else { #ifdef DEBUG ! traceEvent(TRACE_INFO, "Line too long (hackers ?)"); #endif ! return INVALID_HTTP_REQUEST; } - } ! preLastChar = lastChar; ! lastChar = aChar[0]; } } } ! return(contentLen); } /* ************************* */ --- 171,278 ---- rc = recv(newSock, aChar, 1, 0); #endif if(rc != 1) { ! idxChar = 0; #ifdef DEBUG traceEvent(TRACE_INFO, "Socket read returned %d (errno=%d)\n", rc, errno); #endif + /* FIXME (DL): is valid to write to the socket after this condition? */ break; /* Empty line */ + + } else if ((errorCode == 0) && !isprint(aChar[0]) && !isspace(aChar[0])) { + errorCode = HTTP_INVALID_REQUEST; + #ifdef DEBUG + traceEvent(TRACE_INFO, "Rcvd non expected char '%c' [%d/0x%x]\n", aChar[0], aChar[0], aChar[0]); + #endif + } else { ! if(aChar[0] == '\r') { ! /* is ignored as recommended in section 19.3 of RFC 2068 */ ! continue; ! } else if(aChar[0] == '\n') { ! if(lastChar == '\n') { ! idxChar = 0; ! break; ! } ! numLine++; ! lineStr[idxChar] = '\0'; ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "read HTTP %s line: %s [%d]\n", ! (numLine>1) ? "header" : "request", lineStr, idxChar); ! #endif ! if(errorCode != 0) { ! ; /* skip parsing after an error was detected */ ! } else if(numLine == 1) { ! strncpy(httpRequestedURL, lineStr, sizeof(httpRequestedURL)-1)[sizeof(httpRequestedURL)-1] = '\0'; ! if(idxChar < 9) { ! errorCode = HTTP_INVALID_REQUEST; ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Too short request line.\n"); ! #endif ! } else if(strncmp(&lineStr[idxChar-9], " HTTP/", 6) != 0) { ! errorCode = HTTP_INVALID_REQUEST; ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Malformed request line.\n"); ! #endif ! ! } else if((strncmp(&lineStr[idxChar-3], "1.0", 3) != 0) && ! (strncmp(&lineStr[idxChar-3], "1.1", 3) != 0)) { ! errorCode = HTTP_INVALID_VERSION; ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Unsupported HTTP version.\n"); ! #endif ! ! } else { ! ! lineStr[idxChar-9] = '\0'; idxChar -= 9; tmpStr = NULL; ! ! if ((idxChar >= 3) && (strncmp(lineStr, "GET ", 4) == 0)) { ! tmpStr = &lineStr[4]; ! } else if((idxChar >= 4) && (strncmp(lineStr, "POST ", 5) == 0)) { ! tmpStr = &lineStr[5]; ! /* ! HEAD method could be supported with some litle modifications... ! } else if((idxChar >= 4) && (strncmp(lineStr, "HEAD ", 5) == 0)) { ! tmpStr = &lineStr[5]; ! */ ! } else { ! errorCode = HTTP_INVALID_METHOD; #ifdef DEBUG ! traceEvent(TRACE_INFO, "Unrecognized method in request line.\n"); #endif ! } ! if(tmpStr) ! strncpy(theRequestedURL, tmpStr, theRequestedURLLen-1)[theRequestedURLLen-1] = '\0'; } ! } else if((idxChar >= 21) && (strncasecmp(lineStr, "Authorization: Basic ", 21) == 0)) { ! strncpy(thePw, &lineStr[21], thePwLen-1)[thePwLen-1] = '\0'; ! } else if((idxChar >= 16) && (strncasecmp(lineStr, "Content-Length: ", 16) == 0)) { ! contentLen = atoi(&lineStr[16]); ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "len=%d [%s/%s]\n", contentLen, lineStr, &lineStr[16]); ! #endif ! } ! idxChar=0; ! } else if(idxChar > sizeof(lineStr)-2) { ! if (errorCode == 0) { ! errorCode = HTTP_INVALID_REQUEST; ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Line too long (hackers ?)"); ! #endif ! } ! } else { ! lineStr[idxChar++] = aChar[0]; } + } + lastChar = aChar[0]; } ! return((errorCode) ? errorCode : contentLen); } /* ************************* */ *************** *** 310,315 **** --- 440,446 ---- sendStringLen(theString, strlen(theString)); } + #if 0 /* this is not used anymore */ /* ************************* */ void printHTTPheader(void) { *************** *** 323,329 **** --- 454,490 ---- sendString("\n"); sendString("\n\n"); } + #endif + + /* ************************* */ + + void printHTMLheader(char *title, + int headerFlags) { + char buf[BUF_SIZE]; + + sendString("\n\n"); + if(title != NULL) { + snprintf(buf, BUF_SIZE, "%s\n", title); + sendString(buf); + } + if((headerFlags & HTML_FLAG_NO_REFRESH) == 0) { + snprintf(buf, BUF_SIZE, "\n", refreshRate); + sendString(buf); + } + sendString("\n"); + sendString("\n"); + if((headerFlags & HTML_FLAG_NO_STYLESHEET) == 0) { + sendString("\n"); + } + sendString("\n"); + if((headerFlags & HTML_FLAG_NO_BODY) == 0) { + sendString("\n"); + if((title != NULL) && ((headerFlags & HTML_FLAG_NO_HEADING) == 0)) + printSectionTitle(title); + } + } + #if 0 /* this is not used anymore */ /* ************************* */ void printHTTPtrailer(void) { *************** *** 353,358 **** --- 514,550 ---- sendString("]\n
\n
© 1998-2000 by L. Deri" "\n"); } + #endif + + /* ************************* */ + + void printHTMLtrailer(void) { + char buf[BUF_SIZE]; + int i, len; + + sendString("\n


\n\n"); + + snprintf(buf, BUF_SIZE, "Report created on %s [%s]
\n", + ctime(&actTime), formatSeconds(actTime-initialSniffTime)); + sendString(buf); + + snprintf(buf, BUF_SIZE, "Generated by ntop v.%s %s \n[%s] (%s build) ", + version, THREAD_MODE, osName, buildDate); + sendString(buf); + + if(rFileName != NULL) { + snprintf(buf, BUF_SIZE, "listening on [%s]\n", PCAP_NW_INTERFACE); + } else { + for(i=len=0; i0) ? "," : "listening on [", device[i].name); + } + snprintf(&buf[len], BUF_SIZE-len, "]\n"); + } + sendString(buf); + + sendString("
\n
© 1998-2000 by L. Deri
\n"); + sendString("
\n\n\n"); + } /* ******************************* */ *************** *** 378,390 **** struct timeval loggingAt; unsigned long msSpent; struct tm t; if(accessLogFd != NULL) { gettimeofday(&loggingAt, NULL); msSpent = (unsigned long)(delta_time(&loggingAt, &httpRequestedAt)/1000); ! strftime(theDate, 32, "%d/%b/%Y:%H:%M:%S +0000", localtime_r(&actTime, &t)); if((theUser == NULL) || (theUser[0] == '\0')) --- 570,587 ---- struct timeval loggingAt; unsigned long msSpent; struct tm t; + char theZone[6]; + unsigned long gmtoffset; if(accessLogFd != NULL) { gettimeofday(&loggingAt, NULL); msSpent = (unsigned long)(delta_time(&loggingAt, &httpRequestedAt)/1000); ! strftime(theDate, sizeof(theDate), "%d/%b/%Y:%H:%M:%S", localtime_r(&actTime, &t)); ! ! gmtoffset = (thisZone < 0) ? -thisZone : thisZone; ! snprintf(theZone, sizeof(theZone), "%c%2.2ld%2.2ld", (thisZone < 0) ? '-' : '+', gmtoffset/3600, (gmtoffset/60)%60); if((theUser == NULL) || (theUser[0] == '\0')) *************** *** 394,408 **** NTOHL(requestFrom->s_addr); ! fprintf(accessLogFd, "%s -%s- [%s] - \"%s\" %d %d %lu\n", _intoa(*requestFrom, buf, sizeof(buf)), ! myUser, theDate, httpRequestedURL, rc, httpBytesSent, msSpent); fflush(accessLogFd); } } /* ************************* */ static void returnHTTPaccessDenied(void) { --- 591,606 ---- NTOHL(requestFrom->s_addr); ! fprintf(accessLogFd, "%s -%s- [%s %s] - \"%s\" %d %d %lu\n", _intoa(*requestFrom, buf, sizeof(buf)), ! myUser, theDate, theZone, httpRequestedURL, rc, httpBytesSent, msSpent); fflush(accessLogFd); } } + #if 0 /* this is not used anymore */ /* ************************* */ static void returnHTTPaccessDenied(void) { *************** *** 425,433 **** --- 623,705 ---- "

Error 401

\nServer refused to fulfill your request.\n\n\n"); logHTTPaccess(403); } + #endif /* ************************* */ + static void returnHTTPbadRequest(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_400); + } + + static void returnHTTPaccessDenied(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_401 | HTTP_FLAG_NEED_AUTHENTICATION); + } + + static void returnHTTPaccessForbidden(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_403); + } + + static void returnHTTPpageNotFound(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_404); + } + + static void returnHTTPrequestTimedOut(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_408); + } + + static void returnHTTPnotImplemented(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_501); + } + + static void returnHTTPversionNotSupported(void) { + returnHTTPspecialStatusCode(HTTP_FLAG_STATUS_505); + } + + /* ************************* */ + + static void returnHTTPspecialStatusCode(int statusFlag) { + int statusIdx; + char buf[BUF_SIZE]; + + statusIdx = (statusFlag >> 8) & 0xff; + if((statusIdx < 0) || (statusIdx > sizeof(HTTPstatus)/sizeof(HTTPstatus[0]))) { + statusIdx = 0; + statusFlag = 0; + #ifdef DEBUG + traceEvent(TRACE_WARNING, "INTERNAL ERROR: invalid HTTP status id (%d) set to zero.\n", statusIdx); + #endif + } + + sendHTTPHeader(HTTP_TYPE_HTML, statusFlag); + snprintf(buf, sizeof(buf), "Error %d", HTTPstatus[statusIdx].statusCode); + printHTMLheader(buf, HTML_FLAG_NO_REFRESH | HTML_FLAG_NO_HEADING); + snprintf(buf, sizeof(buf), + "

Error %d

\n%s\n", + HTTPstatus[statusIdx].statusCode, HTTPstatus[statusIdx].longDescription); + sendString(buf); + if(strlen(httpRequestedURL) > 0) { + snprintf(buf, sizeof(buf), + "

Received request:

"%s"
", + httpRequestedURL); + sendString(buf); + } + printHTMLtrailer(); + + logHTTPaccess(HTTPstatus[statusIdx].statusCode); + } + + /* *******************************/ + + void returnHTTPredirect(char* destination) { + sendHTTPHeader(HTTP_TYPE_HTML, HTTP_FLAG_STATUS_302 | HTTP_FLAG_NO_CACHE_CONTROL | HTTP_FLAG_MORE_FIELDS); + sendString("Location: /"); + sendString(destination); + sendString("\n\n"); + } + + #if 0 /* this is not used anymore */ + /* ************************* */ + void sendHTTPHeaderType(void) { sendString("Content-type: text/html\n"); sendString("Cache-Control: no-cache\n"); *************** *** 451,456 **** --- 723,810 ---- snprintf(tmpStr, sizeof(tmpStr), "Server: ntop/%s (%s)\n", version, osName); sendString(tmpStr); } + #endif + + /* ************************* */ + + void sendHTTPHeader(int mimeType, + int headerFlags) { + int statusIdx; + char tmpStr[64], theDate[48]; + time_t theTime = actTime - (time_t)thisZone; + struct tm t; + + statusIdx = (headerFlags >> 8) & 0xff; + if((statusIdx < 0) || (statusIdx > sizeof(HTTPstatus)/sizeof(HTTPstatus[0]))){ + statusIdx = 0; + #ifdef DEBUG + traceEvent(TRACE_WARNING, "INTERNAL ERROR: invalid HTTP status id (%d) set to zero.\n", statusIdx); + #endif + } + snprintf(tmpStr, sizeof(tmpStr), "HTTP/1.0 %d %s\n", + HTTPstatus[statusIdx].statusCode, HTTPstatus[statusIdx].reasonPhrase); + sendString(tmpStr); + + strftime(theDate, sizeof(theDate)-1, "%a, %d %b %Y %H:%M:%S GMT", localtime_r(&theTime, &t)); + theDate[sizeof(theDate)-1] = '\0'; + snprintf(tmpStr, sizeof(tmpStr), "Date: %s\n", theDate); + sendString(tmpStr); + + if(headerFlags & HTTP_FLAG_IS_CACHEABLE) { + sendString("Cache-Control: max-age=3600, must-revalidate, public\n"); + } else if((headerFlags & HTTP_FLAG_NO_CACHE_CONTROL) == 0) { + sendString("Cache-Control: no-cache\n"); + } + + if((headerFlags & HTTP_FLAG_KEEP_OPEN) == 0) { + sendString("Connection: close\n"); + } + + snprintf(tmpStr, sizeof(tmpStr), "Server: ntop/%s (%s)\n", version, osName); + sendString(tmpStr); + + if(headerFlags & HTTP_FLAG_NEED_AUTHENTICATION) { + sendString("WWW-Authenticate: Basic realm=\"ntop HTTP server [default user=admin,pw=admin];\"\n"); + } + + switch(mimeType) { + case HTTP_TYPE_HTML: + sendString("Content-Type: text/html\n"); + break; + case HTTP_TYPE_GIF: + sendString("Content-Type: image/gif\n"); + break; + case HTTP_TYPE_JPEG: + sendString("Content-Type: image/jpeg\n"); + break; + case HTTP_TYPE_PNG: + sendString("Content-Type: image/png\n"); + break; + case HTTP_TYPE_CSS: + sendString("Content-Type: text/css\n"); + break; + case HTTP_TYPE_NONE: + break; + #ifdef DEBUG + default: + traceEvent(TRACE_INFO, "INTERNAL ERROR: invalid MIME type code requested (%d)\n", mimeType); + #endif + } + + if(headerFlags & HTTP_FLAG_IS_CACHEABLE) { + theTime += 3600; + strftime(theDate, sizeof(theDate)-1, "%a, %d %b %Y %H:%M:%S GMT", localtime_r(&theTime, &t)); + theDate[sizeof(theDate)-1] = '\0'; + snprintf(tmpStr, sizeof(tmpStr), "Expires: %s\n", theDate); + sendString(tmpStr); + } else if((headerFlags & HTTP_FLAG_NO_CACHE_CONTROL) == 0) { + sendString("Expires: 0\n"); + } + + if((headerFlags & HTTP_FLAG_MORE_FIELDS) == 0) { + sendString("\n"); + } + } /* ************************* */ *************** *** 469,487 **** break; } ! if(rc == 0) ! return(rc); ! else { ! returnHTTPaccessForbidden(); ! return(-1); ! } } /* ************************* */ ! static void returnHTTPPage(char* pageName, int postLen) { char *questionMark = strchr(pageName, '?'); int sortedColumn, printTrailer=1, idx; FILE *fd = NULL; char tmpStr[512]; int revertOrder=0; --- 823,838 ---- break; } ! return(rc); } /* ************************* */ ! static int returnHTTPPage(char* pageName, int postLen) { char *questionMark = strchr(pageName, '?'); int sortedColumn, printTrailer=1, idx; + int errorCode=0; + struct stat statbuf; FILE *fd = NULL; char tmpStr[512]; int revertOrder=0; *************** *** 495,501 **** system files */ if(checkURLsecurity(pageName) != 0) ! return; /* traceEvent(TRACE_INFO, "Page: '%s'\n", pageName); */ --- 846,852 ---- system files */ if(checkURLsecurity(pageName) != 0) ! return (HTTP_FORBIDDEN_PAGE); /* traceEvent(TRACE_INFO, "Page: '%s'\n", pageName); */ *************** *** 539,546 **** } #endif ! if((fd = fopen(tmpStr, "rb")) != NULL) ! break; } #ifdef DEBUG --- 890,900 ---- } #endif ! if(stat(tmpStr, &statbuf) == 0) { ! if((fd = fopen(tmpStr, "rb")) != NULL) ! break; ! traceEvent(TRACE_ERROR, "Cannot open file '%s', ignored...\n", tmpStr); ! } } #ifdef DEBUG *************** *** 548,595 **** #endif if(fd != NULL) { ! int len = strlen(pageName); ! ! if((len > 4) ! && ((strcmp(&pageName[len-4], ".gif") == 0) ! || (strcmp(&pageName[len-4], ".jpg") == 0))) { ! char theDate[48]; ! time_t theTime; ! struct tm t; ! ! sendHTTPProtoHeader(); ! ! theTime = actTime; ! ! strftime(theDate, 32, "%a, %d %b %Y %H:%M:%S GMT", localtime_r(&theTime, &t)); ! snprintf(tmpStr, sizeof(tmpStr), "Date: %s\n", theDate); ! sendString(tmpStr); ! ! theTime += 3600; ! ! strftime(theDate, 32, "%a, %d %b %Y %H:%M:%S GMT", localtime_r(&theTime, &t)); ! snprintf(tmpStr, sizeof(tmpStr), "Expires: %s\n", theDate); ! sendString(tmpStr); ! sendString("Cache-Control: max-age=3600, must-revalidate, public\n"); ! if(strcmp(&pageName[len-4], ".gif") == 0) ! sendString("Content-type: image/gif\n"); ! else ! sendString("Content-type: image/jpeg\n"); ! fseek(fd, 0, SEEK_END); ! snprintf(tmpStr, sizeof(tmpStr), "Content-Length: %d\n\n", (len = ftell(fd))); ! fseek(fd, 0, SEEK_SET); ! sendString(tmpStr); ! ! } else if((len > 4) && ((strcmp(&pageName[len-4], ".css") == 0))) { ! sendHTTPProtoHeader(); ! sendString("Content-type: text/css\n"); ! } else { ! sendHTTPProtoHeader(); ! sendHTTPHeaderType(); ! } for(;;) { len = fread(tmpStr, sizeof(char), 255, fd); --- 902,937 ---- #endif if(fd != NULL) { ! char theDate[48]; ! time_t theTime; ! struct tm t; ! int len = strlen(pageName), mimeType = HTTP_TYPE_HTML; ! if(len > 4) { ! if (strcmp(&pageName[len-4], ".gif") == 0) ! mimeType = HTTP_TYPE_GIF; ! else if(strcmp(&pageName[len-4], ".jpg") == 0) ! mimeType = HTTP_TYPE_JPEG; ! else if(strcmp(&pageName[len-4], ".png") == 0) ! mimeType = HTTP_TYPE_PNG; ! else if(strcmp(&pageName[len-4], ".css") == 0) ! mimeType = HTTP_TYPE_CSS; ! } ! sendHTTPHeader(mimeType, HTTP_FLAG_IS_CACHEABLE | HTTP_FLAG_MORE_FIELDS); ! if (actTime > statbuf.st_mtime) { /* just in case the system clock is wrong... */ ! theTime = statbuf.st_mtime - thisZone; ! strftime(theDate, sizeof(theDate)-1, "%a, %d %b %Y %H:%M:%S GMT", localtime_r(&theTime, &t)); ! theDate[sizeof(theDate)-1] = '\0'; ! snprintf(tmpStr, sizeof(tmpStr), "Last-Modified: %s\n", theDate); ! sendString(tmpStr); ! } ! fseek(fd, 0, SEEK_END); ! snprintf(tmpStr, sizeof(tmpStr), "Content-Length: %d\n", (len = ftell(fd))); ! fseek(fd, 0, SEEK_SET); ! sendString(tmpStr); ! sendString("\n"); /* mark the end of HTTP header */ for(;;) { len = fread(tmpStr, sizeof(char), 255, fd); *************** *** 599,619 **** fclose(fd); /* closeNwSocket(&newSock); */ ! return; } #ifndef WIN32 #ifdef USE_CGI if(strncmp(pageName, CGI_HEADER, strlen(CGI_HEADER)) == 0) { execCGI(&pageName[strlen(CGI_HEADER)]); ! return; } #endif /* USE_CGI */ #endif ! if((strncmp(pageName, PLUGINS_HEADER, strlen(PLUGINS_HEADER)) == 0) ! && handlePluginHTTPRequest(&pageName[strlen(PLUGINS_HEADER)])) ! return; /* Putting this here (and not on top of this function) --- 941,965 ---- fclose(fd); /* closeNwSocket(&newSock); */ ! return (0); } #ifndef WIN32 #ifdef USE_CGI if(strncmp(pageName, CGI_HEADER, strlen(CGI_HEADER)) == 0) { execCGI(&pageName[strlen(CGI_HEADER)]); ! return (0); } #endif /* USE_CGI */ #endif ! if(strncmp(pageName, PLUGINS_HEADER, strlen(PLUGINS_HEADER)) == 0) { ! if(handlePluginHTTPRequest(&pageName[strlen(PLUGINS_HEADER)])) { ! return (0); ! } else { ! return (HTTP_INVALID_PAGE); ! } ! } /* Putting this here (and not on top of this function) *************** *** 625,633 **** #endif if(strcmp(pageName, STR_INDEX_HTML) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! sendString("\n"); ! sendString("Welcome to ntop!\n"); sendString("\n"); sendString(" \n"); sendString(" \n"); --- 971,978 ---- #endif if(strcmp(pageName, STR_INDEX_HTML) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Welcome to ntop!", HTML_FLAG_NO_REFRESH | HTML_FLAG_NO_BODY); sendString("\n"); sendString(" \n"); sendString(" \n"); *************** *** 637,646 **** sendString(" \n"); sendString("\n"); sendString("\n"); } else if((strcmp(pageName, "leftmenu.html") == 0) || (strcmp(pageName, "leftmenu-nojs.html") == 0)) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! sendString("\n\n" "
\n
\n\n
\n\n"); sendString("Welcome
to
\n"); sendString("ntop!
\n
\n
\n"); --- 982,993 ---- sendString(" \n"); sendString("\n"); sendString("\n"); + printTrailer=0; } else if((strcmp(pageName, "leftmenu.html") == 0) || (strcmp(pageName, "leftmenu-nojs.html") == 0)) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader(NULL, HTML_FLAG_NO_REFRESH); ! sendString( "
\n
\n\n
\n\n"); sendString("Welcome
to
\n"); sendString("ntop!
\n
\n
\n"); *************** *** 676,690 **** "Routers\n"); sendString("
  • " "Plugins
  • \n"); ! sendString("
  • " "Thpt Stats
  • \n"); sendString("
  • " "Hosts Info
  • \n"); ! sendString("
  • " "R->L IP Traffic
  • \n"); ! sendString("
  • " "L->R IP Traffic
  • \n"); ! sendString("
  • " "L<->L IP Traffic
  • \n"); sendString("
  • " "Active TCP Sessions
  • \n"); --- 1023,1037 ---- "Routers\n"); sendString("
  • " "Plugins
  • \n"); ! sendString("
  • " "Thpt Stats
  • \n"); sendString("
  • " "Hosts Info
  • \n"); ! sendString("
  • " "R->L IP Traffic
  • \n"); ! sendString("
  • " "L->R IP Traffic
  • \n"); ! sendString("
  • " "L<->L IP Traffic
  • \n"); sendString("
  • " "Active TCP Sessions
  • \n"); *************** *** 723,734 **** sendString("\n\n
    \n\n\n"); printTrailer=0; } else if(strcmp(pageName, "switch.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); switchNwInterface(sortedColumn); } else if(strcmp(pageName, "home.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! sendString("\n
    " ! "

    Welcome to ntop!


    "); sendString("ntop shows the current network usage. It displays a list of hosts that are\n"); sendString("currently using the network and reports information concerning the IP\n"); sendString("(Internet Protocol) traffic generated by each host. The traffic is \n"); --- 1070,1081 ---- sendString("\n\n
    \n\n\n"); printTrailer=0; } else if(strcmp(pageName, "switch.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); switchNwInterface(sortedColumn); } else if(strcmp(pageName, "home.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Welcome to ntop!", HTML_FLAG_NO_REFRESH); ! sendString("\n
    \n"); sendString("ntop shows the current network usage. It displays a list of hosts that are\n"); sendString("currently using the network and reports information concerning the IP\n"); sendString("(Internet Protocol) traffic generated by each host. The traffic is \n"); *************** *** 743,919 **** sendString("to the enclosed licence (see COPYING).

    Problems, bugs, questions, "); sendString("desirable enhancements, source code contributions, etc., should be sent to the "); sendString(" mailing list.\n"); - sendString("\n"); } else if(strncmp(pageName, STR_SORT_DATA_RECEIVED_PROTOS, strlen(STR_SORT_DATA_RECEIVED_PROTOS)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHostsTraffic(0, 0, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_RECEIVED_IP, strlen(STR_SORT_DATA_RECEIVED_IP)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHostsTraffic(0, 1, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_THPT_STATS, strlen(STR_SORT_DATA_THPT_STATS)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printThptStats(sortedColumn); } else if(strncmp(pageName, STR_THPT_STATS_MATRIX, strlen(STR_THPT_STATS_MATRIX)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printThptStatsMatrix(sortedColumn); } else if(strncmp(pageName, STR_SORT_DATA_RECEIVED_THPT, strlen(STR_SORT_DATA_RECEIVED_THPT)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(0, 2, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_RCVD_HOST_TRAFFIC, strlen(STR_SORT_DATA_RCVD_HOST_TRAFFIC)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(0, 3, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_HOST_TRAFFIC, strlen(STR_SORT_DATA_SENT_HOST_TRAFFIC)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(1, 3, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_PROTOS, strlen(STR_SORT_DATA_SENT_PROTOS)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHostsTraffic(1, 0, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_IP, strlen(STR_SORT_DATA_SENT_IP)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHostsTraffic(1, 1, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_THPT, strlen(STR_SORT_DATA_SENT_THPT)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(1, 2, sortedColumn, revertOrder); } else if(strncmp(pageName, HOSTS_INFO_HTML, strlen(HOSTS_INFO_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHostsInfo(sortedColumn, revertOrder); } else if(isLsofPresent && (strncmp(pageName, PROCESS_INFO_HTML, strlen(PROCESS_INFO_HTML)) == 0)) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printProcessInfo(sortedColumn /* process PID */); } else if(isLsofPresent && (strncmp(pageName, STR_LSOF_DATA, strlen(STR_LSOF_DATA)) == 0)) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printLsofData(sortedColumn); } else if(strcmp(pageName, "NetFlows.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); listNetFlows(); } else if(strncmp(pageName, IP_R_2_L_HTML, strlen(IP_R_2_L_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("

    Remote to Local IP Traffic

    \n"); if(sortedColumn == 0) { sortedColumn = 1; } printIpAccounting(REMOTE_TO_LOCAL_ACCOUNTING, sortedColumn, revertOrder); - sendString("

    \n"); } else if(strncmp(pageName, IP_L_2_R_HTML, strlen(IP_L_2_R_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("

    Local to Remote IP Traffic

    \n"); if(sortedColumn == 0) { sortedColumn = 1; } printIpAccounting(LOCAL_TO_REMOTE_ACCOUNTING, sortedColumn, revertOrder); - sendString("

    \n"); } else if(strncmp(pageName, IP_L_2_L_HTML, strlen(IP_L_2_L_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("

    Local IP Traffic

    \n"); if(sortedColumn == 0) { sortedColumn = 1; } printIpAccounting(LOCAL_TO_LOCAL_ACCOUNTING, sortedColumn, revertOrder); - sendString("

    \n"); } else if(strcmp(pageName, "NetNetstat.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("

    Active TCP Sessions

    \n"); printActiveTCPSessions(); - sendString("

    \n"); } else if(strncmp(pageName, SHUTDOWN_NTOP_HTML, strlen(SHUTDOWN_NTOP_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); ! sendString("

    ntop is shutting down...

    \n"); ! sendString("

    \n"); shutdownNtop(); } else if(strncmp(pageName, RESET_STATS_HTML, strlen(RESET_STATS_HTML)) == 0) { /* Courtesy of Daniel Savard */ ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); resetStats(); - sendString("

    " - "All statistics are now reseted

    \n"); - sendString("

    \n"); } else if(strncmp(pageName, STR_MULTICAST_STATS, strlen(STR_MULTICAST_STATS)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printMulticastStats(sortedColumn, revertOrder); } else if(strncmp(pageName, STR_DOMAIN_STATS, strlen(STR_DOMAIN_STATS)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printDomainStats(NULL, abs(sortedColumn), revertOrder); } else if(strncmp(pageName, STR_SHOW_PLUGINS, strlen(STR_SHOW_PLUGINS)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); if(questionMark == NULL) showPluginsList(""); else showPluginsList(&pageName[strlen(STR_SHOW_PLUGINS)+1]); } else if(strncmp(pageName, DOMAIN_INFO_HTML, strlen(DOMAIN_INFO_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); if(questionMark == NULL) questionMark = ""; pageName[strlen(pageName)-5-strlen(questionMark)] = '\0'; printDomainStats(&pageName[strlen(DOMAIN_INFO_HTML)+1], abs(sortedColumn), revertOrder); } else if(strcmp(pageName, TRAFFIC_STATS_HTML) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); printHostsTraffic(2, 0, 0, revertOrder); printProtoTraffic(); sendString("

    \n"); printIpProtocolDistribution(LONG_FORMAT, revertOrder); - sendString("

    \n"); } else if(strcmp(pageName, "ipProtoDistrib.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); printIpProtocolDistribution(SHORT_FORMAT, revertOrder); } else if(strcmp(pageName, "ipTrafficMatrix.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("

    IP Subnet Traffic Matrix

    \n"); printIpTrafficMatrix(); } else if(strcmp(pageName, "localRoutersList.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); printLocalRoutersList(); } else if(strcmp(pageName, "ipProtoUsage.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("

    IP Protocol Subnet Usage

    \n"); printIpProtocolUsage(); #ifdef HAVE_GDCHART } else if(strncmp(pageName, "thptGraph", strlen("thptGraph")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); drawThptGraph(sortedColumn); } else if(strncmp(pageName, "ipTrafficPie", strlen("ipTrafficPie")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); drawTrafficPie(); } else if(strncmp(pageName, "pktCastDistribPie", strlen("pktCastDistribPie")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); pktCastDistribPie(); } else if(strncmp(pageName, "pktSizeDistribPie", strlen("pktSizeDistribPie")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); pktSizeDistribPie(); } else if(strncmp(pageName, "ipProtoDistribPie", strlen("ipProtoDistribPie")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); ipProtoDistribPie(); } else if(strncmp(pageName, "interfaceTrafficPie", strlen("interfaceTrafficPie")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); interfaceTrafficPie(); } else if(strncmp(pageName, "drawGlobalProtoDistribution", strlen("drawGlobalProtoDistribution")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); drawGlobalProtoDistribution(); } else if(strncmp(pageName, "drawGlobalIpProtoDistribution", strlen("drawGlobalIpProtoDistribution")) == 0) { ! sendHTTPProtoHeader(); sendGIFHeaderType(); drawGlobalIpProtoDistribution(); #endif } else if(strncmp(pageName, NW_EVENTS_HTML, strlen(NW_EVENTS_HTML)) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHostEvents(NULL, sortedColumn, revertOrder); } else if(strcmp(pageName, "Credits.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! sendString("\n\n\n"); ! sendString("

    Credits



    ntop has been created by\n"); sendString("Luca Deri while studying how to model\n"); sendString("network traffic. He was unsatisfied of the many network traffic analysis tools\n"); sendString("he had access to, and decided to write a new application able to report network\n"); --- 1090,1242 ---- sendString("to the enclosed licence (see COPYING).

    Problems, bugs, questions, "); sendString("desirable enhancements, source code contributions, etc., should be sent to the "); sendString(" mailing list.\n"); } else if(strncmp(pageName, STR_SORT_DATA_RECEIVED_PROTOS, strlen(STR_SORT_DATA_RECEIVED_PROTOS)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostsTraffic(0, 0, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_RECEIVED_IP, strlen(STR_SORT_DATA_RECEIVED_IP)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostsTraffic(0, 1, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_THPT_STATS, strlen(STR_SORT_DATA_THPT_STATS)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printThptStats(sortedColumn); } else if(strncmp(pageName, STR_THPT_STATS_MATRIX, strlen(STR_THPT_STATS_MATRIX)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printThptStatsMatrix(sortedColumn); } else if(strncmp(pageName, STR_SORT_DATA_RECEIVED_THPT, strlen(STR_SORT_DATA_RECEIVED_THPT)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(0, 2, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_RCVD_HOST_TRAFFIC, strlen(STR_SORT_DATA_RCVD_HOST_TRAFFIC)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(0, 3, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_HOST_TRAFFIC, strlen(STR_SORT_DATA_SENT_HOST_TRAFFIC)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(1, 3, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_PROTOS, strlen(STR_SORT_DATA_SENT_PROTOS)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostsTraffic(1, 0, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_IP, strlen(STR_SORT_DATA_SENT_IP)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostsTraffic(1, 1, sortedColumn, revertOrder); } else if(strncmp(pageName, STR_SORT_DATA_SENT_THPT, strlen(STR_SORT_DATA_SENT_THPT)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = HOST_DUMMY_IDX_VALUE; } printHostsTraffic(1, 2, sortedColumn, revertOrder); } else if(strncmp(pageName, HOSTS_INFO_HTML, strlen(HOSTS_INFO_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostsInfo(sortedColumn, revertOrder); } else if(isLsofPresent && (strncmp(pageName, PROCESS_INFO_HTML, strlen(PROCESS_INFO_HTML)) == 0)) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printProcessInfo(sortedColumn /* process PID */); } else if(isLsofPresent && (strncmp(pageName, STR_LSOF_DATA, strlen(STR_LSOF_DATA)) == 0)) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printLsofData(sortedColumn); } else if(strcmp(pageName, "NetFlows.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); listNetFlows(); } else if(strncmp(pageName, IP_R_2_L_HTML, strlen(IP_R_2_L_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = 1; } printIpAccounting(REMOTE_TO_LOCAL_ACCOUNTING, sortedColumn, revertOrder); } else if(strncmp(pageName, IP_L_2_R_HTML, strlen(IP_L_2_R_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = 1; } printIpAccounting(LOCAL_TO_REMOTE_ACCOUNTING, sortedColumn, revertOrder); } else if(strncmp(pageName, IP_L_2_L_HTML, strlen(IP_L_2_L_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(sortedColumn == 0) { sortedColumn = 1; } printIpAccounting(LOCAL_TO_LOCAL_ACCOUNTING, sortedColumn, revertOrder); } else if(strcmp(pageName, "NetNetstat.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printActiveTCPSessions(); } else if(strncmp(pageName, SHUTDOWN_NTOP_HTML, strlen(SHUTDOWN_NTOP_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); shutdownNtop(); } else if(strncmp(pageName, RESET_STATS_HTML, strlen(RESET_STATS_HTML)) == 0) { /* Courtesy of Daniel Savard */ ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("All statistics are now reseted", HTML_FLAG_NO_REFRESH); resetStats(); } else if(strncmp(pageName, STR_MULTICAST_STATS, strlen(STR_MULTICAST_STATS)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printMulticastStats(sortedColumn, revertOrder); } else if(strncmp(pageName, STR_DOMAIN_STATS, strlen(STR_DOMAIN_STATS)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printDomainStats(NULL, abs(sortedColumn), revertOrder); } else if(strncmp(pageName, STR_SHOW_PLUGINS, strlen(STR_SHOW_PLUGINS)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(questionMark == NULL) showPluginsList(""); else showPluginsList(&pageName[strlen(STR_SHOW_PLUGINS)+1]); } else if(strncmp(pageName, DOMAIN_INFO_HTML, strlen(DOMAIN_INFO_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if(questionMark == NULL) questionMark = ""; pageName[strlen(pageName)-5-strlen(questionMark)] = '\0'; printDomainStats(&pageName[strlen(DOMAIN_INFO_HTML)+1], abs(sortedColumn), revertOrder); } else if(strcmp(pageName, TRAFFIC_STATS_HTML) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostsTraffic(2, 0, 0, revertOrder); printProtoTraffic(); sendString("

    \n"); printIpProtocolDistribution(LONG_FORMAT, revertOrder); } else if(strcmp(pageName, "ipProtoDistrib.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader(NULL, 0); printIpProtocolDistribution(SHORT_FORMAT, revertOrder); } else if(strcmp(pageName, "ipTrafficMatrix.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printIpTrafficMatrix(); } else if(strcmp(pageName, "localRoutersList.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printLocalRoutersList(); } else if(strcmp(pageName, "ipProtoUsage.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printIpProtocolUsage(); #ifdef HAVE_GDCHART } else if(strncmp(pageName, "thptGraph", strlen("thptGraph")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); drawThptGraph(sortedColumn); } else if(strncmp(pageName, "ipTrafficPie", strlen("ipTrafficPie")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); drawTrafficPie(); } else if(strncmp(pageName, "pktCastDistribPie", strlen("pktCastDistribPie")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); pktCastDistribPie(); } else if(strncmp(pageName, "pktSizeDistribPie", strlen("pktSizeDistribPie")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); pktSizeDistribPie(); } else if(strncmp(pageName, "ipProtoDistribPie", strlen("ipProtoDistribPie")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); ipProtoDistribPie(); } else if(strncmp(pageName, "interfaceTrafficPie", strlen("interfaceTrafficPie")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); interfaceTrafficPie(); } else if(strncmp(pageName, "drawGlobalProtoDistribution", strlen("drawGlobalProtoDistribution")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); drawGlobalProtoDistribution(); } else if(strncmp(pageName, "drawGlobalIpProtoDistribution", strlen("drawGlobalIpProtoDistribution")) == 0) { ! sendHTTPHeader(HTTP_TYPE_GIF, 0); drawGlobalIpProtoDistribution(); #endif } else if(strncmp(pageName, NW_EVENTS_HTML, strlen(NW_EVENTS_HTML)) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printHostEvents(NULL, sortedColumn, revertOrder); } else if(strcmp(pageName, "Credits.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Credits", HTML_FLAG_NO_REFRESH); ! sendString("\n"); ! sendString("



    ntop has been created by\n"); sendString("Luca Deri while studying how to model\n"); sendString("network traffic. He was unsatisfied of the many network traffic analysis tools\n"); sendString("he had access to, and decided to write a new application able to report network\n"); *************** *** 936,953 **** sendString("

    \n"); #ifdef HAVE_GDBM_H } else if(strcmp(pageName, "showUsers.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); showUsers(); } else if(strcmp(pageName, "addUser.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); addUser(NULL); } else if(strncmp(pageName, "modifyUser", strlen("modifyUser")) == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); if((questionMark == NULL) || (questionMark[0] == '\0')) addUser(NULL); else addUser(&questionMark[1]); } else if(strncmp(pageName, "deleteUser", strlen("deleteUser")) == 0) { if((questionMark == NULL) || (questionMark[0] == '\0')) deleteUser(NULL); else --- 1259,1277 ---- sendString("

    \n"); #ifdef HAVE_GDBM_H } else if(strcmp(pageName, "showUsers.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); showUsers(); } else if(strcmp(pageName, "addUser.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); addUser(NULL); } else if(strncmp(pageName, "modifyUser", strlen("modifyUser")) == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); if((questionMark == NULL) || (questionMark[0] == '\0')) addUser(NULL); else addUser(&questionMark[1]); } else if(strncmp(pageName, "deleteUser", strlen("deleteUser")) == 0) { + printTrailer=0; if((questionMark == NULL) || (questionMark[0] == '\0')) deleteUser(NULL); else *************** *** 956,984 **** printTrailer=0; doAddUser(postLen /* \r\n */); } else if(strcmp(pageName, "showURLs.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); showURLs(); } else if(strcmp(pageName, "addURL.html") == 0) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); addURL(NULL); } else if(strncmp(pageName, "modifyURL", strlen("modifyURL")) == 0) { if((questionMark == NULL) || (questionMark[0] == '\0')) { - sendHTTPProtoHeader(); sendHTTPHeaderType(); addURL(NULL); } else addURL(&questionMark[1]); } else if(strncmp(pageName, "deleteURL", strlen("deleteURL")) == 0) { if((questionMark == NULL) || (questionMark[0] == '\0')) deleteURL(NULL); else deleteURL(&questionMark[1]); - } else if(strncmp(pageName, INFO_NTOP_HTML, strlen(INFO_NTOP_HTML)) == 0) { - sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); - printNtopConfigInfo(); } else if(strcmp(pageName, "doAddURL") == 0) { printTrailer=0; doAddURL(postLen /* \r\n */); #endif /* HAVE_GDBM_H */ } else if(strlen(pageName) > 5) { int i; char hostName[32]; --- 1280,1309 ---- printTrailer=0; doAddUser(postLen /* \r\n */); } else if(strcmp(pageName, "showURLs.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); showURLs(); } else if(strcmp(pageName, "addURL.html") == 0) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); addURL(NULL); } else if(strncmp(pageName, "modifyURL", strlen("modifyURL")) == 0) { + sendHTTPHeader(HTTP_TYPE_HTML, 0); if((questionMark == NULL) || (questionMark[0] == '\0')) { addURL(NULL); } else addURL(&questionMark[1]); } else if(strncmp(pageName, "deleteURL", strlen("deleteURL")) == 0) { + printTrailer=0; if((questionMark == NULL) || (questionMark[0] == '\0')) deleteURL(NULL); else deleteURL(&questionMark[1]); } else if(strcmp(pageName, "doAddURL") == 0) { printTrailer=0; doAddURL(postLen /* \r\n */); #endif /* HAVE_GDBM_H */ + } else if(strncmp(pageName, INFO_NTOP_HTML, strlen(INFO_NTOP_HTML)) == 0) { + sendHTTPHeader(HTTP_TYPE_HTML, 0); + printNtopConfigInfo(); } else if(strlen(pageName) > 5) { int i; char hostName[32]; *************** *** 991,1012 **** pageName[i] = ':'; strncpy(hostName, pageName, sizeof(hostName)); ! sendHTTPProtoHeader(); ! sendHTTPHeaderType(); ! printHTTPheader(); printAllSessionsHTML(hostName); - sendString("

    \n"); } else { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! printHTTPheader(); ! sendString("\n???\n\n

    Error

    \nUnknown page\n"); } ! if(printTrailer && (postLen == -1)) printHTTPtrailer(); #ifdef MULTITHREADED releaseMutex(&hashResizeMutex); #endif } /* ************************* */ --- 1316,1334 ---- pageName[i] = ':'; strncpy(hostName, pageName, sizeof(hostName)); ! sendHTTPHeader(HTTP_TYPE_HTML, 0); printAllSessionsHTML(hostName); } else { ! printTrailer = 0; ! errorCode = HTTP_INVALID_PAGE; } ! if(printTrailer && (postLen == -1)) printHTMLtrailer(); #ifdef MULTITHREADED releaseMutex(&hashResizeMutex); #endif + return (errorCode); } /* ************************* */ *************** *** 1128,1136 **** --- 1450,1460 ---- #ifdef MULTITHREADED releaseMutex(&gdbmMutex); #endif + if (return_data.dptr != NULL) free(return_data.dptr); return 0; /* The specified user is not among those who are allowed to access the URL */ } + if (return_data.dptr != NULL) free(return_data.dptr); key_data.dptr = users; key_data.dsize = strlen(users)+1; *************** *** 1152,1160 **** releaseMutex(&gdbmMutex); #endif return(rc); } - #endif /* ************************* */ static void returnHTTPnotImplemented(void) { --- 1476,1486 ---- releaseMutex(&gdbmMutex); #endif return(rc); + + #endif /* HAVE_GDBM_H */ } + #if 0 /* this is not used anymore */ /* ************************* */ static void returnHTTPnotImplemented(void) { *************** *** 1166,1177 **** --- 1492,1505 ---- logHTTPaccess(501); } + #endif /* ************************* */ void handleHTTPrequest(struct in_addr from) { int postLen; char requestedURL[512], pw[64]; + int rc; gettimeofday(&httpRequestedAt, NULL); *************** *** 1184,1226 **** postLen = readHTTPheader(requestedURL, sizeof(requestedURL), pw, sizeof(pw)); ! if(postLen == INVALID_HTTP_REQUEST) { /* Courtesy of Vanja Hrustic */ returnHTTPnotImplemented(); return; ! } ! ! if(checkHTTPpassword(requestedURL, sizeof(requestedURL), pw, sizeof(pw) ) != 1) { ! returnHTTPaccessDenied(); return; } - #ifdef DEBUG - fprintf(stdout, "URL = '%s'\n", requestedURL); - #endif - - actTime = time(NULL); /* Don't forget this */ - /* Fix courtesy of Michael Wescott */ ! if((requestedURL[0] == '\0') || (requestedURL[0] == '/')) { ! int len = strlen(requestedURL); ! if(len >= 9) requestedURL[len-9] = '\0'; ! returnHTTPPage(&requestedURL[1], postLen); ! } else { ! char buf[64]; ! ! sendString("HTTP/1.0 200 OK\n"); ! snprintf(buf, sizeof(buf), "Server: ntop/%s (%s)\n", version, osName); ! sendString(buf); ! sendHTTPProtoHeader(); sendHTTPHeaderType(); ! sendString("\n???\n\n" ! "

    Error

    \nUnkown page\n\n\n"); } ! logHTTPaccess(200); ! } --- 1512,1559 ---- postLen = readHTTPheader(requestedURL, sizeof(requestedURL), pw, sizeof(pw)); ! #ifdef DEBUG ! traceEvent(TRACE_INFO, "Requested URL = '%s', length = %d\n", requestedURL, postLen); ! #endif ! ! if(postLen >= -1) { ! ; /* no errors, skip following tests */ ! } else if(postLen == HTTP_INVALID_REQUEST) { ! returnHTTPbadRequest(); ! return; ! } else if(postLen == HTTP_INVALID_METHOD) { /* Courtesy of Vanja Hrustic */ returnHTTPnotImplemented(); return; ! } else if(postLen == HTTP_INVALID_VERSION) { ! returnHTTPversionNotSupported(); ! return; ! } else if(postLen == HTTP_REQUEST_TIMEOUT) { ! returnHTTPrequestTimedOut(); return; } /* Fix courtesy of Michael Wescott */ ! if((requestedURL[0] != '\0') && (requestedURL[0] != '/')) { ! returnHTTPpageNotFound(); ! return; ! } ! if(checkHTTPpassword(requestedURL, sizeof(requestedURL), pw, sizeof(pw) ) != 1) { ! returnHTTPaccessDenied(); ! return; } ! actTime = time(NULL); /* Don't forget this */ + if((rc = returnHTTPPage(&requestedURL[1], postLen)) == 0 ) { + logHTTPaccess(200); + } else if(rc == HTTP_FORBIDDEN_PAGE) { + returnHTTPaccessForbidden(); + } else if(rc == HTTP_INVALID_PAGE) { + returnHTTPpageNotFound(); + } + } *** main.c.orig Tue Oct 24 03:47:33 2000 --- main.c Wed Dec 6 18:58:24 2000 *************** *** 401,407 **** else snprintf(tmpBuf, sizeof(tmpBuf), "%s", device[i].name); ! strncat(ifStr, tmpBuf, sizeof(ifStr)-strlen(ifStr)-1)[sizeof(ifStr)-strlen(ifStr)-1] = '\0'; } traceEvent(TRACE_INFO, "Listening on [%s]", ifStr); --- 401,407 ---- else snprintf(tmpBuf, sizeof(tmpBuf), "%s", device[i].name); ! strncat(ifStr, tmpBuf, sizeof(ifStr)-strlen(ifStr)-1)[sizeof(ifStr)-1] = '\0'; } traceEvent(TRACE_INFO, "Listening on [%s]", ifStr); *** ntop.h.orig Thu Oct 26 04:48:30 2000 --- ntop.h Sat Dec 9 15:45:22 2000 *************** *** 437,443 **** #define DUMMY_SOCKET_VALUE -999 ! #define INVALID_HTTP_REQUEST -2 #define ALARM_TIME 3 #define MIN_ALARM_TIME 1 --- 437,460 ---- #define DUMMY_SOCKET_VALUE -999 ! ! #define HTTP_TYPE_NONE 0 ! #define HTTP_TYPE_HTML 1 ! #define HTTP_TYPE_GIF 2 ! #define HTTP_TYPE_JPEG 3 ! #define HTTP_TYPE_PNG 4 ! #define HTTP_TYPE_CSS 5 ! ! #define HTTP_FLAG_IS_CACHEABLE (1<<0) ! #define HTTP_FLAG_NO_CACHE_CONTROL (1<<1) ! #define HTTP_FLAG_KEEP_OPEN (1<<2) ! #define HTTP_FLAG_NEED_AUTHENTICATION (1<<3) ! #define HTTP_FLAG_MORE_FIELDS (1<<4) ! ! #define HTML_FLAG_NO_REFRESH (1<<0) ! #define HTML_FLAG_NO_STYLESHEET (1<<1) ! #define HTML_FLAG_NO_BODY (1<<2) ! #define HTML_FLAG_NO_HEADING (1<<3) #define ALARM_TIME 3 #define MIN_ALARM_TIME 1 *** pbuf.c.orig Thu Oct 26 04:48:10 2000 --- pbuf.c Mon Dec 11 11:28:54 2000 *************** *** 57,62 **** --- 57,65 ---- #include "ntop.h" + #ifdef DEBUG + # include "globals-report.h" + #endif /* ************************************ */ *************** *** 227,236 **** break; } else if(el->hostIpAddresses[i].s_addr == hostIpAddress->s_addr) break; - else { - el->hostIpAddresses[i].s_addr = hostIpAddress->s_addr; - break; - } } if(el->hostNumIpAddress[0] == '\0') { --- 230,235 ---- *************** *** 323,332 **** device[actualDeviceId].hash_hostTraffic[firstEmptySlot] = el; /* Insert a new entry */ device[actualDeviceId].hostsno++; #ifdef DEBUG traceEvent(TRACE_INFO, "Adding idx=%d on device=%d\n", ! firstEmptySlotx, actualDeviceId); #endif if(ether_addr != NULL) { --- 322,332 ---- device[actualDeviceId].hash_hostTraffic[firstEmptySlot] = el; /* Insert a new entry */ device[actualDeviceId].hostsno++; + idx = firstEmptySlot; #ifdef DEBUG traceEvent(TRACE_INFO, "Adding idx=%d on device=%d\n", ! firstEmptySlot, actualDeviceId); #endif if(ether_addr != NULL) { *************** *** 389,397 **** } else { /* el->hostNumIpAddress == "" */ if(symEthName[0] != '\0') { ! char buf[255]; ! snprintf(buf, sizeof(buf), "%s [MAC]", symEthName); strncpy(el->hostSymIpAddress, buf, MAX_HOST_SYM_NAME_LEN); } else strncpy(el->hostSymIpAddress, --- 389,399 ---- } else { /* el->hostNumIpAddress == "" */ if(symEthName[0] != '\0') { ! char buf[MAX_HOST_SYM_NAME_LEN]; ! snprintf(buf, sizeof(buf)-8, "%s", symEthName); ! buf[sizeof(buf)-8] = '\0'; /* just in case symEthName is too long */ ! strcat(&buf[strlen(buf)], " [MAC]"); strncpy(el->hostSymIpAddress, buf, MAX_HOST_SYM_NAME_LEN); } else strncpy(el->hostSymIpAddress, *************** *** 419,437 **** time_t lastSeenCandidate=0; HostTraffic* hostToFree; ! for(i=0; ilastSeen < lastSeenCandidate)) { candidate = i; ! if((device[actualDeviceId].hash_hostTraffic[idx]->lastSeen +IDLE_HOST_PURGE_TIMEOUT) > actTime) break; else ! lastSeenCandidate = device[actualDeviceId]. ! hash_hostTraffic[idx]->lastSeen; } } --- 421,438 ---- time_t lastSeenCandidate=0; HostTraffic* hostToFree; ! for(i=1; ilastSeen < lastSeenCandidate)) { candidate = i; ! if((device[actualDeviceId].hash_hostTraffic[i]->lastSeen +IDLE_HOST_PURGE_TIMEOUT) > actTime) break; else ! lastSeenCandidate = device[actualDeviceId].hash_hostTraffic[i]->lastSeen; } } *************** *** 583,588 **** --- 584,590 ---- device[actualDeviceId]. hash_hostTraffic[checkSessionIdx(remotePeerIdx)]->hostNumIpAddress))) || (scanner->peersIdx[i] == NO_PEER))) { + /* FIXME (DL): shouldn't be i instead of scanner->lastPeer? */ scanner->peersIdx[scanner->lastPeer] = remotePeerIdx; scanner->lastPeer = (scanner->lastPeer+1) % MAX_NUM_SESSION_PEERS; } *************** *** 808,817 **** --- 810,821 ---- return; #ifdef DEBUG + /* this gives an error when enabling debug mode! traceEvent(TRACE_INFO, "%8x/%8x %8x\n", srcHost->hostIpAddress.s_addr, dstHost->hostIpAddress.s_addr, localHostAddress.s_addr); + */ #endif if(tp == NULL) *************** *** 2210,2216 **** #endif /* The DNS chain will be checked here */ - FD_SET(NAME_SERVER_HOST_FLAG, &srcHost->flags); transactionId = processDNSPacket(bp, length, hlen, &isRequest, &positiveReply); #ifdef DNS_SNIFF_DEBUG --- 2214,2219 ---- *************** *** 2261,2273 **** if(microSecTimeDiff > 0) { if(subnetLocalHost(dstHost)) { ! if((srcHost->dnsStats->fastestMicrosecLocalReqMade == 0) || (microSecTimeDiff < srcHost->dnsStats->fastestMicrosecLocalReqServed)) srcHost->dnsStats->fastestMicrosecLocalReqServed = microSecTimeDiff; if(microSecTimeDiff > srcHost->dnsStats->slowestMicrosecLocalReqServed) srcHost->dnsStats->slowestMicrosecLocalReqServed = microSecTimeDiff; } else { ! if((srcHost->dnsStats->fastestMicrosecRemoteReqMade == 0) || (microSecTimeDiff < srcHost->dnsStats->fastestMicrosecRemoteReqServed)) srcHost->dnsStats->fastestMicrosecRemoteReqServed = microSecTimeDiff; if(microSecTimeDiff > srcHost->dnsStats->slowestMicrosecRemoteReqServed) --- 2264,2276 ---- if(microSecTimeDiff > 0) { if(subnetLocalHost(dstHost)) { ! if((srcHost->dnsStats->fastestMicrosecLocalReqServed == 0) || (microSecTimeDiff < srcHost->dnsStats->fastestMicrosecLocalReqServed)) srcHost->dnsStats->fastestMicrosecLocalReqServed = microSecTimeDiff; if(microSecTimeDiff > srcHost->dnsStats->slowestMicrosecLocalReqServed) srcHost->dnsStats->slowestMicrosecLocalReqServed = microSecTimeDiff; } else { ! if((srcHost->dnsStats->fastestMicrosecRemoteReqServed == 0) || (microSecTimeDiff < srcHost->dnsStats->fastestMicrosecRemoteReqServed)) srcHost->dnsStats->fastestMicrosecRemoteReqServed = microSecTimeDiff; if(microSecTimeDiff > srcHost->dnsStats->slowestMicrosecRemoteReqServed) *************** *** 2295,2300 **** --- 2298,2305 ---- } } + FD_SET(NAME_SERVER_HOST_FLAG, &srcHost->flags); + if(positiveReply) { srcHost->dnsStats->numPositiveReplSent++; dstHost->dnsStats->numPositiveReplRcvd++; *************** *** 2308,2335 **** || (srcHost->nbDomainName == NULL))) { char *name, nbName[64], domain[64]; int nodeType, i; ! ! name = ((char*)bp+hlen+22); ! nodeType = name_interpret(name,nbName); ! srcHost->nbNodeType = (char)nodeType; switch(nodeType) { case 0x0: /* Workstation */ - FD_SET(HOST_TYPE_WORKSTATION, &srcHost->flags); case 0x20: /* Server */ ! FD_SET(HOST_TYPE_SERVER, &srcHost->flags); } ! for(i=0; nbName[i] != '\0'; i++) ! if(nbName[i] == ' ') { nbName[i] = '\0'; break; } ! ! if(srcHost->nbHostName == NULL) ! srcHost->nbHostName = strdup(nbName); ! ! name = ((char*)bp+hlen+22+34); ! nodeType = name_interpret(name, domain); - for(i=0; domain[i] != '\0'; i++) - if(domain[i] == ' ') { domain[i] = '\0'; break; } switch(nodeType) { case 0x1E: /* Domain */ --- 2313,2352 ---- || (srcHost->nbDomainName == NULL))) { char *name, nbName[64], domain[64]; int nodeType, i; ! char *data = (char*)bp + (hlen + sizeof(struct udphdr)); ! u_char *p; ! int offset; ! ! name = data + 14; ! p = (u_char*)name; ! if ((*p & 0xC0) == 0xC0) { ! name = data + (p[1] + 255 * (p[0] & ~0xC0)); ! offset = 2; ! } else { ! while (*p) p += (*p)+1; ! offset = ((char*)p - (char*)data) + 1; ! } ! nodeType = name_interpret(name, nbName); ! switch(nodeType) { case 0x0: /* Workstation */ case 0x20: /* Server */ ! srcHost->nbNodeType = (char)nodeType; ! if(srcHost->nbHostName == NULL) ! srcHost->nbHostName = strdup(nbName); ! switch(nodeType) { ! case 0x0: /* Workstation */ ! FD_SET(HOST_TYPE_WORKSTATION, &srcHost->flags); ! case 0x20: /* Server */ ! FD_SET(HOST_TYPE_SERVER, &srcHost->flags); ! } } ! name = data + offset; ! p = (u_char*)name; ! if ((*p & 0xC0) == 0xC0) ! name = ((char*)bp+hlen+8 + (p[1] + 255 * (p[0] & ~0xC0))); nodeType = name_interpret(name, domain); switch(nodeType) { case 0x1E: /* Domain */ *************** *** 2343,2348 **** --- 2360,2366 ---- } break; + #if 0 case 0x0: /* Workstation */ case 0x20: /* Server */ if(dstHost->nbHostName == NULL) dstHost->nbHostName = strdup(domain); *************** *** 2354,2359 **** --- 2372,2378 ---- FD_SET(HOST_TYPE_SERVER, &dstHost->flags); } break; + #endif } } } *************** *** 2481,2488 **** } #ifdef DEBUG traceEvent(TRACE_INFO, "IP=%d TCP=%d UDP=%d ICMP=%d (len=%d)\n", ! (int)ipBytes, (int)tcpBytes, (int)udpBytes, ! (int)icmpBytes, length); #endif /* Unlock the instance */ --- 2500,2507 ---- } #ifdef DEBUG traceEvent(TRACE_INFO, "IP=%d TCP=%d UDP=%d ICMP=%d (len=%d)\n", ! (int)device[actualDeviceId].ipBytes, (int)device[actualDeviceId].tcpBytes, (int)device[actualDeviceId].udpBytes, ! (int)device[actualDeviceId].icmpBytes, length); #endif /* Unlock the instance */ *** plugin.c.orig Wed Oct 18 09:40:33 2000 --- plugin.c Sat Dec 9 15:36:50 2000 *************** *** 34,40 **** extern PluginInfo* wapPluginEntryFctn(void); extern PluginInfo* remIntPluginEntryFctn(void); #ifdef RMON_SUPPORT ! extern PluginInfo* PluginEntryFctn(void); #endif #endif --- 34,40 ---- extern PluginInfo* wapPluginEntryFctn(void); extern PluginInfo* remIntPluginEntryFctn(void); #ifdef RMON_SUPPORT ! extern PluginInfo* rmonPluginEntryFctn(void); #endif #endif *************** *** 138,149 **** while(flows != NULL) if((flows->pluginStatus.pluginPtr != NULL) && (flows->pluginStatus.pluginPtr->pluginURLname != NULL) - && (flows->pluginStatus.activePlugin) && (flows->pluginStatus.pluginPtr->httpFunct != NULL) && (strncmp(flows->pluginStatus.pluginPtr->pluginURLname, url, strlen(flows->pluginStatus.pluginPtr->pluginURLname)) == 0)) { char *arg; if(strlen(url) == strlen(flows->pluginStatus.pluginPtr->pluginURLname)) arg = ""; else --- 138,163 ---- while(flows != NULL) if((flows->pluginStatus.pluginPtr != NULL) && (flows->pluginStatus.pluginPtr->pluginURLname != NULL) && (flows->pluginStatus.pluginPtr->httpFunct != NULL) && (strncmp(flows->pluginStatus.pluginPtr->pluginURLname, url, strlen(flows->pluginStatus.pluginPtr->pluginURLname)) == 0)) { char *arg; + if(!flows->pluginStatus.activePlugin) { + char buf[BUF_SIZE], name[32]; + + sendHTTPHeader(HTTP_TYPE_HTML, 0); + strncpy(name, flows->pluginStatus.pluginPtr->pluginURLname, sizeof(name)); + name[sizeof(name)-1] = '\0'; /* just in case pluginURLname is too long... */ + if((strlen(name) > 6) && (strcasecmp(&name[strlen(name)-6], "plugin") == 0)) + name[strlen(name)-6] = '\0'; + snprintf(buf, sizeof(buf),"Status for the \"%s\" Plugin", name); + printHTMLheader(buf, HTML_FLAG_NO_REFRESH); + printFlagedWarning("This plugin is currently inactive."); + printHTMLtrailer(); + return(1); + } + if(strlen(url) == strlen(flows->pluginStatus.pluginPtr->pluginURLname)) arg = ""; else *************** *** 290,295 **** --- 304,310 ---- newFlow->fcode[i].bf_insns = NULL; } else { strncpy(tmpBuf, pluginInfo->bpfFilter, sizeof(tmpBuf)); + tmpBuf[sizeof(tmpBuf)-1] = '\0'; /* just in case bpfFilter is too long... */ for(i=0; i"TABLE_OFF"\n"); + sendString("\n"); + PRINT_TOTALS: if(signumber_ignored == 2) { TrafficCounter unicastPkts=0, avgPktLen; *************** *** 447,454 **** */ ! sendString("

    Global Traffic Statistics" ! "

    \n" ""TABLE_ON"\n"); sendString("" --- 458,465 ---- */ ! sendString("
    \n"); ! sendString( ""TABLE_ON"
    Nw Interface Type
    \n"); sendString("" *************** *** 692,702 **** getRowColor(), formatThroughput(device[actualReportDeviceId].peakThroughput/8), device[actualReportDeviceId].peakPacketThroughput); sendString(buf2); ! sendString("
    Nw Interface Type

    \n"); } - } else { - /* if(reportType == 0) */ - sendString("\n"TABLE_OFF"

    \n"); } lastRefreshTime = actTime; --- 703,711 ---- getRowColor(), formatThroughput(device[actualReportDeviceId].peakThroughput/8), device[actualReportDeviceId].peakPacketThroughput); sendString(buf2); ! sendString("\n"); ! sendString("\n"); } } lastRefreshTime = actTime; *************** *** 741,748 **** tmpTable[numEntries++]=el; } ! printHTTPheader(); ! sendString("

    Multicast Statistics

    \n"); if(numEntries > 0) { columnSort = sortedColumn; /* Host name */ --- 750,756 ---- tmpTable[numEntries++]=el; } ! printHTMLheader("Multicast Statistics", 0); if(numEntries > 0) { columnSort = sortedColumn; /* Host name */ *************** *** 798,803 **** --- 806,812 ---- theAnchor[5] = htmlAnchor1; } + sendString("

    \n"); snprintf(buf, sizeof(buf), ""TABLE_ON"\n" "" "" *************** *** 843,848 **** --- 852,858 ---- } sendString("
    %s0>Host%s%s1>Domain%s%s2>Pkts Sent%s
    "TABLE_OFF"\n"); + sendString("
    \n"); } else printNoDataYet(); } *************** *** 872,880 **** columnSort = sortedColumn; ! sortSendMode = 2; /* This is used by print header */ ! ! printHeader(0, revertOrder, abs(sortedColumn)); for(idx=1, numEntries=0; idx\n"); snprintf(buf, sizeof(buf), ""TABLE_ON"\n" "" "" *************** *** 1080,1085 **** --- 1089,1095 ---- } sendString("
    %s1>Host%s%s"DOMAIN_DUMMY_IDX_STR">Domain%s
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } } *************** *** 1103,1111 **** } if(el == NULL) { ! snprintf(buf, sizeof(buf), "

    Unable to generate " ! "requested page [%s]

    \n", host); ! sendString(buf); return; } --- 1113,1120 ---- } if(el == NULL) { ! snprintf(buf, sizeof(buf), "Unable to generate requested page [%s]", host); ! printHTMLheader(buf, 0); return; } *************** *** 1127,1134 **** HostTraffic *peerHost; if(i == 0) { ! sendString("

    IP " ! "Service/Port Usage

    \n"); sendString(""TABLE_ON"\n" "" "" --- 1136,1143 ---- HostTraffic *peerHost; if(i == 0) { ! printSectionTitle("IP Service/Port Usage"); ! sendString("
    \n"); sendString(""TABLE_ON"
    IP ServicePort
    \n" "" "" *************** *** 1192,1198 **** } if(i > 0) ! sendString("
    IP ServicePort
    "TABLE_OFF"

    \n"); printHostSessions(el, elIdx); } --- 1201,1210 ---- } if(i > 0) ! { ! sendString(""TABLE_OFF"

    \n"); ! sendString("\n"); ! } printHostSessions(el, elIdx); } *************** *** 1205,1210 **** --- 1217,1224 ---- u_int idx, i, j, numEntries=0; u_int routerList[MAX_NUM_ROUTERS]; + printHTMLheader("Local Subnet Routers", 0); + for(idx=1; idx

    Local Subnet Routers

    \n"); - if(numEntries == 0) { printNoDataYet(); return; } else { sendString(""TABLE_ON"" "\n"); --- 1243,1253 ---- } } if(numEntries == 0) { printNoDataYet(); return; } else { + sendString("
    \n"); sendString(""TABLE_ON"
    Router NameUsed by
    " "\n"); *************** *** 1262,1268 **** } } ! sendString("
    Router NameUsed by
    "TABLE_OFF"\n"); } } --- 1275,1282 ---- } } ! sendString(""TABLE_OFF"\n"); ! sendString("\n"); } } *************** *** 1275,1280 **** --- 1289,1296 ---- { char *_sport, *_dport, *_sessionType, *direction; + if(logd == NULL) return; + _sport = getPortByNum(theSession->sport, sessionType); _dport = getPortByNum(theSession->dport, sessionType); *************** *** 1382,1387 **** --- 1398,1404 ---- struct hostTraffic *el; struct hostTraffic* tmpTable[HASHNAMESIZE]; char buf[BUF_SIZE], *str=NULL, *sign; + char *title=NULL; TrafficCounter totalBytesSent, totalBytesReceived, totalBytes, a=0, b=0; float sentpct, rcvdpct; time_t timeDiff = time(NULL)-initialSniffTime; *************** *** 1436,1458 **** } } if(numEntries > 0) { columnSort = sortedColumn; sortFilter = remoteToLocal; quicksort(tmpTable, numEntries, sizeof(struct hostTraffic*), cmpHostsFctn); - switch(remoteToLocal) { - case REMOTE_TO_LOCAL_ACCOUNTING: - str = IP_R_2_L_HTML; - break; - case LOCAL_TO_REMOTE_ACCOUNTING: - str = IP_L_2_R_HTML; - break; - case LOCAL_TO_LOCAL_ACCOUNTING: - str = IP_L_2_L_HTML; - break; - } - snprintf(htmlAnchor, sizeof(htmlAnchor), " 0) { columnSort = sortedColumn; sortFilter = remoteToLocal; quicksort(tmpTable, numEntries, sizeof(struct hostTraffic*), cmpHostsFctn); snprintf(htmlAnchor, sizeof(htmlAnchor), "\n"); snprintf(buf, sizeof(buf), ""TABLE_ON"\n" "\n" *************** *** 1574,1579 **** --- 1597,1603 ---- sendString(buf); sendString("
    " "%s1>Host%s%s2>IP Address%s
    "TABLE_OFF"\n"); + sendString("\n"); } else printNoDataYet(); } *************** *** 1585,1590 **** --- 1609,1616 ---- char buf[BUF_SIZE]; int numSessions; + printHTMLheader("Active TCP Sessions", 0); + for(idx=1, numSessions=0; idx\n"); sendString(""TABLE_ON"" "" "" *************** *** 1668,1676 **** } if(numSessions > 0) sendString("
    ClientServer
    "TABLE_OFF"

    \n"); else ! sendString("

    No Active TCP Sessions\n"); } --- 1695,1706 ---- } if(numSessions > 0) + { sendString(""TABLE_OFF"

    \n"); + sendString("\n"); + } else ! printFlagedWarning("No Active TCP Sessions"); } *************** *** 1682,1687 **** --- 1712,1719 ---- u_int i, j, idx1, hostsNum=0, numPorts=0; char buf[BUF_SIZE]; + printHTMLheader("IP Protocol Subnet Usage", 0); + memset(clientPorts, 0, sizeof(clientPorts)); memset(serverPorts, 0, sizeof(serverPorts)); *************** *** 1707,1712 **** --- 1739,1745 ---- /* Hosts are now in a contiguous structure (hosts[])... */ + sendString("

    \n"); sendString(""TABLE_ON"" "\n"); *************** *** 1748,1753 **** --- 1781,1787 ---- } /* for */ sendString("
    ServiceClientsServers
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } *************** *** 1839,1858 **** sign = "-"; if(mode == SHORT_FORMAT) { ! sendString("

    IP Protocol Distribution" ! "


    \n"); #ifdef HAVE_GDCHART ! sendString("

    \n"); #endif ! sendString("

    Local Traffic

    \n"); total = (float)(device[actualReportDeviceId].tcpGlobalTrafficStats.local+ device[actualReportDeviceId].udpGlobalTrafficStats.local)/1024; if(total == 0) printNoDataYet(); else { sendString(""TABLE_ON"" "\n"); if(total == 0) total = 1; /* Avoids divisions by zero */ --- 1873,1892 ---- sign = "-"; if(mode == SHORT_FORMAT) { ! printSectionTitle("IP Protocol Distribution"); #ifdef HAVE_GDCHART ! sendString("
    \n

    \n

    \n"); #endif ! printSectionTitle("Local Traffic"); total = (float)(device[actualReportDeviceId].tcpGlobalTrafficStats.local+ device[actualReportDeviceId].udpGlobalTrafficStats.local)/1024; if(total == 0) printNoDataYet(); else { + sendString("
    \n"); sendString(""TABLE_ON"
    IP ProtocolDataPercentage
    " "\n"); if(total == 0) total = 1; /* Avoids divisions by zero */ *************** *** 1886,1891 **** --- 1920,1926 ---- } sendString("
    IP ProtocolDataPercentage
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } /* ********************************************************** */ *************** *** 1893,1903 **** total = (float)(device[actualReportDeviceId].tcpGlobalTrafficStats.remote2local+ device[actualReportDeviceId].udpGlobalTrafficStats.remote2local)/1024; ! sendString("

    Remote to Local Traffic

    \n"); if(total == 0) printNoDataYet(); else { sendString(""TABLE_ON"" "\n"); --- 1928,1939 ---- total = (float)(device[actualReportDeviceId].tcpGlobalTrafficStats.remote2local+ device[actualReportDeviceId].udpGlobalTrafficStats.remote2local)/1024; ! printSectionTitle("Remote to Local Traffic"); if(total == 0) printNoDataYet(); else { + sendString("
    \n"); sendString(""TABLE_ON"
    IP ProtocolDataPercentage
    " "\n"); *************** *** 1931,1947 **** COLOR_1, remainingTraffic, percentage); } sendString("
    IP ProtocolDataPercentage
    "TABLE_OFF"\n

    \n"); } /* ********************************************************** */ ! sendString("

    Local to Remote Traffic

    \n"); total = (float)(device[actualReportDeviceId].tcpGlobalTrafficStats.local2remote+ device[actualReportDeviceId].udpGlobalTrafficStats.local2remote)/1024; if(total == 0) printNoDataYet(); else { sendString(""TABLE_ON"" "\n"); --- 1967,1985 ---- COLOR_1, remainingTraffic, percentage); } sendString("
    IP ProtocolDataPercentage
    "TABLE_OFF"\n

    \n"); + sendString("\n"); } /* ********************************************************** */ ! printSectionTitle("Local to Remote Traffic"); total = (float)(device[actualReportDeviceId].tcpGlobalTrafficStats.local2remote+ device[actualReportDeviceId].udpGlobalTrafficStats.local2remote)/1024; if(total == 0) printNoDataYet(); else { + sendString("

    \n"); sendString(""TABLE_ON"" "\n"); *************** *** 1975,1992 **** COLOR_1, remainingTraffic, percentage); } sendString("
    IP ProtocolDataPercentage
    "TABLE_OFF"

    \n"); } } else { total = (float)device[actualReportDeviceId].ipBytes/1024; /* total is expressed in KBytes */ ! sendString("

    " ! "Global IP Protocol Distribution" ! "

    \n"); if(total == 0) printNoDataYet(); else { sendString(""TABLE_ON"" "
    " "IP ProtocolData" --- 2013,2030 ---- COLOR_1, remainingTraffic, percentage); } sendString("
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } } else { total = (float)device[actualReportDeviceId].ipBytes/1024; /* total is expressed in KBytes */ ! printSectionTitle("Global IP Protocol Distribution"); if(total == 0) printNoDataYet(); else { + sendString("
    \n"); sendString(""TABLE_ON"" "\n"); #endif sendString("
    " "IP ProtocolData" *************** *** 2023,2031 **** "
    "TABLE_OFF"

    \n"); } } - sendString("

    "); } /* ************************ */ --- 2061,2069 ---- "\n"); #endif sendString(""TABLE_OFF"

    \n"); + sendString("

    \n"); } } } /* ************************ */ *************** *** 2041,2047 **** return; } ! sendString("

    Global Protocol Distribution

    \n"); sendString("

    "TABLE_ON"" "\n"); snprintf(buf, sizeof(buf), "\n"); #endif ! sendString("
    ProtocolDataPercentage
    IP%s" --- 2079,2086 ---- return; } ! printSectionTitle("Global Protocol Distribution"); ! sendString("
    \n"); sendString("

    "TABLE_ON"" "\n"); snprintf(buf, sizeof(buf), "\n"); #endif ! sendString("
    ProtocolDataPercentage
    IP%s" *************** *** 2104,2110 **** "
    "TABLE_OFF"

    \n"); } /* ************************ */ --- 2143,2150 ---- "
    "TABLE_OFF"

    \n"); ! sendString("

    \n"); } /* ************************ */ *************** *** 2122,2143 **** && (processes[i]->pid == processPid)) break; - printHTTPheader(); if(processes[i]->pid != processPid) { ! snprintf(buf, sizeof(buf), "

    Unable to find process PID %d" ! "

    \n", processPid); ! sendString(buf); #ifdef MULTITHREADED releaseMutex(&lsofMutex); #endif return; } ! snprintf(buf, sizeof(buf), "

    Info about process %s" ! "

    \n", processes[i]->command); ! sendString(buf); sendString(""TABLE_ON""); snprintf(buf, sizeof(buf), "", getRowColor()); --- 2162,2181 ---- && (processes[i]->pid == processPid)) break; if(processes[i]->pid != processPid) { ! snprintf(buf, sizeof(buf), "Unable to find process PID %d", processPid); ! printHTMLheader(buf, 0); #ifdef MULTITHREADED releaseMutex(&lsofMutex); #endif return; } ! snprintf(buf, sizeof(buf), "Info about process %s", processes[i]->command); ! printHTMLheader(buf, 0); + sendString("
    \n"); sendString(""TABLE_ON"
    User Name
    "); snprintf(buf, sizeof(buf), "", getRowColor()); *************** *** 2211,2217 **** numEntries++; } ! sendString("\n
    User Name
    "TABLE_OFF"

    \n"); #ifdef MULTITHREADED releaseMutex(&lsofMutex); --- 2249,2256 ---- numEntries++; } ! sendString("\n"TABLE_OFF"

    \n"); ! sendString("\n"); #ifdef MULTITHREADED releaseMutex(&lsofMutex); *************** *** 2227,2239 **** ProcessInfo *processesList[MAX_NUM_PROCESSES]; UsersTraffic usersTraffic[256], *usersTrafficList[256]; - printHTTPheader(); - /* ************************ */ ! sendString("

    Local Network Usage by Process" ! "

    \n"); snprintf(buf, sizeof(buf), ""TABLE_ON"" "" "" --- 2266,2276 ---- ProcessInfo *processesList[MAX_NUM_PROCESSES]; UsersTraffic usersTraffic[256], *usersTrafficList[256]; /* ************************ */ ! printHTMLheader("Local Network Usage by Process", 0); + sendString("
    \n"); snprintf(buf, sizeof(buf), ""TABLE_ON"
    ProcessPID
    " "" "" *************** *** 2290,2301 **** } sendString("
    ProcessPID
    "TABLE_OFF"

    \n"); /* ************************ */ ! sendString("\n

    Local Network Usage by Port" ! "

    \n"); sendString(""TABLE_ON"\n"); for(i=0; i"TABLE_OFF"

    \n"); + sendString("\n"); /* ************************ */ ! printSectionTitle("Local Network Usage by Port"); + sendString("

    \n"); sendString(""TABLE_ON"
    PortProcesses
    \n"); for(i=0; i"); } ! sendString("
    PortProcesses
    "TABLE_OFF"

    \n\n"); /* ******************************* */ --- 2355,2362 ---- sendString(""); } ! sendString(""TABLE_OFF"

    \n"); ! sendString("\n"); /* ******************************* */ *************** *** 2328,2336 **** if(numUsers > maxNumLines) numUsers = maxNumLines; ! sendString("

    Local Network Usage by User" ! "

    \n"); sendString(""TABLE_ON"" "\n"); --- 2367,2375 ---- if(numUsers > maxNumLines) numUsers = maxNumLines; ! printSectionTitle("Local Network Usage by User"); ! sendString("
    \n"); sendString(""TABLE_ON"
    UserTraffic in/out
    " "\n"); *************** *** 2344,2350 **** sendString(buf); } ! sendString("
    UserTraffic in/out
    "TABLE_OFF"

    \n"); } #ifdef MULTITHREADED --- 2383,2390 ---- sendString(buf); } ! sendString(""TABLE_OFF"

    \n"); ! sendString("\n"); } #ifdef MULTITHREADED *************** *** 2361,2366 **** --- 2401,2408 ---- TrafficCounter minTraffic=(TrafficCounter)LONG_MAX, maxTraffic=0, avgTraffic; TrafficCounter avgTrafficLow, avgTrafficHigh, tmpCounter; + printHTMLheader("IP Subnet Traffic Matrix", 0); + for(i=1; i<255; i++) { activeHosts[i] = 0; for(j=1; j<255; j++) { *************** *** 2374,2379 **** --- 2416,2422 ---- if(activeHosts[i] == 1) { if(numEntries == 1) + sendString("

    \n"); sendString(""TABLE_ON"\n"); *************** *** 2452,2457 **** --- 2495,2501 ---- } sendString("
     F " "  To
     r
     o
     m
    "TABLE_OFF"\n

    \n"); + sendString("

    \n"); } /* ************************ */ *************** *** 2462,2472 **** time_t tmpTime; struct tm t; ! printHTTPheader(); ! sendString("

    Throughput Statistics Matrix

    \n"); switch(sortedColumn) { case 1: sendString(""TABLE_ON"\n" "" "" --- 2506,2516 ---- time_t tmpTime; struct tm t; ! printHTMLheader("Throughput Statistics Matrix", 0); switch(sortedColumn) { case 1: + sendString("
    \n"); sendString(""TABLE_ON"
    Sampling PeriodAverage Thpt
    \n" "" "" *************** *** 2576,2581 **** --- 2620,2626 ---- printNoDataYet(); return; } else { + sendString("
    \n"); sendString(""TABLE_ON"
    Sampling PeriodAverage Thpt
    \n" "" "" *************** *** 2682,2687 **** --- 2727,2733 ---- } sendString("
    Sampling PeriodAverage Thpt
    "TABLE_OFF"\n"); + sendString("

    \n"); } /* ************************ */ *************** *** 2689,2702 **** void printThptStats(int sortedColumn _UNUSED_) { char tmpBuf[128]; ! printHTTPheader(); ! sendString("

    Throughput Statistics

    \n"); if(device[actualReportDeviceId].numThptSamples == 0) { printNoDataYet(); return; } #ifdef HAVE_GDCHART sendString("" "
    \n"); --- 2735,2749 ---- void printThptStats(int sortedColumn _UNUSED_) { char tmpBuf[128]; ! printHTMLheader("Throughput Statistics", 0); if(device[actualReportDeviceId].numThptSamples == 0) { printNoDataYet(); return; } + sendString("

    \n"); + #ifdef HAVE_GDCHART sendString("" "
    \n"); *************** *** 2739,2744 **** --- 2786,2792 ---- } #endif } + sendString("
    \n"); } /* ************************ */ *************** *** 2890,2899 **** statsEntry->igmpRcvd += el->igmpReceived; } /* for(;;) */ ! printHTTPheader(); if(numEntries == 0) { - sendString("

    Internet Domain Stats

    \n"); printNoDataYet(); return; } --- 2938,2951 ---- statsEntry->igmpRcvd += el->igmpReceived; } /* for(;;) */ ! if((domainName == NULL) || (numEntries == 0)) { ! snprintf(buf, sizeof(buf), "Internet Domain Stats"); ! } else { ! snprintf(buf, sizeof(buf), "Stats for Domain %s", domainName); ! } ! printHTMLheader(buf, 0); if(numEntries == 0) { printNoDataYet(); return; } *************** *** 2909,2921 **** totBytesRcvd = 1; if(domainName == NULL) { - sendString("

    Internet Domain Stats

    \n"); snprintf(htmlAnchor, sizeof(htmlAnchor), "

    Stats for " - "Domain %s

    \n", domainName); - sendString(buf); snprintf(htmlAnchor, sizeof(htmlAnchor), " */ + sendString("

    \n"); snprintf(buf, sizeof(buf), ""TABLE_ON"" "" *************** *** 3143,3149 **** sendString(buf); } ! sendString("
    %s0>Name%s
    "TABLE_OFF"\n"); } --- 3192,3199 ---- sendString(buf); } ! sendString(""TABLE_OFF"\n"); ! sendString("
    \n"); } *************** *** 3168,3176 **** /* ************************* */ void printNoDataYet(void) { ! sendString("

    " ! "

    No Data To Display (yet)" ! "

    \n"); } /* ************************* */ --- 3218,3224 ---- /* ************************* */ void printNoDataYet(void) { ! printFlagedWarning("No Data To Display (yet)"); } /* ************************* */ *************** *** 3180,3193 **** int numEntries=0; FlowFilterList *list = flowsList; ! printHTTPheader(); if(list != NULL) { while(list != NULL) { if(list->pluginStatus.activePlugin) { if(numEntries == 0) { ! sendString("

    Network Flows

    " ! ""TABLE_ON"" ""); } --- 3228,3242 ---- int numEntries=0; FlowFilterList *list = flowsList; ! printHTMLheader(NULL, 0); if(list != NULL) { while(list != NULL) { if(list->pluginStatus.activePlugin) { if(numEntries == 0) { ! printSectionTitle("Network Flows"); ! sendString("
    \n"); ! sendString(""TABLE_ON"
    Flow NamePacketsTraffic
    " ""); } *************** *** 3204,3210 **** } if(numEntries > 0) ! sendString("
    Flow NamePacketsTraffic
    "TABLE_OFF"

    "); } if(numEntries == 0) { --- 3253,3260 ---- } if(numEntries > 0) ! sendString(""TABLE_OFF"\n"); ! sendString("
    \n"); } if(numEntries == 0) { *************** *** 3225,3231 **** char buf[BUF_SIZE], *arrowGif, *sign; char htmlAnchor[64], htmlAnchor1[64]; ! if(theHost == NULL) printHTTPheader(); memset(theMsgs, 0, sizeof(theMsgs)); --- 3275,3281 ---- char buf[BUF_SIZE], *arrowGif, *sign; char htmlAnchor[64], htmlAnchor1[64]; ! if(theHost == NULL) printHTMLheader(NULL, 0); memset(theMsgs, 0, sizeof(theMsgs)); *************** *** 3490,3496 **** hourId = atoi(theDate); updateHostThpt(el, hourId, 0); ! sendString("

    Host Traffic Stats

    \n"TABLE_ON"\n"); sendString(""); sendString(""); sendString(""); --- 3540,3548 ---- hourId = atoi(theDate); updateHostThpt(el, hourId, 0); ! printSectionTitle("Host Traffic Stats"); ! sendString("
    \n"); ! sendString(""TABLE_ON"
    TimeTot. Traffic Sent% Traffic Sent
    \n"); sendString(""); sendString(""); sendString(""); *************** *** 3552,3556 **** --- 3604,3609 ---- printHostHourlyTrafficEntry(el, 23, tcSent, tcRcvd); sendString("
    TimeTot. Traffic Sent% Traffic Sent
    "TABLE_OFF"\n"); + sendString("

    \n"); } *** reportUtils.c.orig Wed Oct 18 09:40:15 2000 --- reportUtils.c Fri Dec 8 19:39:14 2000 *************** *** 200,205 **** --- 200,230 ---- sendString(buf); } + /* ********************************** */ + + void printSectionTitle(char *text) { + char buf[BUF_SIZE]; + + snprintf(buf, BUF_SIZE, + "
    \n" + "

    %s

    \n" + "

    \n", text); + sendString(buf); + } + + /* ********************************** */ + + void printFlagedWarning(char *text) { + char buf[BUF_SIZE]; + + snprintf(buf, BUF_SIZE, + "
    \n" + "

    \n" + "

    %s\n" + "

    \n", text); + sendString(buf); + } + /* ******************************* */ void printHeader(int reportType, int revertOrder, u_int column) { *************** *** 220,234 **** memset(buf, 0, sizeof(buf)); - printHTTPheader(); - if(sortSendMode) { - if(sortSendMode == 1) - sendString("

    Network Traffic: Data Sent

    \n"); - else { - sendString("

    Host Information

    \n"); - return; - } if((reportType == 0) || (reportType == 1)) { if(reportType == 0) { --- 245,251 ---- *************** *** 256,261 **** --- 273,279 ---- if(abs(column) == 0) { arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; } else { arrow[2] = ""; theAnchor[2] = htmlAnchor1; } + sendString("

    \n"); snprintf(buf, BUF_SIZE, ""TABLE_ON"" "\n" "" *************** *** 268,273 **** --- 286,292 ---- if(abs(column) == DOMAIN_DUMMY_IDX_VALUE) { arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; } else { arrow[1] = ""; theAnchor[1] = htmlAnchor1; } + sendString("
    \n"); snprintf(buf, BUF_SIZE, ""TABLE_ON"
    %s"HOST_DUMMY_IDX_STR">Host%s%s"DOMAIN_DUMMY_IDX_STR">Domain%s
    " "" "\n\n", *************** *** 276,282 **** sendString(buf); } else { - sendString("

    Network Traffic: Data Received

    \n"); if((reportType == 0) || (reportType == 1)) { if(reportType == 0) { --- 295,300 ---- *************** *** 304,309 **** --- 322,328 ---- if(abs(column) == 0) { arrow[2] = arrowGif; theAnchor[2] = htmlAnchor; } else { arrow[2] = ""; theAnchor[2] = htmlAnchor1; } + sendString("

    \n"); snprintf(buf, BUF_SIZE, ""TABLE_ON"
    %s"HOST_DUMMY_IDX_STR">Host%s%s"DOMAIN_DUMMY_IDX_STR">Domain%s
    " "\n" "" *************** *** 316,321 **** --- 335,341 ---- if(abs(column) == DOMAIN_DUMMY_IDX_VALUE) { arrow[1] = arrowGif; theAnchor[1] = htmlAnchor; } else { arrow[1] = ""; theAnchor[1] = htmlAnchor1;} + sendString("
    \n"); snprintf(buf, BUF_SIZE, ""TABLE_ON"
    %s"HOST_DUMMY_IDX_STR">Host%s%s"DOMAIN_DUMMY_IDX_STR">Domain%s
    " "" "\n\n", *************** *** 1356,1363 **** case 4: /* Data Rcvd */ switch(sortFilter) { case REMOTE_TO_LOCAL_ACCOUNTING: ! a_ = (*a)->bytesReceivedFromRemote; ! b_ = (*b)->bytesReceivedFromRemote; break; case LOCAL_TO_REMOTE_ACCOUNTING: a_ = (*a)->bytesReceivedFromRemote; --- 1376,1383 ---- case 4: /* Data Rcvd */ switch(sortFilter) { case REMOTE_TO_LOCAL_ACCOUNTING: ! a_ = (*a)->bytesReceivedLocally; ! b_ = (*b)->bytesReceivedLocally; break; case LOCAL_TO_REMOTE_ACCOUNTING: a_ = (*a)->bytesReceivedFromRemote; *************** *** 1419,1425 **** +el->nullPktsSent.value+el->nullPktsRcvd.value) == 0)) return; ! sendString("

    TCP Packets Stats

    \n" ""TABLE_ON"

    %s"HOST_DUMMY_IDX_STR">Host%s%s"DOMAIN_DUMMY_IDX_STR">Domain%s
    " "" "\n"); --- 1439,1446 ---- +el->nullPktsSent.value+el->nullPktsRcvd.value) == 0)) return; ! printSectionTitle("TCP Packets Stats"); ! sendString("
    \n" ""TABLE_ON"
    FlagsPkts SentPkts Received
    " "" "\n"); *************** *** 1464,1469 **** --- 1485,1491 ---- sendString("\n"); } sendString("
    FlagsPkts SentPkts Received
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } /* ************************************ */ *************** *** 1498,1504 **** el->udpReceivedLocally+el->udpReceivedFromRemote) == 0) return; ! sendString("

    IP Protocol Distribution

    \n" ""TABLE_ON"" "" "\n"); --- 1520,1527 ---- el->udpReceivedLocally+el->udpReceivedFromRemote) == 0) return; ! printSectionTitle("IP Protocol Distribution"); ! sendString("
    \n" ""TABLE_ON"
    ProtocolData SentData Received
    " "" "\n"); *************** *** 1578,1583 **** --- 1601,1607 ---- 100*((float)SD(el->otherReceived, totalReceived))); /*#endif */ sendString("
    ProtocolData SentData Received
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } /* ************************************ */ *************** *** 1599,1605 **** if(ok) { struct hostTraffic *el1; ! sendString("

    Last Contacted Peers

    \n" "
    \n"); for(numEntries = 0, i=0; i\n" "
    \n"); for(numEntries = 0, i=0; i"TABLE_OFF"\n"); sendString("

    \n"); + sendString("\n"); } /* ok */ } } *************** *** 1701,1707 **** static char _sport[8], _dport[8]; if((el->tcpSessionList != NULL) || (el->udpSessionList != NULL)) { ! sendString("

    IP Session History

    \n"); } for(scanIdx=0; scanIdx<2; scanIdx++) --- 1727,1733 ---- static char _sport[8], _dport[8]; if((el->tcpSessionList != NULL) || (el->udpSessionList != NULL)) { ! printSectionTitle("IP Session History"); } for(scanIdx=0; scanIdx<2; scanIdx++) *************** *** 1742,1747 **** --- 1768,1774 ---- } if(numSessions == 0) { + sendString("

    \n"); snprintf(buf, sizeof(buf), ""TABLE_ON"\n" "" "
    %s ServiceRole" *************** *** 1801,1807 **** --- 1828,1837 ---- } if(numSessions > 0) + { sendString("
    "TABLE_OFF"

    \n"); + sendString("

    \n"); + } } /* while */ *************** *** 1821,1827 **** char fragStrSent[64], fragStrRcvd[64]; if(numSessions == 0) { ! sendString("

    Active TCP Sessions

    \n"); sendString(""TABLE_ON"" "" "" --- 1851,1858 ---- char fragStrSent[64], fragStrRcvd[64]; if(numSessions == 0) { ! printSectionTitle("Active TCP Sessions"); ! sendString("
    \n"); sendString(""TABLE_ON"
    Local PortRemote Peer:Port
    " "" "" *************** *** 1957,1963 **** --- 1988,1997 ---- } if(numSessions > 0) + { sendString("
    Local PortRemote Peer:Port
    "TABLE_OFF"

    \n"); + sendString("\n"); + } } /* ************************************ */ *************** *** 1972,1991 **** #endif if(el->hostSymIpAddress[0] == '\0') ! snprintf(buf, sizeof(buf), "

    Info about" ! " %s

    \n", el->ethAddressString); else ! snprintf(buf, sizeof(buf), "

    Info about" ! " %s

    \n", el->hostNumIpAddress, el->hostSymIpAddress); #ifdef MULTITHREADED releaseMutex(&addressResolutionMutex); #endif ! sendString(buf); sendString("

    "TABLE_ON"\n"); if(el->hostNumIpAddress[0] != '\0') { --- 2006,2024 ---- #endif if(el->hostSymIpAddress[0] == '\0') ! snprintf(buf, sizeof(buf), "Info about %s", el->ethAddressString); else ! snprintf(buf, sizeof(buf), "Info about %s", el->hostNumIpAddress, el->hostSymIpAddress); #ifdef MULTITHREADED releaseMutex(&addressResolutionMutex); #endif ! printHTMLheader(buf, 0); + sendString("
    \n"); sendString("

    "TABLE_ON"

    \n"); if(el->hostNumIpAddress[0] != '\0') { *************** *** 2316,2321 **** --- 2349,2355 ---- sendString("\n"); sendString("
    "TABLE_OFF"

    \n"); + sendString("

    \n"); } /* ************************************ */ *************** *** 2424,2431 **** tot += el->httpStats->numLocalReqSent+el->httpStats->numRemoteReqSent; if(tot > 0) { ! sendString("

    IP Service Stats: Client Role

    \n"); sendString(""TABLE_ON"\n" "" "" --- 2458,2466 ---- tot += el->httpStats->numLocalReqSent+el->httpStats->numRemoteReqSent; if(tot > 0) { ! printSectionTitle("IP Service Stats: Client Role"); + sendString("
    \n"); sendString(""TABLE_ON"
     # Loc. Req. Sent
    \n" "" "" *************** *** 2440,2445 **** --- 2475,2481 ---- if(el->httpStats) printServiceStats("HTTP", el->httpStats, 1); sendString("
     # Loc. Req. Sent
    "TABLE_OFF"\n"); + sendString("

    \n"); } /* ************ */ *************** *** 2453,2460 **** tot += el->httpStats->numLocalReqRcvd+el->httpStats->numRemoteReqRcvd; if(tot > 0) { ! sendString("

    IP Service Stats: Server Role

    \n"); sendString("

    "TABLE_ON"\n" "" "" --- 2489,2497 ---- tot += el->httpStats->numLocalReqRcvd+el->httpStats->numRemoteReqRcvd; if(tot > 0) { ! printSectionTitle("IP Service Stats: Server Role"); + sendString("
    \n"); sendString("

    "TABLE_ON"

     # Loc. Req. Rcvd
    \n" "" "" *************** *** 2469,2474 **** --- 2506,2512 ---- if(el->httpStats) printServiceStats("HTTP", el->httpStats, 0); sendString("
     # Loc. Req. Rcvd
    "TABLE_OFF"\n"); + sendString("\n"); } } *** ssl.c.orig Wed Oct 18 09:39:57 2000 --- ssl.c Sat Dec 9 16:21:24 2000 *************** *** 148,153 **** --- 148,157 ---- } #ifdef DEBUG + { + /* the following declarations are needed to put debug mode to work */ + X509 *peer; + char *str, buf[BUFSIZ]; peer=SSL_get_peer_certificate(con); if (peer != NULL) { traceEvent(TRACE_INFO, "Client certificate\n"); *************** *** 166,171 **** --- 170,176 ---- if (SSL_ctrl(con,SSL_CTRL_GET_FLAGS,0,NULL) & TLS1_FLAGS_TLS_PADDING_BUG) traceEvent(TRACE_WARNING, "Peer has incorrect TLSv1 block padding\n"); + } #endif return(1); *** util.c.orig Tue Oct 24 09:00:05 2000 --- util.c Sat Dec 9 16:23:26 2000 *************** *** 482,488 **** networkMask = ~networkMask; #ifdef DEBUG ! traceEvent(TRACE_INFO "Nw=%08X - Mask: %08X [%08X]\n", network, networkMask, (network & networkMask)); #endif if((networkMask >= 0xFFFFFF00) /* Courtesy of Roy-Magne Mo */ && ((network & networkMask) != network)) { --- 482,488 ---- networkMask = ~networkMask; #ifdef DEBUG ! traceEvent(TRACE_INFO, "Nw=%08X - Mask: %08X [%08X]\n", network, networkMask, (network & networkMask)); #endif if((networkMask >= 0xFFFFFF00) /* Courtesy of Roy-Magne Mo */ && ((network & networkMask) != network)) { *************** *** 1350,1360 **** sockFd = fileno(fd); if(additionalInfo != NULL) additionalInfo[0]='\0'; - wait_time.tv_sec = PIPE_READ_TIMEOUT, wait_time.tv_usec = 0; while(1) { FD_ZERO(&mask); FD_SET(sockFd, &mask); if(select(sockFd+1, &mask, 0, 0, &wait_time) == 0) { break; /* Timeout */ --- 1350,1360 ---- sockFd = fileno(fd); if(additionalInfo != NULL) additionalInfo[0]='\0'; while(1) { FD_ZERO(&mask); FD_SET(sockFd, &mask); + wait_time.tv_sec = PIPE_READ_TIMEOUT; wait_time.tv_usec = 0; if(select(sockFd+1, &mask, 0, 0, &wait_time) == 0) { break; /* Timeout */ *************** *** 1363,1368 **** --- 1363,1372 ---- if((operatingSystem = fgets(line, 383, fd)) == NULL) break; + len = strlen(operatingSystem); + if ((operatingSystem[len-1] == '\n') || (operatingSystem[len-1] == '\r')) + operatingSystem[len-1] = '\0'; /* strip NL or CR from end-of-line */ + if(strncmp(operatingSystem, OS_GUESS, strlen(OS_GUESS)) == 0) { operatingSystem = &operatingSystem[strlen(OS_GUESS)]; found = 1; *************** *** 1403,1412 **** --- 1407,1427 ---- } } + memset(staticOsName, 0, sizeof(staticOsName)); + if(found) { + len = strlen(operatingSystem); + strncpy(staticOsName, operatingSystem, len); + staticOsName[sizeof(staticOsName)-1] = '\0'; + #ifdef DEBUG + traceEvent(TRACE_INFO, "OS is: '%s'\n", operatingSystem); + #endif + } + /* Read remaining data (if any) */ while(1) { FD_ZERO(&mask); FD_SET(sockFd, &mask); + wait_time.tv_sec = PIPE_READ_TIMEOUT; wait_time.tv_usec = 0; if(select(sockFd+1, &mask, 0, 0, &wait_time) == 0) { break; /* Timeout */ *************** *** 1418,1433 **** } pclose(fd); - memset(staticOsName, 0, sizeof(staticOsName)); - - if(found) { - #ifdef DEBUG - traceEvent(TRACE_INFO, "OS is: '%s'\n", operatingSystem); - #endif - len = strlen(operatingSystem); - strncpy(staticOsName, operatingSystem, len-1); - } - return(staticOsName); #endif /* WIN32 */ } --- 1433,1438 ---- *************** *** 1489,1494 **** --- 1494,1500 ---- int name_interpret(char *in, char *out) { int ret, len = (*in++) / 2; + char *b=out; *out=0; *************** *** 1505,1512 **** in += 2; out++; } *out = 0; ! ret = out[-1]; return(ret); } --- 1511,1521 ---- in += 2; out++; } + ret = *(--out); *out = 0; ! ! /* Trim trailing whitespace from the returned string */ ! for(out--; out>=b && *out==' '; out--) *out = '\0'; return(ret); } *** webInterface.c.orig Tue Oct 24 04:33:24 2000 --- webInterface.c Fri Dec 8 20:30:59 2000 *************** *** 167,174 **** flows->pluginStatus.activePlugin = newPluginStatus; if(!printHeader) { ! /* printHTTPheader(); */ ! sendString("

    Available Plugins

    \n

    " ""TABLE_ON"\n"); sendString("" "" --- 167,174 ---- flows->pluginStatus.activePlugin = newPluginStatus; if(!printHeader) { ! printHTMLheader("Available Plugins", 0); ! sendString("
    \n" ""TABLE_ON"
    NameDescriptionVersion
    \n"); sendString("" "" *************** *** 201,211 **** } if(!printHeader) { ! sendString("

    " ! "No Plugins available

    " ! "

    \n"); } else { sendString("

    NameDescriptionVersion
    "TABLE_OFF"

    \n"); } } --- 201,210 ---- } if(!printHeader) { ! printHTMLheader("No Plugins available", 0); } else { sendString("

    "TABLE_OFF"

    \n"); + sendString("

    \n"); } } *************** *** 257,262 **** --- 256,262 ---- #ifdef HAVE_OPENSSL if(sslInitialized) if(FD_ISSET(sock_ssl, fdmask)) + { if(accept_ssl_connection(newSock) == -1) { traceEvent(TRACE_WARNING, "Unable to accept SSL connection\n"); closeNwSocket(&newSock); *************** *** 264,269 **** --- 264,270 ---- } else { newSock = -newSock; } + } #endif /* HAVE_OPENSSL */ #ifdef HAVE_LIBWRAP *************** *** 297,303 **** actualReportDeviceId = 0; #ifdef DEBUG ! numChildren = 0; #endif if(webPort > 0) { --- 298,304 ---- actualReportDeviceId = 0; #ifdef DEBUG ! /* numChildren = 0; gives an error when debug mode is enabled! */ #endif if(webPort > 0) { *************** *** 702,710 **** int i, mwInterface=_interface-1; char buf[BUF_SIZE], *selected; ! sendString("\n
    " ! "

    Network Interface Switch" ! "


    "); if(mergeInterfaces) { snprintf(buf, sizeof(buf), "You can switch among different inferfaces if the -M " --- 703,711 ---- int i, mwInterface=_interface-1; char buf[BUF_SIZE], *selected; ! printHTMLheader("Network Interface Switch", HTML_FLAG_NO_REFRESH); ! ! sendString("


    \n

    \n\n"); if(mergeInterfaces) { snprintf(buf, sizeof(buf), "You can switch among different inferfaces if the -M " *************** *** 739,746 **** --- 740,749 ---- sendString("

     \n\n"); + sendString(""); } + sendString(""); sendString("

    \n"); } *************** *** 810,819 **** /* **************************************** */ void shutdownNtop(void) { ! cleanup(0); ! termAccessLog(); termReports(); } /* **************************************** */ --- 813,823 ---- /* **************************************** */ void shutdownNtop(void) { ! printHTMLheader("ntop is shutting down...", HTML_FLAG_NO_REFRESH); ! closeNwSocket(&newSock); termAccessLog(); termReports(); + cleanup(0); } /* **************************************** */ *************** *** 833,840 **** void printNtopConfigInfo(void) { char buf[BUF_SIZE]; ! sendString("

    Current ntop Configuration

    \n"); sendString("


    "TABLE_ON"\n"); --- 837,845 ---- void printNtopConfigInfo(void) { char buf[BUF_SIZE]; + printHTMLheader("Current ntop Configuration", 0); ! sendString("
    \n"); sendString("


    "TABLE_ON"

    \n"); *************** *** 912,916 **** --- 917,922 ---- #endif sendString("
    "TABLE_OFF"\n"); + sendString("

    \n"); } *** plugins/arpPlugin.c.orig Wed Oct 18 09:38:49 2000 --- plugins/arpPlugin.c Sun Dec 10 09:08:58 2000 *************** *** 242,251 **** arpColumnSort = atoi(url); } ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); ! sendString("" ! "

    Welcome to arpWatch

    \n

    " ""); snprintf(tmpStr, sizeof(tmpStr), "" --- 242,251 ---- arpColumnSort = atoi(url); } ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Welcome to arpWatch", 0); ! sendString("
    \n

    \n" "

    %s?%s1>Host
    "); snprintf(tmpStr, sizeof(tmpStr), "" *************** *** 345,352 **** } ! sendString("
    %s?%s1>Host

    \n"); ! printHTTPtrailer(); } /* ****************************** */ --- 345,353 ---- } ! sendString("\n

    \n"); ! sendString("

    \n"); ! printHTMLtrailer(); } /* ****************************** */ *** plugins/icmpPlugin.c.orig Wed Oct 18 09:38:45 2000 --- plugins/icmpPlugin.c Sun Dec 10 09:20:00 2000 *************** *** 774,780 **** printIcmpPkt(&icmpHostsList[num]); sendString("\n"); ! printHTTPtrailer(); } /* ******************************* */ --- 774,780 ---- printIcmpPkt(&icmpHostsList[num]); sendString("\n"); ! printHTMLtrailer(); } /* ******************************* */ *************** *** 873,880 **** fclose(fd); ! sendHTTPProtoHeader(); ! sendGIFHeaderType(); fd = fopen(fileName, "rb"); for(;;) { --- 873,879 ---- fclose(fd); ! sendHTTPHeader(HTTP_TYPE_GIF, 0); fd = fopen(fileName, "rb"); for(;;) { *************** *** 902,914 **** icmpId = atoi(strtok_r(NULL, "&", &strtokState)); } ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); ! sendString("

    ICMP Statistics

    \n"); if(num == 0) { printNoDataYet(); ! printHTTPtrailer(); return; } --- 901,913 ---- icmpId = atoi(strtok_r(NULL, "&", &strtokState)); } ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("ICMP Statistics", 0); if(num == 0) { printNoDataYet(); ! printHTMLtrailer(); return; } *************** *** 922,927 **** --- 921,927 ---- return; } + sendString("

    \n"); sendString("\n"); snprintf(buf, sizeof(buf), "" "" *************** *** 1181,1187 **** sendString("

    \n"); ! printHTTPtrailer(); free(s); free(r); free(lbls); free(hosts); --- 1181,1187 ---- sendString("

    \n"); ! printHTMLtrailer(); free(s); free(r); free(lbls); free(hosts); *** plugins/lastSeenPlugin.c.orig Thu Sep 21 12:40:07 2000 --- plugins/lastSeenPlugin.c Sun Dec 10 09:29:44 2000 *************** *** 132,140 **** int entry = 0, num_hosts; if (disabled) { ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); ! sendString("

    Plugin Disabled

    \n"); ! printHTTPtrailer(); return; } --- 132,141 ---- int entry = 0, num_hosts; if (disabled) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Status for the \"lastSeen\" Plugin", HTML_FLAG_NO_REFRESH); ! printFlagedWarning("This plugin is disabled."); ! printHTMLtrailer(); return; } *************** *** 144,161 **** return; } ! sendHTTPProtoHeader(); sendHTTPHeaderType(); printHTTPheader(); if ( url && strncmp(url,"P",1)==0 ) { entry = recv(newSock, &postData[0],127,0); postData[entry] = '\0'; addNotes( url+1, &postData[6]); char_ip.s_addr = strtoul(url+1,NULL,10); ! snprintf(tmpStr, sizeof(tmpStr), "

    OK! Added comments for %s." ! "

    \n",intoa(char_ip)); ! sendString(tmpStr); sendString("
    Reload"); ! printHTTPtrailer(); return; } --- 145,162 ---- return; } ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader(NULL, 0); if ( url && strncmp(url,"P",1)==0 ) { entry = recv(newSock, &postData[0],127,0); postData[entry] = '\0'; addNotes( url+1, &postData[6]); char_ip.s_addr = strtoul(url+1,NULL,10); ! snprintf(tmpStr, sizeof(tmpStr), "OK! Added comments for %s.", intoa(char_ip)); ! printSectionTitle(tmpStr); sendString("
    Reload"); ! printHTMLtrailer(); return; } *************** *** 200,206 **** quicksort(( void *)&tablehost[0],entry,sizeof(LsHostInfo),SortLS); num_hosts=entry; entry--; ! sendString("

    Last Seen Statistics

    \n"); sendString("

    %s?%s1>Host
    [Pkt Sent/Rcvd]
    %s?%s2>Echo Req.
    \n"); sendString("\n"); while ( entry >= 0 ) { --- 201,207 ---- quicksort(( void *)&tablehost[0],entry,sizeof(LsHostInfo),SortLS); num_hosts=entry; entry--; ! printSectionTitle("Last Seen Statistics"); sendString("
    HostAddressLastSeenCommentsOptions
    \n"); sendString("\n"); while ( entry >= 0 ) { *************** *** 256,262 **** "
    %u host(s) collected.

    ", num_hosts); sendString(tmpStr); ! printHTTPtrailer(); } /* Adding notes changing the key */ --- 257,263 ---- "
    %u host(s) collected.

    ", num_hosts); sendString(tmpStr); ! printHTMLtrailer(); } /* Adding notes changing the key */ *************** *** 311,321 **** releaseMutex(&gdbmMutex); #endif ! printHTTPheader(); ! sendString("Manage Notes\n"); ! sendString("\n"); ! snprintf(tmp, sizeof(tmp), "

    Notes for %s


    \n",ip_addr); ! sendString(tmp); snprintf(tmp, sizeof(tmp), "
    \n",addr); sendString(tmp); if ( content.dptr ) { --- 312,321 ---- releaseMutex(&gdbmMutex); #endif ! snprintf(tmp, sizeof(tmp), "Notes for %s", ip_addr); ! printHTMLheader(tmp, 0); ! ! sendString("


    \n"); snprintf(tmp, sizeof(tmp), "\n",addr); sendString(tmp); if ( content.dptr ) { *************** *** 327,332 **** --- 327,333 ---- } sendString("

    \n"); sendString("\n"); + sendString("\n"); } static void deletelastSeenURL( char *addr ) { *** plugins/nfsPlugin.c.orig Wed Oct 18 09:38:37 2000 --- plugins/nfsPlugin.c Sun Dec 10 09:31:47 2000 *************** *** 73,79 **** secsDiff = now-nextNfsUpdate+THROUGHPUT_REFRESH_TIME; #ifdef DEBUG ! traceEvent(TRACE_INFO, "Updating NFS thpt (%d)...\n"); #endif for(i=0; i" ! "

    Welcome to nfsWatch

    \n

    "); if(numEntries > 0) { sendString("

    HostAddressLastSeenCommentsOptions
    "); snprintf(tmpStr, sizeof(tmpStr), "" --- 246,256 ---- } } ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("Welcome to nfsWatch", 0); if(numEntries > 0) { + sendString("
    \n"); sendString("
    %s?%s1>Host
    "); snprintf(tmpStr, sizeof(tmpStr), "" *************** *** 303,309 **** printNoDataYet(); } ! printHTTPtrailer(); } /* ****************************** */ --- 302,308 ---- printNoDataYet(); } ! printHTMLtrailer(); } /* ****************************** */ *** plugins/remoteInterface.c.orig Wed Oct 18 09:38:31 2000 --- plugins/remoteInterface.c Sun Dec 10 09:33:38 2000 *************** *** 322,335 **** /* ****************************** */ static void handleRemIntHTTPrequest(char* url _UNUSED_) { ! sendHTTPProtoHeader(); ! sendHTTPHeaderType(); ! printHTTPheader(); ! ! sendString("

    " ! "ntop Remote Interface" ! "

    \n"); ! printHTTPtrailer(); } /* ****************************** */ --- 322,330 ---- /* ****************************** */ static void handleRemIntHTTPrequest(char* url _UNUSED_) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("ntop Remote Interface", 0); ! printHTMLtrailer(); } /* ****************************** */ *** plugins/rmonPlugin.c.orig Wed Oct 18 09:38:11 2000 --- plugins/rmonPlugin.c Sun Dec 10 09:35:02 2000 *************** *** 71,84 **** /* ****************************** */ static void handleRmonHTTPrequest(char* url _UNUSED_) { ! sendHTTPProtoHeader(); ! sendHTTPHeaderType(); ! printHTTPheader(); ! ! sendString("

    " ! "ntop RMON Interface" ! "

    \n"); ! printHTTPtrailer(); } /* ****************************** */ --- 71,79 ---- /* ****************************** */ static void handleRmonHTTPrequest(char* url _UNUSED_) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("ntop RMON Interface", 0); ! printHTMLtrailer(); } /* ****************************** */ *************** *** 140,155 **** /* ****************************** */ static void handleRmonHTTPrequest(char* url) { ! sendHTTPProtoHeader(); ! sendHTTPHeaderType(); ! printHTTPheader(); ! ! sendString("

    " ! "ntop RMON Interface" ! "

    \n" ! "

    This plugin is disabled as UCD-SNMP is missing" ! "

    \n"); ! printHTTPtrailer(); } /* ****************************** */ --- 135,144 ---- /* ****************************** */ static void handleRmonHTTPrequest(char* url) { ! sendHTTPHeader(HTTP_TYPE_HTML, 0); ! printHTMLheader("ntop RMON Interface", 0); ! printFlagedWarning("This plugin is disabled as UCD-SNMP is missing"); ! printHTMLtrailer(); } /* ****************************** */ *** plugins/wapPlugin.c.orig Wed Oct 18 09:38:05 2000 --- plugins/wapPlugin.c Sun Dec 10 09:36:50 2000 *************** *** 26,36 **** /* ****************************** */ void printWMLheader(void) { ! char tmpStr[64]; ! ! sendString("HTTP/1.0 200 OK\n"); ! snprintf(tmpStr, 64, "Server: ntop/%s (%s)\n", version, osName); ! sendString(tmpStr); sendString("Content-Type: text/vnd.wap.wml;charset=UTF-8\n\n"); } --- 26,32 ---- /* ****************************** */ void printWMLheader(void) { ! sendHTTPHeader(HTTP_TYPE_NONE, HTTP_FLAG_NO_CACHE_CONTROL | HTTP_FLAG_MORE_FIELDS); sendString("Content-Type: text/vnd.wap.wml;charset=UTF-8\n\n"); } *** intop/intop.1.orig Tue Aug 29 14:45:44 2000 --- intop/intop.1 Thu Nov 16 13:08:17 2000 *************** *** 22,27 **** --- 22,32 ---- .\" along with this program; if not, write to the Free Software .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. .\" + . + .de It + .TP 1.2 + .B "\\$1 " + .. .if t .nr Dd .4v .if n .nr Dd 1v .de Sp
    %s?%s1>Host