📄 connectionhandler.cpp
字号:
fdt.tunnel(proxysock.getFD(), peerconn.getFD()); // not expected to exception docsize = fdt.throughput; decideHowToLog(clientuser, clientip, url.toCharArray(), header.port, exceptionreason, header.requesttype().toCharArray(), docsize, o.ll, false, isexception, o.log_exception_hits, false, &thestart, cachehit, 200, mimetype); } catch (exception& e) {} try { proxysock.close(); // close connection to proxy } catch (exception& e) {} return; // connection dealt with so exit } if (!checkme.isItNaughty) { proxysock.readyForOutput(10); header.out(&proxysock); // send header to proxy proxysock.checkForInput(120); docheader.in(&proxysock); // get header from proxy #ifdef DGDEBUG std::cout << "got header from proxy" << std::endl; #endif wasrequested = true; // so we know where we are later if (isbypass) { docheader.setCookie("GBYPASS", hashedCookie(&urldomain, filtergroup, &clientip, bypasstimestamp).toCharArray()); } mimetype = docheader.getcontenttype().toCharArray(); unsigned int p = (*o.fg[filtergroup]).banned_mimetype_list;// i = o.banned_mimetype_list.findInList((char*)mimetype.c_str()); if ((i = (*o.lm.l[p]).findInList((char*)mimetype.c_str())) != NULL) { checkme.whatIsNaughty = o.language_list.getTranslation(800); // Banned MIME Type: checkme.whatIsNaughty += i; checkme.whatIsNaughtyLog = checkme.whatIsNaughty; checkme.isItNaughty = true; } #ifdef DGDEBUG std::cout << mimetype.length() << std::endl; std::cout << ":" << mimetype; std::cout << ":" << std::endl; #endif if (!checkme.isItNaughty && !docheader.isRedirection()) { // Can't ban file extensions of URLs that just redirect String tempurl = urld; String tempdispos = docheader.disposition(); if (tempdispos.length() > 1) { // dispos filename must take presidense #ifdef DGDEBUG std::cout << "Disposition filename:" << tempdispos << ":" << std::endl; #endif // The function expects a url so we have to // generate a psudo one. tempdispos = "http://foo.bar/" + tempdispos; if ((i = (*o.fg[filtergroup]).inBannedExtensionList(tempdispos)) != NULL) { checkme.whatIsNaughty = o.language_list.getTranslation(900); // Banned extension: checkme.whatIsNaughty += i; checkme.whatIsNaughtyLog = checkme.whatIsNaughty; checkme.isItNaughty = true; } } else { if (!tempurl.contains("?")) {// i = o.inBannedExtensionList(tempurl); if ((i = (*o.fg[filtergroup]).inBannedExtensionList(tempurl)) != NULL) { checkme.whatIsNaughty = o.language_list.getTranslation(900); // Banned extension: checkme.whatIsNaughty += i; checkme.whatIsNaughtyLog = checkme.whatIsNaughty; checkme.isItNaughty = true; } } if (String(mimetype.c_str()).contains("application/")) { while (tempurl.endsWith("?")) { tempurl.chop(); } while(tempurl.contains("/")) { // no slash no url if ((i = (*o.fg[filtergroup]).inBannedExtensionList(tempurl)) != NULL) { checkme.whatIsNaughty = o.language_list.getTranslation(900); // Banned extension: checkme.whatIsNaughty += i; checkme.whatIsNaughtyLog = checkme.whatIsNaughty; checkme.isItNaughty = true; break; } while (tempurl.contains("/") && !tempurl.endsWith("?")) { tempurl.chop(); } tempurl.chop(); // get rid of the ? } } } } if (!checkme.isItNaughty && forceauthrequest && !docheader.authRequired()) { requestChecks(&header, &checkme, &urld, &clientip, &clientuser, filtergroup, &ispostblock); } if (docheader.iscontenttype("text") && !checkme.isItNaughty) { // here we check if its a known good one // if so we skip content checking waschecked = true; proxysock.checkForInput(120); if (docheader.isCompressed()) { docbody.setDecompress(docheader.contentEncoding()); } #ifdef DGDEBUG std::cout << docheader.contentEncoding() << std::endl; std::cout << "about to get body from proxy" << std::endl; #endif pausedtoobig = docbody.in(&proxysock); // get body from proxy #ifdef DGDEBUG if (pausedtoobig) { std::cout << "got PARTIAL body from proxy" << std::endl; } else { std::cout << "got body from proxy" << std::endl; } #endif int dblen = docbody.length(); docsize = dblen; if (o.url_cache_number > 0) { if (wasClean(urld)) { wasclean = true; cachehit = true; #ifdef DGDEBUG std::cout << "url was clean skipping content checking" << std::endl; #endif } // was not clean else { #ifdef DGDEBUG system("date"); #endif if (dblen <= o.max_content_filter_size || o.max_content_filter_size == 0) { checkme.checkme(&docbody); // content filtering } #ifdef DGDEBUG else { std::cout << "content length large so skipping content filtering" << std::endl; } system("date"); #endif } } // urlcache is not used else { #ifdef DGDEBUG system("date"); #endif if (dblen <= o.max_content_filter_size || o.max_content_filter_size == 0) { checkme.checkme(&docbody); // content filtering } #ifdef DGDEBUG else { std::cout << "content length large so skipping content filtering" << std::endl; } system("date"); #endif } bool contentmodified = false; if (dblen <= o.max_content_filter_size || o.max_content_filter_size == 0) { contentmodified = docbody.contentRegExp(filtergroup); // content modifying // uses global variable } #ifdef DGDEBUG else { std::cout << "content length large so skipping content modifying" << std::endl; } system("date"); #endif if (contentmodified) { #ifdef DGDEBUG std::cout << "content modification made" << std::endl; #endif if (docheader.isCompressed()) { docheader.removeEncoding(dblen); // need to modify header to mark as not compressed // it also modifies Content-Length as well } else { docheader.setContentLength(docbody.buffer_length); } } else { docbody.swapbacktocompressed(); // if we've not modified it might as well go back to // the original compressed version (if there) and send // that to the browser } // here if its OK then request addition to good url database } } if (checkme.isException) { isexception = true; exceptionreason = checkme.whatIsNaughtyLog; } if (docheader.isRedirection()) { checkme.isItNaughty = false; } if (o.url_cache_number > 0) { if (!wasclean && !checkme.isItNaughty && docheader.iscontenttype("text") && header.requesttype() == "GET") { addToClean(urld); } } if (checkme.isItNaughty && !isbypass) { // then we deny, unless we were told to bypass the block decideHowToLog(clientuser, clientip, url.toCharArray(), header.port, checkme.whatIsNaughtyLog, header.requesttype().toCharArray(), docsize, o.ll, true, false, false, false, &thestart, cachehit, 403, mimetype); if (denyAccess(&peerconn, &proxysock, &header, &docheader, &url, &checkme, &clientuser, &clientip, filtergroup, ispostblock)) { return; // not stealth mode } // if get here in stealth mode } if (wasrequested == false) { proxysock.readyForOutput(10); // exceptions on error/timeout header.out(&proxysock); // exceptions on error/timeout proxysock.checkForInput(120); // exceptions on error/timeout docheader.in(&proxysock); // get reply header from proxy } #ifdef DGDEBUG std::cout << "sending header to client" << std::endl; #endif peerconn.readyForOutput(10); // exceptions on error/timeout docheader.out(&peerconn); // send header to client #ifdef DGDEBUG std::cout << "sent header to client" << std::endl; #endif if (waschecked) { if(!docheader.authRequired() && !pausedtoobig) { decideHowToLog(clientuser, clientip, url.toCharArray(), header.port, exceptionreason, header.requesttype().toCharArray(), docsize, o.ll, false, isexception, o.log_exception_hits, docheader.iscontenttype("text"), &thestart, cachehit, 200, mimetype); } #ifdef DGDEBUG std::cout << "sending body to client" << std::endl; #endif peerconn.readyForOutput(10); // check for error/timeout needed docbody.out(&peerconn); // send doc body to client #ifdef DGDEBUG if (pausedtoobig) { std::cout << "sent PARTIAL body to client" << std::endl; } else { std::cout << "sent body to client" << std::endl; } #endif if (pausedtoobig) { #ifdef DGDEBUG std::cout << "about to start tunnel to send the rest" << std::endl; #endif FDTunnel fdt; #ifdef DGDEBUG std::cout << "tunnel activated" << std::endl; #endif fdt.tunnel(proxysock.getFD(), peerconn.getFD()); docsize += fdt.throughput; decideHowToLog(clientuser, clientip, url.toCharArray(), header.port, exceptionreason, header.requesttype().toCharArray(), docsize, o.ll, false, isexception, o.log_exception_hits, docheader.iscontenttype("text"), &thestart, cachehit, 200, mimetype); } } else { // was not supposed to be checked FDTunnel fdt; #ifdef DGDEBUG std::cout << "tunnel activated" << std::endl; #endif fdt.tunnel(proxysock.getFD(), peerconn.getFD()); docsize = fdt.throughput; decideHowToLog(clientuser, clientip, url.toCharArray(), header.port, exceptionreason, header.requesttype().toCharArray(), docsize, o.ll, false, isexception, o.log_exception_hits, docheader.iscontenttype("text"), &thestart, cachehit, 200, mimetype); } } catch (exception& e) { #ifdef DGDEBUG std::cout << "connection handler caught an exception" << std::endl; #endif try { proxysock.close(); // close connection to proxy } catch (exception& e) {} return; } try { proxysock.close(); // close conection to squid } catch (exception& e) {} try { peerconn.readyForOutput(10); } catch (exception& e) { return; } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -