You can subscribe to this list here.
2012 |
Jan
|
Feb
|
Mar
|
Apr
(24) |
May
(35) |
Jun
(5) |
Jul
(8) |
Aug
|
Sep
|
Oct
(7) |
Nov
(3) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
(7) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2015 |
Jan
|
Feb
(2) |
Mar
(3) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
(1) |
Feb
(3) |
Mar
(7) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(4) |
Oct
(4) |
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <com...@bi...> - 2013-08-03 14:33:18
|
1 new commit in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/b5961644fa62/ Changeset: b5961644fa62 User: roggan87 Date: 2013-08-03 16:32:52 Summary: Completed feature #8, now also loading embedded URLs as children. I had to create a dummy field in the hits table, because I couldn't come up with a better way to use the TypeHandler and getting rowids. Affected #: 5 files diff -r 5437416b3866e205252ffbf960c8d331548b2865 -r b5961644fa62fcff83bacf0b2721e29f81048c1c include/HTTPHit.h --- a/include/HTTPHit.h +++ b/include/HTTPHit.h @@ -82,7 +82,8 @@ HTTPHit(const HTTPResponse& response); HTTPHit(const HTTPHit& hit); - HTTPHit& operator=(const HTTPHit& hit); + HTTPHit& operator = (const HTTPHit& hit); + int operator () (); string getUrl() const; /// Will return the URL visited, like www.example.com/test.php. @@ -121,11 +122,16 @@ bool isWhitelistMatch(int threshold = 0); /// Returns true if the HTTPHit is whitelisted. + int getRowid() const; + int getParent() const; + /// If it is an embedded hit, like image, script etc. this + /// method will return the rowid of the parent. void setHost(string hostname); void setPath(string path); void setUrl(string url); + void setRowid(int rowid); void setParent(int parent); void addBlacklistKeyword(BlacklistKeyword keyword); void setBlacklistKeywords(const std::set<BlacklistKeyword> keywords); @@ -142,6 +148,7 @@ protected: string _host; string _path; + int _rowid; int _parent; vector<Token> _tokens; @@ -165,12 +172,13 @@ public: static size_t size() { - return 8; // we handle four columns of the Table! + return 9; } static void bind(size_t pos, const ::NetResponsibility::HTTPHit& obj, AbstractBinder* pBinder) { poco_assert_dbg (pBinder != 0); + TypeHandler<int>::bind(pos++, obj.getRowid(), pBinder); TypeHandler<std::string>::bind(pos++, obj.getHost(), pBinder); TypeHandler<std::string>::bind(pos++, obj.getPath(), pBinder); TypeHandler<Int64>::bind(pos++, obj.getDateTime().epochTime(), pBinder); @@ -185,6 +193,7 @@ AbstractPreparation* pPrepare) { poco_assert_dbg (pBinder != 0); + TypeHandler<int>::prepare(pos++, obj.getRowid(), pPrepare); TypeHandler<std::string>::prepare(pos++, obj.getHost(), pPrepare); TypeHandler<std::string>::prepare(pos++, obj.getPath(), pPrepare); TypeHandler<Int64>::prepare(pos++, obj.getDateTime().epochTime(), pPrepare); @@ -201,6 +210,7 @@ { poco_assert_dbg (pExt != 0); + int rowid; std::string hostname; std::string path; Int64 dt; @@ -209,7 +219,8 @@ int parent; int strength; std::string keywords; - + + TypeHandler<int>::extract(pos++, rowid, defVal.getRowid(), pExt); TypeHandler<std::string>::extract(pos++, hostname, defVal.getHost(), pExt); TypeHandler<std::string>::extract(pos++, path, defVal.getPath(), pExt); TypeHandler<Int64>::extract(pos++, dt, 0, pExt); @@ -218,7 +229,8 @@ TypeHandler<int>::extract(pos++, parent, defVal.getParent(), pExt); TypeHandler<int>::extract(pos++, strength, defVal.getStrength(), pExt); TypeHandler<std::string>::extract(pos++, keywords, defVal.getJoinedBlacklistKeywords(), pExt); - + + obj.setRowid(rowid); obj.setHost(hostname); obj.setPath(path); obj.setDateTime(Timestamp::fromEpochTime(dt)); diff -r 5437416b3866e205252ffbf960c8d331548b2865 -r b5961644fa62fcff83bacf0b2721e29f81048c1c include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -128,6 +128,12 @@ /// /// Root -> Children + STRUCTURE_EMBEDDED, + /// Same as STRUCTURE_FLAT, but embedded URLs are added as children + /// to their parents. + /// + /// Root -> HTTPHits -> Embedded + STRUCTURE_DOMAIN, /// The HTTPHits are grouped together by top domain, not /// only hostname. For example @@ -135,7 +141,7 @@ /// is grouped together with all other hits from /// netresponsibility.com. /// - /// Root -> Domain -> HTTPHits + /// Root -> Domain -> HTTPHits -> Embedded STRUCTURE_STRENGTH_LEVEL /// Group all Nodes by their StrengthLevel. diff -r 5437416b3866e205252ffbf960c8d331548b2865 -r b5961644fa62fcff83bacf0b2721e29f81048c1c plugins/DefaultReport/include/Report.h --- a/plugins/DefaultReport/include/Report.h +++ b/plugins/DefaultReport/include/Report.h @@ -85,6 +85,7 @@ void makeAttHistorySection(); void applyTemplate(); void saveAttachedReport(); + // TODO: string nodeToJsArray(NodePtr node); string jsContent(string); string makeColoredStrength(int); string makeTableBranch(string, string, string anchorName = ""); diff -r 5437416b3866e205252ffbf960c8d331548b2865 -r b5961644fa62fcff83bacf0b2721e29f81048c1c src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -38,7 +38,7 @@ _session = new Session("SQLite", _options->getString("path.database")); // TODO: DROP old tables if found *_session <<"CREATE TABLE IF NOT EXISTS hits " - <<"(hostname TEXT, path TEXT, datetime DATETIME, " + <<"(dummyId INT, hostname TEXT, path TEXT, datetime DATETIME, " <<"contentType TEXT, title TEXT, parent INT, " <<"strength INT, keywords TEXT)", now; *_session <<"CREATE TABLE IF NOT EXISTS reports " @@ -104,8 +104,8 @@ NodePtr bypasses = new Node("Bypasses"); TRY_RETRY(30) vector<Bypass> rows; - *_session <<"SELECT type, strftime('%s', datetime, 'utc')" - <<", details, timespan FROM bypasses", into(rows), now; + *_session <<"SELECT type, strftime('%s', datetime, 'utc'), " + <<"details, timespan FROM bypasses", into(rows), now; for (vector<Bypass>::iterator it = rows.begin(); it != rows.end(); it++) { bypasses->addChild(new Bypass(*it)); @@ -329,8 +329,9 @@ <<" AND datetime > datetime('now', '-1 hour') " <<"ORDER BY datetime DESC", into(_parent, 0), use(_referer), range(1, 1); *_removeGrandParent <<"UPDATE hits SET parent = 0 WHERE rowid = :parent", use(_parent); - *_logHitStatement <<"INSERT INTO hits VALUES " - <<"(:hostname, :path, datetime(:datetime, 'unixepoch', 'localtime'), " + *_logHitStatement <<"INSERT INTO hits (dummyId, hostname, path, datetime, " + <<"contentType, title, parent, strength, keywords) VALUES " + <<"(:id, :hostname, :path, datetime(:datetime, 'unixepoch', 'localtime'), " <<":contentType, :title, :parent, :strength, :keywords)", use(_hit); } @@ -429,26 +430,42 @@ Node::StrengthLevel level) const { NodePtr tree = new Node(); - vector<HTTPHit> rows; + map<int, HTTPHit> rows; if (where != "") where = " WHERE " + where; TRY_RETRY(30) - *_session <<"SELECT hostname, path, strftime('%s', datetime, 'utc'), " - <<"contentType, title, parent, " + *_session <<"SELECT rowid, hostname, path, " + <<"strftime('%s', datetime, 'utc'), contentType, title, parent, " <<"strength, keywords FROM hits" <<where, into(rows), now; CATCH_RETRY(30, 200, getHistory) - if (structure == Node::STRUCTURE_FLAT) { + if (structure != Node::STRUCTURE_FLAT) { + map<int, HTTPHit>::iterator it = rows.begin(); + while (it != rows.end()) { + int parent = it->second.getParent(); + if (parent > 0 && rows.find(parent) != rows.end()) { + rows[parent].addChild(new HTTPHit(it->second)); + map<int, HTTPHit>::iterator eraseThis = it++; + rows.erase(eraseThis); + } + else + it++; + } + } - for (vector<HTTPHit>::iterator it = rows.begin(); + if (structure == Node::STRUCTURE_FLAT + || structure == Node::STRUCTURE_EMBEDDED) + { + + for (map<int, HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { - NodePtr hit = new HTTPHit(*it); + NodePtr hit = new HTTPHit(it->second); if (isCorrectLevel(hit, level)) - tree->addChild(new HTTPHit(*it)); + tree->addChild(hit); } } @@ -460,12 +477,12 @@ map <string, NodeVector> domains; - for (vector<HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { + for (map<int, HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { string host; - if (!secondLevel.extract(it->getHost(), host, 0)) - host = it->getHost(); + if (!secondLevel.extract(it->second.getHost(), host, 0)) + host = it->second.getHost(); - NodePtr hit = new HTTPHit(*it); + NodePtr hit = new HTTPHit(it->second); // Only add the hit if it's the specified level. if (isCorrectLevel(hit, level)) domains[host].push_back(hit); @@ -483,9 +500,9 @@ else if (structure == Node::STRUCTURE_STRENGTH_LEVEL) { map <Node::StrengthLevel, NodeVector> levels; - for (vector<HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { + for (map<int, HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { - NodePtr hit = new HTTPHit(*it); + NodePtr hit = new HTTPHit(it->second); // Only add the hit if it's the specified level. if (isCorrectLevel(hit, level)) levels[hit->getStrengthLevel()].push_back(hit); diff -r 5437416b3866e205252ffbf960c8d331548b2865 -r b5961644fa62fcff83bacf0b2721e29f81048c1c src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -42,19 +42,27 @@ HTTPHit& HTTPHit::operator = (const HTTPHit& hit) { copyHeaders(hit); - _host = hit._host; - _path = hit._path; - _tokens = hit._tokens; - _strength = hit._strength; - _dateTime = hit._dateTime; + _host = hit._host; + _path = hit._path; + _tokens = hit._tokens; + _strength = hit._strength; + _dateTime = hit._dateTime; + _children = hit._children; _blacklistKeywords = hit._blacklistKeywords; - _nodeType = hit._nodeType; - _parent = hit._parent; + _nodeType = hit._nodeType; + _rowid = hit._rowid; + _parent = hit._parent; return *this; } +int HTTPHit::operator () () { + return _rowid; +} + + + string HTTPHit::getUrl() const { return _host + _path; } @@ -173,6 +181,12 @@ +int HTTPHit::getRowid() const { + return _rowid; +} + + + int HTTPHit::getParent() const { return _parent; } @@ -204,6 +218,12 @@ +void HTTPHit::setRowid(int rowid) { + _rowid = rowid; +} + + + void HTTPHit::setParent(int parent) { _parent = parent; } @@ -302,6 +322,7 @@ void HTTPHit::setDefaultValues() { _strength = 0; _dateTime.update(); + _rowid = 0; _parent = 0; _nodeType = Node::TYPE_HTTPHIT; } Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: <com...@bi...> - 2013-07-18 13:37:28
|
16 new commits in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/879ad7de0fce/ Changeset: 879ad7de0fce User: roggan87 Date: 2013-07-05 16:19:02 Summary: Implemented unregexpalize method to BlacklistKeyword. Closing feature #22. Affected #: 2 files diff -r 2377918df8a6afb3de9f0d053ca268348146d5fd -r 879ad7de0fce7d144a9c60f66cfb0f3f88035b2c include/BlacklistKeyword.h --- a/include/BlacklistKeyword.h +++ b/include/BlacklistKeyword.h @@ -77,6 +77,8 @@ string getCategory() const; + string getUnregexpalized() const; + BlacklistKeyword::Type getType() const; RegexpIterator begin() const; diff -r 2377918df8a6afb3de9f0d053ca268348146d5fd -r 879ad7de0fce7d144a9c60f66cfb0f3f88035b2c src/BlacklistKeyword.cpp --- a/src/BlacklistKeyword.cpp +++ b/src/BlacklistKeyword.cpp @@ -123,6 +123,24 @@ +string BlacklistKeyword::getUnregexpalized() const { + + string keyword = _asString; + RegularExpression a ("\\(.*\\)\\?", 0, false); + RegularExpression b ("\\(([^\\|]+).*\\)", 0, false); + RegularExpression c (".\\?", 0, false); + RegularExpression d ("[^a-zA-Z\\s]", 0, false); + + a.subst(keyword, "", RegularExpression::RE_GLOBAL); + b.subst(keyword, "$1", RegularExpression::RE_GLOBAL); + c.subst(keyword, "", RegularExpression::RE_GLOBAL); + d.subst(keyword, "", RegularExpression::RE_GLOBAL); + + return keyword; +} + + + BlacklistKeyword::Type BlacklistKeyword::getType() const { return _type; } https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/59ef8a6a9b48/ Changeset: 59ef8a6a9b48 User: roggan87 Date: 2013-07-10 11:34:41 Summary: Implemented Node::getRawStrength() which returns the strength in its original shape, not neccessarily 0-100. This method is used with the improvement data for example. Affected #: 3 files diff -r 879ad7de0fce7d144a9c60f66cfb0f3f88035b2c -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -160,7 +160,14 @@ virtual NodePtr operator [] (unsigned int i); int getStrength() const; + /// Returns the strength, but always in a value between 0-100. + + int getRawStrength() const; + /// Returns the strength, as it is rendered. Could be negative + /// or really big. + int size() const; + /// Get the number of children in this Node. virtual string getName() const; /// Get the name of this Node. The value may vary depending on diff -r 879ad7de0fce7d144a9c60f66cfb0f3f88035b2c -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 src/Node.cpp --- a/src/Node.cpp +++ b/src/Node.cpp @@ -83,7 +83,18 @@ int Node::getStrength() const { - return (_strength > 100 ? 100 : _strength); + if (_strength < 0) + return 0; + else if (_strength > 100) + return 100; + else + return _strength; +} + + + +int Node::getRawStrength() const { + return _strength; } diff -r 879ad7de0fce7d144a9c60f66cfb0f3f88035b2c -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -192,7 +192,8 @@ <<"url: " <<(*it)->getUrl() <<endl <<"boldUrl: " <<(*it)->getBoldUrl() <<endl <<"abbrUrl: " <<(*it)->getAbbrUrl() <<endl - <<"strength: " <<(*it)->getStrength() <<endl + <<"strength: " <<(*it)->getRawStrength() <<endl + // It's more useful to get the strength in it's original shape, not formatted 0-100. <<"keywords: " <<(*it)->getJoinedBlacklistKeywords() <<endl <<endl <<endl https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/9156ce96fa75/ Changeset: 9156ce96fa75 User: roggan87 Date: 2013-07-11 18:39:57 Summary: Updated some documentation Affected #: 8 files diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/Blacklist.h --- a/include/Blacklist.h +++ b/include/Blacklist.h @@ -18,7 +18,7 @@ // You should have received a copy of the GNU General Public License // along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. // -// <Blacklist> provides some structs for storing the blacklists and matches +// <Blacklist> conatins inappropiate keywords and similar to be used by the Filter. @@ -41,6 +41,8 @@ using namespace ::std; class Blacklist + /// Net Responsibility uses several Blacklists to filter out inappriate + /// websites. The class Blacklist contains one such category of keywords. { public: Blacklist(); @@ -49,14 +51,19 @@ Blacklist(const Blacklist& blacklist); string getName() const; - bool isComplementary() const; + /// Get the name of this particular Blacklist. void addKeyword(BlacklistKeyword keyword); - // TODO: Also require keyword type + /// Add a BlacklistKeyword to this Blacklist. const vector<BlacklistKeyword> &getKeywords(); - // TODO: use getKeywords(BLACKLIST_TYPE) for both + /// Get all regular BlacklistKeywords that belongs to this Blacklist. + const vector<BlacklistKeyword> &getComplementary(); + /// Get all complementary BlacklistKeywords that belongs to this + /// Blacklist. These won't trigger an alert by themselves, but if + /// a website seems to contain material related to this Blacklist, + /// it is also checked against these complementary keywords. private: string _name; diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/BlacklistKeyword.h --- a/include/BlacklistKeyword.h +++ b/include/BlacklistKeyword.h @@ -43,6 +43,7 @@ using namespace ::std; typedef vector< SharedPtr<RegularExpression> >::const_iterator RegexpIterator; + /// This iterator is used to run through each sub-keyword. class BlacklistKeyword /// This is a small class to hold each keyword, as a string, compiled as @@ -74,12 +75,21 @@ double getStrength() const; string getKeyword() const; + /// Get the keyword in string form. string getCategory() const; string getUnregexpalized() const; + /// This method tries to strip off the "Regular expression" syntax + /// from the keyword, giving you a readable keyword. Some examples: + /// + /// REGULAR EXPRESSION UNREGEXPALIZED + /// sex(y|iest) -> sexy + /// (anal|doggy)? sex -> sex + /// bad keywords? -> bad keyword BlacklistKeyword::Type getType() const; + /// What kind of BlacklistKeyword is it? RegexpIterator begin() const; @@ -89,10 +99,10 @@ protected: double _strength; - /// The strength of this keyword. 100 is default. + /// The strength of this keyword. 1.0 is default. string _asString; - /// The keyword displayed as a string. + /// The keyword in string form. string _category; diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/BootHistory.h --- a/include/BootHistory.h +++ b/include/BootHistory.h @@ -38,9 +38,7 @@ class BootHistory /// BootHistory processes the computer's boot history to determine whether or /// not Net Responsibility have been shut down manually. - /// - /// Almost all code is taken from the Linux command "last", so credit goes to - /// Miquel van Smoorenburg, mi...@ci... + /// This is done a little different depending on the platform. { public: BootHistory(); diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/MyXml.h --- a/include/MyXml.h +++ b/include/MyXml.h @@ -51,8 +51,6 @@ class MyXml : public ::Poco::Util::XMLConfiguration /// MyXml inherits XMLConfiguration and adds some extra functionality to it. - /// It's most important task is to extract and compile the blacklists, as - /// well as the txtfile. { public: MyXml(); diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -183,6 +183,7 @@ /// Get the current date and time as a Timestamp. NodeVector getChildren() const; + /// Returns all children of this Node in a NodeVector. void addChild(NodePtr node); /// Add a child to the children. The children will then be diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/ReportBase.h --- a/include/ReportBase.h +++ b/include/ReportBase.h @@ -91,17 +91,17 @@ /// "text/plain". void logFinish(); - /// Logs that the report was successfully created and sent + /// Logs that the report was successfully created and sent. void sendImprovementData(); /// Sends improvement data to the servers. This is optional for every /// user. void install(); - /// Call this function if it is an install report + /// Call this function if it is an install report. void uninstall(); - /// Call this function if it is an uninstall report + /// Call this function if it is an uninstall report. virtual int send(bool receiveCopy = false); /// Send the report. Set receiveCopy to true if you wish to send a @@ -116,10 +116,10 @@ /// debugging but really nothing else. virtual void test(); - /// Call this function if it is an test report + /// Call this function if it is an test report. virtual void generate() = 0; - /// Override this method in Report to generate nicely formatted reports + /// Override this method in Report to generate nicely formatted reports. virtual string name() const = 0; /// Override this method in Report. Should actually only return the diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d include/SnifferSubsystem.h --- a/include/SnifferSubsystem.h +++ b/include/SnifferSubsystem.h @@ -33,7 +33,6 @@ #if defined(POCO_OS_FAMILY_UNIX) #include <signal.h> -#include "BootHistory.h" #endif #include "Poco/Util/Application.h" diff -r 59ef8a6a9b48a2d81c9cba6e4e46492656931759 -r 9156ce96fa75604d40108ee20a1a2d519d72532d src/Blacklist.cpp --- a/src/Blacklist.cpp +++ b/src/Blacklist.cpp @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. // -// <Blacklist> is what we're using to filter the HTTPHits +// <Blacklist> conatins inappropiate keywords and similar to be used by the Filter. #include "Blacklist.h" @@ -71,14 +71,6 @@ -bool Blacklist::isComplementary() const -{ - // TODO determine! - return false; -} - - - void Blacklist::addKeyword(BlacklistKeyword keyword) { _keywords.push_back(keyword); https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/dee82cc09ec3/ Changeset: dee82cc09ec3 User: roggan87 Date: 2013-07-11 18:40:29 Summary: Small fix Affected #: 1 file diff -r 9156ce96fa75604d40108ee20a1a2d519d72532d -r dee82cc09ec3657933f270b6d7e80edf52d23721 src/Request.cpp --- a/src/Request.cpp +++ b/src/Request.cpp @@ -200,10 +200,10 @@ try { // Get values from server string downloaded = send(options, "/request/downloaded.php"); - stringstream ss(downloaded); - // Parse XML file - AutoPtr<XMLConfiguration> xml(new XMLConfiguration(ss)); if (downloaded != "") { + stringstream ss(downloaded); + // Parse XML file + AutoPtr<XMLConfiguration> xml(new XMLConfiguration(ss)); // Read values and set them accordingly configDownloaded = xml->getInt("config", 0); blacklistsDownloaded = xml->getInt("blacklist", 0); https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/223e68c41f6d/ Changeset: 223e68c41f6d User: roggan87 Date: 2013-07-15 11:50:47 Summary: Changed the design for accessing Node-inheritors methods Now cast the NodePtr to a pointer of the correct class and reach the methods directly. Much cleaner and more logical. Be careful with the type casting though! Affected #: 7 files diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e include/HTTPHit.h --- a/include/HTTPHit.h +++ b/include/HTTPHit.h @@ -62,6 +62,7 @@ /// The HTTPHit can be constructed by either passing a /// Poco::Net::HTTPRequest, or Poco::Net::HTTPResponse to the /// constructor. + { public: diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -38,13 +38,15 @@ namespace NetResponsibility { - + using ::Poco::Timestamp; using ::Poco::DateTimeFormatter; using ::Poco::SharedPtr; using ::Poco::Exception; using namespace ::std; +class Bypass; +class HTTPHit; class Node; typedef SharedPtr<Node> NodePtr; @@ -58,6 +60,16 @@ /// /// It is especially important to grasp the concept of this class /// if you're about to write a report plugin. + /// + /// With Node::sort() you can decide how you want the + /// tree to be sorted at any time. You're also able to decide the structure + /// of the tree on creation by specifying the Node::Structure, see for example + /// Database::getWarnings(); + /// + /// The public methods are intended to work with all Nodes no matter what + /// class that inherits it. + /// The classes that inherits Node will have their own specific methods too. + /// To reach those, use the cast<>() method, but use it with care! { public: @@ -218,25 +230,18 @@ virtual StrengthLevel getStrengthLevel(); /// Returns the StrengthLevel of the Node. - - // Some virtual methods used by derived classes: - - virtual string getUrl() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual string getHost() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual string getPath() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual string getBoldUrl() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual string getAbbrUrl() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual string getJoinedBlacklistKeywords() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual string getTitle() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual bool isMatch(int threshold = 0) { throw Exception(VIRTUAL_EXCEPTION); } - virtual bool isWhitelistMatch(int threshold = 0) { throw Exception(VIRTUAL_EXCEPTION); } - virtual int getParent() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual std::set<BlacklistKeyword> getBlacklistKeywords() { throw Exception(VIRTUAL_EXCEPTION); } - - virtual string getDetails() const { throw Exception(VIRTUAL_EXCEPTION); } - virtual void setDetails(string details) { throw Exception(VIRTUAL_EXCEPTION); } - virtual void setBypassType(int) { throw Exception(VIRTUAL_EXCEPTION); } - virtual int getBypassType() { throw Exception(VIRTUAL_EXCEPTION); } + template <class T> T cast(); + /// Use this method to cast the Node it's original class. It's really + /// important to make sure the casting is done right. If the given + /// class is incorrect, 0 is returned. Also note that it must be a + /// class pointer, such as HTTPHit* or Bypass*. + /// Example: + /// + /// if (node.getNodeType() == Node::TYPE_HTTPHIT) { + /// HTTPHit* hit = node.cast<HTTPHit*>(); + /// if (hit != 0) + /// cout <<"Url: " <<hit->getUrl(); + /// } protected: string _name; @@ -246,8 +251,6 @@ Node::Sort _order; Node::Type _nodeType; - static const string VIRTUAL_EXCEPTION; - static bool sortByNameAsc(const NodePtr lhs, const NodePtr rhs); static bool sortByNameDesc(const NodePtr lhs, const NodePtr rhs); static bool sortByStrengthAsc(const NodePtr lhs, const NodePtr rhs); @@ -257,5 +260,6 @@ }; } // namespace NetResponsibility - +#include "Bypass.h" +#include "HTTPHit.h" #endif // NODE_H diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e plugins/DefaultReport/src/Report.cpp --- a/plugins/DefaultReport/src/Report.cpp +++ b/plugins/DefaultReport/src/Report.cpp @@ -47,15 +47,15 @@ attContent = "", details; for(NodeIterator it = bypasses->begin(); it != bypasses->end(); it++) { - - details = (*it)->getDetails(); - content += "<i>" + (*it)->getDateTime( + Bypass *bypass = (*it)->cast<Bypass*>(); + details = bypass->getDetails(); + content += "<i>" + bypass->getDateTime( _options->getString("dateTimeFormat")) + "</i> - " - + (*it)->getName() + + bypass->getName() + (details != "" ? " (" + details + ")" : ""); - attContent += "['" + jsContent((*it)->getName()) + attContent += "['" + jsContent(bypass->getName()) + (details != "" ? " (" + jsContent(details) + ")" : "") - + "', [''],, '" + jsContent((*it)->getDateTime( + + "', [''],, '" + jsContent(bypass->getDateTime( _options->getString("dateTimeFormat"))) + "']"; if (it != bypasses->end() - 1) { @@ -66,10 +66,10 @@ } if (_options->hasChildValue("cfg.plugins.DefaultReport.reportParts", "bypasses")) _body <<makeTableBranch( - _options->getString("report.bypassesTitle"), content); + _options->getString("report.title.bypasses"), content); if (_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", "bypasses")) _attached <<makeJavascriptBranch( - jsContent(_options->getString("report.bypassesTitle")), + jsContent(_options->getString("report.title.bypasses")), attContent); } } @@ -94,14 +94,15 @@ stringstream attUrlsContent; for(NodeIterator it2 = (*it)->begin(); it2 != (*it)->end(); it2++) - { - urlsContent <<makeColoredStrength((*it2)->getStrength()) - <<" " <<(*it2)->getAbbrUrl(); - attUrlsContent <<"['" <<jsContent((*it2)->getAbbrUrl()) - <<"', ['http://" <<jsContent((*it2)->getUrl()) <<"'],, '" - <<jsContent((*it2)->getDateTime( + { + HTTPHit* hit = (*it2)->cast<HTTPHit*>(); + urlsContent <<makeColoredStrength(hit->getStrength()) + <<" " <<hit->getAbbrUrl(); + attUrlsContent <<"['" <<jsContent(hit->getAbbrUrl()) + <<"', ['http://" <<jsContent(hit->getUrl()) <<"'],, '" + <<jsContent(hit->getDateTime( _options->getString("dateTimeFormat"))) - <<"', " <<(*it2)->getStrength()<<"]"; + <<"', " <<hit->getStrength()<<"]"; if (it2 != (*it)->end()) { urlsContent <<"<br>"; @@ -122,10 +123,10 @@ if (_options->hasChildValue("cfg.plugins.DefaultReport.reportParts", "warnings")) _body <<makeTableBranch( - _options->getString("report.warningsTitle"), keywordsContent); + _options->getString("report.title.warnings"), keywordsContent); if (_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", "warnings")) _attached <<makeJavascriptBranch( - jsContent(_options->getString("report.warningsTitle")), + jsContent(_options->getString("report.title.warnings")), attKeywordsContent); } @@ -135,10 +136,11 @@ NodePtr whitelist = _db->getWhitelist(Node::STRUCTURE_FLAT); if (whitelist->size() > 0) { string urlsContent = "", attUrlsContent = ""; - for(NodeIterator it = whitelist->begin(); it != whitelist->end(); it++) { - urlsContent += (*it)->getAbbrUrl(); - attUrlsContent += "['" + jsContent((*it)->getAbbrUrl()) - + "', ['http://" + jsContent((*it)->getUrl()) + "'],, '" + for(NodeIterator it = whitelist->begin(); it != whitelist->end(); it++) { + HTTPHit* hit = (*it)->cast<HTTPHit*>(); + urlsContent += hit->getAbbrUrl(); + attUrlsContent += "['" + jsContent(hit->getAbbrUrl()) + + "', ['http://" + jsContent(hit->getUrl()) + "'],, '" + jsContent((*it)->getDateTime( _options->getString("dateTimeFormat"))) + "']"; @@ -150,10 +152,10 @@ } if (_options->hasChildValue("cfg.plugins.DefaultReport.reportParts", "whitelist")) _body <<makeTableBranch( - _options->getString("report.whitelistTitle"), urlsContent); + _options->getString("report.title.whitelist"), urlsContent); if (_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", "whitelist")) _attached <<makeJavascriptBranch( - jsContent(_options->getString("report.whitelistTitle")), + jsContent(_options->getString("report.title.whitelist")), attUrlsContent); } } @@ -181,10 +183,11 @@ { if (doIncludePaths) { string paths; - for(NodeIterator it2 = (*it)->begin(); it2 != (*it)->end(); it2++) { - paths += "['" + jsContent((*it2)->getUrl()) + for(NodeIterator it2 = (*it)->begin(); it2 != (*it)->end(); it2++) { + HTTPHit* hit = (*it2)->cast<HTTPHit*>(); + paths += "['" + jsContent(hit->getUrl()) + "', ['http'],, '" - + jsContent((*it2)->getDateTime( + + jsContent(hit->getDateTime( _options->getString("dateTimeFormat"))) + "'],\n"; } @@ -199,7 +202,7 @@ + "', ['']]"; _attached <<makeJavascriptBranch(jsContent(_options - ->getString("report.historyTitle")), domains); + ->getString("report.title.history")), domains); } @@ -221,7 +224,7 @@ _attached << _options->getString("report.attached.header") <<endl <<"var subject = \"" <<_subject <<"\";" <<endl - <<"var version = \"" <<_options->get<string>("program.version") <<"\";" + <<"var version = \"" <<_options->getString("program.version") <<"\";" <<endl <<"var arrNodes = [['Report', ['',,'folder'], [" <<endl <<attachedContent <<endl @@ -235,7 +238,7 @@ try { string date = DateTimeFormatter::format(Timestamp(), "%Y%m%d"), iStr, - dir = _options->get<string>("path.reports"); + dir = _options->getString("path.reports"); int i = 0, tempInt; RegularExpression patt("^report_" + date + "_(\\d+)\\.(htm|zip)$", 0, true); diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -278,7 +278,6 @@ else return Node::LEVEL_NONE; } - // Protected methods: diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e src/Node.cpp --- a/src/Node.cpp +++ b/src/Node.cpp @@ -26,8 +26,6 @@ namespace NetResponsibility { -const string Node::VIRTUAL_EXCEPTION = "This method must be overridden"; - Node::Node() { @@ -235,6 +233,12 @@ } +template <class T> +T Node::cast() { + return dynamic_cast<T>(this); +} + + // Protected methods @@ -273,5 +277,9 @@ } +// Explicitly instantiate some templates +template Bypass* Node::cast<Bypass*>(); +template HTTPHit* Node::cast<HTTPHit*>(); + } // namespace NetResponsibility diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -187,14 +187,15 @@ int i = 0; for (NodeIterator it = warnings->begin(); it != warnings->end(); it++) { - // Do we still need to encode the urls? + // TODO: Do we still need to encode the urls? + HTTPHit* hit = (*it)->cast<HTTPHit*>(); impData <<"#" <<i++ <<endl - <<"url: " <<(*it)->getUrl() <<endl - <<"boldUrl: " <<(*it)->getBoldUrl() <<endl - <<"abbrUrl: " <<(*it)->getAbbrUrl() <<endl - <<"strength: " <<(*it)->getRawStrength() <<endl + <<"url: " <<hit->getUrl() <<endl + <<"boldUrl: " <<hit->getBoldUrl() <<endl + <<"abbrUrl: " <<hit->getAbbrUrl() <<endl + <<"strength: " <<hit->getRawStrength() <<endl // It's more useful to get the strength in it's original shape, not formatted 0-100. - <<"keywords: " <<(*it)->getJoinedBlacklistKeywords() <<endl + <<"keywords: " <<hit->getJoinedBlacklistKeywords() <<endl <<endl <<endl <<endl; diff -r dee82cc09ec3657933f270b6d7e80edf52d23721 -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e src/Request.cpp --- a/src/Request.cpp +++ b/src/Request.cpp @@ -1,4 +1,3 @@ -// This file is part of Net Responsibility. // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/b67124ebdb20/ Changeset: b67124ebdb20 User: roggan87 Date: 2013-07-15 12:07:18 Summary: Removed redundant and confusing debug message Affected #: 1 file diff -r 223e68c41f6d6348806c1dec1f2c86ca23629e4e -r b67124ebdb20e32caf61bd7f922d43dc785a0fd1 src/BootHistory.cpp --- a/src/BootHistory.cpp +++ b/src/BootHistory.cpp @@ -137,7 +137,9 @@ if (lastBoot != 0) pushBoot(lastBoot, u->ut_tv.tv_sec); else if (!isFirstEntry) - std::cout <<"ERROR2.0!"; // TODO: Handle incorrect entry! + ; // There might be a double entry of shutdown, since this one + // misses a related boot time, but is it important enough + // to care about? lastBoot = 0; isFirstEntry = false; } https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/3362d8567d93/ Changeset: 3362d8567d93 User: roggan87 Date: 2013-07-15 19:15:02 Summary: Also store timespan for Bypasses This is primarily interesting for shutdowns, since we can then see how long NR was down. Affected #: 4 files diff -r b67124ebdb20e32caf61bd7f922d43dc785a0fd1 -r 3362d8567d93a0c202589af30469cf380d8894f9 include/Bypass.h --- a/include/Bypass.h +++ b/include/Bypass.h @@ -26,6 +26,7 @@ #include "Node.h" #include "Poco/Timestamp.h" +#include "Poco/Timespan.h" #include "Poco/Data/Common.h" #include "Poco/Data/Connector.h" #include "Poco/Data/SQLite/Connector.h" @@ -33,6 +34,7 @@ namespace NetResponsibility { using ::Poco::Timestamp; +using ::Poco::Timespan; class Bypass : public Node @@ -54,7 +56,7 @@ Bypass(); Bypass(Bypass::BypassType type, string details); - Bypass(Bypass::BypassType type, string details, Timestamp dateTime); + Bypass(Bypass::BypassType type, string details, Timestamp dateTime, int timespan = 0); virtual ~Bypass(); Bypass& operator = (const Bypass& bypass); @@ -69,11 +71,15 @@ void setDetails(string details); void setBypassType(BypassType type); + void setTimespan(int timespan); BypassType getBypassType() const; + Timespan getTimespan() const; + protected: string _details; BypassType _bypassType; + int _timespan; }; @@ -89,7 +95,7 @@ public: static size_t size() { - return 3; // we handle four columns of the Table! + return 4; // we handle four columns of the Table! } static void bind(size_t pos, const ::NetResponsibility::Bypass& obj, AbstractBinder* pBinder) @@ -98,6 +104,7 @@ TypeHandler<int>::bind(pos++, obj.getBypassType(), pBinder); TypeHandler<Poco::Int64>::bind(pos++, obj.getDateTime().epochTime(), pBinder); TypeHandler<std::string>::bind(pos++, obj.getDetails(), pBinder); + TypeHandler<int>::bind(pos++, obj.getTimespan().totalSeconds(), pBinder); } static void prepare(size_t pos, const ::NetResponsibility::Bypass& obj, @@ -107,6 +114,7 @@ TypeHandler<int>::prepare(pos++, obj.getBypassType(), pPrepare); TypeHandler<Poco::Int64>::prepare(pos++, obj.getDateTime().epochTime(), pPrepare); TypeHandler<std::string>::prepare(pos++, obj.getDetails(), pPrepare); + TypeHandler<int>::prepare(pos++, obj.getTimespan().totalSeconds(), pPrepare); } static void extract(size_t pos, ::NetResponsibility::Bypass& obj, @@ -117,13 +125,16 @@ int type; Int64 dt; std::string details; + int timespan; TypeHandler<int>::extract(pos++, type, defVal.getBypassType(), pExt); TypeHandler<Int64>::extract(pos++, dt, defVal.getDateTime().epochTime(), pExt); TypeHandler<std::string>::extract(pos++, details, defVal.getDetails(), pExt); + TypeHandler<int>::extract(pos++, timespan, 0, pExt); obj.setBypassType((NetResponsibility::Bypass::BypassType)type); obj.setDateTime(Timestamp::fromEpochTime(dt)); obj.setDetails(details); + obj.setTimespan(timespan); } }; diff -r b67124ebdb20e32caf61bd7f922d43dc785a0fd1 -r 3362d8567d93a0c202589af30469cf380d8894f9 include/Database.h --- a/include/Database.h +++ b/include/Database.h @@ -85,6 +85,8 @@ // TODO: change the string to something less malicious, like Type // and switch-case. + Timestamp getLastReport(); + NodePtr getBypasses(Node::Sort sortBy = Node::SORT_NAME_ASC) const; /// Return all Bypasses found. diff -r b67124ebdb20e32caf61bd7f922d43dc785a0fd1 -r 3362d8567d93a0c202589af30469cf380d8894f9 src/Bypass.cpp --- a/src/Bypass.cpp +++ b/src/Bypass.cpp @@ -40,12 +40,13 @@ -Bypass::Bypass(Bypass::BypassType type, string details, Timestamp dateTime) +Bypass::Bypass(Bypass::BypassType type, string details, Timestamp dateTime, int timespan) { _nodeType = Node::TYPE_BYPASS; _bypassType = type; _details = details; _dateTime = dateTime; + _timespan = timespan; } @@ -102,10 +103,22 @@ +void Bypass::setTimespan(int timespan) { + _timespan = timespan; +} + + + Bypass::BypassType Bypass::getBypassType() const { return _bypassType; } +Timespan Bypass::getTimespan() const { + return Timespan(_timespan, 0); +} + + + } // namespace NetResponsibility diff -r b67124ebdb20e32caf61bd7f922d43dc785a0fd1 -r 3362d8567d93a0c202589af30469cf380d8894f9 src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -46,7 +46,7 @@ *_session <<"CREATE TABLE IF NOT EXISTS reports " <<"(type INT, datetime DATETIME, completed INT)", now; *_session <<"CREATE TABLE IF NOT EXISTS bypasses " - <<"(type INT, datetime DATETIME, details TEXT)", now; + <<"(type INT, datetime DATETIME, details TEXT, timespan INT)", now; *_session <<"CREATE TABLE IF NOT EXISTS sessions " <<"(boot DATETIME, start DATETIME, stop DATETIME)", now; i = FINISHED; @@ -130,6 +130,31 @@ } } return count; +} + + + +Timestamp Database::getLastReport() { + const int FINISHED = 30; + for (int i = 0; i <= FINISHED; i++) { + try { + int dt = 0; + *_session <<"SELECT strftime('%s', datetime, 'utc') FROM reports " + <<"WHERE completed = 1 ORDER BY datetime DESC", limit(1), into(dt), now; + return Timestamp::fromEpochTime(dt); + } + catch (DBLockedException &e) { + if (i < FINISHED) { + _logger->debug("dbLockRetry.getLastReport"); + Thread::sleep(200); + } + else + _logger->warning("dbLockFail.getLastReport"); + } + catch (Exception &e) { + _logger->warning(e.displayText()); + } + } } @@ -141,7 +166,7 @@ try { vector<Bypass> rows; *_session <<"SELECT type, strftime('%s', datetime, 'utc')" - <<", details FROM bypasses", into(rows), now; + <<", details, timespan FROM bypasses", into(rows), now; for (vector<Bypass>::iterator it = rows.begin(); it != rows.end(); it++) { bypasses->addChild(new Bypass(*it)); @@ -210,7 +235,7 @@ for (int i = 0; i <= FINISHED; i++) { try { *_session <<"INSERT INTO bypasses VALUES " - <<"(:type, :datetime, :details)", + <<"(:type, :datetime, :details, :timespan)", use(bypass), now; i = FINISHED; } @@ -498,7 +523,7 @@ } Timestamp dt = Timestamp::fromEpochTime(datetime); - Bypass bypass(Bypass::BYPASS_SHUTDOWN, msg, dt); + Bypass bypass(Bypass::BYPASS_SHUTDOWN, msg, dt, gap); logBypass(bypass); _logger->debug("bypass.shutdown"); } https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/7b17b1fac67f/ Changeset: 7b17b1fac67f User: roggan87 Date: 2013-07-15 20:43:36 Summary: Cleaned up in Database Added a Macro and got rid of ~200 lines, or 30% of Database.cpp. Not bad if you ask me :) It's also looking a lot better code wise. Affected #: 2 files diff -r 3362d8567d93a0c202589af30469cf380d8894f9 -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 include/Database.h --- a/include/Database.h +++ b/include/Database.h @@ -47,6 +47,27 @@ #include <vector> #include <set> +#define TRY_RETRY(TRIES) \ + for (int tries = 0; tries <= TRIES; tries++) { \ + try { + +#define CATCH_RETRY(TRIES, SLEEP, LOGGER_ENTRY) \ + tries = TRIES; \ + } \ + catch (DBLockedException &e) { \ + if (tries < TRIES) { \ + _logger->debug("dbLockRetry." #LOGGER_ENTRY); \ + Thread::sleep(SLEEP); \ + } \ + else \ + _logger->warning("dbLockFail." #LOGGER_ENTRY); \ + } \ + catch (Exception &e) { \ + _logger->warning(e.displayText()); \ + } \ + } \ + + namespace NetResponsibility { @@ -86,6 +107,7 @@ // and switch-case. Timestamp getLastReport(); + /// When was the last successful report sent? NodePtr getBypasses(Node::Sort sortBy = Node::SORT_NAME_ASC) const; /// Return all Bypasses found. diff -r 3362d8567d93a0c202589af30469cf380d8894f9 -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -33,36 +33,21 @@ _options = &Options::instance(); - const int FINISHED = 20; - for (int i = 0; i <= FINISHED; i++) { - try { - SQLite::Connector::registerConnector(); - _session = new Session("SQLite", _options->get<string>("path.database")); - // TODO: DROP old tables if found - *_session <<"CREATE TABLE IF NOT EXISTS hits " - <<"(hostname TEXT, path TEXT, datetime DATETIME, " - <<"contentType TEXT, title TEXT, parent INT, " - <<"strength INT, keywords TEXT)", now; - *_session <<"CREATE TABLE IF NOT EXISTS reports " - <<"(type INT, datetime DATETIME, completed INT)", now; - *_session <<"CREATE TABLE IF NOT EXISTS bypasses " - <<"(type INT, datetime DATETIME, details TEXT, timespan INT)", now; - *_session <<"CREATE TABLE IF NOT EXISTS sessions " - <<"(boot DATETIME, start DATETIME, stop DATETIME)", now; - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.loadDatabase"); - Thread::sleep(100); - } - else - _logger->warning("dbLockFail.loadDatabase"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + TRY_RETRY(20) + SQLite::Connector::registerConnector(); + _session = new Session("SQLite", _options->getString("path.database")); + // TODO: DROP old tables if found + *_session <<"CREATE TABLE IF NOT EXISTS hits " + <<"(hostname TEXT, path TEXT, datetime DATETIME, " + <<"contentType TEXT, title TEXT, parent INT, " + <<"strength INT, keywords TEXT)", now; + *_session <<"CREATE TABLE IF NOT EXISTS reports " + <<"(type INT, datetime DATETIME, completed INT)", now; + *_session <<"CREATE TABLE IF NOT EXISTS bypasses " + <<"(type INT, datetime DATETIME, details TEXT, timespan INT)", now; + *_session <<"CREATE TABLE IF NOT EXISTS sessions " + <<"(boot DATETIME, start DATETIME, stop DATETIME)", now; + CATCH_RETRY(20, 100, loadDatabase) setStatements(); logInitBypasses(_options->getInitBypasses()); @@ -83,108 +68,49 @@ if (frequency <= 0) return false; - int count = -1; - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"SELECT COUNT() FROM reports " - <<"WHERE datetime > datetime('now', '-" <<frequency <<" days', 'localtime')" - <<" AND completed = 1", into(count), now; - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.determineReportTime"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.determineReportTime"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + int count = -1; + TRY_RETRY(30) + *_session <<"SELECT COUNT() FROM reports " + <<"WHERE datetime > datetime('now', '-" <<frequency <<" days', 'localtime')" + <<" AND completed = 1", into(count), now; + CATCH_RETRY(30, 200, determineReportTime) return (count == 0); } int Database::getCount(string from) const { - int count = 0; - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"SELECT COUNT() FROM " <<from, into(count), now; - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.getCount"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.getCount"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + int count = 0; + TRY_RETRY(30) + *_session <<"SELECT COUNT() FROM " <<from, into(count), now; + CATCH_RETRY(30, 200, getCount) return count; } -Timestamp Database::getLastReport() { - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - int dt = 0; - *_session <<"SELECT strftime('%s', datetime, 'utc') FROM reports " - <<"WHERE completed = 1 ORDER BY datetime DESC", limit(1), into(dt), now; - return Timestamp::fromEpochTime(dt); - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.getLastReport"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.getLastReport"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } +Timestamp Database::getLastReport() { + int dt = 0; + TRY_RETRY(30) + *_session <<"SELECT strftime('%s', datetime, 'utc') FROM reports " + <<"WHERE completed = 1 ORDER BY datetime DESC", limit(1), into(dt), now; + CATCH_RETRY(30, 200, getLastReport) + return Timestamp::fromEpochTime(dt); } NodePtr Database::getBypasses(Node::Sort sortBy) const { - NodePtr bypasses = new Node("Bypasses"); - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - vector<Bypass> rows; - *_session <<"SELECT type, strftime('%s', datetime, 'utc')" - <<", details, timespan FROM bypasses", into(rows), now; + NodePtr bypasses = new Node("Bypasses"); + TRY_RETRY(30) + vector<Bypass> rows; + *_session <<"SELECT type, strftime('%s', datetime, 'utc')" + <<", details, timespan FROM bypasses", into(rows), now; - for (vector<Bypass>::iterator it = rows.begin(); it != rows.end(); it++) { - bypasses->addChild(new Bypass(*it)); - } - i = FINISHED; + for (vector<Bypass>::iterator it = rows.begin(); it != rows.end(); it++) { + bypasses->addChild(new Bypass(*it)); } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.getBypasses"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.getBypasses"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + CATCH_RETRY(30, 200, getBypasses) bypasses->sort(sortBy); return bypasses; } @@ -230,27 +156,12 @@ -void Database::logBypass(Bypass bypass) { - const int FINISHED = 10; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"INSERT INTO bypasses VALUES " - <<"(:type, :datetime, :details, :timespan)", - use(bypass), now; - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.logBypass"); - Thread::sleep(i * 1000); - } - else - _logger->warning("dbLockFail.logBypass"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } +void Database::logBypass(Bypass bypass) { + TRY_RETRY(10) + *_session <<"INSERT INTO bypasses VALUES " + <<"(:type, :datetime, :details, :timespan)", + use(bypass), now; + CATCH_RETRY(10, tries * 1000, logBypass) } @@ -266,85 +177,34 @@ void Database::logReportStart(int &id) { int type = Options::instance().getInt("arg.report", 0); - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"INSERT INTO reports VALUES " - <<"(:type, datetime('now', 'localtime'), 0)", - use(type), now; - _getLastRowId->execute(); - id = _lastRowId; - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.logReportStart"); - Thread::sleep(200); - } - else { - _logger->warning("dbLockFail.logReportStart"); - e.rethrow(); - } - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + TRY_RETRY(30) + *_session <<"INSERT INTO reports VALUES " + <<"(:type, datetime('now', 'localtime'), 0)", + use(type), now; + _getLastRowId->execute(); + id = _lastRowId; + CATCH_RETRY(30, 200, logReportStart) } void Database::logReportFinish(int id) { - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"UPDATE reports SET completed=1 WHERE rowId=:id", - use(id), now; - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.logReportFinish"); - Thread::sleep(200); - } - else { - _logger->warning("dbLockFail.logReportFinish"); - e.rethrow(); - } - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + TRY_RETRY(30) + *_session <<"UPDATE reports SET completed=1 WHERE rowId=:id", use(id), now; + CATCH_RETRY(30, 200, logReportFinish) } void Database::rotateLog(int reportId) { - int dt; - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"SELECT strftime('%s', datetime) " - <<"FROM reports WHERE rowid=:id", use(reportId), into(dt), now; - string condition = " WHERE datetime < datetime(:dt, 'unixepoch')"; - *_session <<"DELETE FROM hits" <<condition, use(dt), now; - *_session <<"DELETE FROM bypasses" <<condition, use(dt), now; - - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.rotateLog"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.rotateLog"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + TRY_RETRY(30) + int dt; + *_session <<"SELECT strftime('%s', datetime) " + <<"FROM reports WHERE rowid=:id", use(reportId), into(dt), now; + string condition = " WHERE datetime < datetime(:dt, 'unixepoch')"; + *_session <<"DELETE FROM hits" <<condition, use(dt), now; + *_session <<"DELETE FROM bypasses" <<condition, use(dt), now; + CATCH_RETRY(30, 200, rotateLog) } @@ -359,63 +219,47 @@ return; } _timestamp.update(); - int start = _timestamp.epochTime(), - prevRowid, - prevBoot, - prevStop; - const int FINISHED = 30, - ALLOWED_GAP = 60; - for (int i = 0; i <= FINISHED; i++) { - try { - // First try to load existing entries with the current bootTime. - // If stop is also found, check the length of the gap, - // otherwise report that the previous session was killed. - *_session <<"SELECT rowid, strftime('%s', boot, 'utc'), " - <<"strftime('%s', stop, 'utc') FROM sessions " - <<"WHERE strftime('%s', boot, 'utc') = '" <<boot <<"' " - <<"ORDER BY boot DESC", - into(prevRowid), into(prevBoot), into(prevStop, -1), limit(1), now; + int start = _timestamp.epochTime(); + int prevRowid; + int prevBoot; + int prevStop; + const int ALLOWED_GAP = 60; + TRY_RETRY(30) + // First try to load existing entries with the current bootTime. + // If stop is also found, check the length of the gap, + // otherwise report that the previous session was killed. + *_session <<"SELECT rowid, strftime('%s', boot, 'utc'), " + <<"strftime('%s', stop, 'utc') FROM sessions " + <<"WHERE strftime('%s', boot, 'utc') = '" <<boot <<"' " + <<"ORDER BY boot DESC", + into(prevRowid), into(prevBoot), into(prevStop, -1), limit(1), now; - // Check if a session is found - if (prevBoot == boot) { - // Check if previous instance was killed - int gap = start - prevStop; - if (prevStop == -1) { - logBypassShutdown(start); - } - // Otherwise if the gap between instances was a little too long - else if (gap > ALLOWED_GAP) { - logBypassShutdown(prevStop, gap); - } - *_session <<"UPDATE sessions SET stop = null " - <<"WHERE rowid = :prevRowid", use(prevRowid), now; - _sessionRowId = prevRowid; + // Check if a session is found + if (prevBoot == boot) { + // Check if previous instance was killed + int gap = start - prevStop; + if (prevStop == -1) { + logBypassShutdown(start); } - else { - // Insert a new entry into sessions - *_session <<"INSERT INTO sessions (boot, start) VALUES " - <<"(datetime(:boot, 'unixepoch', 'localtime'), " - <<"datetime(:start, 'unixepoch', 'localtime'))", - use(boot), use(start), now; + // Otherwise if the gap between instances was a little too long + else if (gap > ALLOWED_GAP) { + logBypassShutdown(prevStop, gap); + } + *_session <<"UPDATE sessions SET stop = null " + <<"WHERE rowid = :prevRowid", use(prevRowid), now; + _sessionRowId = prevRowid; + } + else { + // Insert a new entry into sessions + *_session <<"INSERT INTO sessions (boot, start) VALUES " + <<"(datetime(:boot, 'unixepoch', 'localtime'), " + <<"datetime(:start, 'unixepoch', 'localtime'))", + use(boot), use(start), now; - _getLastRowId->execute(); - _sessionRowId = _lastRowId; - } - - i = FINISHED; + _getLastRowId->execute(); + _sessionRowId = _lastRowId; } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.logSnifferStart"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.logSnifferStart"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + CATCH_RETRY(30, 200, logSnifferStart) } @@ -424,28 +268,12 @@ if (_sessionRowId == -1) return; _timestamp.update(); - int stop = _timestamp.epochTime(); - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - *_session <<"UPDATE sessions SET stop=" - <<"datetime(:stop, 'unixepoch', 'localtime') WHERE rowid = " - <<_sessionRowId, use(stop), now; - - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.logSnifferStop"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.logSnifferStop"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + int stop = _timestamp.epochTime(); + TRY_RETRY(30) + *_session <<"UPDATE sessions SET stop=" + <<"datetime(:stop, 'unixepoch', 'localtime') WHERE rowid = " + <<_sessionRowId, use(stop), now; + CATCH_RETRY(30, 200, logSnifferStop) } @@ -473,28 +301,12 @@ -void Database::logHit(HTTPHit& hit) -{ - const int FINISHED = 10; - for (int i = 0; i <= FINISHED; i++) { - try { - _hit = hit; - _logHitStatement->execute(); - _getLastRowId->execute(); - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.logUrl"); - Thread::sleep(i * 1000); - } - else - _logger->warning("dbLockFail.logUrl"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } +void Database::logHit(HTTPHit& hit) { + TRY_RETRY(10) + _hit = hit; + _logHitStatement->execute(); + _getLastRowId->execute(); + CATCH_RETRY(10, tries * 1000, logUrl) } @@ -531,75 +343,59 @@ void Database::processPreviousSessions() { - const int FINISHED = 20; - const int ALLOWED_GAP = 180; // Allowed gap right after boot and right before halt - for (int i = 0; i <= FINISHED; i++) { - try { - vector< Tuple<int, int, int, int> > sess; // rowid, boot, start, stop - set<int> logged; - *_session <<"SELECT rowid, strftime('%s', boot, 'utc'), " - <<"strftime('%s', start, 'utc'), " - <<"strftime('%s', stop, 'utc') FROM sessions ", - into(sess), now; - for (vector< Tuple<int, int, int, int> >::const_iterator it = sess.begin(); - it != sess.end(); it++) - { - int boot = it->get<1>(); - logged.insert(boot); - int halt = _bootHistory->getHaltTime(boot); - if (halt > 0) { - int rowid = it->get<0>(); - int start = it->get<2>(); - int stop = it->get<3>(); + const int ALLOWED_GAP = 180; // Allowed gap right after boot and right before halt + TRY_RETRY(20) + vector< Tuple<int, int, int, int> > sess; // rowid, boot, start, stop + set<int> logged; + *_session <<"SELECT rowid, strftime('%s', boot, 'utc'), " + <<"strftime('%s', start, 'utc'), " + <<"strftime('%s', stop, 'utc') FROM sessions ", + into(sess), now; + for (vector< Tuple<int, int, int, int> >::const_iterator it = sess.begin(); + it != sess.end(); it++) + { + int boot = it->get<1>(); + logged.insert(boot); + int halt = _bootHistory->getHaltTime(boot); + if (halt > 0) { + int rowid = it->get<0>(); + int start = it->get<2>(); + int stop = it->get<3>(); - // Check if the start of Net Responsibility was delayed - int gap = start - boot; - if (gap > ALLOWED_GAP) - logBypassShutdown(boot, gap); + // Check if the start of Net Responsibility was delayed + int gap = start - boot; + if (gap > ALLOWED_GAP) + logBypassShutdown(boot, gap); - // Check if NR stopped too early - gap = halt - stop; - if (stop <= 0) // Is this a proper way to find out if stop is null? - logBypassShutdown(stop); - else if (gap > ALLOWED_GAP) - logBypassShutdown(stop, gap); + // Check if NR stopped too early + gap = halt - stop; + if (stop <= 0) // Is this a proper way to find out if stop is null? + logBypassShutdown(stop); + else if (gap > ALLOWED_GAP) + logBypassShutdown(stop, gap); - *_session <<"DELETE FROM sessions WHERE rowid = :rowid", - use(rowid), now; - } - else if (boot != _bootHistory->getBootTime()) { - // The computer halted improperly, no need to report that. - int rowid = it->get<0>(); - *_session <<"DELETE FROM sessions WHERE rowid = :rowid", - use(rowid), now; - } + *_session <<"DELETE FROM sessions WHERE rowid = :rowid", + use(rowid), now; } + else if (boot != _bootHistory->getBootTime()) { + // The computer halted improperly, no need to report that. + int rowid = it->get<0>(); + *_session <<"DELETE FROM sessions WHERE rowid = :rowid", + use(rowid), now; + } + } - // Determine if NR has been omitted in earlier sessions - map<int, int> omitted = _bootHistory->getOmittedSessions(logged); - map<int, int>::iterator it; + // Determine if NR has been omitted in earlier sessions + map<int, int> omitted = _bootHistory->getOmittedSessions(logged); + map<int, int>::iterator it; - for (it = omitted.begin(); it != omitted.end(); it++) { - int gap = it->second - it->first; - if (gap > ALLOWED_GAP) - logBypassShutdown(it->first, gap); - } - - i = FINISHED; + for (it = omitted.begin(); it != omitted.end(); it++) { + int gap = it->second - it->first; + if (gap > ALLOWED_GAP) + logBypassShutdown(it->first, gap); } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.processSessions"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.processSessions"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } + CATCH_RETRY(20, 200, processSessions) } @@ -613,31 +409,12 @@ if (where != "") where = " WHERE " + where; - const int FINISHED = 30; - for (int i = 0; i <= FINISHED; i++) { - try { - - - *_session <<"SELECT hostname, path, strftime('%s', datetime, 'utc'), " - <<"contentType, title, parent, " - <<"strength, keywords FROM hits" - <<where, into(rows), now; - - i = FINISHED; - } - catch (DBLockedException &e) { - if (i < FINISHED) { - _logger->debug("dbLockRetry.getHistory"); - Thread::sleep(200); - } - else - _logger->warning("dbLockFail.getHistory"); - } - catch (Exception &e) { - _logger->warning(e.displayText()); - } - } - + TRY_RETRY(30) + *_session <<"SELECT hostname, path, strftime('%s', datetime, 'utc'), " + <<"contentType, title, parent, " + <<"strength, keywords FROM hits" + <<where, into(rows), now; + CATCH_RETRY(30, 200, getHistory) if (structure == Node::STRUCTURE_FLAT) { https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/5b0fdcd2f879/ Changeset: 5b0fdcd2f879 User: roggan87 Date: 2013-07-15 21:57:53 Summary: Replaced the old report plugin with a new one This new report plugin aims to be easy to grasp what's going on. The focus lies on the accountability partner more than before. It's also less explicit, everything is not written out like before, simply enough to give a clue about the status of the user's browsing history. Affected #: 8 files diff -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 -r 5b0fdcd2f879aa81a2a7c8b0acb201098f93b6ec include/ReportBase.h --- a/include/ReportBase.h +++ b/include/ReportBase.h @@ -38,6 +38,7 @@ #include <vector> #include "Poco/Timestamp.h" +#include "Poco/DateTime.h" #include "Poco/DateTimeFormatter.h" #include "Poco/Net/MailMessage.h" #include "Poco/Net/MailRecipient.h" @@ -53,6 +54,7 @@ namespace NetResponsibility { using ::Poco::Timestamp; +using ::Poco::DateTime; using ::Poco::DateTimeFormatter; using ::Poco::Net::MailMessage; using ::Poco::Net::MailRecipient; diff -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 -r 5b0fdcd2f879aa81a2a7c8b0acb201098f93b6ec locale/en_EN.xml --- a/locale/en_EN.xml +++ b/locale/en_EN.xml @@ -48,6 +48,7 @@ <determineReportTime>Database locked, couldn't determine report time</determineReportTime><getCount>Database locked, couldn't get count</getCount><getLastRowid>Database locked, couldn't get lastrowid</getLastRowid> + <getLastReport>Database locked, couldn't get last report time</getLastReport><getHostnames>Database locked, couldn't get hostnames</getHostnames><getBypasses>Database locked, couldn't get bypasses</getBypasses><getHistory>Database locked, couldn't get history</getHistory> @@ -121,6 +122,7 @@ <determineReportTime>Database locked, will retry to determine report time</determineReportTime><getCount>Database locked, will retry to get count</getCount><getLastRowid>Database locked, will retry to get lastrowid</getLastRowid> + <getLastReport>Database locked, will retry to get last report time</getLastReport><getHostnames>Database locked, will retry to get hostnames</getHostnames><getBypasses>Database locked, will retry to get bypasses</getBypasses><getHistory>Database locked, will retry to get history</getHistory> diff -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 -r 5b0fdcd2f879aa81a2a7c8b0acb201098f93b6ec plugins/DefaultReport/Makefile.am --- a/plugins/DefaultReport/Makefile.am +++ b/plugins/DefaultReport/Makefile.am @@ -10,7 +10,7 @@ DefaultReport_la_SOURCES = \ src/Report.cpp DefaultReport_la_LDFLAGS = -module -no-undefined $(ldFlags) -DefaultReport_la_LIBADD = -lNetResponsibility +DefaultReport_la_LIBADD = -lNetResponsibility -lPocoFoundation -lPocoNet -lPocoZip DefaultReport_la_CPPFLAGS = -I../../include -Iinclude @CPPFLAGS@ # Locale files diff -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 -r 5b0fdcd2f879aa81a2a7c8b0acb201098f93b6ec plugins/DefaultReport/include/Report.h --- a/plugins/DefaultReport/include/Report.h +++ b/plugins/DefaultReport/include/Report.h @@ -27,6 +27,7 @@ #include "ReportBase.h" +#include "Poco/Timespan.h" #include "Poco/RegularExpression.h" #include "Poco/DirectoryIterator.h" #include "Poco/ClassLibrary.h" @@ -39,6 +40,7 @@ namespace NetResponsibility { +using ::Poco::Timespan; using ::Poco::RegularExpression; using ::Poco::DirectoryIterator; using ::Poco::Zip::Compress; @@ -74,11 +76,14 @@ */ private: stringstream _attached; - void makeBypassesSection(); - void makeWarningsSection(); - void makeWhitelistSection(); - void makeHistorySection(); - void addTemplate(); + NodePtr _tree; + void makeTopRatedSites(); + void makeSummary(); + void makeAttBypassesSection(); + void makeAttWarningsSection(); + void makeAttWhitelistSection(); + void makeAttHistorySection(); + void applyTemplate(); void saveAttachedReport(); string jsContent(string); string makeColoredStrength(int); diff -r 7b17b1fac67fa2777ce6d7e4b66125cb382e0566 -r 5b0fdcd2f879aa81a2a7c8b0acb201098f93b6ec plugins/DefaultReport/locale/en_EN.xml --- a/plugins/DefaultReport/locale/en_EN.xml +++ b/plugins/DefaultReport/locale/en_EN.xml @@ -2,153 +2,336 @@ <locale language="en_EN"><translator> - <name>Dustin Miller</name> - <email>du...@gm...</email> - <nrVersion>3.1</nrVersion> - </translator> - <translator><name>Robert Rosman</name><email>rob...@gm...</email><nrVersion>3.1</nrVersion></translator> - + <!-- Format of date and time --><dateTimeFormat>%d/%m - %H:%M:%S</dateTimeFormat><report> - <generatedBy>This report was generated by ${report.links.netResponsibility}.</generatedBy> - <troubleshooting>For more information and troubleshooting, please read the ${report.links.documentation}.</troubleshooting> - <noReply>Replies to this email will go to ${name}.</noReply> - - <suspicious> - <dontPanic> - <header>Don't panic!</header> - <description>Things that look suspicious may actually be innocuous. Look at everything in context and be sure to talk to the account user about anything that you don't understand.</description> - </dontPanic> - <beSafe> - <header>Be safe!</header> - <description>Only links that look like this: ${report.links.goToUrl} will take you to another web page. These links are listed because they are suspicious so be especially cautious clicking on them.</description> - </beSafe> - <getHelp> - <header>Get help!</header> - <description></description> - </getHelp> - </suspicious> + <sitesOkay>Net Responsibility couldn't find any inappropriate material in the browsing history, which is good!</sitesOkay><noWarnings>No warnings</noWarnings><noWhitelist>No whitelist matches</noWhitelist><noHistory>Found no recorded history</noHistory> - <goToUrl>Go to URL</goToUrl> - <backToTop>back to top</backToTop> - <bypassesTitle>Bypasses</bypassesTitle> - <warningsTitle>Warnings</warningsTitle> - <whitelistTitle>Whitelist</whitelistTitle> - <historyTitle>History</historyTitle> - + + <downtime> + <minutes>${report.vars.summary.downtime.minutes}m</minutes> + <hoursMinutes>${report.vars.summary.downtime.hours}h ${report.vars.summary.downtime.minutes}m</hoursMinutes> + <daysHoursMinutes>${report.vars.summary.downtime.days}d ${report.vars.summary.downtime.hours}h ${report.vars.summary.downtime.minutes}m</daysHoursMinutes> + </downtime> + + <!-- Used to display when last report was sent. "today" will be parsed through DateTimeFormatter --> + <lastReport> + <today>Today %H:%M</today> + <yesterday>Yesterday</yesterday> + <daysAgo>${report.vars.summary.lastReport.days} days ago</daysAgo> + </lastReport> + + <title> + <bypasses>Bypasses</bypasses> + <warnings>Warnings</warnings> + <whitelist>Whitelist</whitelist> + <history>History</history> + </title> + <documentation>documentation</documentation> + <tooltips> + <summary> + <header>A short summary of the activity since the last report</header> + <user>This is the user who sent you the report</user> + <strength>This should be a low value, maximum 100</strength> + <downtime>This is the total time of Net Responsibility being shut down. Ideally it shouldn't have been shut down at all</downtime> + <lastReport>Days since the last report was sent</lastReport> + <version>Version of Net Responsibility used to generate this report</version> + <strengthLevels> + <safe>SAFE!</safe> + <lowRisk>LOWRISK</lowRisk> + <suspicious>SUSPICIOUS</suspicious> + <highRisk>HIGHRISK</highRisk> + <danger>DANGER</danger> + </strengthLevels> + </summary> + <whatsThis> + <header>Not sure why you're receiving these mails or what to do with them? Read below.</header> + </whatsThis> + <topRatedSites> + <header>These are the visited sites that are most likely to contain forbidden material</header> + <contains>This site seems to contain: ${report.vars.topRated.blacklists}</contains> + <strengthLevels> + <safe>This site is probably safe</safe> + <lowRisk>It seems like this site could be harmless, but we're not sure</lowRisk> + <suspicious>This is could be a bad site, what do you think?</suspicious> + <highRisk>This is likely a bad site, but look at things in context to determine</highRisk> + <danger>This is certainly a bad site</danger> + </strengthLevels> + </topRatedSites> + </tooltips> + <paragraphs> + <whyMe>You're receiving this email because RR have chosen you to be an accountability partner.</whyMe> + <how>You should be able to hover over things you don't understand to get a quick tooltip. You may also want to read our ${report.links.documentation}.</how> + <addContact>If the email is looking strange or considered to be spam, please add re...@ne... to your contacts, that will usually help.</addContact> + <reply>If you think the user have visited forbidden sites, you can hit reply to follow up. Make sure that the email is not sent to re...@ne..., but to the user's email address.</reply> + <details>More details ma... [truncated message content] |
From: <com...@bi...> - 2013-07-05 14:01:35
|
14 new commits in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/df24d8f0e056/ Changeset: df24d8f0e056 User: roggan87 Date: 2012-11-17 18:33:21 Summary: No need to rename the new plugin locale files any more. Affected #: 1 file diff -r 9e74594abafeade82e16d0178ef7310824d746ce -r df24d8f0e056da2ab376c563e746df7c056d3053 plugins/create.sh --- a/plugins/create.sh +++ b/plugins/create.sh @@ -69,8 +69,6 @@ fi done -mv ${C_NAME}/locale/en_EN/general.xml ${C_NAME}/locale/en_EN/${C_NAME}.xml - echo "" echo "Your plugin is set up. Customize README, write your code, tweak " echo "configure.ac and Makefile.am if needed, then run the following " https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/98da4d89d8a0/ Changeset: 98da4d89d8a0 User: roggan87 Date: 2012-11-17 23:48:35 Summary: Putting the configuration inside a ConfigurationMapper, and closing #53. Restructuring the configuration file to more reflect the plugin separation. Affected #: 8 files diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd include/Options.h --- a/include/Options.h +++ b/include/Options.h @@ -39,6 +39,7 @@ #include "Poco/Environment.h" #include "Poco/Util/Application.h" #include "Poco/Util/LayeredConfiguration.h" +#include "Poco/Util/ConfigurationMapper.h" #include "Poco/Logger.h" #include "Poco/SharedLibrary.h" #include "Poco/DynamicAny.h" @@ -83,6 +84,7 @@ using ::Poco::SingletonHolder; using ::Poco::Util::Application; using ::Poco::Util::LayeredConfiguration; +using ::Poco::Util::ConfigurationMapper; using namespace ::std; class MainApplication; @@ -130,20 +132,10 @@ virtual ~Options(); - bool doSaveHistory() const; - - bool doSendImprovementData() const; - /// Returns true if we're supposed to send the improvement data to - /// the server. - - bool doCompressAttachedReport() const; - /// Returns true if the report should be zipped. - - bool isReportPart(string part) const; - /// Returns true if the given part should be included in the regular report. - - bool isAttachedReportPart(string part) const; - /// Returns true if the given part should be included in the attached report. + bool hasChildValue(string key, string value) const; + /// Returns true if the given value is found in one of the + /// children to given key. Useful for checking up report parts + /// etc. bool isAccountEnabled() const; /// Returns false if accounts are disabled at compilation time. @@ -189,7 +181,6 @@ map<string, string> _txt; MyLogger *_logger; vector<Bypass> _initBypasses; - AutoPtr<MyXml> _xml; void loadDefaultValues(); void loadLocale(string plugin = "general"); diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd plugins/DefaultReport/src/Report.cpp --- a/plugins/DefaultReport/src/Report.cpp +++ b/plugins/DefaultReport/src/Report.cpp @@ -64,10 +64,10 @@ } } - if (_options->isReportPart("bypasses")) + if (_options->hasChildValue("cfg.plugins.DefaultReport.reportParts", "bypasses")) _body <<makeTableBranch( _options->getString("report.bypassesTitle"), content); - if (_options->isAttachedReportPart("bypasses")) + if (_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", "bypasses")) _attached <<makeJavascriptBranch( jsContent(_options->getString("report.bypassesTitle")), attContent); @@ -120,10 +120,10 @@ + jsContent(_options->getString("report.noWarnings")) + "', ['']]"; } - if (_options->isReportPart("warnings")) + if (_options->hasChildValue("cfg.plugins.DefaultReport.reportParts", "warnings")) _body <<makeTableBranch( _options->getString("report.warningsTitle"), keywordsContent); - if (_options->isAttachedReportPart("warnings")) + if (_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", "warnings")) _attached <<makeJavascriptBranch( jsContent(_options->getString("report.warningsTitle")), attKeywordsContent); @@ -148,10 +148,10 @@ } } - if (_options->isReportPart("whitelist")) + if (_options->hasChildValue("cfg.plugins.DefaultReport.reportParts", "whitelist")) _body <<makeTableBranch( _options->getString("report.whitelistTitle"), urlsContent); - if (_options->isAttachedReportPart("whitelist")) + if (_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", "whitelist")) _attached <<makeJavascriptBranch( jsContent(_options->getString("report.whitelistTitle")), attUrlsContent); @@ -160,8 +160,19 @@ -void Report::makeHistorySection() { - bool doIncludePaths = _options->isAttachedReportPart("history_paths"); +void Report::makeHistorySection() { + // Don't bother running through the complete history if it's not going to + // be included in the report anyway. + if (!_options->hasChildValue("cfg.plugins.DefaultReport.attachedReportParts", + "history_hostnames") && !_options->hasChildValue + ("cfg.plugins.DefaultReport.attachedReportParts", "history_paths")) + { + return; + } + + bool doIncludePaths = _options->hasChildValue + ("cfg.plugins.DefaultReport.reportParts", "history_paths"); + NodePtr history = _db->getHistory(Node::STRUCTURE_DOMAIN); string domains; @@ -252,7 +263,9 @@ StreamCopier::copyStream(_attached, htmFile); htmFile.close(); int fsize = File(fname).getSize(); - if (_options->doCompressAttachedReport() || fsize > (10 * 1024 * 1024)) { + if (_options->getBool("cfg.plugins.DefaultReport.compressAttachedReport") + || fsize > (10 * 1024 * 1024)) + { string zfname(dir + ss.str() + ".zip"); ofstream zipFile(zfname.c_str(), std::ios::binary); Compress c(zipFile, true); diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd src/ConfigSubsystem.cpp --- a/src/ConfigSubsystem.cpp +++ b/src/ConfigSubsystem.cpp @@ -38,15 +38,15 @@ Options* options = &Options::instance(); if (options->getBool("arg.config", false)) { if (options->isAccountEnabled()) { - string username = options->getString("username", ""), - password = options->getString("password", ""); + string username = options->getString("cfg.username", ""), + password = options->getString("cfg.password", ""); if ((username == "" || password == "") && MainApplication::instance().isInteractive()) { getLogin(username, password); } else if (username == "") - username = options->getString("username", ""); + username = options->getString("cfg.username", ""); options->setUsername(username); Request::addMac(options, password); } diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd src/MainApplication.cpp --- a/src/MainApplication.cpp +++ b/src/MainApplication.cpp @@ -118,7 +118,7 @@ void MainApplication::defineOptions(OptionSet& options) { ServerApplication::defineOptions(options); - config().setString("logfile", ""); + config().setString("arg.logfile", ""); options.addOption( Option("install", "", "Send installation report") .required(false) @@ -201,7 +201,7 @@ .required(false) .repeatable(false) .argument("file") - .binding("logfile")); + .binding("arg.logfile")); options.addOption( Option("no-sniffer", "ns", "Skip the sniffer on this instance") @@ -229,7 +229,7 @@ .required(false) .repeatable(false) .argument("xx_ZZ") - .binding("locale")); + .binding("arg.locale")); } diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd src/MyLogger.cpp --- a/src/MyLogger.cpp +++ b/src/MyLogger.cpp @@ -99,7 +99,7 @@ LayeredConfiguration *appConfig = &Application::instance().config(); string level; string logfile = ""; - string customLogfile = appConfig->getString("logfile", ""); + string customLogfile = appConfig->getString("arg.logfile", ""); bool isInteractive = !(appConfig->getBool("application.runAsDaemon", false) || appConfig->getBool("application.runAsService", false)); bool debug = appConfig->getBool("arg.debug", false); diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd src/Options.cpp --- a/src/Options.cpp +++ b/src/Options.cpp @@ -54,39 +54,11 @@ -bool Options::doSaveHistory() const { - return isAttachedReportPart("history_hostnames") - || isAttachedReportPart("history_paths"); -} - - - -bool Options::doSendImprovementData() const { - return _sendImprovementData; -} - - - -bool Options::doCompressAttachedReport() const { - return _compressAttachedReport; -} - - - -bool Options::isReportPart(string part) const { - vector<string> parts = this->getVector<string>("reportParts"); +bool Options::hasChildValue(string key, string value) const { + vector<string> children = this->getVector<string>(key.c_str()); vector<string>::const_iterator it; - it = find (parts.begin(), parts.end(), part); - return it != parts.end(); -} - - - -bool Options::isAttachedReportPart(string part) const { - vector<string> parts = this->getVector<string>("attachedReportParts"); - vector<string>::const_iterator it; - it = find (parts.begin(), parts.end(), part); - return it != parts.end(); + it = find (children.begin(), children.end(), value); + return it != children.end(); } @@ -175,11 +147,9 @@ string pluginName; string path(PLUGIN_DIR); if (pluginType == "report") - pluginName = this->getString - ("plugin[@type='report'][@selected='true'][@name]", "DefaultReport"); + pluginName = this->getString("cfg.plugins.selected.report", "DefaultReport"); else - pluginName = this->getString - ("plugin[@type='sniffer'][@selected='true'][@name]", "DefaultSniffer"); + pluginName = this->getString("cfg.plugins.selected.sniffer", "DefaultSniffer"); path += pluginName; path += ::Poco::SharedLibrary::suffix(); loadLocale(pluginName); @@ -196,7 +166,7 @@ void Options::setUsername(string username) { - this->setString("username", username); + this->setString("cfg.username", username); } @@ -210,10 +180,9 @@ this->setString("path.reports", REPORT_DIR); this->setString("server.hostname", SERVER); this->setString("program.version", VERSION); - this->setInt("reportFrequency", 7); - this->setInt("reportStrengthThreshold", 0); - this->setBool("improveData", false); - this->setBool("compressAttachedReport", false); + this->setInt("cfg.reportFrequency", 7); + this->setInt("cfg.reportStrengthThreshold", 0); + this->setBool("cfg.improvementData", false); _logger->debug("Version ${program.version}"); } @@ -224,11 +193,14 @@ bool doUpdate = this->getBool("arg.update-files", false); for (int moreTries = 3; moreTries > 0; moreTries--) { try { - _xml = new MyXml(this->getString("path.config")); + AutoPtr<MyXml> unmapped = new MyXml(this->getString("path.config")); + + AutoPtr<ConfigurationMapper> mapper; + mapper = new ConfigurationMapper("", "cfg", unmapped); // Add the configurations from our XML file to the LayeredConfiguration. // This is top priority. - this->add(_xml, 0); + this->add(mapper, 0); // If the account is enabled, update and retry if needed. if (!this->isAccountEnabled() || !Request::updateConfig(this, doUpdate)) @@ -306,7 +278,7 @@ // TODO: Configuration file // Command argument - string cliLocale = this->getString("locale", ""); + string cliLocale = this->getString("arg.locale", ""); if (cliLocale != "") _locales.push_back(cliLocale); diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -100,12 +100,13 @@ int ReportBase::send(bool receiveCopy) { try { - MailMessage message; - message.setSender(_options->get<string>("name") + " <re...@ne...>"); - message.set("Reply-To", _options->get<string>("emailFrom")); - vector<string> recipients = _options->getVector<string>("emailTo"); + MailMessage message; + string userEmail = _options->getString("cfg.email"); + message.setSender(_options->getString("cfg.name") + " <re...@ne...>"); + message.set("Reply-To", userEmail); + vector<string> recipients = _options->getVector<string>("accountabilityPartners"); if (receiveCopy) - recipients.push_back(_options->get<string>("emailFrom")); + recipients.push_back(userEmail); for (vector<string>::iterator it = recipients.begin(); it != recipients.end(); it++) { @@ -128,8 +129,8 @@ new FilePartSource(it->toString(), mimeType)); } - string host = _options->getString("smtp.host", "dummy"); - int port = _options->getInt("smtp.port", 25); + string host = _options->getString("cfg.smtp.host", "dummy"); + int port = _options->getInt("cfg.smtp.port", 25); SMTPClientSession session(host, port); session.login(SMTPClientSession::AUTH_LOGIN, @@ -182,7 +183,7 @@ void ReportBase::sendImprovementData() { NodePtr warnings = _db->getImprovementData(); - if (_options->getBool("improveData", false) && warnings->size() > 0) { + if (_options->getBool("cfg.improvementData", false) && warnings->size() > 0) { stringstream impData; int i = 0; for (NodeIterator it = warnings->begin(); it != warnings->end(); it++) { diff -r df24d8f0e056da2ab376c563e746df7c056d3053 -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd src/Request.cpp --- a/src/Request.cpp +++ b/src/Request.cpp @@ -165,7 +165,7 @@ HTTPRequest req(HTTPRequest::HTTP_POST, path); req.setContentType("application/x-www-form-urlencoded"); string reqBody = ""; - reqBody += "online_user=" + options->getString("username", "") + reqBody += "online_user=" + options->getString("cfg.username", "") + "&mac=" + options->getMacAddress() + "&version=" + options->getString("program.version"); if (morePostVars != "") https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/58b41a68360a/ Changeset: 58b41a68360a User: roggan87 Date: 2012-11-18 23:06:04 Summary: Send improvement data regardless of Report plugin used. Affected #: 2 files diff -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd -r 58b41a68360a85ec578dbe1683db404fab06afa5 src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -138,7 +138,6 @@ "407298f00758c47a635065f7bfa1954d"); session.sendMessage(message); session.close(); - sendImprovementData(); } catch (::Poco::Net::NoAddressFoundException& exc) { return 1; diff -r 98da4d89d8a04feb0fd6d677bd33fcb1dfbc97fd -r 58b41a68360a85ec578dbe1683db404fab06afa5 src/ReportSubsystem.cpp --- a/src/ReportSubsystem.cpp +++ b/src/ReportSubsystem.cpp @@ -69,8 +69,9 @@ ::Poco::Thread::sleep(20000); errorCode = report->send(); } - if (errorCode == 0) { - _logger->notice("reportFinished"); + if (errorCode == 0) { + _logger->notice("reportFinished"); + report->sendImprovementData(); report->logFinish(); _options->setInt("arg.report", REPORT_FALSE); } https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/6d02885c1f9b/ Changeset: 6d02885c1f9b User: roggan87 Date: 2013-03-25 20:42:41 Summary: Cleaned up some small warnings. Affected #: 7 files diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 configure.ac --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.58) -AC_INIT([Net Responsibility],[3.1r323],[co...@ne...]) +AC_INIT([Net Responsibility],[3.1.0-dev],[co...@ne...]) AC_SUBST([LIBTOOL_DEPS]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_SRCDIR([src/main.cpp]) diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 include/Filter.h --- a/include/Filter.h +++ b/include/Filter.h @@ -53,7 +53,7 @@ /// This class will run all test to find out if the URLs are appropriate or /// not. It is done by initially loading the blacklists, and then testing /// each URL against them. When keywords are found within the given text, - /// Filter thries to determine how strong the match is. This means every + /// Filter tries to determine how strong the match is. This means every /// match will be given an individual strength to indicate how likely it is /// to be an inappropriate site. (The higher number, the more likely). /// @@ -66,7 +66,7 @@ Filter(string blacklistFile); /// Load the Filter, given the path to the blacklist. This is - /// especially useful when improvign the algorithms. + /// especially useful when improving the algorithms. void loadBlacklist(string path); diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 plugins/DefaultReport/include/Report.h --- a/plugins/DefaultReport/include/Report.h +++ b/plugins/DefaultReport/include/Report.h @@ -62,17 +62,16 @@ /// Generates the report. This method invokes a number of other methods protected: - /*Inherited: - stringstream _body; - string _subject; - string _contentType; - vector<Path> _attachments; - Options *_options; - Database *_db; - Logger *_logger; - - */ - + /* Inherited members: + * + * stringstream _body; + * string _subject; + * string _contentType; + * vector<Path> _attachments; + * Options *_options; + * Database *_db; + * MyLogger *_logger; + */ private: stringstream _attached; void makeBypassesSection(); diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 plugins/Template/include/Report.h --- a/plugins/Template/include/Report.h +++ b/plugins/Template/include/Report.h @@ -48,7 +48,7 @@ * vector<Path> _attachments; * Options *_options; * Database *_db; - * Logger *_logger; + * MyLogger *_logger; */ private: diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 src/BlacklistKeyword.cpp --- a/src/BlacklistKeyword.cpp +++ b/src/BlacklistKeyword.cpp @@ -66,6 +66,7 @@ _category = keyword._category; _strength = keyword._strength; _regexps = keyword._regexps; + return *this; } diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -15,7 +15,7 @@ // // <Filter> determines whether the URLs are appropriate or not. -#include "Filter.h" +#include "Filter.h" namespace NetResponsibility { diff -r 58b41a68360a85ec578dbe1683db404fab06afa5 -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 src/Options.cpp --- a/src/Options.cpp +++ b/src/Options.cpp @@ -106,7 +106,7 @@ vector<T> vec; vector<string> subkeys; vector<string>::iterator it; - string prefix = (property == "" ? "" : string(property) + string(".")); + string prefix = (property == string("") ? string("") : string(property) + string(".")); this->keys(property, subkeys); for (it = subkeys.begin(); it != subkeys.end(); ++it) { string p = prefix + *it; @@ -121,7 +121,7 @@ map<string, T> Options::getMap(const char* property) const { map<string, T> m; vector<string> subkeys; - string prefix = (property == "" ? "" : string(property) + string(".")); + string prefix = (property == string("") ? string("") : string(property) + string(".")); this->keys(property, subkeys); for (vector<string>::iterator it = subkeys.begin(); it != subkeys.end(); ++it) @@ -235,7 +235,6 @@ void Options::loadLocale(string plugin) { string path; - bool isFound = false; for (vector<string>::reverse_iterator it = _locales.rbegin(); it != _locales.rend(); it++) { @@ -247,7 +246,6 @@ this->setString("path.txt", path); _logger->debug("printPath.txt"); - isFound = true; } } catch (::Poco::Exception &err) { https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/463bc7245ea7/ Changeset: 463bc7245ea7 User: roggan87 Date: 2013-03-26 18:28:21 Summary: Added the Blacklist as a real class. Bringing consistency to the terminology. BlacklistCategory -> Blacklist vector<Blacklist> -> Blacklists Affected #: 14 files diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -5,6 +5,7 @@ lib_LTLIBRARIES = libNetResponsibility.la libNetResponsibility_la_SOURCES = \ @top_srcdir@/src/MainApplication.cpp\ + @top_srcdir@/src/Blacklist.cpp\ @top_srcdir@/src/BlacklistKeyword.cpp\ @top_srcdir@/src/BootHistory.cpp\ @top_srcdir@/src/Bypass.cpp\ diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e include/Blacklist.h --- a/include/Blacklist.h +++ b/include/Blacklist.h @@ -29,68 +29,34 @@ #include "BlacklistKeyword.h" -#include "Poco/RegularExpression.h" #include "Poco/SharedPtr.h" -#include "Poco/Timestamp.h" -#include "Poco/Data/Common.h" -#include "Poco/Data/Connector.h" -#include "Poco/Data/SQLite/Connector.h" + namespace NetResponsibility { - -using ::Poco::Timestamp; + using ::Poco::SharedPtr; -using ::Poco::RegularExpression; -using namespace ::Poco::Data; using namespace ::std; - - -struct BlacklistCategory - /// This struct holds each specific category. -{ - string name; - /// The name of the category. +class Blacklist +{ + public: + Blacklist(); + Blacklist(string name); + Blacklist(const Blacklist& blacklist); - vector<BlacklistKeyword> keyword; // Change to keywords since its more than one - /// All the keywords. -}; - - - -struct BlacklistMatch - /// If the filter catches a match, in other words a suspicious URL, it's - /// stored inside a BlacklistMatch. Here we have all the important - /// information related to the match. -{ - string boldUrl; - /// The URL with every suspicious word in bold. + string getName() const; + bool isComplementary() const; - string abbrUrl; - /// The same as boldUrl, but abbreviated to be easier to read and save - /// some space. + void addKeyword(BlacklistKeyword keyword); - int strength; - /// The total strength of the match. This is displayed in the reports - /// if this strength is lower than reportStrengthThreshold. - - bool whitelist; - /// This bool is set to true if it is a whitelist match. In that case it - /// will show up in the whitelist section of the report. - - vector<BlacklistKeyword> keyword; // Change to keywords, more than one. - /// The keywords that are found in the URL. -}; - - - -typedef vector<BlacklistCategory> Blacklist; - /// Blacklist is the top-level container for all the blacklists. - // Change this typedef to: - // typedef map<string, vector<BlacklistKeyword> > Blacklist; - // This way we can skip BlacklistCategory. - + const vector<BlacklistKeyword> &getKeywords(); + private: + string _name; + vector<BlacklistKeyword> _keywords; +}; + +typedef vector<Blacklist> Blacklists; struct Extension { /// The strength of the BlacklistMatch will also take the type of the URL in @@ -115,96 +81,4 @@ } // namespace NetResponsibility -namespace Poco { -namespace Data { - -template <> -class TypeHandler<class ::NetResponsibility::BlacklistMatch> -{ -public: - static size_t size() - { - return 4; // we handle four columns of the Table! - } - - static void bind(size_t pos, const ::NetResponsibility::BlacklistMatch& obj, - AbstractBinder* pBinder) - { - poco_assert_dbg (pBinder != 0); - TypeHandler<std::string>::bind(pos++, obj.boldUrl, pBinder); - TypeHandler<std::string>::bind(pos++, obj.abbrUrl, pBinder); - TypeHandler<int>::bind(pos++, obj.strength, pBinder); - TypeHandler<int>::bind(pos++, (int)obj.whitelist, pBinder); - } - - static void prepare(size_t pos, const ::NetResponsibility::BlacklistMatch& obj, - AbstractPreparation* pPrepare) - { - poco_assert_dbg (pBinder != 0); - TypeHandler<std::string>::prepare(pos++, obj.boldUrl, pPrepare); - TypeHandler<std::string>::prepare(pos++, obj.abbrUrl, pPrepare); - TypeHandler<int>::prepare(pos++, obj.strength, pPrepare); - TypeHandler<int>::prepare(pos++, (int)obj.whitelist, pPrepare); - } - - static void extract(size_t pos, ::NetResponsibility::BlacklistMatch& obj, - const ::NetResponsibility::BlacklistMatch& defVal, AbstractExtractor* pExt) - /// obj will contain the result, defVal contains values we should use when one column is NULL - { - poco_assert_dbg (pExt != 0); - int w; - TypeHandler<std::string>::extract(pos++, obj.boldUrl, defVal.boldUrl, pExt); - TypeHandler<std::string>::extract(pos++, obj.abbrUrl, defVal.abbrUrl, pExt); - TypeHandler<int>::extract(pos++, obj.strength, defVal.strength, pExt); - TypeHandler<int>::extract(pos++, w, defVal.whitelist, pExt); - obj.whitelist = (w != 0); - } -}; - - -template <> -class TypeHandler<class ::NetResponsibility::BlacklistKeyword> -{ -public: - static size_t size() - { - return 3; // we handle four columns of the Table! - } - - static void bind(size_t pos, const ::NetResponsibility::BlacklistKeyword& obj, - AbstractBinder* pBinder) - { - poco_assert_dbg (pBinder != 0); - TypeHandler<std::string>::bind(pos++, obj.getKeyword(), pBinder); - TypeHandler<std::string>::bind(pos++, obj.getCategory(), pBinder); - TypeHandler<int>::bind(pos++, obj.getStrength(), pBinder); - } - - static void prepare(size_t pos, const ::NetResponsibility::BlacklistKeyword& obj, - AbstractPreparation* pPrepare) - { - poco_assert_dbg (pBinder != 0); - TypeHandler<std::string>::prepare(pos++, obj.getKeyword(), pPrepare); - TypeHandler<std::string>::prepare(pos++, obj.getCategory(), pPrepare); - TypeHandler<int>::prepare(pos++, obj.getStrength(), pPrepare); - } - - static void extract(size_t pos, ::NetResponsibility::BlacklistKeyword& obj, - const ::NetResponsibility::BlacklistKeyword& defVal, AbstractExtractor* pExt) - /// obj will contain the result, defVal contains values we should use when one column is NULL - { - poco_assert_dbg (pExt != 0); - std::string keyword; - std::string category; - int strength; - TypeHandler<std::string>::extract(pos++, keyword, defVal.getKeyword(), pExt); - TypeHandler<std::string>::extract(pos++, category, defVal.getCategory(), pExt); - TypeHandler<int>::extract(pos++, strength, defVal.getStrength(), pExt); - obj = ::NetResponsibility::BlacklistKeyword(keyword, category, strength); - } -}; - -} } // namespace Poco::Data - - #endif // BLACKLIST_H_INCLUDED diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e include/BlacklistKeyword.h --- a/include/BlacklistKeyword.h +++ b/include/BlacklistKeyword.h @@ -29,13 +29,17 @@ #include <vector> #include "Poco/RegularExpression.h" -#include "Poco/SharedPtr.h" +#include "Poco/SharedPtr.h" +#include "Poco/Data/Common.h" +#include "Poco/Data/Connector.h" +#include "Poco/Data/SQLite/Connector.h" namespace NetResponsibility { using ::Poco::SharedPtr; -using ::Poco::RegularExpression; +using ::Poco::RegularExpression; + using namespace ::std; typedef vector< SharedPtr<RegularExpression> >::const_iterator RegexpIterator; @@ -79,4 +83,51 @@ } // namespace NetResponsibility +namespace Poco { +namespace Data { + +template <> +class TypeHandler<class ::NetResponsibility::BlacklistKeyword> +{ +public: + static size_t size() + { + return 3; // we handle four columns of the Table! + } + + static void bind(size_t pos, const ::NetResponsibility::BlacklistKeyword& obj, + AbstractBinder* pBinder) + { + poco_assert_dbg (pBinder != 0); + TypeHandler<std::string>::bind(pos++, obj.getKeyword(), pBinder); + TypeHandler<std::string>::bind(pos++, obj.getCategory(), pBinder); + TypeHandler<int>::bind(pos++, obj.getStrength(), pBinder); + } + + static void prepare(size_t pos, const ::NetResponsibility::BlacklistKeyword& obj, + AbstractPreparation* pPrepare) + { + poco_assert_dbg (pBinder != 0); + TypeHandler<std::string>::prepare(pos++, obj.getKeyword(), pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.getCategory(), pPrepare); + TypeHandler<int>::prepare(pos++, obj.getStrength(), pPrepare); + } + + static void extract(size_t pos, ::NetResponsibility::BlacklistKeyword& obj, + const ::NetResponsibility::BlacklistKeyword& defVal, AbstractExtractor* pExt) + /// obj will contain the result, defVal contains values we should use when one column is NULL + { + poco_assert_dbg (pExt != 0); + std::string keyword; + std::string category; + int strength; + TypeHandler<std::string>::extract(pos++, keyword, defVal.getKeyword(), pExt); + TypeHandler<std::string>::extract(pos++, category, defVal.getCategory(), pExt); + TypeHandler<int>::extract(pos++, strength, defVal.getStrength(), pExt); + obj = ::NetResponsibility::BlacklistKeyword(keyword, category, strength); + } +}; + +} } // namespace Poco::Data + #endif // BLACKLISTKEYWORD_H diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e include/Filter.h --- a/include/Filter.h +++ b/include/Filter.h @@ -68,9 +68,9 @@ /// Load the Filter, given the path to the blacklist. This is /// especially useful when improving the algorithms. - void loadBlacklist(string path); + void loadBlacklists(string path); - void loadBlacklist(Options* options, Database* db); + void loadBlacklists(Options* options, Database* db); void run(HTTPHit& hit); /// This is the method used for running a complete scan on the @@ -82,7 +82,7 @@ bool isTokenMatch(HTTPHit& hit); private: - Blacklist _blacklist; + Blacklists _blacklists; Extensions _extensions; SharedPtr<RegularExpression> _splitToken; SharedPtr<RegularExpression> _splitExtension; diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e include/MyXml.h --- a/include/MyXml.h +++ b/include/MyXml.h @@ -77,7 +77,7 @@ map<string, string> getStringMap() const; /// Returns a map<string, string> with all values found in the document. - Blacklist getBlacklist(); + Blacklists getBlacklists(); /// Extracts and compiles the keywords in the blacklist file. Extensions getExtensions(); diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -157,7 +157,7 @@ virtual ~Node(); virtual Node& operator = (const Node& node); virtual Node& operator += (NodePtr node); - virtual NodePtr operator [] (int i); + virtual NodePtr operator [] (unsigned int i); int getStrength() const; int size() const; diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e include/Request.h --- a/include/Request.h +++ b/include/Request.h @@ -77,8 +77,8 @@ static void downloadConfig(Options* options, string password = ""); /// Download a new config file. - static void downloadBlacklist(Options* options); - /// Download a new blacklist + static void downloadBlacklists(Options* options); + /// Download a new blacklist file. static string sendImprovementData(Options* options, string impData); /// Send the improvement data to the server. It's given in impData. @@ -87,7 +87,7 @@ /// Updates the config file from the server if it's modifed or doForce /// is true. Returns true if the file was updated. - static bool updateBlacklist(Options* options, bool doForce = false); + static bool updateBlacklists(Options* options, bool doForce = false); /// Updates the blacklist file from the server if it's modifed or /// doForce is true. Returns true if the file was updated. @@ -95,7 +95,7 @@ /// The last time the config file was downloaded from the server. Used /// to determine if the file has been modified. - static int blacklistDownloaded; + static int blacklistsDownloaded; /// The last time the blacklists were downloaded from the server. Used /// to determine if the file has been modified. diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e projectFiles/linux/net-responsibility.cbp --- a/projectFiles/linux/net-responsibility.cbp +++ b/projectFiles/linux/net-responsibility.cbp @@ -168,6 +168,7 @@ <Unit filename="../../plugins/DefaultSniffer/include/SnifferThread.h" /><Unit filename="../../plugins/DefaultSniffer/src/Sniffer.cpp" /><Unit filename="../../plugins/DefaultSniffer/src/SnifferThread.cpp" /> + <Unit filename="../../src/Blacklist.cpp" /><Unit filename="../../src/BlacklistKeyword.cpp" /><Unit filename="../../src/BootHistory.cpp" /><Unit filename="../../src/Bypass.cpp" /> diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e src/Blacklist.cpp --- /dev/null +++ b/src/Blacklist.cpp @@ -0,0 +1,75 @@ +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <Blacklist> is what we're using to filter the HTTPHits + + +#include "Blacklist.h" + + + +namespace NetResponsibility { + + + +Blacklist::Blacklist() +{ + //ctor +} + + + +Blacklist::Blacklist(string name) +{ + _name = name; +} + + +Blacklist::Blacklist(const Blacklist& blacklist) +{ + _name = blacklist._name; + _keywords = blacklist._keywords; +} + + + +string Blacklist::getName() const +{ + return _name; +} + + + +bool Blacklist::isComplementary() const +{ + // TODO determine! + return false; +} + +void Blacklist::addKeyword(BlacklistKeyword keyword) +{ + _keywords.push_back(keyword); +} + + + +const vector<BlacklistKeyword> &Blacklist::getKeywords() +{ + return _keywords; +} + + + +} // namespace NetResponsibility diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -25,25 +25,26 @@ Options* options = &Options::instance(); Database* db = &Database::instance(); setRegexps(); - loadBlacklist(options, db); + loadBlacklists(options, db); } Filter::Filter(string blacklistFile) { setRegexps(); - loadBlacklist(blacklistFile); + loadBlacklists(blacklistFile); } -void Filter::loadBlacklist(string path) { +void Filter::loadBlacklists(string path) { try { - AutoPtr<MyXml> xmlBlacklist (new MyXml(path)); - _blacklist = xmlBlacklist->getBlacklist(); - _extensions = xmlBlacklist->getExtensions(); + AutoPtr<MyXml> xmlBlacklists (new MyXml(path)); + _blacklists = xmlBlacklists->getBlacklists(); + _extensions = xmlBlacklists->getExtensions(); } - catch (Exception &err) { + catch (Exception &err) { + cout <<err.displayText() <<endl; Application::instance().logger().information("Couldn't load blacklist"); //download new } @@ -52,19 +53,19 @@ -void Filter::loadBlacklist(Options *options, Database *db) { +void Filter::loadBlacklists(Options *options, Database *db) { for (int moreTries = 3; moreTries > 0; moreTries--) { try { if (options->isAccountEnabled()) { // Update the blacklist if it's modified bool doUpdate = options->getBool("arg.update-files", false); - Request::updateBlacklist(options, doUpdate); + Request::updateBlacklists(options, doUpdate); } // Load it - AutoPtr<MyXml> xmlBlacklist (new MyXml(options->get<string>("path.blacklist"))); - _blacklist = xmlBlacklist->getBlacklist(); - _extensions = xmlBlacklist->getExtensions(); + AutoPtr<MyXml> xmlBlacklists (new MyXml(options->get<string>("path.blacklist"))); + _blacklists = xmlBlacklists->getBlacklists(); + _extensions = xmlBlacklists->getExtensions(); moreTries = 0; } catch (::Poco::FileNotFoundException &err) { @@ -75,7 +76,7 @@ db->logBypass(Bypass(Bypass::BYPASS_MISSING_FILE, "Blacklist")); if (options->isAccountEnabled()) - Request::downloadBlacklist(options); + Request::downloadBlacklists(options); else moreTries = 0; } @@ -87,7 +88,7 @@ db->logBypass(Bypass(Bypass::BYPASS_MODIFIED_FILE, "Blacklist")); if (options->isAccountEnabled()) - Request::downloadBlacklist(options); + Request::downloadBlacklists(options); else moreTries = 0; } @@ -111,9 +112,10 @@ int strength = 0; RegularExpression::Match m; - for (Blacklist::iterator c = _blacklist.begin(); c != _blacklist.end(); c++) { - for (vector<BlacklistKeyword>::iterator k = c->keyword.begin(); - k != c->keyword.end(); k++) + for (Blacklists::iterator b = _blacklists.begin(); b != _blacklists.end(); b++) { + vector<BlacklistKeyword> keywords = b->getKeywords(); + for (vector<BlacklistKeyword>::iterator k = keywords.begin(); + k != keywords.end(); k++) { isSubMatch = true; for (RegexpIterator r = k->begin(); r != k->end(); r++) @@ -126,7 +128,7 @@ if (isSubMatch) { BlacklistKeyword keyword = *k; hit.addBlacklistKeyword(keyword); - if (c->name != "Whitelist") { + if (b->getName() != "Whitelist") { strength += k->getStrength(); isMatch = true; } diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -138,7 +138,7 @@ bool HTTPHit::isWhitelistMatch(int threshold) { - int whitelistKeywords = 0; + unsigned int whitelistKeywords = 0; for (std::set<BlacklistKeyword>::const_iterator k = _blacklistKeywords.begin(); k != _blacklistKeywords.end(); k++) { diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e src/MyXml.cpp --- a/src/MyXml.cpp +++ b/src/MyXml.cpp @@ -72,7 +72,7 @@ vector<T> vec; vector<string> subkeys; vector<string>::iterator it; - string prefix = (property == "" ? "" : string(property) + string(".")); + string prefix = (property == string("") ? string("") : string(property) + string(".")); this->keys(property, subkeys); for (it = subkeys.begin(); it != subkeys.end(); ++it) { string p = prefix + *it; @@ -87,7 +87,7 @@ map<string, T> MyXml::getMap(const char* property) const { map<string, T> m; vector<string> subkeys; - string prefix = (property == "" ? "" : string(property) + string(".")); + string prefix = (property == string("") ? string("") : string(property) + string(".")); this->keys(property, subkeys); for (vector<string>::iterator it = subkeys.begin(); it != subkeys.end(); ++it) @@ -127,43 +127,43 @@ -Blacklist MyXml::getBlacklist() { - Blacklist blacklist; - BlacklistCategory tempCategory; - vector<string> categories, keywords; +Blacklists MyXml::getBlacklists() { + Blacklists blacklists; + // TODO: change the elements 'category' to 'blacklist' in blacklist file! + vector<string> stringBlacklists, keywords; const int DEFAULT_STRENGTH = 100; - this->keys(categories); + this->keys(stringBlacklists); - for (vector<string>::iterator c = categories.begin(); - c != categories.end(); c++) + for (vector<string>::iterator b = stringBlacklists.begin(); + b != stringBlacklists.end(); b++) { - if (this->hasProperty(*c + "[@name]")) { - tempCategory.name = this->getString(*c + "[@name]"); - blacklist.push_back(tempCategory); - this->keys(*c, keywords); + if (this->hasProperty(*b + "[@name]")) { + Blacklist blacklist(this->getString(*b + "[@name]")); + this->keys(*b, keywords); for (vector<string>::iterator k = keywords.begin(); k != keywords.end(); k++) { string keyword; try { - keyword = this->getString(*c + '.' + *k); - int strength = (this->hasProperty(*c + '.' + *k + "[@s]") - ? this->getInt(*c + '.' + *k + "[@s]") : DEFAULT_STRENGTH); - BlacklistKeyword tempKeyword(keyword, tempCategory.name, strength); - blacklist.back().keyword.push_back(tempKeyword); + keyword = this->getString(*b + '.' + *k); + int strength = (this->hasProperty(*b + '.' + *k + "[@s]") + ? this->getInt(*b + '.' + *k + "[@s]") : DEFAULT_STRENGTH); + BlacklistKeyword tempKeyword(keyword, blacklist.getName(), strength); + blacklist.addKeyword(tempKeyword); } catch (::Poco::Exception &err) { _logger->information(err.displayText() + (string)": " + keyword); continue; } - } + } + blacklists.push_back(blacklist); } } - return blacklist; + return blacklists; } diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e src/Node.cpp --- a/src/Node.cpp +++ b/src/Node.cpp @@ -61,16 +61,18 @@ _children = node._children; _order = node._order; _nodeType = Node::TYPE_NODE; + return *this; } Node& Node::operator += (NodePtr node) { addChild(node); + return *this; } -NodePtr Node::operator [] (int i) { +NodePtr Node::operator [] (unsigned int i) { if (_children.size() > i) return _children[i]; else diff -r 6d02885c1f9bc02b10be7d78fc133d3d9f0026d2 -r 463bc7245ea71b2b05f131e0e4325c9b242d836e src/Request.cpp --- a/src/Request.cpp +++ b/src/Request.cpp @@ -24,7 +24,7 @@ int Request::configDownloaded = -1; -int Request::blacklistDownloaded = -1; +int Request::blacklistsDownloaded = -1; void Request::addMac(Options *options, string password) { @@ -51,7 +51,7 @@ -void Request::downloadBlacklist(Options *options) { +void Request::downloadBlacklists(Options *options) { MyLogger::instance().information("downloading.blacklists"); send(options, "/request/blacklist.php", options->get<string>("path.blacklist")); setDownloadedTime(options); @@ -120,15 +120,15 @@ -bool Request::updateBlacklist(Options *options, bool doForce) { +bool Request::updateBlacklists(Options *options, bool doForce) { try { - if (blacklistDownloaded == -1) + if (blacklistsDownloaded == -1) setDownloadedTime(options); // Determine what time the blacklist file was edited last Timestamp ft = File(options->get<string>("path.blacklist")).getLastModified(); - if (ft.epochTime() > (blacklistDownloaded + 15)) { - downloadBlacklist(options); + if (ft.epochTime() > (blacklistsDownloaded + 15)) { + downloadBlacklists(options); // This won't get caught as a bypass, but maybe it doesn't have to // either, as long as we get the correct blacklist? Bypass bypass(Bypass::BYPASS_MODIFIED_FILE, "Blacklist file"); @@ -136,7 +136,7 @@ return true; } else if (doForce) { - downloadBlacklist(options); + downloadBlacklists(options); return true; } else @@ -206,7 +206,7 @@ if (downloaded != "") { // Read values and set them accordingly configDownloaded = xml->getInt("config", 0); - blacklistDownloaded = xml->getInt("blacklist", 0); + blacklistsDownloaded = xml->getInt("blacklist", 0); } } catch (Exception& exc) { https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/e15bfcd6123c/ Changeset: e15bfcd6123c User: roggan87 Date: 2013-03-26 20:20:04 Summary: Now possible to create HTTPHit by URL directly. Affected #: 2 files diff -r 463bc7245ea71b2b05f131e0e4325c9b242d836e -r e15bfcd6123c05daa59def5071f064a15f18e108 include/HTTPHit.h --- a/include/HTTPHit.h +++ b/include/HTTPHit.h @@ -65,6 +65,7 @@ public: HTTPHit(); + HTTPHit(string url); HTTPHit(const HTTPRequest& request); HTTPHit(const HTTPResponse& response); HTTPHit(const HTTPHit& hit); @@ -112,6 +113,7 @@ void setHost(string hostname); void setPath(string path); + void setUrl(string url); void addBlacklistKeyword(BlacklistKeyword keyword); void setBlacklistKeywords(const std::set<BlacklistKeyword> keywords); void setBlacklistKeywords(const string keywords); diff -r 463bc7245ea71b2b05f131e0e4325c9b242d836e -r e15bfcd6123c05daa59def5071f064a15f18e108 src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -8,6 +8,13 @@ +HTTPHit::HTTPHit(string url) { + setDefaultValues(); + setUrl(url); +} + + + HTTPHit::HTTPHit(const HTTPRequest& request) { setDefaultValues(); @@ -168,6 +175,19 @@ +void HTTPHit::setUrl(string url) { + RegularExpression::MatchVec m; + SharedPtr<RegularExpression> regexp = new RegularExpression("^(\\w+:\\/\\/)?([^\\/]+)", 0, true); + regexp->match(url, 0, m); + unsigned int off = m[2].offset; + unsigned int len = m[2].length; + _host = url.substr(off, len); + if (url.length() > off + len) + _path = url.substr(off + len); +} + + + void HTTPHit::addBlacklistKeyword(BlacklistKeyword keyword) { _blacklistKeywords.insert(keyword); } https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/35f188063572/ Changeset: 35f188063572 User: roggan87 Date: 2013-03-26 20:20:56 Summary: Moved the most basic NR filtering method to BlacklistKeyword. Affected #: 3 files diff -r e15bfcd6123c05daa59def5071f064a15f18e108 -r 35f18806357231523ab4d779fb52014fa5aabf86 include/BlacklistKeyword.h --- a/include/BlacklistKeyword.h +++ b/include/BlacklistKeyword.h @@ -68,6 +68,8 @@ RegexpIterator end() const; + RegularExpression::MatchVec match(string token) const; + protected: int _strength; /// The strength of this keyword. 100 is default. diff -r e15bfcd6123c05daa59def5071f064a15f18e108 -r 35f18806357231523ab4d779fb52014fa5aabf86 src/BlacklistKeyword.cpp --- a/src/BlacklistKeyword.cpp +++ b/src/BlacklistKeyword.cpp @@ -123,4 +123,17 @@ } + +RegularExpression::MatchVec BlacklistKeyword::match(string token) const { + RegularExpression::MatchVec matches, empty; + for (RegexpIterator r = _regexps.begin(); r != _regexps.end(); r++) { + RegularExpression::Match m; + if ((**r).match(token, m)) + matches.push_back(m); + else + return empty; + } + return matches; +} + } // namespace NetResponsibility diff -r e15bfcd6123c05daa59def5071f064a15f18e108 -r 35f18806357231523ab4d779fb52014fa5aabf86 src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -106,26 +106,17 @@ bool Filter::isUrlMatch(HTTPHit& hit) { - string url = hit.getUrl(); - bool isSubMatch; bool isMatch = false; int strength = 0; - RegularExpression::Match m; for (Blacklists::iterator b = _blacklists.begin(); b != _blacklists.end(); b++) { vector<BlacklistKeyword> keywords = b->getKeywords(); for (vector<BlacklistKeyword>::iterator k = keywords.begin(); k != keywords.end(); k++) - { - isSubMatch = true; - for (RegexpIterator r = k->begin(); r != k->end(); r++) - { - if (!(**r).match(url, m)) { - isSubMatch = false; - break; - } - } - if (isSubMatch) { + { + string url = hit.getUrl(); + RegularExpression::MatchVec matches = k->match(url); + if (matches.size() > 0) { BlacklistKeyword keyword = *k; hit.addBlacklistKeyword(keyword); if (b->getName() != "Whitelist") { https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/fb5d7d6b7fb8/ Changeset: fb5d7d6b7fb8 User: roggan87 Date: 2013-03-26 22:42:55 Summary: Added a Token struct to be able to give tokens different strength. Splitting of tokens now happens right in the HTTPHit. Affected #: 4 files diff -r 35f18806357231523ab4d779fb52014fa5aabf86 -r fb5d7d6b7fb832dccc786b6e07f575a4bbaa6ef0 include/Blacklist.h --- a/include/Blacklist.h +++ b/include/Blacklist.h @@ -58,6 +58,10 @@ typedef vector<Blacklist> Blacklists; +// TODO: Put extensions, or more correctly; MimeTypes into each Blacklist. +// Different blacklists may have different viewpoints on what kind of files +// that are harmful. + struct Extension { /// The strength of the BlacklistMatch will also take the type of the URL in /// consideration. If it's an image or video it will be much stronger than diff -r 35f18806357231523ab4d779fb52014fa5aabf86 -r fb5d7d6b7fb832dccc786b6e07f575a4bbaa6ef0 include/HTTPHit.h --- a/include/HTTPHit.h +++ b/include/HTTPHit.h @@ -37,6 +37,7 @@ #include "Poco/SharedPtr.h" #include "Poco/Timestamp.h" #include "Poco/DateTimeFormatter.h" +#include "Poco/URI.h" #include "Poco/Net/HTTPRequest.h" #include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPMessage.h" @@ -64,6 +65,16 @@ { public: + + struct Token + /// This struct makes it possible to make each different + /// token have its own strength. + { + Token(string c, int s): content(c), strength(s) {} + string content; + int strength; + }; + HTTPHit(); HTTPHit(string url); HTTPHit(const HTTPRequest& request); @@ -120,6 +131,8 @@ std::set<BlacklistKeyword> getBlacklistKeywords(); + vector<HTTPHit::Token> getTokens(); + Node::StrengthLevel getStrengthLevel(); /// Returns the StrengthLevel of the HTTPHit. Slightly modified /// version of Node::getStrengthLevel(). @@ -128,6 +141,7 @@ string _host; string _path; int _parent; + vector<Token> _tokens; std::set<BlacklistKeyword> _blacklistKeywords; diff -r 35f18806357231523ab4d779fb52014fa5aabf86 -r fb5d7d6b7fb832dccc786b6e07f575a4bbaa6ef0 src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -134,67 +134,55 @@ bool Filter::isTokenMatch(HTTPHit& hit) { bool isMatch = false; - RegularExpression::Match m, n; + RegularExpression::Match n; float strength = 0; float wordFactor = 0.5; int tokenMatches = 0; - unsigned int o = 0; - string url = hit.getUrl(); - string decodedUrl = ""; - try { - ::Poco::URI::decode(url, decodedUrl); - } - catch (::Poco::Exception &exc) { - decodedUrl = url; - } - while (o < decodedUrl.length()) { - _splitToken->match(decodedUrl, o, m); - if (m.offset == string::npos) - m.offset = decodedUrl.length(); - string token = decodedUrl.substr(o, m.offset-o); - if (token.length() > 2) { - tokenMatches = 0; - std::set<BlacklistKeyword> keywords = hit.getBlacklistKeywords(); - for (std::set<BlacklistKeyword>::const_iterator - k = keywords.begin(); k != keywords.end(); k++) + + vector<HTTPHit::Token> tokens = hit.getTokens(); + for(vector<HTTPHit::Token>::iterator it = tokens.begin(); + it != tokens.end(); it++) + { + tokenMatches = 0; + std::set<BlacklistKeyword> keywords = hit.getBlacklistKeywords(); + for (std::set<BlacklistKeyword>::const_iterator + k = keywords.begin(); k != keywords.end(); k++) + { + bool isSubMatch = true; + float strengthFactor = 0; + string token = it->content; + for (RegexpIterator r = k->begin(); r != k->end(); r++) { - bool isSubMatch = true; - float strengthFactor = 0; - for (RegexpIterator r = k->begin(); r != k->end(); r++) - { - if ((**r).match(token, n)) { - while (n.offset != string::npos) { - if (n.offset == 0 - || _wordDelimiter-> - match(token.substr(n.offset-1, 1))) - wordFactor += 0.5; - if (n.offset + n.length == token.length() - || _wordDelimiter->match( - token.substr(n.offset + n.length, 1))) - wordFactor += 0.5; - strengthFactor += (float)n.length/token.length() - * wordFactor; - wordFactor = 0.5; - tokenMatches++; - (**r).match(token, n.offset + n.length, n); - } - } - else { - isSubMatch = false; - break; + if ((**r).match(token, n)) { + while (n.offset != string::npos) { + if (n.offset == 0 + || _wordDelimiter-> + match(token.substr(n.offset-1, 1))) + wordFactor += 0.5; + if (n.offset + n.length == token.length() + || _wordDelimiter->match( + token.substr(n.offset + n.length, 1))) + wordFactor += 0.5; + strengthFactor += (float)n.length/token.length() + * wordFactor; + wordFactor = 0.5; + tokenMatches++; + (**r).match(token, n.offset + n.length, n); } } - if (isSubMatch) { - isMatch = true; - strengthFactor += strengthFactor/tokenMatches; - strength += strengthFactor * k->getStrength(); + else { + isSubMatch = false; + break; } - + } + if (isSubMatch) { + isMatch = true; + strengthFactor += strengthFactor/tokenMatches; + strength += strengthFactor * k->getStrength(); } } - o = m.offset + m.length; } - strength *= getExtensionFactor(url); + strength *= getExtensionFactor(hit.getUrl()); if (isMatch) hit.setStrength((int)strength); diff -r 35f18806357231523ab4d779fb52014fa5aabf86 -r fb5d7d6b7fb832dccc786b6e07f575a4bbaa6ef0 src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -44,6 +44,7 @@ copyHeaders(hit); _host = hit._host; _path = hit._path; + _tokens = hit._tokens; _strength = hit._strength; _dateTime = hit._dateTime; _blacklistKeywords = hit._blacklistKeywords; @@ -221,6 +222,40 @@ +vector<HTTPHit::Token> HTTPHit::getTokens() { + // Adding host and path to tokens at request. + // Not before, in case they would change. + vector<Token> ret = _tokens; + ret.push_back(Token(_host, 150)); + + string decoded; + unsigned int o = 0; + RegularExpression::Match m; + SharedPtr<RegularExpression> _splitToken + = new RegularExpression("((\\?|\\&|;).*?\\=)|\\/|(\\%2F)|#", 0, true); + + try { + ::Poco::URI::decode(_path, decoded); + } + catch (::Poco::Exception &exc) { + decoded = _path; + } + + while (o < decoded.length()) { + _splitToken->match(decoded, o, m); + if (m.offset == string::npos) + m.offset = decoded.length(); + string token = decoded.substr(o, m.offset-o); + if (token.length() > 2) + ret.push_back(Token(token, 100)); + o = m.offset + m.length; + } + + return ret; +} + + + Node::StrengthLevel HTTPHit::getStrengthLevel() { if (isMatch()) return (Node::StrengthLevel)(((_strength + 12) / 25) + 2); https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/9533905bcc12/ Changeset: 9533905bcc12 User: roggan87 Date: 2013-03-26 22:44:28 Summary: Removed _splitToken from Filter too. Affected #: 2 files diff -r fb5d7d6b7fb832dccc786b6e07f575a4bbaa6ef0 -r 9533905bcc12e37a529ccdedf96b6e51f3251040 include/Filter.h --- a/include/Filter.h +++ b/include/Filter.h @@ -84,7 +84,6 @@ private: Blacklists _blacklists; Extensions _extensions; - SharedPtr<RegularExpression> _splitToken; SharedPtr<RegularExpression> _splitExtension; SharedPtr<RegularExpression> _wordDelimiter; diff -r fb5d7d6b7fb832dccc786b6e07f575a4bbaa6ef0 -r 9533905bcc12e37a529ccdedf96b6e51f3251040 src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -192,8 +192,6 @@ void Filter::setRegexps() { - _splitToken = - new RegularExpression("((\\?|\\&|;).*?\\=)|\\/|(\\%2F)|#", 0, true); _wordDelimiter = new RegularExpression("[\\s-_+\"']|\\.", 0, true); _splitExtension = new RegularExpression("/?(?:[^/?#]+/)+(?:[^?#]+\\.)" "([a-zA-Z0-9]{1,4})(?:$|\\?|#).*", 0, true); https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/cc3313daf508/ Changeset: cc3313daf508 User: roggan87 Date: 2013-03-26 23:06:21 Summary: Added Filter::findMatches() to eventually replace isUrlMatch(). Affected #: 2 files diff -r 9533905bcc12e37a529ccdedf96b6e51f3251040 -r cc3313daf508b5f52a1ed7fe74dd74a1b8b616fb include/Filter.h --- a/include/Filter.h +++ b/include/Filter.h @@ -77,6 +77,10 @@ /// HTTPHit. The result is writted to the hit in terms of /// strength, keywords found etc. + void findMatches(HTTPHit& hit); + /// This method runs a quick scan on the HTTPHit to sort + /// out which BlacklistKeywords that are found in it. + bool isUrlMatch(HTTPHit& hit); bool isTokenMatch(HTTPHit& hit); diff -r 9533905bcc12e37a529ccdedf96b6e51f3251040 -r cc3313daf508b5f52a1ed7fe74dd74a1b8b616fb src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -101,6 +101,40 @@ isUrlMatch(hit); isTokenMatch(hit); // TODO: Don't count as a match unless isTokenMatch +} + + + +void Filter::findMatches(HTTPHit& hit) { + set<BlacklistKeyword> keywords; + string url = hit.getUrl(); + + // First run through all blacklists and put matches => keywords + for (Blacklists::iterator b = _blacklists.begin(); b != _blacklists.end(); b++) { + vector<BlacklistKeyword> bk = b->getKeywords(); + for (vector<BlacklistKeyword>::iterator k =bk.begin(); k != bk.end(); k++) { + RegularExpression::MatchVec matches = k->match(url); + if (matches.size() > 0) + keywords.insert(*k); + } + } + + // Next find out if the keywords survive the token test + vector<HTTPHit::Token> tokens = hit.getTokens(); + for (set<BlacklistKeyword>::iterator k = keywords.begin(); + k != keywords.end(); k++) + { + bool doPass = false; + for (vector<HTTPHit::Token>::iterator t = tokens.begin(); t != tokens.end(); t++) { + RegularExpression::MatchVec m = k->match(t->content); + if (m.size() > 0) + doPass = true; + } + if (!doPass) + keywords.erase(k); + } + + hit.setBlacklistKeywords(keywords); } https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/1c8a1fdc4073/ Changeset: 1c8a1fdc4073 User: roggan87 Date: 2013-03-26 23:20:18 Summary: Added Filter::determineStrength() to eventually replace isTokenMatch(). Affected #: 2 files diff -r cc3313daf508b5f52a1ed7fe74dd74a1b8b616fb -r 1c8a1fdc4073bfdc41b834916d8d1b0cf6e61104 include/Filter.h --- a/include/Filter.h +++ b/include/Filter.h @@ -81,6 +81,11 @@ /// This method runs a quick scan on the HTTPHit to sort /// out which BlacklistKeywords that are found in it. + void determineStrength(HTTPHit& hit); + /// Here we use the BlacklistKeywords found with findMatches() + /// and run several tests on the HTTPHit to determine how + /// strong the match is. + bool isUrlMatch(HTTPHit& hit); bool isTokenMatch(HTTPHit& hit); diff -r cc3313daf508b5f52a1ed7fe74dd74a1b8b616fb -r 1c8a1fdc4073bfdc41b834916d8d1b0cf6e61104 src/Filter.cpp --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -136,7 +136,25 @@ hit.setBlacklistKeywords(keywords); } - + + + +void Filter::determineStrength(HTTPHit& hit) { + float strength = 0; // TODO: Base strength on number of keywords #45 + vector<HTTPHit::Token> tokens = hit.getTokens(); + set<BlacklistKeyword> keywords = hit.getBlacklistKeywords(); + for (vector<HTTPHit::Token>::iterator t = tokens.begin(); t != tokens.end(); t++) { + for (set<BlacklistKeyword>::iterator k = keywords.begin(); + k != keywords.end(); k++) + { + RegularExpression::MatchVec m = k->match(t->content); + // TODO: Handle suborder #46 + } + // TODO: Handle total length of matches vs. tokenlength + } + hit.setStrength((int)strength); +} + bool Filter::isUrlMatch(HTTPHit& hit) { https://bitbucket.org/netresponsibilityteam/net-responsibility/commits/dfbfbacfa58f/ Changeset: dfbfbacfa58f User: roggan87 Date: 2013-07-05 11:17:08 Summary: Using utmpx to parse the boot history (optional) Now it's possible to use either utmp or utmpx to extract the boot history. For Windows we'll need something else. It's possible to disable either technique at build time like $ ./configure --disable-utmpx --disable-utmp This closes bug #34. Affected #: 6 files diff -r 1c8a1fdc4073bfdc41b834916d8d1b0cf6e61104 -r dfbfbacfa58f306ace1643080d6de990ca2dedd1 Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -55,11 +55,20 @@ ldFlags += -L$(top_srcdir)/lib endif +defines = -DPKGDATADIR='$(pkgdatadir)'\ + -DPKGLIBDIR='$(pkglibdir)'\ + -DDATABASEDIR='$(databasedir)'\ + -DPIDDIR='$(piddir)' + +if UTMPX_ENABLED + defines += -DUTMPX_ENABLED=1 +endif +if UTMP_ENABLED + defines += -DUTMP_ENABLED=1 +endif + cppFlags = $(incDirs)\ - -DPKGDATADIR='$(pkgdatadir)'\ - -DPKGLIBDIR='$(pkglibdir)'\ - -DDATABASEDIR='$(databasedir)'\ - -DPIDDIR='$(piddir)'\ + $(defines)\ @CPPFLAGS@ AM_CXXFLAGS = $(incDirs) @CXXFLAGS@ diff -r 1c8a1fdc4073bfdc41b834916d8d1b0cf6e61104 -r dfbfbacfa58f306ace1643080d6de990ca2dedd1 configure.ac --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ [AS_HELP_STRING( [--with-initdir=/path], [Install init script to /path.] - )], + )], [AC_SUBST([initdir], [$withval])], [AC_SUBST([initdir], ['/etc/init.d'])] ) @@ -31,7 +31,7 @@ [AS_HELP_STRING( [--with-databasedir=/path], [Save the database in /path.] - )], + )], [AC_SUBST([databasedir], [$withv... [truncated message content] |
From: Bitbucket <com...@bi...> - 2012-11-16 20:24:46
|
6 new commits in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/2987f8a25641/ changeset: 2987f8a25641 user: roggan87 date: 2012-11-07 00:20:29 summary: I should've included the projectFile in the last commit, but here it is. affected #: 1 file diff -r c59e51fb40fabfe03642a23e0e3ec49c4415f7ca -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 projectFiles/linux/net-responsibility.cbp --- a/projectFiles/linux/net-responsibility.cbp +++ b/projectFiles/linux/net-responsibility.cbp @@ -146,13 +146,12 @@ <Unit filename="../../include/Blacklist.h" /><Unit filename="../../include/BlacklistKeyword.h" /><Unit filename="../../include/BootHistory.h" /> - <Unit filename="../../include/Bypasses.h" /> + <Unit filename="../../include/Bypass.h" /><Unit filename="../../include/ConfigSubsystem.h" /><Unit filename="../../include/Database.h" /><Unit filename="../../include/Filter.h" /><Unit filename="../../include/HTTPHit.h" /><Unit filename="../../include/HTTPHitHandler.h" /> - <Unit filename="../../include/History.h" /><Unit filename="../../include/MainApplication.h" /><Unit filename="../../include/MyLogger.h" /><Unit filename="../../include/MyXml.h" /> @@ -163,7 +162,6 @@ <Unit filename="../../include/ReportSubsystem.h" /><Unit filename="../../include/Request.h" /><Unit filename="../../include/SnifferSubsystem.h" /> - <Unit filename="../../include/Warnings.h" /><Unit filename="../../plugins/DefaultReport/include/Report.h" /><Unit filename="../../plugins/DefaultReport/src/Report.cpp" /><Unit filename="../../plugins/DefaultSniffer/include/Sniffer.h" /> @@ -172,13 +170,12 @@ <Unit filename="../../plugins/DefaultSniffer/src/SnifferThread.cpp" /><Unit filename="../../src/BlacklistKeyword.cpp" /><Unit filename="../../src/BootHistory.cpp" /> - <Unit filename="../../src/Bypasses.cpp" /> + <Unit filename="../../src/Bypass.cpp" /><Unit filename="../../src/ConfigSubsystem.cpp" /><Unit filename="../../src/Database.cpp" /><Unit filename="../../src/Filter.cpp" /><Unit filename="../../src/HTTPHit.cpp" /><Unit filename="../../src/HTTPHitHandler.cpp" /> - <Unit filename="../../src/History.cpp" /><Unit filename="../../src/MainApplication.cpp" /><Unit filename="../../src/MyLogger.cpp" /><Unit filename="../../src/MyXml.cpp" /> @@ -188,7 +185,6 @@ <Unit filename="../../src/ReportSubsystem.cpp" /><Unit filename="../../src/Request.cpp" /><Unit filename="../../src/SnifferSubsystem.cpp" /> - <Unit filename="../../src/Warnings.cpp" /><Unit filename="../../src/main.cpp" /><Extensions><code_completion /> https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/eb4ff7df7079/ changeset: eb4ff7df7079 user: roggan87 date: 2012-11-08 17:09:47 summary: Added the enum Node::Structure to be able to specify the tree structure of the Node requested from the database. Changed name of Node::NodeSort to Node::Sort and Node::NodeType to Node::Type to avoid redundancy. affected #: 7 files diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a include/Database.h --- a/include/Database.h +++ b/include/Database.h @@ -82,23 +82,26 @@ int getCount(string from) const; /// Return the number of rows found in the table 'from'. - // TODO: change the string to something less malicious, like NodeType + // TODO: change the string to something less malicious, like Type // and switch-case. - NodePtr getBypasses(Node::NodeSort sortBy = Node::SORT_NAME_ASC) const; - /// Return all Bypasses found. + NodePtr getBypasses(Node::Sort sortBy = Node::SORT_NAME_ASC) const; + /// Return all Bypasses found. - NodePtr getHistory(Node::NodeSort sortBy = Node::SORT_NAME_ASC) const; - /// Return all History. + NodePtr getHistory(Node::Structure structure, + Node::Sort sortBy = Node::SORT_NAME_ASC) const; + /// Return all History. - NodePtr getWarnings(int threshold = 0, Node::NodeSort sortBy = Node::SORT_NAME_ASC) const; - /// Return all Warnings with a strength greater than the - /// threshold. + NodePtr getWarnings(Node::Structure structure, + int threshold = 0, Node::Sort sortBy = Node::SORT_NAME_ASC) const; + /// Return all Warnings with a strength greater than the + /// threshold. - NodePtr getWhitelist(int threshold = 0, Node::NodeSort sortBy = Node::SORT_NAME_ASC) const; - /// Return all matches that are whitelisted for some reason. This - /// is wrapped up in a Warnings object, since it's actually - /// the same thing, but the matches are also considered clean. + NodePtr getWhitelist(Node::Structure structure, + int threshold = 0, Node::Sort sortBy = Node::SORT_NAME_ASC) const; + /// Return all matches that are whitelisted for some reason. This + /// is wrapped up in a Warnings object, since it's actually + /// the same thing, but the matches are also considered clean. void logBypass(Bypass bypass); /// Log attempts to bypass the software. @@ -147,9 +150,11 @@ void processPreviousSessions(); /// Process the previous sessions, and log any attempts to bypass NR. - NodePtr getHits(string where, Node::StrengthLevel level) const; + NodePtr getHits(Node::Structure structure, string where, Node::StrengthLevel level) const; /// Return HTTPHits filtered by the where-string. + bool isCorrectLevel(NodePtr hit, Node::StrengthLevel level) const; + friend class HTTPHitHandler; private: diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -61,7 +61,7 @@ { public: - enum NodeType + enum Type /// This enum specifies what kind of Node we're dealing with. /// It should be set in constructor, and accessed by getNodeType(). { @@ -75,7 +75,7 @@ /// The Node is a Bypass. }; - enum NodeSort + enum Sort /// This enum is used with the sort() method to specify in /// what order the children should be sorted. { @@ -107,6 +107,30 @@ }; + enum Structure + /// Indicates how you want to structure the tree. + { + STRUCTURE_FLAT, + /// All children are accessed from the root Node, no + /// deeper levels, no grouping of the children. + /// + /// Root -> Children + + STRUCTURE_DOMAIN, + /// The HTTPHits are grouped together by top domain, not + /// only hostname. For example + /// http://forum.netresponsibility.com/example.php + /// is grouped together with all other hits from + /// netresponsibility.com. + /// + /// Root -> Domain -> HTTPHits + + STRUCTURE_STRENGTH_LEVEL + /// Group all Nodes by their StrengthLevel. + /// + /// Root -> StrengthLevel -> Children + }; + enum StrengthLevel /// Depending on the strength of the Node it is classed as /// one of these levels. @@ -161,8 +185,8 @@ void setChildren(NodeVector nodes); void setStrength(int strength); void setDateTime(Timestamp dateTime); - void sort(NodeSort sortBy, bool isRecursive = true); - /// Sorts all children of this Node. Use a NodeSort value + void sort(Node::Sort sortBy, bool isRecursive = true); + /// Sorts all children of this Node. Use a Node::Sort value /// to specify which order you want. The order is stored and /// used when new children are added. /// @@ -177,10 +201,10 @@ /// Returns an iterator referring to the past-the-end /// child Node. - NodeSort getOrder() const; + Node::Sort getOrder() const; /// Returns the order that is set for the children of this node. - NodeType getNodeType() const; + Node::Type getNodeType() const; /// Returns the type of the Node. virtual StrengthLevel getStrengthLevel(); @@ -211,8 +235,8 @@ int _strength; Timestamp _dateTime; NodeVector _children; - NodeSort _order; - NodeType _nodeType; + Node::Sort _order; + Node::Type _nodeType; static const string VIRTUAL_EXCEPTION; diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a plugins/DefaultReport/src/Report.cpp --- a/plugins/DefaultReport/src/Report.cpp +++ b/plugins/DefaultReport/src/Report.cpp @@ -81,7 +81,7 @@ string attKeywordsContent; int threshold = _options->getInt("reportStrengthThreshold", 0); - NodePtr warnings = _db->getWarnings(threshold); + NodePtr warnings = _db->getWarnings(Node::STRUCTURE_DOMAIN, threshold); if (warnings->size() > 0) { for(NodeIterator it = warnings->begin(); it != warnings->end(); it++) { @@ -90,9 +90,8 @@ for(NodeIterator it2 = (*it)->begin(); it2 != (*it)->end(); it2++) { - urlsContent <<makeColoredStrength((*it2)->getStrength()) - <<" " <<(*it2)->getJoinedBlacklistKeywords() - <<(*it2)->getAbbrUrl(); + urlsContent <<makeColoredStrength((*it2)->getStrength()) + <<" " <<(*it2)->getAbbrUrl(); attUrlsContent <<"['" <<jsContent((*it2)->getAbbrUrl()) <<"', ['http://" <<jsContent((*it2)->getUrl()) <<"'],, '" <<jsContent((*it2)->getDateTime( @@ -128,23 +127,21 @@ void Report::makeWhitelistSection() { int threshold = _options->getInt("reportStrengthThreshold", 0); - NodePtr whitelist = _db->getWhitelist(threshold); + NodePtr whitelist = _db->getWhitelist(Node::STRUCTURE_FLAT, threshold); if (whitelist->size() > 0) { string urlsContent = "", attUrlsContent = ""; - for(NodeIterator it = whitelist->begin(); it != whitelist->end(); it++) { - for(NodeIterator it2 = (*it)->begin(); it2 != (*it)->end(); it2++) { - urlsContent += (*it2)->getAbbrUrl(); - attUrlsContent += "['" + jsContent((*it2)->getAbbrUrl()) - + "', ['http://" + jsContent((*it2)->getUrl()) + "'],, '" - + jsContent((*it2)->getDateTime( - _options->getString("dateTimeFormat"))) + "']"; + for(NodeIterator it = whitelist->begin(); it != whitelist->end(); it++) { + urlsContent += (*it)->getAbbrUrl(); + attUrlsContent += "['" + jsContent((*it)->getAbbrUrl()) + + "', ['http://" + jsContent((*it)->getUrl()) + "'],, '" + + jsContent((*it)->getDateTime( + _options->getString("dateTimeFormat"))) + "']"; - if (it2 != (*it)->end() - 1) { - urlsContent += "<br>"; - attUrlsContent += ",\n"; - } - - } + if (it != whitelist->end() - 1) { + urlsContent += "<br>"; + attUrlsContent += ",\n"; + } + } if (_options->isReportPart("whitelist")) _body <<makeTableBranch( @@ -160,7 +157,7 @@ void Report::makeHistorySection() { bool doIncludePaths = _options->isAttachedReportPart("history_paths"); - NodePtr history = _db->getHistory(); + NodePtr history = _db->getHistory(Node::STRUCTURE_DOMAIN); string domains; if (history->size() > 0) { diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -134,7 +134,7 @@ -NodePtr Database::getBypasses(Node::NodeSort sortBy) const { +NodePtr Database::getBypasses(Node::Sort sortBy) const { NodePtr bypasses = new Node("Bypasses"); const int FINISHED = 30; for (int i = 0; i <= FINISHED; i++) { @@ -166,28 +166,30 @@ -NodePtr Database::getHistory(Node::NodeSort sortBy) const { - NodePtr hits = getHits("", Node::LEVEL_NONE); +NodePtr Database::getHistory(Node::Structure structure, Node::Sort sortBy) const { + NodePtr hits = getHits(structure, "", Node::LEVEL_NONE); hits->sort(sortBy); return hits; } -NodePtr Database::getWarnings(int threshold, Node::NodeSort sortBy) const { +NodePtr Database::getWarnings(Node::Structure structure, + int threshold, Node::Sort sortBy) const { stringstream where; where <<"keywords != '' AND strength >= " <<threshold; - NodePtr hits = getHits(where.str(), Node::LEVEL_DANGEROUS); + NodePtr hits = getHits(structure, where.str(), Node::LEVEL_DANGEROUS); hits->sort(sortBy); return hits; } -NodePtr Database::getWhitelist(int threshold, Node::NodeSort sortBy) const { +NodePtr Database::getWhitelist(Node::Structure structure, + int threshold, Node::Sort sortBy) const { stringstream where; where <<"keywords != '' AND strength >= " <<threshold; - NodePtr hits = getHits(where.str(), Node::LEVEL_WHITELIST); + NodePtr hits = getHits(structure, where.str(), Node::LEVEL_WHITELIST); hits->sort(sortBy); return hits; } @@ -567,11 +569,11 @@ -NodePtr Database::getHits(string where, Node::StrengthLevel level) const { - NodePtr history = new Node("History"); - // This regexp extracts the second-level domains, like example.com. - RegularExpression secondLevel("(^\\d+\\.\\d+\\.\\d+\\.\\d+(:\\d*)?$)" - "|(([^\\.]+\\.)([^\\.]+)$)", 0, true); +NodePtr Database::getHits(Node::Structure structure, string where, + Node::StrengthLevel level) const +{ + NodePtr tree = new Node(); + vector<HTTPHit> rows; if (where != "") where = " WHERE " + where; @@ -579,52 +581,12 @@ const int FINISHED = 30; for (int i = 0; i <= FINISHED; i++) { try { - vector<HTTPHit> hits; - map<string, NodeVector> domains; + *_session <<"SELECT hostname, path, strftime('%s', datetime, 'utc'), " <<"contentType, title, parent, " <<"strength, keywords FROM hits" - <<where, into(hits), now; - - for (vector<HTTPHit>::iterator it = hits.begin(); it != hits.end(); it++) { - string host; - if (!secondLevel.extract(it->getHost(), host, 0)) - host = it->getHost(); - - NodePtr hit = new HTTPHit(*it); - // Only add the hit if it's the specified level. - switch (level) { - case Node::LEVEL_NONE: - domains[host].push_back(hit); - break; - - case Node::LEVEL_WHITELIST: - if (hit->getStrengthLevel() == level) - domains[host].push_back(hit); - break; - - case Node::LEVEL_SAFE: - case Node::LEVEL_PROBABLY_SAFE: - case Node::LEVEL_SUSPICIOUS: - case Node::LEVEL_UNSAFE: - case Node::LEVEL_DANGEROUS: - if (hit->getStrengthLevel() >= Node::LEVEL_SAFE) - domains[host].push_back(hit); - break; - - default: - break; - } - } - - for (map<string, NodeVector>::iterator it = domains.begin(); - it != domains.end(); it++) - { - NodePtr domain = new Node(it->first); - domain->setChildren(it->second); - history->addChild(domain); - } + <<where, into(rows), now; i = FINISHED; } @@ -639,10 +601,82 @@ catch (Exception &e) { _logger->warning(e.displayText()); } - } - return history; + } + + + if (structure == Node::STRUCTURE_FLAT) { + + for (vector<HTTPHit>::iterator it = rows.begin(); + it != rows.end(); it++) + { + NodePtr hit = new HTTPHit(*it); + if (isCorrectLevel(hit, level)) + tree->addChild(new HTTPHit(*it)); + + } + } + + else if (structure == Node::STRUCTURE_DOMAIN) { + // This regexp extracts the second-level domains, like example.com. + RegularExpression secondLevel("(^\\d+\\.\\d+\\.\\d+\\.\\d+(:\\d*)?$)" + "|(([^\\.]+\\.)([^\\.]+)$)", 0, true); + + map <string, NodeVector> domains; + + for (vector<HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { + string host; + if (!secondLevel.extract(it->getHost(), host, 0)) + host = it->getHost(); + + NodePtr hit = new HTTPHit(*it); + // Only add the hit if it's the specified level. + if (isCorrectLevel(hit, level)) + domains[host].push_back(hit); + } + + for (map<string, NodeVector>::iterator it = domains.begin(); + it != domains.end(); it++) + { + NodePtr domain = new Node(it->first); + domain->setChildren(it->second); + tree->addChild(domain); + } + + } + + + return tree; } + + +bool Database::isCorrectLevel(NodePtr hit, Node::StrengthLevel level) const { + switch (level) { + case Node::LEVEL_NONE: + return true; + break; + + case Node::LEVEL_WHITELIST: + if (hit->getStrengthLevel() == level) + return true; + break; + + case Node::LEVEL_SAFE: + case Node::LEVEL_PROBABLY_SAFE: + case Node::LEVEL_SUSPICIOUS: + case Node::LEVEL_UNSAFE: + case Node::LEVEL_DANGEROUS: + if (hit->getStrengthLevel() >= Node::LEVEL_SAFE) + return true; + break; + + default: + return false; + break; + } + return false; +} + } // namespace NetResponsibility diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -130,7 +130,7 @@ bool HTTPHit::isMatch(int threshold) { - return (_strength > threshold + return (_strength >= threshold && !_blacklistKeywords.empty() && !isWhitelistMatch(threshold)); } @@ -141,7 +141,7 @@ for (std::set<BlacklistKeyword>::const_iterator k = _blacklistKeywords.begin(); k != _blacklistKeywords.end(); k++) { - if (_strength > threshold && k->getCategory() == "Whitelist") + if (_strength >= threshold && k->getCategory() == "Whitelist") return true; } return false; @@ -202,7 +202,7 @@ Node::StrengthLevel HTTPHit::getStrengthLevel() { if (isMatch()) - return (Node::StrengthLevel)((_strength / 20) + 2); + return (Node::StrengthLevel)(((_strength + 12) / 25) + 2); else if (isWhitelistMatch()) return Node::LEVEL_WHITELIST; else diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a src/Node.cpp --- a/src/Node.cpp +++ b/src/Node.cpp @@ -150,7 +150,7 @@ -void Node::sort(Node::NodeSort sortBy, bool isRecursive) { +void Node::sort(Node::Sort sortBy, bool isRecursive) { switch (sortBy) { case SORT_NAME_ASC: std::sort(_children.begin(), _children.end(), Node::sortByNameAsc); @@ -197,13 +197,13 @@ -Node::NodeSort Node::getOrder() const { +Node::Sort Node::getOrder() const { return _order; } -Node::NodeType Node::getNodeType() const { +Node::Type Node::getNodeType() const { return _nodeType; } @@ -213,7 +213,7 @@ if (_strength == 0) return Node::LEVEL_NONE; else - return (Node::StrengthLevel)((_strength / 20) + 2); + return (Node::StrengthLevel)(((_strength + 12) / 25) + 2); } diff -r 2987f8a256413c9d9e7bc1d1bda5e15cb5caaab2 -r eb4ff7df7079eb0799506405403d83d8c6fbf12a src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -180,25 +180,24 @@ -void ReportBase::sendImprovementData() { - NodePtr warnings = _db->getWarnings(_options->getInt("reportStrengthThreshold")); +void ReportBase::sendImprovementData() { + int threshold = _options->getInt("reportStrengthThreshold"); + NodePtr warnings = _db->getWarnings(Node::STRUCTURE_FLAT, threshold); if (_options->getBool("improveData", false) && warnings->size() > 0) { stringstream impData; int i = 0; - for (NodeIterator it = warnings->begin(); it != warnings->end(); it++) { - for (NodeIterator it2 = (*it)->begin(); it2 != (*it)->end(); it2++) { + for (NodeIterator it = warnings->begin(); it != warnings->end(); it++) { - // Do we still need to encode the urls? - impData <<"#" <<i++ <<endl - <<"url: " <<(*it2)->getUrl() <<endl - <<"boldUrl: " <<(*it2)->getBoldUrl() <<endl - <<"abbrUrl: " <<(*it2)->getAbbrUrl() <<endl - <<"strength: " <<(*it2)->getStrength() <<endl - <<"keywords: " <<(*it2)->getJoinedBlacklistKeywords() <<endl - <<endl - <<endl - <<endl; - } + // Do we still need to encode the urls? + impData <<"#" <<i++ <<endl + <<"url: " <<(*it)->getUrl() <<endl + <<"boldUrl: " <<(*it)->getBoldUrl() <<endl + <<"abbrUrl: " <<(*it)->getAbbrUrl() <<endl + <<"strength: " <<(*it)->getStrength() <<endl + <<"keywords: " <<(*it)->getJoinedBlacklistKeywords() <<endl + <<endl + <<endl + <<endl; } string retMsg = Request::sendImprovementData(_options, impData.str()); https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/453a460c0ae7/ changeset: 453a460c0ae7 user: roggan87 date: 2012-11-11 00:34:13 summary: Implemented Node::STRUCTURE_STRENGTH_LEVEL in Database and Report. Now warnings are grouped by their strength level in the reports. affected #: 2 files diff -r eb4ff7df7079eb0799506405403d83d8c6fbf12a -r 453a460c0ae73c5acfcf10729c4e799fe3acfb41 plugins/DefaultReport/src/Report.cpp --- a/plugins/DefaultReport/src/Report.cpp +++ b/plugins/DefaultReport/src/Report.cpp @@ -78,10 +78,16 @@ void Report::makeWarningsSection() { string keywordsContent; - string attKeywordsContent; + string attKeywordsContent; + + // TODO: Make these labels dynamic, put in locale + string levels[] = {"None", "Whitelist", "Safe", "Low risk", + "Suspicious", "High risk", "Danger"}; int threshold = _options->getInt("reportStrengthThreshold", 0); - NodePtr warnings = _db->getWarnings(Node::STRUCTURE_DOMAIN, threshold); + NodePtr warnings = _db->getWarnings(Node::STRUCTURE_STRENGTH_LEVEL, + threshold, Node::SORT_STRENGTH_DESC); + if (warnings->size() > 0) { for(NodeIterator it = warnings->begin(); it != warnings->end(); it++) { @@ -102,10 +108,11 @@ urlsContent <<"<br>"; attUrlsContent <<","; } - } - keywordsContent += makeTableBranch((*it)->getName(), urlsContent.str()); + } + string title = levels[(*it)->getStrengthLevel()]; + keywordsContent += makeTableBranch(title, urlsContent.str()); attKeywordsContent - += makeJavascriptBranch((*it)->getName(), attUrlsContent.str()); + += makeJavascriptBranch(title, attUrlsContent.str()); } } else { diff -r eb4ff7df7079eb0799506405403d83d8c6fbf12a -r 453a460c0ae73c5acfcf10729c4e799fe3acfb41 src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -643,7 +643,26 @@ } } + else if (structure == Node::STRUCTURE_STRENGTH_LEVEL) { + map <Node::StrengthLevel, NodeVector> levels; + for (vector<HTTPHit>::iterator it = rows.begin(); it != rows.end(); it++) { + + NodePtr hit = new HTTPHit(*it); + // Only add the hit if it's the specified level. + if (isCorrectLevel(hit, level)) + levels[hit->getStrengthLevel()].push_back(hit); + } + + for (map<Node::StrengthLevel, NodeVector>::iterator it = levels.begin(); + it != levels.end(); it++) + { + NodePtr lvl = new Node(); + lvl->setChildren(it->second); + lvl->setStrength((it->first - 2) * 25); + tree->addChild(lvl); + } + } return tree; } https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/bb6d50df927f/ changeset: bb6d50df927f user: roggan87 date: 2012-11-11 00:34:37 summary: Strength cannot be lower than 0 or higher than 100 any more. affected #: 1 file diff -r 453a460c0ae73c5acfcf10729c4e799fe3acfb41 -r bb6d50df927f2dacb0e8694832d7fe7553a65fe7 src/Node.cpp --- a/src/Node.cpp +++ b/src/Node.cpp @@ -139,6 +139,11 @@ void Node::setStrength(int strength) { + if (strength < 0) + strength = 0; + else if (strength > 100) + strength = 100; + _strength = strength; } https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/f6c9b4e12592/ changeset: f6c9b4e12592 user: roggan87 date: 2012-11-11 00:40:17 summary: Changing some of the strength levels' names. affected #: 2 files diff -r bb6d50df927f2dacb0e8694832d7fe7553a65fe7 -r f6c9b4e125928bae2da496fca6636a6940a0d447 include/Node.h --- a/include/Node.h +++ b/include/Node.h @@ -142,13 +142,13 @@ /// Considered clean, since it's whitelisted. LEVEL_SAFE, /// This is definitely a false positive. - LEVEL_PROBABLY_SAFE, + LEVEL_LOW_RISK, /// This was a match, but is unlikely a really dangerous site. LEVEL_SUSPICIOUS, /// It's a match, but not necessarily dangerous. - LEVEL_UNSAFE, + LEVEL_HIGH_RISK, /// This is most probably something to worry about. - LEVEL_DANGEROUS + LEVEL_DANGER /// This is not only a match, it's definitely a bad site. }; diff -r bb6d50df927f2dacb0e8694832d7fe7553a65fe7 -r f6c9b4e125928bae2da496fca6636a6940a0d447 src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -178,7 +178,7 @@ int threshold, Node::Sort sortBy) const { stringstream where; where <<"keywords != '' AND strength >= " <<threshold; - NodePtr hits = getHits(structure, where.str(), Node::LEVEL_DANGEROUS); + NodePtr hits = getHits(structure, where.str(), Node::LEVEL_DANGER); hits->sort(sortBy); return hits; } @@ -681,10 +681,10 @@ break; case Node::LEVEL_SAFE: - case Node::LEVEL_PROBABLY_SAFE: + case Node::LEVEL_LOW_RISK: case Node::LEVEL_SUSPICIOUS: - case Node::LEVEL_UNSAFE: - case Node::LEVEL_DANGEROUS: + case Node::LEVEL_HIGH_RISK: + case Node::LEVEL_DANGER: if (hit->getStrengthLevel() >= Node::LEVEL_SAFE) return true; break; https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/9e74594abafe/ changeset: 9e74594abafe user: roggan87 date: 2012-11-16 14:20:19 summary: Applying the reportStrengthThreshold in the Database class, instead of passing it from Report and ReportBase. affected #: 5 files diff -r f6c9b4e125928bae2da496fca6636a6940a0d447 -r 9e74594abafeade82e16d0178ef7310824d746ce include/Database.h --- a/include/Database.h +++ b/include/Database.h @@ -88,21 +88,23 @@ NodePtr getBypasses(Node::Sort sortBy = Node::SORT_NAME_ASC) const; /// Return all Bypasses found. - NodePtr getHistory(Node::Structure structure, - Node::Sort sortBy = Node::SORT_NAME_ASC) const; + NodePtr getHistory(Node::Structure structure, Node::Sort sortBy = Node::SORT_NAME_ASC) const; /// Return all History. - NodePtr getWarnings(Node::Structure structure, - int threshold = 0, Node::Sort sortBy = Node::SORT_NAME_ASC) const; - /// Return all Warnings with a strength greater than the - /// threshold. + NodePtr getWarnings(Node::Structure structure, Node::Sort sortBy = Node::SORT_NAME_ASC) const; + /// Return all Warnings with a higher strength than the + /// threshold given in configuration. - NodePtr getWhitelist(Node::Structure structure, - int threshold = 0, Node::Sort sortBy = Node::SORT_NAME_ASC) const; + NodePtr getWhitelist(Node::Structure structure, Node::Sort sortBy = Node::SORT_NAME_ASC) const; /// Return all matches that are whitelisted for some reason. This /// is wrapped up in a Warnings object, since it's actually /// the same thing, but the matches are also considered clean. + NodePtr getImprovementData() const; + /// Return all Warnings regardless of strength, with a flat + /// node structure. + + void logBypass(Bypass bypass); /// Log attempts to bypass the software. diff -r f6c9b4e125928bae2da496fca6636a6940a0d447 -r 9e74594abafeade82e16d0178ef7310824d746ce plugins/DefaultReport/src/Report.cpp --- a/plugins/DefaultReport/src/Report.cpp +++ b/plugins/DefaultReport/src/Report.cpp @@ -83,10 +83,9 @@ // TODO: Make these labels dynamic, put in locale string levels[] = {"None", "Whitelist", "Safe", "Low risk", "Suspicious", "High risk", "Danger"}; - - int threshold = _options->getInt("reportStrengthThreshold", 0); + NodePtr warnings = _db->getWarnings(Node::STRUCTURE_STRENGTH_LEVEL, - threshold, Node::SORT_STRENGTH_DESC); + Node::SORT_STRENGTH_DESC); if (warnings->size() > 0) { for(NodeIterator it = warnings->begin(); it != warnings->end(); it++) @@ -132,9 +131,8 @@ -void Report::makeWhitelistSection() { - int threshold = _options->getInt("reportStrengthThreshold", 0); - NodePtr whitelist = _db->getWhitelist(Node::STRUCTURE_FLAT, threshold); +void Report::makeWhitelistSection() { + NodePtr whitelist = _db->getWhitelist(Node::STRUCTURE_FLAT); if (whitelist->size() > 0) { string urlsContent = "", attUrlsContent = ""; for(NodeIterator it = whitelist->begin(); it != whitelist->end(); it++) { diff -r f6c9b4e125928bae2da496fca6636a6940a0d447 -r 9e74594abafeade82e16d0178ef7310824d746ce src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -174,8 +174,8 @@ -NodePtr Database::getWarnings(Node::Structure structure, - int threshold, Node::Sort sortBy) const { +NodePtr Database::getWarnings(Node::Structure structure, Node::Sort sortBy) const { + int threshold = _options->getInt("reportStrengthThreshold", 0); stringstream where; where <<"keywords != '' AND strength >= " <<threshold; NodePtr hits = getHits(structure, where.str(), Node::LEVEL_DANGER); @@ -185,8 +185,8 @@ -NodePtr Database::getWhitelist(Node::Structure structure, - int threshold, Node::Sort sortBy) const { +NodePtr Database::getWhitelist(Node::Structure structure, Node::Sort sortBy) const { + int threshold = _options->getInt("reportStrengthThreshold", 0); stringstream where; where <<"keywords != '' AND strength >= " <<threshold; NodePtr hits = getHits(structure, where.str(), Node::LEVEL_WHITELIST); @@ -194,6 +194,15 @@ return hits; } + + + +NodePtr Database::getImprovementData() const { + string where = "keywords != ''"; + NodePtr hits = getHits(Node::STRUCTURE_FLAT, where, Node::LEVEL_DANGER); + return hits; +} + void Database::logBypass(Bypass bypass) { diff -r f6c9b4e125928bae2da496fca6636a6940a0d447 -r 9e74594abafeade82e16d0178ef7310824d746ce src/HTTPHit.cpp --- a/src/HTTPHit.cpp +++ b/src/HTTPHit.cpp @@ -138,13 +138,14 @@ bool HTTPHit::isWhitelistMatch(int threshold) { + int whitelistKeywords = 0; for (std::set<BlacklistKeyword>::const_iterator k = _blacklistKeywords.begin(); k != _blacklistKeywords.end(); k++) { if (_strength >= threshold && k->getCategory() == "Whitelist") - return true; + whitelistKeywords++; } - return false; + return whitelistKeywords > 0 && whitelistKeywords < _blacklistKeywords.size(); } diff -r f6c9b4e125928bae2da496fca6636a6940a0d447 -r 9e74594abafeade82e16d0178ef7310824d746ce src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -180,9 +180,8 @@ -void ReportBase::sendImprovementData() { - int threshold = _options->getInt("reportStrengthThreshold"); - NodePtr warnings = _db->getWarnings(Node::STRUCTURE_FLAT, threshold); +void ReportBase::sendImprovementData() { + NodePtr warnings = _db->getImprovementData(); if (_options->getBool("improveData", false) && warnings->size() > 0) { stringstream impData; int i = 0; Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-11-16 13:17:18
|
2 new commits in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/b9a17241bed5/ changeset: b9a17241bed5 branch: multiuser user: roggan87 date: 2012-10-25 23:46:04 summary: Merging default branch into multiuser affected #: 87 files Diff too large to display. https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/042eabe08037/ changeset: 042eabe08037 branch: multiuser user: roggan87 date: 2012-10-26 00:04:02 summary: Fixed broken debug option in HTTPHitHandler affected #: 1 file diff -r b9a17241bed553aa7a6bc607fbc9500e0610a9a2 -r 042eabe08037de39e6bd954c54ddb96ad1642c8c src/HTTPHitHandler.cpp --- a/src/HTTPHitHandler.cpp +++ b/src/HTTPHitHandler.cpp @@ -19,8 +19,10 @@ { BlacklistMatch match; bool isMatch, - isDebugging = Application::instance().config().getBool("debug", false); - hit.setUser(_cache->getUID(hit.src, hit.dest)); + isDebugging = Application::instance().config().getBool("arg.debug", false); + + // Not ready to get UID quite yet + //hit.setUser(_cache->getUID(hit.src, hit.dest)); isMatch = _filter->isMatch(hit, match); HTTPHitHandler::logUrl(hit); Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-11-06 23:19:28
|
15 new commits in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/9b3c4e9761bc/ changeset: 9b3c4e9761bc user: roggan87 date: 2012-10-28 22:21:54 summary: Introducing the HTTPHit and HTTPHitHandler. affected #: 5 files diff -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -12,6 +12,8 @@ @top_srcdir@/src/Filter.cpp\ @top_srcdir@/src/History.cpp\ @top_srcdir@/src/MyLogger.cpp\ + @top_srcdir@/src/HTTPHit.cpp\ + @top_srcdir@/src/HTTPHitHandler.cpp\ @top_srcdir@/src/MyXml.cpp\ @top_srcdir@/src/Options.cpp\ @top_srcdir@/src/ReportBase.cpp\ diff -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff include/HTTPHit.h --- /dev/null +++ b/include/HTTPHit.h @@ -0,0 +1,74 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: HTTPHit +// +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <HTTPHit> stores all relevant information about a visited page. + + + +#ifndef HTTPHIT_H +#define HTTPHIT_H + +#include <iostream> +#include <string> +#include <sstream> + +#include "Poco/Net/HTTPRequest.h" +#include "Poco/Net/HTTPResponse.h" +#include "Poco/Net/HTTPMessage.h" +#include "Poco/Net/NameValueCollection.h" + +namespace NetResponsibility { + +using ::Poco::Net::HTTPMessage; +using ::Poco::Net::HTTPRequest; +using ::Poco::Net::HTTPResponse; +using ::Poco::Net::NameValueCollection; +using namespace ::std; + +class HTTPHit : public ::Poco::Net::HTTPMessage + /// Every visited URL consists of an HTTPRequest and an HTTPResponse. + /// Net Responsibility likes to treat them as a pair. All relevant + /// information about the visited page is handled as an HTTPHit. + /// The HTTPHit can be constructed by either passing a + /// Poco::Net::HTTPRequest, or Poco::Net::HTTPResponse to the + /// constructor. +{ + + public: + HTTPHit(); + HTTPHit(const HTTPRequest& request); + HTTPHit(const HTTPResponse& response); + HTTPHit(const HTTPHit& hit); + + string getUrl(); + string getHost(); + string getUri(); + + + protected: + string _host; + string _uri; + + void copyHeaders(const HTTPMessage& message); +}; + +} //NetResponsibility + +#endif //HTTPHIT_H diff -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff include/HTTPHitHandler.h --- /dev/null +++ b/include/HTTPHitHandler.h @@ -0,0 +1,59 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: HTTPHitHandler +// +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <HTTPHitHandler> is taking care of all HTTPHits sniffer by the Sniffer. + + + +#ifndef HTTPHITHANDLER_H +#define HTTPHITHANDLER_H + +#include <vector> +#include "Database.h" +#include "Filter.h" +#include "Blacklist.h" +#include "Poco/LogStream.h" +#include "HTTPHit.h" + +namespace NetResponsibility{ + +using namespace std; +using Poco::LogStream; + + +class HTTPHitHandler + /// HTTPHitHandler is the middleman between the sniffer and + /// database. Every HTTPHit passes through here, gets filtered + /// and stored. + +{ + public: + HTTPHitHandler(LogStream* logStream); + void handleHit(HTTPHit hit); + protected: + Filter *_filter; + Database *_db; + LogStream *_logStream; +}; + +} //NetResponsibilty + + +#endif // HTTPHITHANDLER_H diff -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff src/HTTPHit.cpp --- /dev/null +++ b/src/HTTPHit.cpp @@ -0,0 +1,59 @@ +#include "HTTPHit.h" + +namespace NetResponsibility{ + +HTTPHit::HTTPHit() { + +} + + + +HTTPHit::HTTPHit(const HTTPRequest& request) { + copyHeaders(request); + _host = request.getHost(); + _uri = request.getURI(); +} + + + +HTTPHit::HTTPHit(const HTTPResponse& response) { + copyHeaders(response); +} + + + +HTTPHit::HTTPHit(const HTTPHit& hit) { + copyHeaders(hit); + _host = hit._host; + _uri = hit._uri; +} + + + +string HTTPHit::getUrl() { + return _uri + _host; +} + + + +string HTTPHit::getHost() { + return _host; +} + + + +string HTTPHit::getUri() { + return _uri; +} + + + +void HTTPHit::copyHeaders(const HTTPMessage& message) { + for (NameValueCollection::ConstIterator it = message.begin(); + it != message.end(); it++) + { + set(it->first, it->second); + } +} + +} //NetResponsibility diff -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff src/HTTPHitHandler.cpp --- /dev/null +++ b/src/HTTPHitHandler.cpp @@ -0,0 +1,33 @@ +//HTTPHitHandler.cpp +#include "HTTPHitHandler.h" + +namespace NetResponsibility { + + +HTTPHitHandler::HTTPHitHandler(LogStream* logstream) +{ + _db = &Database::instance(); + _filter = new Filter(); + _logStream = logstream; +} + + + +void HTTPHitHandler::handleHit(HTTPHit hit) +{ + BlacklistMatch match; + bool isMatch, + isDebugging = Application::instance().config().getBool("arg.debug", false); + + isMatch = _filter->isMatch(hit, match); + _db->logUrl(hit); + if (isMatch) + _db->logWarning(match); + + if (isDebugging) + *_logStream <<isMatch <<endl; + +} + + +} //NetResponsibility https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/9a0afa43961f/ changeset: 9a0afa43961f user: roggan87 date: 2012-10-28 22:26:25 summary: Implementing the HTTPHit to the rest of the code. It's at least used all the way to the database. Not yet used from the database to the reports. It seems like the manual merge maybe created some redundant changes that'll be included in the diff. affected #: 32 files diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/BootHistory.h --- a/include/BootHistory.h +++ b/include/BootHistory.h @@ -3,21 +3,21 @@ // Package: Core // Module: BootHistory // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// // <BootHistory> processes the computers boot history to determine whether or // not Net Responsibility have been shut down manually. // Almost all code is taken from the Linux command "last", so credit goes to @@ -33,13 +33,19 @@ #if defined(POCO_OS_FAMILY_UNIX) #include <time.h> -#include <utmp.h> #include <errno.h> -#include <malloc.h> #include <stdlib.h> #include <string.h> #include <signal.h> +/*#if defined(POCO_OS_MAC_OS_X) +#include <stdio.h> +#include <utmpx.h> +#else*/ +#include <malloc.h> +#include <utmp.h> +//#endif //POCO_OS_MAC_OS_X + #include "Poco/Timestamp.h" #define OLD_LINESIZE 12 diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/Bypasses.h --- a/include/Bypasses.h +++ b/include/Bypasses.h @@ -3,45 +3,45 @@ // Package: Core // Module: Bypasses // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// // <Bypasses> is able to store all useful information about attempts to bypass -// the software - +// the software + #ifndef BYPASSES_H #define BYPASSES_H - + #include "Poco/Timestamp.h" -#include "Poco/Data/Common.h" -#include "Poco/Data/Connector.h" -#include "Poco/Data/SQLite/Connector.h" -#include "Poco/DateTimeFormatter.h" - -#include <iostream> -#include <vector> +#include "Poco/Data/Common.h" +#include "Poco/Data/Connector.h" +#include "Poco/Data/SQLite/Connector.h" +#include "Poco/DateTimeFormatter.h" + +#include <iostream> +#include <vector> namespace NetResponsibility { -using ::Poco::Timestamp; -using ::Poco::DateTimeFormatter; -using namespace ::Poco::Data; +using ::Poco::Timestamp; +using ::Poco::DateTimeFormatter; +using namespace ::Poco::Data; using namespace ::std; class Database; - + enum BypassType /// What kind of bypass is it? { @@ -49,17 +49,17 @@ BYPASS_SHUTDOWN, BYPASS_MISSING_FILE, BYPASS_MODIFIED_FILE -}; +}; struct BypassRow /// A simple class to contain each Bypass. -{ +{ public: int type; /// Type of the bypass, given as BypassType. - + Timestamp date; - Timestamp time; + Timestamp time; Timestamp dateTime; string details; /// Additional details about the bypass. Could be which file that was @@ -75,11 +75,11 @@ public: Bypasses(); virtual ~Bypasses(); - void setRows(vector<BypassRow, allocator<BypassRow> > &rows); + void setRows(vector<BypassRow, allocator<BypassRow> > &rows); void addRow(BypassRow); void addRow(int type, string details = ""); /// Add a row by giving its BypassType and details. - + int getIndex() const; /// Returns the index of the current BypassRow. This may be used to /// access this specific element later. @@ -91,7 +91,7 @@ int size() const; string getDateTime(string fmt) const; /// Returns a DateTime string formatted as specified in fmt. - + string getDateTime(string fmt, int index) const; string getDetails() const; string getDetails(int index) const; @@ -99,85 +99,85 @@ /// Returns a message that tries to explain what type of bypass it is. /// These messages are loaded from the txtfile. - string getTypeString(int index) const; - Timestamp getDate() const; - Timestamp getDate(int index) const; - Timestamp getTime() const; - Timestamp getTime(int index) const; - Timestamp getDateTime() const; + string getTypeString(int index) const; + Timestamp getDate() const; + Timestamp getDate(int index) const; + Timestamp getTime() const; + Timestamp getTime(int index) const; + Timestamp getDateTime() const; Timestamp getDateTime(int index) const; vector<BypassRow> getRows() const; - /// Get all _bypassRows inside a vector. - + /// Get all _bypassRows inside a vector. + bool hasMore() const; /// Returns true if Bypasses contains more elements to iterate through. - - void previous(); + + void previous(); void next(); void clear(); - /// Clear out all _bypassRows. - - protected: + /// Clear out all _bypassRows. + + protected: vector<BypassRow, allocator<BypassRow> > _bypassRows; /// All BypassRows stored in a vector. - + int _index; - /// The current index. + /// The current index. }; -} // namespace NetResponsibility - - -namespace Poco { -namespace Data { - -template <> -class TypeHandler<class ::NetResponsibility::BypassRow> -{ -public: - static size_t size() - { - return 4; // we handle four columns of the Table! - } - - static void bind(size_t pos, const ::NetResponsibility::BypassRow& obj, AbstractBinder* pBinder) - { - poco_assert_dbg (pBinder != 0); - TypeHandler<int>::bind(pos++, obj.type, pBinder); - TypeHandler<Poco::Int64>::bind(pos++, obj.date.epochTime(), pBinder); +} // namespace NetResponsibility + + +namespace Poco { +namespace Data { + +template <> +class TypeHandler<class ::NetResponsibility::BypassRow> +{ +public: + static size_t size() + { + return 4; // we handle four columns of the Table! + } + + static void bind(size_t pos, const ::NetResponsibility::BypassRow& obj, AbstractBinder* pBinder) + { + poco_assert_dbg (pBinder != 0); + TypeHandler<int>::bind(pos++, obj.type, pBinder); + TypeHandler<Poco::Int64>::bind(pos++, obj.date.epochTime(), pBinder); TypeHandler<Poco::Int64>::bind(pos++, obj.time.epochTime(), pBinder); - TypeHandler<std::string>::bind(pos++, obj.details, pBinder); - } - - static void prepare(size_t pos, const ::NetResponsibility::BypassRow& obj, - AbstractPreparation* pPrepare) - { - poco_assert_dbg (pBinder != 0); - TypeHandler<int>::prepare(pos++, obj.type, pPrepare); - TypeHandler<Poco::Int64>::prepare(pos++, obj.date.epochTime(), pPrepare); + TypeHandler<std::string>::bind(pos++, obj.details, pBinder); + } + + static void prepare(size_t pos, const ::NetResponsibility::BypassRow& obj, + AbstractPreparation* pPrepare) + { + poco_assert_dbg (pBinder != 0); + TypeHandler<int>::prepare(pos++, obj.type, pPrepare); + TypeHandler<Poco::Int64>::prepare(pos++, obj.date.epochTime(), pPrepare); TypeHandler<Poco::Int64>::prepare(pos++, obj.time.epochTime(), pPrepare); - TypeHandler<std::string>::prepare(pos++, obj.details, pPrepare); - } - - static void extract(size_t pos, ::NetResponsibility::BypassRow& obj, - const ::NetResponsibility::BypassRow& defVal, AbstractExtractor* pExt) - /// obj will contain the result, defVal contains values we should use when one column is NULL - { - poco_assert_dbg (pExt != 0); - Int64 d, t, dt; - TypeHandler<int>::extract(pos++, obj.type, defVal.type, pExt); - TypeHandler<Int64>::extract(pos++, d, defVal.date.epochTime(), pExt); + TypeHandler<std::string>::prepare(pos++, obj.details, pPrepare); + } + + static void extract(size_t pos, ::NetResponsibility::BypassRow& obj, + const ::NetResponsibility::BypassRow& defVal, AbstractExtractor* pExt) + /// obj will contain the result, defVal contains values we should use when one column is NULL + { + poco_assert_dbg (pExt != 0); + Int64 d, t, dt; + TypeHandler<int>::extract(pos++, obj.type, defVal.type, pExt); + TypeHandler<Int64>::extract(pos++, d, defVal.date.epochTime(), pExt); TypeHandler<Int64>::extract(pos++, t, defVal.time.epochTime(), pExt); - TypeHandler<std::string>::extract(pos++, obj.details, defVal.details, pExt); - dt = d + (t % 86400); - obj.date = Timestamp::fromEpochTime(d); - obj.time = Timestamp::fromEpochTime(t); - obj.dateTime = Timestamp::fromEpochTime(dt); - } -}; - + TypeHandler<std::string>::extract(pos++, obj.details, defVal.details, pExt); + dt = d + (t % 86400); + obj.date = Timestamp::fromEpochTime(d); + obj.time = Timestamp::fromEpochTime(t); + obj.dateTime = Timestamp::fromEpochTime(dt); + } +}; + } } // namespace Poco::Data #include "Options.h" - -#endif // BYPASSES_H + +#endif // BYPASSES_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/ConfigSubsystem.h --- a/include/ConfigSubsystem.h +++ b/include/ConfigSubsystem.h @@ -3,45 +3,45 @@ // Package: Core // Module: ConfigSubsystem // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <ConfigSubsystem> is a Subsystem that takes care of configuration - - - -#ifndef CONFIGSUBSYSTEM_H -#define CONFIGSUBSYSTEM_H - +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <ConfigSubsystem> is a Subsystem that takes care of configuration + + + +#ifndef CONFIGSUBSYSTEM_H +#define CONFIGSUBSYSTEM_H + #include "Options.h" #include "Request.h" -#include "MyLogger.h" - -#include "Poco/Util/Application.h" -#include "Poco/Util/Subsystem.h" -#include "Poco/ClassLoader.h" +#include "MyLogger.h" + +#include "Poco/Util/Application.h" +#include "Poco/Util/Subsystem.h" +#include "Poco/ClassLoader.h" #include "Poco/Thread.h" -#include <iostream> - - +#include <iostream> + + namespace NetResponsibility { using ::Poco::Util::Application; using namespace ::std; -class MainApplication; +class MainApplication; class ConfigSubsystem: public ::Poco::Util::Subsystem /// ConfigSubsystem is a Subsystem that takes care of the configuration. @@ -50,12 +50,12 @@ { public: const char* name() const; - void reinitialize(Application &app); + void reinitialize(Application &app); - protected: + protected: MyLogger *_logger; void initialize(Application &self); - void uninitialize(); + void uninitialize(); void getLogin(string &username, string &password); /// Get the username and password through std::cin. This is not /// neccessary if --username=X and --password=Y are given as arguments. @@ -63,5 +63,5 @@ } // namespace NetResponsibility -#include "MainApplication.h" -#endif // CONFIGSUBSYSTEM_H +#include "MainApplication.h" +#endif // CONFIGSUBSYSTEM_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/Database.h --- a/include/Database.h +++ b/include/Database.h @@ -3,52 +3,52 @@ // Package: Core // Module: Database // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <Database> handles all connections from and to the database. - -#ifndef DATABASE_H -#define DATABASE_H - -#include "Poco/Data/Common.h" -#include "Poco/Data/Connector.h" -#include "Poco/Data/SQLite/Connector.h" +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <Database> handles all connections from and to the database. + +#ifndef DATABASE_H +#define DATABASE_H + +#include "Poco/Data/Common.h" +#include "Poco/Data/Connector.h" +#include "Poco/Data/SQLite/Connector.h" #include "Poco/Data/SQLite/SQLiteException.h" -#include "Poco/Exception.h" +#include "Poco/Exception.h" #include "Poco/Timestamp.h" -#include "Poco/Tuple.h" -#include "Poco/Util/ServerApplication.h" -#include "Poco/Net/HTTPRequest.h" +#include "Poco/Tuple.h" +#include "Poco/Util/ServerApplication.h" +#include "HTTPHit.h" #include "Poco/Thread.h" #include "Poco/Process.h" -#include "Poco/SingletonHolder.h" - -#include "Blacklist.h" -#include "Options.h" -#include "History.h" +#include "Poco/SingletonHolder.h" + +#include "Blacklist.h" +#include "Options.h" +#include "History.h" #include "Warnings.h" #include "Bypasses.h" #include "BootHistory.h" -#include "MyLogger.h" - +#include "MyLogger.h" + #include <iostream> -#include <sstream> +#include <sstream> #include <vector> -#include <set> - +#include <set> + namespace NetResponsibility { @@ -61,7 +61,9 @@ using ::Poco::Net::HTTPRequest; using namespace ::Poco::Data; using namespace ::std; - + +class HTTPHitHandler; + class Database /// Database handles all connections to the SQLite database. The Database /// object is instanciated in by MainApplication, and may be accessed by the @@ -76,21 +78,21 @@ /// customize the return values. /// /// Queries that are done repeatedly are stored inside Statements. This will - /// enchance their speed. -{ - public: - Database(); + /// enchance their speed. +{ + public: + Database(); ~Database(); - + bool isReportTime(int frequency); /// Check if it's time to send a scheduled report, depending on /// 'frequency'. - + int getCount(string from) const; /// Return the number of rows found in the table 'from'. - + int getLastRowId() const; - + vector<string> getDistinctHostnames(string where = "hostname <> ''", string orderBy = "hostname ASC") const; /// Return all unique hostnames in a simple vector. By default @@ -100,20 +102,20 @@ Bypasses getBypasses(string where = "", string orderBy = "date, time ASC") const; /// Return all Bypasses found, in a Bypasses object. - + History getHistory(string where = "hostname <> ''", string orderBy = "hostname ASC") const; /// Return all History. - + Warnings getWarnings(string where = "", string orderBy = "u.hostname ASC", bool = false) const; /// Return all Warnings found. - + Warnings getWhitelist(string where = "", string orderBy = "u.hostname ASC") const; /// Return all matches that are whitelisted for some reason. This /// is wrapped up in a Warnings object, since it's actually /// the same thing, but the matches are also considered clean. - + void logBypass(int type, string details = "", int datetime = 0); /// Log attempts to bypass the software. You'll need to enter /// the type (BYPASS_TYPE), and optionally more verbose details. @@ -129,7 +131,7 @@ void logReportStart(int& id); /// Log that the reporting process have started. You'll need the id /// later to properly "close" the report. - + void logReportFinish(int id); /// Log that the report finished successfully. You'll need to enter the /// id given by logReportStart(). @@ -142,25 +144,24 @@ void logSessionStop(); /// Log that the current instance stopped. - + void rotateLog(int reportId); /// This method rotated the database, to clean up everything that have /// been included. Only entries older than the time for the report with /// reportId will be deleted. The reportId was given by logReportStart(). static Database& instance(); - /// Use this method to get the one and only instance of Database. + /// Use this method to get the one and only instance of Database. - - friend class Sniffer; + protected: void setStatements(); - - void logUrl(HTTPRequest& request); - /// Log a URL that's visited. This may only be done by the Sniffer class. + + void logUrl(HTTPHit& hit); + /// Log a URL that's visited. This may only be done by the HTTPHitHandler class. // This will later be replaced by HTTPHit. - + void logWarning(BlacklistMatch match); /// Log a Warning that is flagged by the Filter. It is connected to /// the last URL inserted. @@ -172,31 +173,32 @@ void getMatches(vector<int> urlId, vector<BlacklistMatch>& bm) const; void processPreviousSessions(); - /// Process the previous sessions, and log any attempts to bypass NR. - - private: - Session *_session; - Timestamp _timestamp; + /// Process the previous sessions, and log any attempts to bypass NR. + friend class HTTPHitHandler; + + private: + Session *_session; + Timestamp _timestamp; int _lastRowId; - int _sessionRowId; - int _strength; - int _date; - int _time; - string _hostname; - string _path; - string _keyword; + int _sessionRowId; + int _strength; + int _date; + int _time; + string _hostname; + string _path; + string _keyword; string _category; - Options *_options; + Options *_options; MyLogger *_logger; - BootHistory *_bootHistory; - BlacklistMatch _blacklistMatch; - Statement *_getLastRowId; - Statement *_logUrlStatement; - Statement *_logWarningStatement; - Statement *_logMatchStatement; -}; + BootHistory *_bootHistory; + BlacklistMatch _blacklistMatch; + Statement *_getLastRowId; + Statement *_logUrlStatement; + Statement *_logWarningStatement; + Statement *_logMatchStatement; +}; } // namespace NetResponsibility - -#endif // DATABASE_H + +#endif // DATABASE_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/Filter.h --- a/include/Filter.h +++ b/include/Filter.h @@ -3,38 +3,38 @@ // Package: Core // Module: Filter // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <Filter> determines whether the URLs are appropriate or not. - -#ifndef FILTER_H -#define FILTER_H - -#include "Blacklist.h" -#include "MyXml.h" - -#include <iostream> -#include <fstream> -#include <vector> - -#include "Poco/RegularExpression.h" -#include "Poco/SharedPtr.h" +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <Filter> determines whether the URLs are appropriate or not. + +#ifndef FILTER_H +#define FILTER_H + +#include "Blacklist.h" +#include "MyXml.h" + +#include <iostream> +#include <fstream> +#include <vector> + +#include "Poco/RegularExpression.h" +#include "Poco/SharedPtr.h" #include "Poco/Exception.h" -#include "Poco/URI.h" -#include "Poco/Net/HTTPRequest.h" +#include "Poco/URI.h" +#include "HTTPHit.h" #include "Poco/Util/Application.h" namespace NetResponsibility { @@ -47,7 +47,7 @@ class Options; class Database; - + class Filter /// This class will run all test to find out if the URLs are appropriate or /// not. It is done by initially loading the blacklists, and then testing @@ -57,48 +57,48 @@ /// to be an inappropriate site. (The higher number, the more likely). /// /// The URLs are filtered instantly, rather than at report time, as done in - /// several previous versions. -{ - public: + /// several previous versions. +{ + public: Filter(); /// The regular constructor, loads the Filter. - + Filter(string blacklistFile); /// Load the Filter, given the path to the blacklist. This is /// especially useful when improvign the algorithms. - - bool isMatch(HTTPRequest& request, BlacklistMatch& blacklistMatch); + + bool isMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch); /// This is the method used for running a complete scan on the URL. /// The URL is given as a HTTPRequest, and the result with a formatted /// URL, strength etc. is returned in blacklistMatch. The return value /// is true if the URL is considered suspicious, otherwise false. - bool isUrlMatch(HTTPRequest& request, BlacklistMatch& blacklistMatch); - - bool isTokenMatch(HTTPRequest& request, BlacklistMatch& blacklistMatch); - + bool isUrlMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch); + + bool isTokenMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch); + void loadBlacklist(string path); - void loadBlacklist(Options* options, Database* db); - - private: + void loadBlacklist(Options* options, Database* db); + + private: Blacklist _blacklist; - Extensions _extensions; - SharedPtr<RegularExpression> _splitToken; + Extensions _extensions; + SharedPtr<RegularExpression> _splitToken; SharedPtr<RegularExpression> _splitExtension; - SharedPtr<RegularExpression> _wordDelimiter; - + SharedPtr<RegularExpression> _wordDelimiter; + string abbrUrl(string boldUrl); void setRegexps(); float getExtensionFactor(string url); - + }; -} // namespace NetResponsibility +} // namespace NetResponsibility #include "Database.h" #include "Request.h" #include "Options.h" - -#endif // FILTER_H + +#endif // FILTER_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/MainApplication.h --- a/include/MainApplication.h +++ b/include/MainApplication.h @@ -3,39 +3,39 @@ // Package: Core // Module: MainApplication // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <MainApplication> is responsibility for making Net Responsibility a -// service/daemon and handle CLI arguments, logging etc. - - - -#ifndef MAINAPPLICATION_H -#define MAINAPPLICATION_H +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <MainApplication> is responsibility for making Net Responsibility a +// service/daemon and handle CLI arguments, logging etc. + + + +#ifndef MAINAPPLICATION_H +#define MAINAPPLICATION_H #include "Options.h" #include "MyLogger.h" -#include "Database.h" -#include "Request.h" +#include "Database.h" +#include "Request.h" #include "ConfigSubsystem.h" -#include "ReportSubsystem.h" -#include "SnifferSubsystem.h" - -#include "Poco/Util/Application.h" -#include "Poco/Util/ServerApplication.h" +#include "ReportSubsystem.h" +#include "SnifferSubsystem.h" + +#include "Poco/Util/Application.h" +#include "Poco/Util/ServerApplication.h" #include "Poco/Util/Subsystem.h" #include "Poco/Util/Option.h" #include "Poco/Util/OptionSet.h" @@ -44,27 +44,27 @@ #include "Poco/Platform.h" #include "Poco/Exception.h" #include "Poco/Logger.h" -#include "Poco/FileChannel.h" -#include "Poco/ConsoleChannel.h" -#include "Poco/SplitterChannel.h" -#include "Poco/FormattingChannel.h" +#include "Poco/FileChannel.h" +#include "Poco/ConsoleChannel.h" +#include "Poco/SplitterChannel.h" +#include "Poco/FormattingChannel.h" #include "Poco/PatternFormatter.h" -#include "Poco/AutoPtr.h" +#include "Poco/AutoPtr.h" #include "Poco/Thread.h" #include "Poco/Process.h" #include "Poco/PipeStream.h" #include "Poco/StreamCopier.h" #include <iostream> -#include <sstream> - -#if defined(POCO_OS_FAMILY_UNIX) +#include <sstream> + +#if defined(POCO_OS_FAMILY_UNIX) #include "unistd.h" #include "signal.h" #include "Poco/SyslogChannel.h" -namespace NetResponsibility { +namespace NetResponsibility { using ::Poco::SyslogChannel; -} -#endif +} +#endif namespace NetResponsibility { @@ -86,7 +86,7 @@ using ::Poco::Process; using ::Poco::ProcessHandle; using namespace ::std; - + class MainApplication: public ::Poco::Util::ServerApplication /// MainApplication is the skeleton of Net Responsibility. This is where all /// Options are processed, the Database loaded, the Logger set up, the signals @@ -100,14 +100,14 @@ /// Default constructor. Sets some class variables and registers the /// Subsystems that are to be invoked. - ~MainApplication(); - + ~MainApplication(); + static MainApplication &instance(); /// A public static method to access this very instance from any class. static void terminateNicely(bool deletePidfile= false); /// Terminate Net Responsibility nicely. This unmasks all singals, - /// deleted the pidfile if told to, and tells the instance to shut down. + /// deleted the pidfile if told to, and tells the instance to shut down. protected: void initialize(Application& self); @@ -124,7 +124,7 @@ void handleHelp(const string& name, const string& value); /// This method is called if the --help argument is specified. It will /// only print out all available arguments with displayHelp() and exit. - + void setOption(const string& name, const string& value); /// The default way that Poco handles configurations is not ideal for /// our purposes. It's way to flexible for accountability softwares. @@ -152,14 +152,14 @@ /// is run inside the Subsystems. private: - bool _helpRequested; - static MainApplication *_instance; - Options *_options; + bool _helpRequested; + static MainApplication *_instance; + Options *_options; Database *_database; MyLogger *_logger; }; -} // namespace NetResponsibility - -#endif // MAINAPPLICATION_H +} // namespace NetResponsibility + +#endif // MAINAPPLICATION_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/MyXml.h --- a/include/MyXml.h +++ b/include/MyXml.h @@ -3,42 +3,42 @@ // Package: Core // Module: MyXml // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <MyXml> adds extra functionality to XMLConfiguration - - - -#ifndef MYXML_H -#define MYXML_H +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <MyXml> adds extra functionality to XMLConfiguration - -#include <iostream> -#include <vector> -#include <map> -#include "Poco/Util/XMLConfiguration.h" + +#ifndef MYXML_H +#define MYXML_H + + + +#include <iostream> +#include <vector> +#include <map> +#include "Poco/Util/XMLConfiguration.h" #include "Poco/Util/Application.h" -#include "Poco/RegularExpression.h" -#include "Poco/AutoPtr.h" +#include "Poco/RegularExpression.h" +#include "Poco/AutoPtr.h" #include "Poco/Exception.h" -#include "Poco/DynamicAny.h" - +#include "Poco/DynamicAny.h" + #include "Blacklist.h" -#include "MyLogger.h" +#include "MyLogger.h" namespace NetResponsibility { @@ -48,15 +48,15 @@ using ::Poco::RegularExpression; using ::Poco::DynamicAny; using namespace ::std; - + class MyXml : public ::Poco::Util::XMLConfiguration /// MyXml inherits XMLConfiguration and adds some extra functionality to it. /// It's most important task is to extract and compile the blacklists, as - /// well as the txtfile. -{ - public: + /// well as the txtfile. +{ + public: MyXml(); - + MyXml(string path); /// Load the XML file found at path. @@ -70,13 +70,13 @@ /// This template returns all subkeys to property inside /// a map<string, T>, where the first value is the name of /// the subkey and the second value is the value itself. - + vector<string> getStringVector(string key) const; /// Returns a string vector with the values found at "key". - + map<string, string> getStringMap() const; /// Returns a map<string, string> with all values found in the document. - + Blacklist getBlacklist(); /// Extracts and compiles the keywords in the blacklist file. @@ -84,9 +84,9 @@ /// Extracts every Extension shipped with the blacklists. protected: - MyLogger* _logger; -}; + MyLogger* _logger; +}; } // namespace NetResponsibility - -#endif // MYXML_H + +#endif // MYXML_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/Options.h --- a/include/Options.h +++ b/include/Options.h @@ -3,53 +3,53 @@ // Package: Core // Module: Options // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <Options> stores the configurations and other useful variables - - - -#ifndef OPTIONS_H -#define OPTIONS_H - -#include <iostream> -#include <stdio.h> -#include <vector> -#include <map> +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <Options> stores the configurations and other useful variables + + + +#ifndef OPTIONS_H +#define OPTIONS_H + +#include <iostream> +#include <stdio.h> +#include <vector> +#include <map> #include "MyXml.h" -#include "MyLogger.h" -#include "Request.h" +#include "MyLogger.h" +#include "Request.h" -#include "Poco/File.h" -#include "Poco/Exception.h" -#include "Poco/Environment.h" +#include "Poco/File.h" +#include "Poco/Exception.h" +#include "Poco/Environment.h" #include "Poco/Util/Application.h" -#include "Poco/Util/LayeredConfiguration.h" +#include "Poco/Util/LayeredConfiguration.h" #include "Poco/Logger.h" #include "Poco/SharedLibrary.h" #include "Poco/DynamicAny.h" -#include "Poco/SingletonHolder.h" - -//#if HAVE_CONFIG_H -#include "config.h" +#include "Poco/SingletonHolder.h" + +//#if HAVE_CONFIG_H +#include "config.h" //#endif - -#define STRINGIFY(path, file) #path #file -#define CONCAT(x, y) STRINGIFY(x, y) + +#define STRINGIFY(path, file) #path #file +#define CONCAT(x, y) STRINGIFY(x, y) #ifndef DATABASEDIR #define DATABASEDIR /var/log @@ -61,20 +61,20 @@ #ifndef DISABLE_ACCOUNT #define DISABLE_ACCOUNT 0 #endif - + #define DATABASEFILE CONCAT(DATABASEDIR, /net-responsibility.db) #define PIDFILE CONCAT(PIDDIR, /net-responsibility.pid) -#define CONFIGFILE CONCAT(PKGDATADIR, /config.xml) -#define BLACKLISTFILE CONCAT(PKGDATADIR, /blacklist.xml) +#define CONFIGFILE CONCAT(PKGDATADIR, /config.xml) +#define BLACKLISTFILE CONCAT(PKGDATADIR, /blacklist.xml) #define TXTFILE CONCAT(PKGDATADIR, /txt.xml) #define LOCALE_DIR CONCAT(PKGDATADIR, /locale) #define REPORT_DIR CONCAT(PKGDATADIR, /reports/) -#define PLUGIN_DIR CONCAT(PKGLIBDIR, /) +#define PLUGIN_DIR CONCAT(PKGLIBDIR, /) #define SERVER "www.netresponsibility.com" -#ifndef VERSION +#ifndef VERSION #define VERSION "0" -#endif //VERSION +#endif //VERSION namespace NetResponsibility { @@ -87,7 +87,7 @@ class MainApplication; class Bypasses; - + class Options : public ::Poco::Util::LayeredConfiguration /// Options adds extra functionality to the already built in /// Poco::Util::LayeredConfiguration. Here we store values given @@ -120,18 +120,18 @@ /// in any of these places, the given default value will be /// returned, or a NotFoundException will be thrown depending on /// what method you've used. - -{ - public: + +{ + public: Options(); - + Options(int argc, char* argv[]); /// Deprecated, use the default contructor Options() instead. - + virtual ~Options(); - bool doSaveHistory() const; - + bool doSaveHistory() const; + bool doSendImprovementData() const; /// Returns true if we're supposed to send the improvement data to /// the server. @@ -159,7 +159,7 @@ /// This template returns all subkeys to property inside /// a map<string, T>, where the first value is the name of /// the subkey and the second value is the value itself. - + string getMacAddress() const; /// Returns the computer's MAC Address. This is used when communicating /// with the server. @@ -177,27 +177,27 @@ /// if it's corrupt. static Options& instance(); - /// Use this method to get the one and only instance of Options. - + /// Use this method to get the one and only instance of Options. + private: string _pluginSniffer; string _pluginReport; - vector<string> _locales; - bool _sendImprovementData; + vector<string> _locales; + bool _sendImprovementData; bool _compressAttachedReport; - int _confPrio; - map<string, string> _txt; + int _confPrio; + map<string, string> _txt; MyLogger *_logger; Bypasses *_initBypasses; - AutoPtr<MyXml> _xml; - - void loadDefaultValues(); + AutoPtr<MyXml> _xml; + + void loadDefaultValues(); void loadLocale(string plugin = "general"); - void setLocales(); + void setLocales(); }; } // namespace NetResponsibility - + #include "Bypasses.h" - -#endif // OPTIONS_H + +#endif // OPTIONS_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/ReportBase.h --- a/include/ReportBase.h +++ b/include/ReportBase.h @@ -3,97 +3,97 @@ // Package: Core // Module: ReportBase // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <ReportBase> sets up basic functionality for making/sending reports. Must be -// inherited by <Report> - - - -#ifndef REPORTBASE_H -#define REPORTBASE_H - -#include "Options.h" -#include "Database.h" +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <ReportBase> sets up basic functionality for making/sending reports. Must be +// inherited by <Report> + + + +#ifndef REPORTBASE_H +#define REPORTBASE_H + +#include "Options.h" +#include "Database.h" #include "Bypasses.h" -#include "History.h" -#include "Warnings.h" +#include "History.h" +#include "Warnings.h" #include "Request.h" -#include "MyLogger.h" - -#include <sstream> -#include <iostream> -#include <vector> - +#include "MyLogger.h" + +#include <sstream> +#include <iostream> +#include <vector> + #include "Poco/Timestamp.h" -#include "Poco/DateTimeFormatter.h" -#include "Poco/Net/MailMessage.h" -#include "Poco/Net/MailRecipient.h" -#include "Poco/Net/SMTPClientSession.h" +#include "Poco/DateTimeFormatter.h" +#include "Poco/Net/MailMessage.h" +#include "Poco/Net/MailRecipient.h" +#include "Poco/Net/SMTPClientSession.h" #include "Poco/Net/StringPartSource.h" -#include "Poco/Net/FilePartSource.h" -#include "Poco/Net/NetException.h" -#include "Poco/Util/Application.h" +#include "Poco/Net/FilePartSource.h" +#include "Poco/Net/NetException.h" +#include "Poco/Util/Application.h" #include "Poco/Exception.h" #include "Poco/URI.h" -#include "Poco/Path.h" +#include "Poco/Path.h" -namespace NetResponsibility { - +namespace NetResponsibility { + using ::Poco::Timestamp; -using ::Poco::DateTimeFormatter; -using ::Poco::Net::MailMessage; -using ::Poco::Net::MailRecipient; -using ::Poco::Net::SMTPClientSession; +using ::Poco::DateTimeFormatter; +using ::Poco::Net::MailMessage; +using ::Poco::Net::MailRecipient; +using ::Poco::Net::SMTPClientSession; using ::Poco::Net::StringPartSource; -using ::Poco::Net::FilePartSource; -using ::Poco::Net::NoAddressFoundException; -using ::Poco::Util::Application; +using ::Poco::Net::FilePartSource; +using ::Poco::Net::NoAddressFoundException; +using ::Poco::Util::Application; using ::Poco::Exception; using ::Poco::Path; - -class MainApplication; - + +class MainApplication; + class ReportBase /// ReportBase provides basic functionality for making and sending reports, - /// but must be inherited by Report. -{ - public: + /// but must be inherited by Report. +{ + public: ReportBase(); /// Default constructor. Assigns some default values and logs that the /// creating of a report started. - + ReportBase(const ReportBase&); /// Copy constructor - + virtual ~ReportBase(); - + string getBody() const; /// Returns the content of the reports body - + string getSubject() const; /// Returns the email's subject - + string getContentType() const; /// Returns what content-type the email consist of. By default it is /// "text/plain". - + void logFinish(); /// Logs that the report was successfully created and sent - + void sendImprovementData(); /// Sends improvement data to the servers. This is optional for every /// user. @@ -103,11 +103,11 @@ void uninstall(); /// Call this function if it is an uninstall report - + virtual int send(bool receiveCopy = false); /// Send the report. Set receiveCopy to true if you wish to send a /// report to the user as well as the Accountability Partners. - + virtual void sendCout(); /// Write the report to stdout instead of mailing it. Useful for /// debugging but really nothing else. @@ -118,34 +118,34 @@ virtual void test(); /// Call this function if it is an test report - + virtual void generate() = 0; /// Override this method in Report to generate nicely formatted reports - + virtual string name() const = 0; /// Override this method in Report. Should actually only return the - /// class name, which is "Report". - - protected: - Options *_options; - Database *_db; - MyLogger *_logger; + /// class name, which is "Report". + + protected: + Options *_options; + Database *_db; + MyLogger *_logger; stringstream _body; /// The body of the report. Use it to build your Report. - + vector<Path> _attachments; /// Attachments to the report. Each Path will be included. - + string _contentType; /// The content-type of the report. You may change it to "text/html" or /// whatever suits your purpose. - + string _subject; /// The subject to be shown in the subject line. - - int _reportId; + + int _reportId; }; -} // namespace NetResponsibility - -#endif // REPORTBASE_H +} // namespace NetResponsibility + +#endif // REPORTBASE_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/ReportSubsystem.h --- a/include/ReportSubsystem.h +++ b/include/ReportSubsystem.h @@ -3,40 +3,40 @@ // Package: Core // Module: ReportSubsystem // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <ReportSubsystem> is a Subsystem that takes care of sending reports - - - -#ifndef REPORTSUBSYSTEM_H -#define REPORTSUBSYSTEM_H - -#include "Options.h" -#include "Database.h" +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <ReportSubsystem> is a Subsystem that takes care of sending reports + + + +#ifndef REPORTSUBSYSTEM_H +#define REPORTSUBSYSTEM_H + +#include "Options.h" +#include "Database.h" #include "ReportBase.h" -#include "MyLogger.h" - -#include "Poco/Util/Application.h" -#include "Poco/Util/Subsystem.h" -#include "Poco/ClassLoader.h" +#include "MyLogger.h" + +#include "Poco/Util/Application.h" +#include "Poco/Util/Subsystem.h" +#include "Poco/ClassLoader.h" #include "Poco/Thread.h" #include "Poco/File.h" #include <iostream> -#include <fstream> +#include <fstream> namespace NetResponsibility { @@ -47,18 +47,18 @@ using namespace ::std; class MainApplication; - -enum ReportType -{ - REPORT_FALSE, - REPORT_MANUAL, - REPORT_SCHEDULED, - REPORT_INSTANT, + +enum ReportType +{ + REPORT_FALSE, + REPORT_MANUAL, + REPORT_SCHEDULED, + REPORT_INSTANT, REPORT_TEST, REPORT_INSTALL, - REPORT_UNINSTALL -}; - + REPORT_UNINSTALL +}; + class ReportSubsystem: public ::Poco::Util::Subsystem /// ReportSubsystem is a Poco::Util::Subsystem that determines if we should /// send a report, and makes sure it's done properly. @@ -67,20 +67,20 @@ const char* name() const; /// Returns the name of the class: "ReportSubsystem" - void reinitialize(Application& app); + void reinitialize(Application& app); - protected: + protected: MyLogger *_logger; Options *_options; void initialize(Application& self); /// Run the Subsystem - void uninitialize(); + void uninitialize(); void setScheduledReport(int& type); /// Check if it's time to send a scheduled report, and in that case /// set type to REPORT_SCHEDULED }; } // namespace NetResponsibility - -#endif // REPORTSUBSYSTEM_H + +#endif // REPORTSUBSYSTEM_H diff -r 9b3c4e9761bc44fc8a37f17bcdbec1823e046eff -r 9a0afa43961fa4fb01274dea72358cfead098eab include/Request.h --- a/include/Request.h +++ b/include/Request.h @@ -3,48 +3,48 @@ // Package: Core // Module: Request // -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <Request> is in charge of interaction with the server - - - -#ifndef REQUEST_H -#define REQUEST_H - -#include <iostream> -#include <fstream> -#include <sstream> - -#include "Options.h" +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <Request> is in charge of interaction with the server + + + +#ifndef REQUEST_H +#define REQUEST_H + +#include <iostream> +#include <fstream> +#include <sstream> + +#include "Options.h" #include "Blacklist.h" -#include "MyLogger.h" - -#include "Poco/Net/HTTPClientSession.h" -#include "Poco/Net/HTTPRequest.h" +#include "MyLogger.h" + +#include "Poco/Net/HTTPClientSession.h" +#include "Poco/Net/HTTPRequest.h" #include "Poco/Net/HTTPResponse.h" -#include "Poco/Util/XMLConfiguration.h" -#include "Poco/StreamCopier.h" -#include "Poco/Timestamp.h" -#include "Poco/Path.h" -#include "Poco/File.h" -#include "Poco/URI.h" -#include "Poco/Exception.h" -#include "Poco/Thre... [truncated message content] |
From: Bitbucket <com...@bi...> - 2012-10-23 02:05:37
|
3 new commits in net-responsibility-documentation: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/776a99d3b948/ changeset: 776a99d3b948 user: duststuff date: 2012-10-23 03:11:41 summary: Fixed links messed up by word wrap, and included a note in 'Documentation' about the possibility of word wrap messing up links. affected #: 2 files diff -r ab1807877dc4a7b5eb19ba9d10439481034e501c -r 776a99d3b948ad163a30fb876cc6136d319cc8dc pages/5001-StartCoding.page --- a/pages/5001-StartCoding.page +++ b/pages/5001-StartCoding.page @@ -22,10 +22,11 @@ !!POCO -Net Responsibility heavily relies on the [[http://www.pocoproject.org POCO C++ -libraries]]. The first thing to do is download and install Poco. Note that the +Net Responsibility heavily relies on the +[[http://www.pocoproject.org POCO C++ libraries]]. +The first thing to do is download and install Poco. Note that the version needs to be 1.4 or later. Start by downloading the complete edition. -Unpack it and open a terminal. cd yourself to the dir you unpacked Poco to. +Unpack it and open a terminal. Use <*cd*> to go to the directory you unpacked Poco to. There you configure, compile and install. The procedure should look like this: cd poco-* @@ -96,14 +97,15 @@ If you got this far Net Responsibility should be installed. As an initial test of a successful installation, when running "ps -ef|grep net-responsibility" you should get an output line similar to "net-responsibility --daemon". If you need -to do further testing, see [[0309-TroubleshootingInstallation.html#0 this -guide]]. +to do further testing, see +[[0309-TroubleshootingInstallation.html#0 this guide]]. !!!Understanding the program structure -The program's structure is described in [[5010-ProgramStructure.html another -guide]]. It is recommended to read it to understand the concepts and different +The program's structure is described in +[[5010-ProgramStructure.html another guide]]. +It is recommended to read it to understand the concepts and different steps Net Responsibility is built around. @@ -111,14 +113,15 @@ Now you're ready for the fun part -- the coding. The two main areas to lay your hands on are bugs and feature requests. You'll find both of these in our -[[https://issues.netresponsibility.com/projects/net-responsibility/issues issue -tracker]]. Grab a bug that sounds interesting and provide a solution, or see if +[[https://issues.netresponsibility.com/projects/net-responsibility/issues issue tracker]]. +Grab a bug that sounds interesting and provide a solution, or see if there's any feature requests you'd like to implement. If you'd rather work on something that is not listed, please create a new issue about it, and a note that you're working on it. When you try to access the issue tracker, your browser may display a security warning. You can safely ignore this and grant a -permanent security exception. For more info, [[0901-FAQ.html#19 see this FAQ -entry]]. Anyone can view the contents of the issue tracker, but in order to +permanent security exception. For more info, +[[0901-FAQ.html#19 see this FAQ entry]]. Anyone can view the contents of the +issue tracker, but in order to create a new issue you will need to sign in with your NR user login information. The first time you do this, you may need to give some basic additional information in order to gain access. Also, even if you're already logged in to diff -r ab1807877dc4a7b5eb19ba9d10439481034e501c -r 776a99d3b948ad163a30fb876cc6136d319cc8dc pages/5004-Documentation.page --- a/pages/5004-Documentation.page +++ b/pages/5004-Documentation.page @@ -32,8 +32,7 @@ !!!Getting started Of course, you may contact us and say something like "I think you should change -the words 'blah blah blah' in paragraph 3 in the page called 'Source Code -Management', +the words 'blah blah blah' in paragraph 3 in the page called 'Ten Steps to NR Happiness', to 'losum ipsum'." We can take care of it from there. It would be even better though if you followed these instructions, since this will make it easier for all of us in the @@ -58,8 +57,8 @@ which also gives more flexibility. We recommend that NR developers use BitBucket to fork a repo, and then <*clone*> that forked repo to their systems to serve as a local repo. To create a fork, log in to BitBucket, go to the -[[https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation -NR documentation repo page]], click on the 'Fork' button, and enter the +[[https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation NR documentation repo page]], +click on the 'Fork' button, and enter the necessary information, etc. to complete the process. Once you've done that, here is a sample of the terminal command you would use (from within the desired directory) to clone your new fork to your local system (you will need to replace @@ -78,7 +77,7 @@ When you execute the terminal command above, it will clone (create) a current copy of the NR documentation repo in whatever directory (folder) you were in when you ran the command. For many systems, this is the 'home' folder by -default, but you can choose to put it wherever you want. This folder will then +default, but you can choose to put it wherever you want. The repo folder will contain several subfolders, described briefly as follows: cfg - Config (configuration) files (with .xml extension) used when generating @@ -110,7 +109,8 @@ characters long. While you may not notice a difference on your own system, this will help make the documentation and the changes you've made easier to read in certain environments, such as on BitBucket or when using Mercurial-related -tools. +tools. <*When applying word wrap, make sure that links are not split across +lines; otherwise they will not show up properly.*> !!Syntax @@ -245,9 +245,9 @@ generates the documentation. First, you need to make sure you have a clone of the NR software repo on your system. If you don't already have a local NR software repo or if you need a separate one, you can clone one by following the -instructions in the [[#1 Getting Started]] section of this document, but using -the [[https://bitbucket.org/netresponsibilityteam/net-responsibility NR software -repo page]] instead of the NR documentation repo page. If you will only be using +instructions in the [[#1 Getting Started]] section of this document, but using the +[[https://bitbucket.org/netresponsibilityteam/net-responsibility NR software repo page]] +instead of the NR documentation repo page. If you will only be using this local NR software repo for generating documentation and not for doing any development on the NR source code itself, then you can simply do a clone of the main NR repo without first forking a branch. Secondly, because a newly cloned https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/f12bd1c9ead5/ changeset: f12bd1c9ead5 user: duststuff date: 2012-10-23 03:48:16 summary: Updated Arch Linux info in a way that will avoid the need for future updates based only on a different version of NR. affected #: 1 file diff -r 776a99d3b948ad163a30fb876cc6136d319cc8dc -r f12bd1c9ead5a5e498fd848f906b5bdc7a4e892c pages/0304-InstallFromPackages.page --- a/pages/0304-InstallFromPackages.page +++ b/pages/0304-InstallFromPackages.page @@ -2,52 +2,92 @@ A03NR_Install !!!Introduction -New to Linux/Ubuntu? Read these articles for some helpful info: [[http://www.psychocats.net/ubuntu/installingsoftware Installing Software in Ubuntu]] and [[http://www.psychocats.net/ubuntu/terminal Where's the Terminal?]]. <!Warning:!> Read [[http://ubuntuforums.org/announcement.php?f=100 this]] (post by <*jdong*>, Nov 18, 2007 - Jan 31, 2013) before copying/pasting anything into the terminal. Basic rule: Take time to make sure you have at least a basic idea of what and why you are running a certain command in the terminal. +New to Linux/Ubuntu? Read these articles for some helpful info: +[[http://www.psychocats.net/ubuntu/installingsoftware Installing Software in Ubuntu]] +and [[http://www.psychocats.net/ubuntu/terminal Where's the Terminal?]]. +<!Warning:!> Read [[http://ubuntuforums.org/announcement.php?f=100 this]] +(post by <*jdong*>, Nov 18, 2007 - Jan 31, 2013) before copying/pasting +anything into the terminal. Basic rule: Take time to make sure you have at least +a basic idea of what and why you are running a certain command in the terminal. <!Please note the following:!> -1. Before installing Net Responsibility (NR), you'll need to [[http://netresponsibility.com/register.php register an account]] if you haven't already. +1. Before installing Net Responsibility (NR), you'll need to +[[http://netresponsibility.com/register.php register an account]] if you haven't +already. -2. Older versions are provided but not recommended. [[https://sourceforge.net/projects/responsibility/files/net-responsibility/ You may find them here]]. +2. Older versions are provided but not recommended. +[[https://sourceforge.net/projects/responsibility/files/net-responsibility/ You may find them here]]. !!!About binary packages -We hope to supply binary packages (installation files) for as many platforms (operating systems) as possible. If there is none for your platform, you'll need to download and compile the [[0305-CompileFromSource.html source code]]. If you would be interested in creating such packages for any platform, please [[mailto:res...@li... let us know]]. +We hope to supply binary packages (installation files) for as many platforms +(operating systems) as possible. If there is none for your platform, you'll need +to download and compile the [[0305-CompileFromSource.html source code]]. If you +would be interested in creating such packages for any platform, please +[[mailto:res...@li... let us know]]. !!!Ubuntu -<!Note:!> If you have version 2.0.2 or earlier installed, you will need to uninstall it before installing a later version. The older versions are named <*netresponsibility*> (without a dash), whereas the newer ones are named <*net-responsibility*> (with a dash). +<!Note:!> If you have version 2.0.2 or earlier installed, you will need to +uninstall it before installing a later version. The older versions are named +<*netresponsibility*> (without a dash), whereas the newer ones are named +<*net-responsibility*> (with a dash). -There is a PPA (Personal Package Archive) for users of Ubuntu versions that are currently supported by Canonical. To add the PPA to your system and install the latest version of NR, simply run these commands in a terminal: +There is a PPA (Personal Package Archive) for users of Ubuntu versions that are +currently supported by Canonical. To add the PPA to your system and install the +latest version of NR, simply run these commands in a terminal: sudo add-apt-repository ppa:roggan87/nr sudo apt-get update sudo apt-get install net-responsibility ---- -During the last step, you need to enter a username and password. Simply use the same as you did when registering your NR account. +During the last step, you need to enter a username and password. Simply use the +same as you did when registering your NR account. -This could also be done through your favorite package manager, such as Synaptic Package Manager or Ubuntu Software Center. If you are interested, you could change <*roggan87/nr*> to <*roggan87/nrdev*>. Then you will also get notified of new beta versions that are not being tested by a wider range of people. +This could also be done through your favorite package manager, such as Synaptic +Package Manager or Ubuntu Software Center. If you are interested, you could +change <*roggan87/nr*> to <*roggan87/nrdev*>. Then you will also get notified of +new beta versions that are not being tested by a wider range of people. -Alternative manual installation method: Download the [[https://sourceforge.net/projects/responsibility/files/net-responsibility/ DEB (.deb) package]] of the latest version, double-click on it, and follow the on-screen prompts. +Alternative manual installation method: Download the +[[https://sourceforge.net/projects/responsibility/files/net-responsibility/ DEB (.deb) package]] +of the latest version, double-click on it, and follow the +on-screen prompts. !!!Mac OS X -We're working on creating packages for Mac users. It is technically possible to download the [[0305-CompileFromSource.html source code]] and compile it. More information about compiling it on Mac can be [[http://forum.netresponsibility.com/index.php?topic=63.0 found here]]. However, the easiest thing would be to wait (or help us out with creating the package). +We're working on creating packages for Mac users. It is technically possible to +download the [[0305-CompileFromSource.html source code]] and compile it. More +information about compiling it on Mac can be +[[http://forum.netresponsibility.com/index.php?topic=63.0 found here]]. However, +the easiest thing would be to wait (or help us out with creating the package). !!!Windows -Our goal is to supply NR for all major platforms, including Windows. There are some important features that are not yet implemented in the Windows version. Therefore we've decided to wait before we release it. Once those things are fixed, we'll create an installation file and post it here. +Our goal is to supply NR for all major platforms, including Windows. There are +some important features that are not yet implemented in the Windows version. +Therefore we've decided to wait before we release it. Once those things are +fixed, we'll create an installation file and post it here. -If you're interested in the Windows development process, we'll keep you updated through [[http://forum.netresponsibility.com/index.php?topic=55.0 this thread]]. When logged in, you may want to click "Notify" for this topic in order to automatically get update emails about new posts. +If you're interested in the Windows development process, we'll keep you updated +through [[http://forum.netresponsibility.com/index.php?topic=55.0 this thread]]. +When logged in, you may want to click "Notify" for this topic in order to +automatically get update emails about new posts. !!!Arch Linux -If [[http://archlinux.fr/yaourt-en yaourt]] is installed you just run the following command: +If [[http://archlinux.fr/yaourt-en yaourt]] is installed you just run the +following command: yaourt -S net-responsibility ---- Otherwise simply follow these instructions: -1. [[https://aur.archlinux.org/packages/ne/net-responsibility/net-responsibility.tar.gz Download the tarball]] (archived file) and extract/unpack it to the folder/directory of your choice. +1. +[[https://aur.archlinux.org/packages/ne/net-responsibility/net-responsibility.tar.gz Download the tarball]] +(archived file) and extract/unpack it to the folder/directory of your choice. -2. Open a terminal window and use the <*cd*> command to go to the extracted folder. Example: If you put the extracted contents into the folder <*/my/arch/nr*> then you would use the following command: +2. Open a terminal window and use the <*cd*> command to go to the extracted +folder. Example: If you put the extracted contents into the folder +<*/my/arch/nr*> then you would use the following command: cd /my/arch/nr @@ -55,22 +95,44 @@ makepkg -s -4. Then run this command: +4. Then you will need to run a command like the following SAMPLE command: sudo pacman -U ./net-responsibility-3.0.1-3-[ i386 or x86_64 ].pkg.tar.xz -(Note that you'll need to replace the [bracketed] portion of the above command with either i386 or x86_64 in order to specify what your system's architecture is.) +The above command is for the NR package <*net-responsibility 3.0.1-3*>, so that +portion of the command will need to be adjusted, depending on what version you +are installing. +[[https://aur.archlinux.org/packages.php?ID=55800 See this link]] +to find out the latest version number. Also, note that you'll need to replace +the [bracketed] portion of the above command with either i386 or x86_64 in order +to specify what your system's architecture is. -For more information regarding installation of packages in Arch Linux, [[https://wiki.archlinux.org/index.php/AUR#Installing_packages look here]]. +For more information regarding installation of packages in Arch Linux, +[[https://wiki.archlinux.org/index.php/AUR#Installing_packages look here]]. !!!Debian-based distributions (distros) other than Ubuntu -<!Note:!> If you have version 2.0.2 or earlier installed, you will need to uninstall it before installing a later version. The older versions are named <*netresponsibility*> (without a dash), whereas the newer ones are named <*net-responsibility*> (with a dash). +<!Note:!> If you have version 2.0.2 or earlier installed, you will need to +uninstall it before installing a later version. The older versions are named +<*netresponsibility*> (without a dash), whereas the newer ones are named +<*net-responsibility*> (with a dash). -Some Debian-based distros do not support installing from the Ubuntu PPA. In this case, you may try to install [[https://sourceforge.net/projects/responsibility/files/net-responsibility/ our debian packages]] manually. Note that you'll need to install libpoco, version 1.4 or later, first. If your distro does not have libpoco precompiled, you can download [[https://sourceforge.net/projects/responsibility/files/libpoco/ all its packages here]]. +Some Debian-based distros do not support installing from the Ubuntu PPA. In this +case, you may try to install +[[https://sourceforge.net/projects/responsibility/files/net-responsibility/ our debian packages]] +manually. Note that you'll need to install libpoco, version 1.4 or later, first. +If your distro does not have libpoco precompiled, you can download +[[https://sourceforge.net/projects/responsibility/files/libpoco/ all its packages here]]. -When installing, you'll have to install the libpoco packages first, in the correct order. After that is done, you can install NR. You should be able to use your favorite package manager, or the command line tool [[http://en.wikipedia.org/wiki/Dpkg dpkg]]. +When installing, you'll have to install the libpoco packages first, in the +correct order. After that is done, you can install NR. You should be able to use +your favorite package manager, or the command line tool +[[http://en.wikipedia.org/wiki/Dpkg dpkg]]. -During the last step, you need to enter a username and password. Simply use the same as you did when registering your NR account. +During the last step, you need to enter a username and password. Simply use the +same as you did when registering your NR account. !!!Testing the installation -If you've successfully worked through the steps above, NR should now be installed. If you want to test to see if it is running as it should, see the [[0309-TroubleshootingInstallation.html#0 Troubleshooting Installation and Configuration]] guide for instructions on the best way to do this. +If you've successfully worked through the steps above, NR should now be +installed. If you want to test to see if it is running as it should, see the +[[0309-TroubleshootingInstallation.html#0 Troubleshooting Installation and Configuration]] +guide for instructions on the best way to do this. https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/8355f0cb3a5f/ changeset: 8355f0cb3a5f user: duststuff date: 2012-10-23 03:48:51 summary: Added note that the PPA won't work for Ubuntu versions not currently supported by Canonical. affected #: 1 file diff -r f12bd1c9ead5a5e498fd848f906b5bdc7a4e892c -r 8355f0cb3a5fe6fd2d64c8fe4966759dce6bc798 pages/0903-ContributeToNR.page --- a/pages/0903-ContributeToNR.page +++ b/pages/0903-ContributeToNR.page @@ -26,7 +26,10 @@ !Bug reports If you encounter a bug in the software, please report it. It is best to add it -to our [[https://issues.netresponsibility.com/projects/net-responsibility/issues issue tracker]]. (You may want to first scan through the other bug reports to make sure the same or something similar has not already been reported.) +to our +[[https://issues.netresponsibility.com/projects/net-responsibility/issues issue tracker]]. +(You may want to first scan through the other bug reports to +make sure the same or something similar has not already been reported.) Please try to be as specific as possible, and include <*the version of your installation*> and <*what platform you're running*>. If you manage to install the software, but not to get it running properly, please try to run it with this @@ -38,17 +41,40 @@ !Feature requests -We are interested to hear about any features you would like to see in Net Responsibility. We're constantly working toward implementing and stabilizing more features and your requests are valuable. Some of you might have experience with other accountability software, or simply have some stunning ideas that we could've never come up with on our own. Think outside the box. +We are interested to hear about any features you would like to see in Net +Responsibility. We're constantly working toward implementing and stabilizing +more features and your requests are valuable. Some of you might have experience +with other accountability software, or simply have some stunning ideas that we +could've never come up with on our own. Think outside the box. -Please remember that it may take time for us to implement a requested feature, and if you want it more quickly, you may be interested in working on it yourself. In any case, the first step is to [[https://issues.netresponsibility.com/projects/net-responsibility/issues add it as a feature request]] in the NR issue tracker. (You may want to first scan through the other feature requests to make sure the same or something similar has not already been added.) Try to be as specific as possible: What do you want to see implemented? What is the difference from what you're seeing now and what you would like to see? Are you able to illustrate the end product? Do you have a proposal of how to get there? +Please remember that it may take time for us to implement a requested feature, +and if you want it more quickly, you may be interested in working on it +yourself. In any case, the first step is to +[[https://issues.netresponsibility.com/projects/net-responsibility/issues add it as a feature request]] +in the NR issue tracker. (You may want to first scan +through the other feature requests to make sure the same or something similar +has not already been added.) Try to be as specific as possible: What do you want +to see implemented? What is the difference from what you're seeing now and what +you would like to see? Are you able to illustrate the end product? Do you have a +proposal of how to get there? !Website Bugs or Feature Requests -If you wish to report bugs or submit feature requests related to the NR website, you can do this in [[https://issues.netresponsibility.com/projects/net-responsibility-website/issues this section of NR's issue tracker]]. +If you wish to report bugs or submit feature requests related to the NR website, +you can do this in +[[https://issues.netresponsibility.com/projects/net-responsibility-website/issues this section of NR's issue tracker]]. !Accessing the issue tracker: Security warning, and Login -When you try to access the issue tracker, your browser may display a security warning. You can safely ignore this and grant a permanent security exception. For more info, [[0901-FAQ.html#19 see this FAQ entry]]. +When you try to access the issue tracker, your browser may display a security +warning. You can safely ignore this and grant a permanent security exception. +For more info, [[0901-FAQ.html#19 see this FAQ entry]]. -Anyone can go to the issue tracker and view the various bug reports, feature requests and other information there. However, in order to create a new issue (bug report, feature request, etc.), you will need to sign in with your NR user login information. The first time you do this, you may need to give some basic additional information in order to gain access. Also, even if you're already logged in to the general NR website itself, you may still need to log in to the issue tracker area of the website. +Anyone can go to the issue tracker and view the various bug reports, feature +requests and other information there. However, in order to create a new issue +(bug report, feature request, etc.), you will need to sign in with your NR user +login information. The first time you do this, you may need to give some basic +additional information in order to gain access. Also, even if you're already +logged in to the general NR website itself, you may still need to log in to the +issue tracker area of the website. !!Forum @@ -59,8 +85,8 @@ !!!Stay updated -Whether you're actively involved in developing Net Responsibility or not, it would help a lot for you -to stay updated. This way you'll more easily be able to +Whether you're actively involved in developing Net Responsibility or not, it +would help a lot for you to stay updated. This way you'll more easily be able to give relevant suggestions, patches, bug reports, etc. !!Mailing lists @@ -75,8 +101,11 @@ [[https://lists.sourceforge.net/lists/listinfo/responsibility-devel Subscribe here]]. <*res...@li...*>. -Whenever someone <*pushes*> one or more changes to our Mercurial repository (where we keep the NR source code), a "commit email" -will be sent to this list. It will include the log message (brief note about the change) and the <*diff*> (detailed before/after comparison of the things changed). This +Whenever someone <*pushes*> one or more changes to our Mercurial repository +(where we keep the NR source code), a "commit email" +will be sent to this list. It will include the log message (brief note about the +change) and the <*diff*> (detailed before/after comparison of the things +changed). This is also an excellent way to stay updated and see what changes are made to the code. It can also help us to spot bugs or come up with alternative suggestions faster. Even if you don't understand the <*diffs*>, you'll be able @@ -88,8 +117,11 @@ !!Running the latest versions By using the latest versions of Net Responsibility, you'll be more in sync -with the developers, and therefore have more relevant information to provide. Also, you'll be able to help us spot bugs that may slip into new versions. Ubuntu -users with the PPA added will automatically run the latest stable release. +with the developers, and therefore have more relevant information to provide. +Also, you'll be able to help us spot bugs that may slip into new versions. +Ubuntu users with the PPA added will automatically run the latest stable release +if they are using a version of Ubuntu currently supported by Canonical. Otherwise, +they will need to install from a DEB package or from the source code. Before releasing new versions we try to test them in a beta stage. Whenever we're ready for beta testing, we'll announce it on the devel mailing list. The more people that are willing to bug test the beta releases, the more @@ -103,18 +135,23 @@ !!!Improve the reports -You can provide valuable help in improving the accuracy of items listed in the <*Warnings*> section of the reports. More information can be [[0705-UnderstandingReports.html#9 found here]]. +You can provide valuable help in improving the accuracy of items listed in the +<*Warnings*> section of the reports. More information can be +[[0705-UnderstandingReports.html#9 found here]]. !!!Code contributions Since Net Responsibility is free and open source, anyone can -contribute with their programming skills. [[5001-StartCoding.html Read this guide]] to find out how to begin +contribute with their programming skills. +[[5001-StartCoding.html Read this guide]] to find out how to begin coding. !!!Create packages For many users the availability of precompiled packages means the difference -between staying with Net Responsibility or moving on to another solution. Struggling through compilation -without any knowledge about it can frustrate anyone. Thus there is a -huge need to have user-friendly and working packages/install files. If you're interested in helping with this, you can find out more details in [[5006-CreatingPackages.html this guide]]. +between staying with Net Responsibility or moving on to another solution. +Struggling through compilation without any knowledge about it can frustrate +anyone. Thus there is a huge need to have user-friendly and working +packages/install files. If you're interested in helping with this, you can find +out more details in [[5006-CreatingPackages.html this guide]]. Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-10-21 23:21:06
|
2 new commits in net-responsibility-documentation: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/8cb5a74456b0/ changeset: 8cb5a74456b0 user: duststuff date: 2012-10-22 01:18:04 summary: Additional edits to reflect switch from SVN to Mercurial. affected #: 1 file diff -r 7e40d82e7627e031616d1033492ce3009b4eab46 -r 8cb5a74456b01f7c21f3700f31135b8e60b8bfe6 pages/5001-StartCoding.page --- a/pages/5001-StartCoding.page +++ b/pages/5001-StartCoding.page @@ -4,19 +4,29 @@ !!!Windows note -For Windows users it is recommended to compile and install everything inside a MinGW + MSYS environment. +For Windows users it is recommended to compile and install everything inside a +MinGW + MSYS environment. !!!The environment -Most developers are using [[http://www.codeblocks.org/ Code::Blocks]] as the editor. In the SVN trunk you'll find a Code::Blocks project file. However, you'll need to compile and run Net Responsibility in a regular terminal. This is because several steps in the installation process doesn't run if built and run through Code::Blocks. There is no need to use Code::Blocks, since you're able to edit any file in your favorite text editor. +Most developers are using [[http://www.codeblocks.org/ Code::Blocks]] as their +editor. In the Mercurial repository you'll find a Code::Blocks project file. +However, you'll need to compile and run Net Responsibility in a regular +terminal. This is because several steps in the installation process don't run if +built and run through Code::Blocks. There is no need to use Code::Blocks, since +you're able to edit any file in your favorite text editor. !!!Get all libraries !!POCO -Net Responsibility heavily relies on the [[http://www.pocoproject.org POCO C++ libraries]]. The first thing to do is download and install Poco. Note that the version needs to be 1.4 or later. Start by downloading the complete edition. Unpack it and open a terminal. cd yourself to the dir you unpacked Poco to. There you configure, compile and install. The procedure should look like this: +Net Responsibility heavily relies on the [[http://www.pocoproject.org POCO C++ +libraries]]. The first thing to do is download and install Poco. Note that the +version needs to be 1.4 or later. Start by downloading the complete edition. +Unpack it and open a terminal. cd yourself to the dir you unpacked Poco to. +There you configure, compile and install. The procedure should look like this: cd poco-* ./configure --shared --no-tests --no-samples @@ -24,27 +34,53 @@ sudo make install ---- -More information on installing Poco may be found here in [[00200-GettingStarted.html this tutorial]]. +More information on installing Poco may be found here in +[[00200-GettingStarted.html this tutorial]]. !!Libpcap -When you've installed the Poco libs, you also need libpcap. Many systems either have it installed by default, or provides packages for libpcap. Note that you'll need the developer's package. It is usually called libpcap-dev. +When you've installed the Poco libs, you also need libpcap. Many systems either +have it installed by default, or provide packages for libpcap. Note that you'll +need the developer's package. It is usually called libpcap-dev. !!!Mercurial and BitBucket: Joining the development team -We use the [[http://mercurial.selenic.com/ Mecurial]] distributed version control system (DVCS) to manage our code development, and we host our code repository (repo) at [[https://bitbucket.org/ BitBucket]]. In order to contribute to development, you will need to have Mercurial installed on your system and have a BitBucket account (individual, not team). If you are unfamiliar with Mercurial, [[http://www.hginit.com/ this basic tutorial]] will help you get started with it. If you're new to BitBucket, you will find [[https://confluence.atlassian.com/display/BITBUCKET/bitbucket+101 this guide]] helpful. For those interested in a graphical interface, we recommend [[http://tortoisehg.bitbucket.org/ TortoiseHG]]. +We use the [[http://mercurial.selenic.com/ Mecurial]] distributed version +control system (DVCS) to manage our code development, and we host our code +repository (repo) at [[https://bitbucket.org/ BitBucket]]. In order to +contribute to development, you will need to have Mercurial installed on your +system and have a BitBucket account (individual, not team). If you are +unfamiliar with Mercurial, [[http://www.hginit.com/ this basic tutorial]] will +help you get started with it. If you're new to BitBucket, you will find +[[https://confluence.atlassian.com/display/BITBUCKET/bitbucket+101 this guide]] +helpful. For those interested in a graphical interface, we recommend +[[http://tortoisehg.bitbucket.org/ TortoiseHG]]. -One of the advantages of a DVCS like Mercurial is an easy and reliable system for creating <*branches*> off of the main repo and then later submitting those changes back to the main repo, which provides more freedom and flexibility in development. An advantage of BitBucket is that you can also <*fork*> a repo, which also gives more flexibility. We recommend that NR developers use BitBucket to fork a repo, and then <*clone*> that forked repo to their systems to serve as a local repo. To create a fork, log in to BitBucket, go to the [[https://bitbucket.org/netresponsibilityteam/net-responsibility NR repo page]], click on the 'Fork' button, and enter the necessary information, etc. to complete the process. Once you've done that, here is a sample of the terminal command you would use (from within the desired directory) to clone your new fork to your local system (you will need to replace <*<path/to/forked/repo>*> with whatever the path is to your forked repo on BitBucket): +One of the advantages of a DVCS like Mercurial is an easy and reliable system +for creating <*branches*> off of the main repo and then later submitting those +changes back to the main repo, which provides more freedom and flexibility in +development. An advantage of BitBucket is that you can also <*fork*> a repo, +which also gives more flexibility. We recommend that NR developers use BitBucket +to fork a repo, and then <*clone*> that forked repo to their systems to serve as +a local repo. To create a fork, log in to BitBucket, go to the +[[https://bitbucket.org/netresponsibilityteam/net-responsibility NR repo page]], +click on the 'Fork' button, and enter the necessary information, etc. to +complete the process. Once you've done that, here is a sample of the terminal +command you would use (from within the desired directory) to clone your new fork +to your local system (you will need to replace <*<path/to/forked/repo>*> with +whatever the path is to your forked repo on BitBucket): hg clone <path/to/forked/repo> ---- -If you are on the BitBucket page of your forked repo, you can also just click on the 'Clone' button and copy the command from the window that opens. +If you are on the BitBucket page of your forked repo, you can also just click on +the 'Clone' button and copy the command from the window that opens. !!!Compile Net Responsibility -Once you have your own local repo, you can compile NR itself by running this make-chain: +Once you have your own local repo, you can compile NR itself by running this +make-chain: cd /local/repo/directory autoreconf -i @@ -53,21 +89,46 @@ sudo make install ---- -In the last step you will also be prompted to type your NR username and password, if it's the first time you install. Note that you'll need autoreconf and libtool installed. +In the last step you will also be prompted to type your NR username and +password, if it's the first time you install. Note that you'll need autoreconf +and libtool installed. -If you got this far Net Responsibility should be installed. As an initial test of a successful installation, when running "ps -ef|grep net-responsibility" you should get an output line similar to "net-responsibility --daemon". If you need to do further testing, see [[0309-TroubleshootingInstallation.html#0 this guide]]. +If you got this far Net Responsibility should be installed. As an initial test +of a successful installation, when running "ps -ef|grep net-responsibility" you +should get an output line similar to "net-responsibility --daemon". If you need +to do further testing, see [[0309-TroubleshootingInstallation.html#0 this +guide]]. !!!Understanding the program structure -The program's structure is described in [[5010-ProgramStructure.html another guide]]. It is recommended to read it to understand the concepts and different steps Net Responsibility is built around. +The program's structure is described in [[5010-ProgramStructure.html another +guide]]. It is recommended to read it to understand the concepts and different +steps Net Responsibility is built around. !!!Where to start digging -Now you're ready for the fun part -- the coding. The two main areas to lay your hands on are bugs and feature requests. You'll find both of these in our [[https://issues.netresponsibility.com/projects/net-responsibility/issues issue tracker]]. Grab a bug that sounds interesting and provide a solution, or see if there's any feature requests you'd like to implement. If you'd rather work on something that is not listed, please create a new issue about it, and a note that you're working on it. When you try to access the issue tracker, your browser may display a security warning. You can safely ignore this and grant a permanent security exception. For more info, [[0901-FAQ.html#19 see this FAQ entry]]. Anyone can view the contents of the issue tracker, but in order to create a new issue you will need to sign in with your NR user login information. The first time you do this, you may need to give some basic additional information in order to gain access. Also, even if you're already logged in to the general NR website itself, you may still need to log in to the issue tracker area of the website. +Now you're ready for the fun part -- the coding. The two main areas to lay your +hands on are bugs and feature requests. You'll find both of these in our +[[https://issues.netresponsibility.com/projects/net-responsibility/issues issue +tracker]]. Grab a bug that sounds interesting and provide a solution, or see if +there's any feature requests you'd like to implement. If you'd rather work on +something that is not listed, please create a new issue about it, and a note +that you're working on it. When you try to access the issue tracker, your +browser may display a security warning. You can safely ignore this and grant a +permanent security exception. For more info, [[0901-FAQ.html#19 see this FAQ +entry]]. Anyone can view the contents of the issue tracker, but in order to +create a new issue you will need to sign in with your NR user login information. +The first time you do this, you may need to give some basic additional +information in order to gain access. Also, even if you're already logged in to +the general NR website itself, you may still need to log in to the issue tracker +area of the website. !!!Submit source code changes -When you've created a solution or implemented a new feature, you don't want to keep it for yourself, do you? One of the best things with open source projects is the ability to contribute. For more information about how to submit your changes, see the [[5007-RepoManagement.html Repository Management]] guide. +When you've created a solution or implemented a new feature, you don't want to +keep it for yourself, do you? One of the best things with open source projects +is the ability to contribute. For more information about how to submit your +changes, see the [[5007-RepoManagement.html Repository Management]] guide. https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/ab1807877dc4/ changeset: ab1807877dc4 user: duststuff date: 2012-10-22 01:20:15 summary: Deleted reference to docs being included with tarballs, and included a note to use word wrap in the 'Guidelines' section. affected #: 1 file diff -r 8cb5a74456b01f7c21f3700f31135b8e60b8bfe6 -r ab1807877dc4a7b5eb19ba9d10439481034e501c pages/5004-Documentation.page --- a/pages/5004-Documentation.page +++ b/pages/5004-Documentation.page @@ -5,7 +5,8 @@ Good documentation is crucial for all kinds of software. If you're having a hard time installing and getting a program working, and there's no good -documentation, you'll just give up and go looking for a different program, right? +documentation, you'll just give up and go looking for a different program, +right? On the other hand, if there is good documentation available, you'll likely manage to set it up and then everyone is happy. @@ -14,72 +15,131 @@ the users are comfortable with compiling and have a basic understanding about programming. This is certainly not always the case. -It is actually even better if the creator of the documentation is <*not the programmer*>. -The more involved one is in the nuts and bolts, the more likely it is that important questions will be neglected because they may seem obvious. The ideal documentation -author is often someone not involved in the actual programming, but who still has -an ongoing dialogue with those who are. <*However, anyone is welcome to contribute*>, -since the goal is to create documentation that is as clear and up-to-date as possible, and +It is actually even better if the creator of the documentation is <*not the +programmer*>. +The more involved one is in the nuts and bolts, the more likely it is that +important questions will be neglected because they may seem obvious. The ideal +documentation +author is often someone not involved in the actual programming, but who still +has +an ongoing dialogue with those who are. <*However, anyone is welcome to +contribute*>, +since the goal is to create documentation that is as clear and up-to-date as +possible, and of course we'd like your help! !!!Getting started Of course, you may contact us and say something like "I think you should change -the words 'blah blah blah' in paragraph 3 in the page called 'Source Code Management', -to 'losum ipsum'." We can take care of it from there. It would be even better though if you +the words 'blah blah blah' in paragraph 3 in the page called 'Source Code +Management', +to 'losum ipsum'." We can take care of it from there. It would be even better +though if you followed these instructions, since this will make it easier for all of us in the long run. -The documentation, like the rest of the source code, is handled by the distributed version -control system (DVCS) [[http://mercurial.selenic.com/ Mecurial]], and hosted at [[https://bitbucket.org/ BitBucket]]. In order to contribute to the documentation development, you will need to have Mercurial installed on your system and have a BitBucket account (individual, not team). If you are unfamiliar with Mercurial, [[http://www.hginit.com/ this basic tutorial]] will help you get started with it. If you're new to BitBucket, you will find [[https://confluence.atlassian.com/display/BITBUCKET/bitbucket+101 this guide]] helpful. If you're interested in using a graphical interface rather than the command-line, we recommend [[http://tortoisehg.bitbucket.org/ TortoiseHG]]. +The documentation, like the rest of the source code, is handled by the +distributed version +control system (DVCS) [[http://mercurial.selenic.com/ Mecurial]], and hosted at +[[https://bitbucket.org/ BitBucket]]. In order to contribute to the +documentation development, you will need to have Mercurial installed on your +system and have a BitBucket account (individual, not team). If you are +unfamiliar with Mercurial, [[http://www.hginit.com/ this basic tutorial]] will +help you get started with it. If you're new to BitBucket, you will find +[[https://confluence.atlassian.com/display/BITBUCKET/bitbucket+101 this guide]] +helpful. If you're interested in using a graphical interface rather than the +command-line, we recommend [[http://tortoisehg.bitbucket.org/ TortoiseHG]]. -One of the advantages of a DVCS like Mercurial is an easy and reliable system for creating <*branches*> off of the main repo and then later submitting those changes back to the main repo, which provides more freedom and flexibility in development. An advantage of BitBucket is that you can also <*fork*> a repo, which also gives more flexibility. We recommend that NR developers use BitBucket to fork a repo, and then <*clone*> that forked repo to their systems to serve as a local repo. To create a fork, log in to BitBucket, go to the [[https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation NR documentation repo page]], click on the 'Fork' button, and enter the necessary information, etc. to complete the process. Once you've done that, here is a sample of the terminal command you would use (from within the desired directory) to clone your new fork to your local system (you will need to replace <*<path/to/forked/repo>*> with whatever the path is to your forked repo on BitBucket): +One of the advantages of a DVCS like Mercurial is an easy and reliable system +for creating <*branches*> off of the main repo and then later submitting those +changes back to the main repo, which provides more freedom and flexibility in +development. An advantage of BitBucket is that you can also <*fork*> a repo, +which also gives more flexibility. We recommend that NR developers use BitBucket +to fork a repo, and then <*clone*> that forked repo to their systems to serve as +a local repo. To create a fork, log in to BitBucket, go to the +[[https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation +NR documentation repo page]], click on the 'Fork' button, and enter the +necessary information, etc. to complete the process. Once you've done that, here +is a sample of the terminal command you would use (from within the desired +directory) to clone your new fork to your local system (you will need to replace +<*<path/to/forked/repo>*> with whatever the path is to your forked repo on +BitBucket): hg clone <path/to/forked/repo> ---- -If you go to the BitBucket page of your forked repo, you can also just click on the 'Clone' button and copy the command from the window that opens. +If you go to the BitBucket page of your forked repo, you can also just click on +the 'Clone' button and copy the command from the window that opens. More information about how to work with Mercurial and BitBucket is found in the [[5007-RepoManagement.html Repository Management]] guide. There it is also described how to submit changes to the main repo. -When you execute the terminal command above, it will clone (create) a current copy of the NR documentation repo in whatever directory (folder) you were in when you ran the command. For many systems, this is the 'home' folder by default, but you can choose to put it wherever you want. This folder will then contain several subfolders, described briefly as follows: +When you execute the terminal command above, it will clone (create) a current +copy of the NR documentation repo in whatever directory (folder) you were in +when you ran the command. For many systems, this is the 'home' folder by +default, but you can choose to put it wherever you want. This folder will then +contain several subfolders, described briefly as follows: -cfg - Config (configuration) files (with .xml extension) used when generating the documentation from the page files (with .page extension). +cfg - Config (configuration) files (with .xml extension) used when generating +the documentation from the page files (with .page extension). -doc - When the documentation is 'generated' from the page files, it creates HTML files here that can then be opened with a web browser to see how they will appear to the user. +doc - When the documentation is 'generated' from the page files, it creates HTML +files here that can then be opened with a web browser to see how they will +appear to the user. -pages - The raw pages where all writing and editing happens, and that will then be used to generate the documentation. +pages - The raw pages where all writing and editing happens, and that will then +be used to generate the documentation. -resources - Images, stylesheets etc. that are used in generating the documentation. +resources - Images, stylesheets etc. that are used in generating the +documentation. -If your primary goal is creating and editing documentation, then you will only need to work with the files in the 'pages' folder, which can be opened and edited in your choice of text editor. However, you may also want to set up your system to generate documents and then access the files in the 'doc' folder to see how the pages you are working on will appear to the user. +If your primary goal is creating and editing documentation, then you will only +need to work with the files in the 'pages' folder, which can be opened and +edited in your choice of text editor. However, you may also want to set up your +system to generate documents and then access the files in the 'doc' folder to +see how the pages you are working on will appear to the user. !!!Guidelines +!!General + +When you edit the 'pages' files, you will want to use a text editor that allows +you to apply word wrap, which ensures that each line of text is around 80 +characters long. While you may not notice a difference on your own system, this +will help make the documentation and the changes you've made easier to read in +certain environments, such as on BitBucket or when using Mercurial-related +tools. + !!Syntax Once you get going the syntax will be pretty easy to understand. The first two -lines in the document contain the title and the category. The title should explain +lines in the document contain the title and the category. The title should +explain briefly what the page is all about. The category must follow the guidelines described below. Next you can divide the page into smaller sections (depending on the size, of -course). Each section should have a large heading (<{!!!Large heading}>), and may -also contain smaller headings if appropriate (<{!!Medium heading, !Small heading}>). +course). Each section should have a large heading (<{!!!Large heading}>), and +may +also contain smaller headings if appropriate (<{!!Medium heading, !Small +heading}>). The headings will also be displayed on top of the page, and serve as a table of contents. Choose names here carefully. The paragraphs are divided by blank lines. More examples on how to add links, images, bold, italic text, etc. can be found in the file -<*pages/samplePage.txt*> or by looking in some of the other 'page' files that include whatever you are wanting to use. +<*pages/samplePage.txt*> or by looking in some of the other 'page' files that +include whatever you are wanting to use. !!Bold vs. Italic -Be careful with using bold text. If you want to emphasize something, <*please do so in -italic*>. This is more natural for the eyes, but the point is still clear. In some +Be careful with using bold text. If you want to emphasize something, <*please do +so in +italic*>. This is more natural for the eyes, but the point is still clear. In +some cases you may find it more appropriate to use bold text, and it's not forbidden, but be careful with it. @@ -87,7 +147,8 @@ !!Categories All pages are grouped into categories. The names of the categories can be -found in the config files (in the 'cfg' folder), in a section that looks like this: +found in the config files (in the 'cfg' folder), in a section that looks like +this: <A01NR_Appetizer>Appetizer</A01NR_Appetizer><A03NR_Install>Installation and Configuration</A03NR_Install> @@ -97,23 +158,28 @@ ---- You may find the tag names awkward at first, but there is a reason they're -named like this. We want to separate the Net Responsibility (NR) pages from the POCO-related pages, and we +named like this. We want to separate the Net Responsibility (NR) pages from the +POCO-related pages, and we want them to show up in the correct order. The beginning 'A' is to put it above the POCO-related pages, and because XML doesn't allow us to use a number first. The numbers used in the category abbreviations have a little gap between them -to make sure there's room to add more categories later on if we want. All categories with a number less -than 50 are considered to be user documentation, and will be found on the regular -website, as well as shipped with the source code tarballs. All categories with a number -of 50 and above are considered to be documentation for developers only. These pages -can include more technical (i.e. 'geekier') language, and writers can take more knowledge for granted. +to make sure there's room to add more categories later on if we want. All +categories with a number less +than 50 are considered to be user documentation, and will show up on the regular +website. All categories with a number +of 50 and above are considered to be documentation for developers only. These +pages +can include more technical (i.e. 'geekier') language, and writers can take more +knowledge for granted. These pages will only be displayed in the [[http://www.netresponsibility.com/dev/docs/ Developers Documentation]]. 'NR' in the category name just makes it clear that this is part of the Net Responsibility documentation. -Everything to the right of the underscore is just an abbreviation of the full category +Everything to the right of the underscore is just an abbreviation of the full +category name. It needs to be obvious what it's supposed to abbreviate. !!Filenames @@ -122,11 +188,13 @@ '5004-Documentation.page'. The first two digits are the category number. Since this page is a part of 'A50NR_DevIntro', the number is '50'. -The next two digits make it clear what place the page should have in the ordering of pages inside the +The next two digits make it clear what place the page should have in the +ordering of pages inside the category. After the dash comes an abbreviation of the title. The same thing applies here -as with the category abbreviation explained above -- it needs to be obvious which +as with the category abbreviation explained above -- it needs to be obvious +which title it abbreviates, so one can easily find the right file to edit. @@ -134,20 +202,32 @@ Note that <*you may contribute to the documentation without generating it*>. -The documentation is generated (i.e., converted into HTML, making it viewable in a web browser) with a utility called PocoDoc. To be able to use -it, you'll need to compile it together with the rest of POCO. To do this, first extract -the latest version of POCO (the <*basic edition*> is okay to use), putting its contents in a folder of your choice. Then you need to go to that folder, open the file called 'components' in a text editor and add the following two lines to it: +The documentation is generated (i.e., converted into HTML, making it viewable in +a web browser) with a utility called PocoDoc. To be able to use +it, you'll need to compile it together with the rest of POCO. To do this, first +extract +the latest version of POCO (the <*basic edition*> is okay to use), putting its +contents in a folder of your choice. Then you need to go to that folder, open +the file called 'components' in a text editor and add the following two lines to +it: CppParser PocoDoc ---- -Once you have done this, save the file. Then open a terminal window and use the <*cd*> command to put yourself in the folder where you put the extracted POCO file contents earlier. For instance, if you put the POCO files in <*/home/name/poco*> then you would use the command <*cd /home/name/poco*> to enter that folder. Once you are in the folder where you put the POCO files, run the following commands to compile POCO, download and compile PocoDoc and +Once you have done this, save the file. Then open a terminal window and use the +<*cd*> command to put yourself in the folder where you put the extracted POCO +file contents earlier. For instance, if you put the POCO files in +<*/home/name/poco*> then you would use the command <*cd /home/name/poco*> to +enter that folder. Once you are in the folder where you put the POCO files, run +the following commands to compile POCO, download and compile PocoDoc and CppParser, and install everything. export POCO_BASE=$(pwd) - svn checkout https://poco.svn.sourceforge.net/svnroot/poco/sandbox/PocoDoc/ ./PocoDoc - svn checkout https://poco.svn.sourceforge.net/svnroot/poco/sandbox/CppParser/ ./CppParser + svn checkout https://poco.svn.sourceforge.net/svnroot/poco/sandbox/PocoDoc/ +./PocoDoc + svn checkout +https://poco.svn.sourceforge.net/svnroot/poco/sandbox/CppParser/ ./CppParser ./configure make -s make -s --directory=./CppParser @@ -155,23 +235,69 @@ make install ---- -Make sure the last command <*make install*> is run as 'root'. In Ubuntu/Debian this means using <*sudo*> and running the command as <*sudo make install*> . Other Linux systems might use <*su*> in the same way. The main thing is that you need to run the command as 'root', however your particular system handles that. +Make sure the last command <*make install*> is run as 'root'. In Ubuntu/Debian +this means using <*sudo*> and running the command as <*sudo make install*> . +Other Linux systems might use <*su*> in the same way. The main thing is that you +need to run the command as 'root', however your particular system handles that. -Once you've successfully compiled and installed PocoDoc, you will want to make sure that PocoDoc will be able to access the needed NR source code when it generates the documentation. First, you need to make sure you have a clone of the NR software repo on your system. If you don't already have a local NR software repo or if you need a separate one, you can clone one by following the instructions in the [[#1 Getting Started]] section of this document, but using the [[https://bitbucket.org/netresponsibilityteam/net-responsibility NR software repo page]] instead of the NR documentation repo page. If you will only be using this local NR software repo for generating documentation and not for doing any development on the NR source code itself, then you can simply do a clone of the main NR repo without first forking a branch. Secondly, because a newly cloned local repo represents the latest development version of the NR software, you need to make sure it is <*updated*> so it represents the correct version/release you are generating documentation for (this will normally be the latest stable release). To update the repo to the latest stable release, run the command <*hg update stable*> in whatever directory it is located. Then, each time a new stable version is released, you will want to make sure and <*pull*> all the changes from the main repo to your local repo in order to update it. You can run the command <*hg pull && hg update*> to both pull the changes and then update your repo with them. If you ever want to confirm what version of NR your local repo currently represents, you can open the <*configure.ac*> file in that directory and look at the line near the top that starts with 'AC_Init'. This line should include the version number in brackets. +Once you've successfully compiled and installed PocoDoc, you will want to make +sure that PocoDoc will be able to access the needed NR source code when it +generates the documentation. First, you need to make sure you have a clone of +the NR software repo on your system. If you don't already have a local NR +software repo or if you need a separate one, you can clone one by following the +instructions in the [[#1 Getting Started]] section of this document, but using +the [[https://bitbucket.org/netresponsibilityteam/net-responsibility NR software +repo page]] instead of the NR documentation repo page. If you will only be using +this local NR software repo for generating documentation and not for doing any +development on the NR source code itself, then you can simply do a clone of the +main NR repo without first forking a branch. Secondly, because a newly cloned +local repo represents the latest development version of the NR software, you +need to make sure it is <*updated*> so it represents the correct version/release +you are generating documentation for (this will normally be the latest stable +release). To update the repo to the latest stable release, run the command <*hg +update stable*> in whatever directory it is located. Then, each time a new +stable version is released, you will want to make sure and <*pull*> all the +changes from the main repo to your local repo in order to update it. You can run +the command <*hg pull && hg update*> to both pull the changes and then update +your repo with them. If you ever want to confirm what version of NR your local +repo currently represents, you can open the <*configure.ac*> file in that +directory and look at the line near the top that starts with 'AC_Init'. This +line should include the version number in brackets. -Now that you have PocoDoc installed and your local NR software repo set up, you are able to use the -./generate script in the NR documentation repo directory to generate documents from the 'page' files. The first time you run the script, you will be asked to enter the paths of three different variables, POCO_BASE, DOC_BASE and NR_BASE, according to wherever you've put the POCO files, the NR documentation repo, and the NR software repo. This will create a file in the same directory called <*paths.txt*> that stores the paths you entered. You can later use a text editor to open this file and make any necessary changes, or if you delete this file, you will be prompted to enter the paths again the next time you run the script. Once you've entered the correct paths you can use a terminal window and enter the directory where you cloned the documentation repo (using the <*cd*> command as shown above) and run the script from there with the following command: +Now that you have PocoDoc installed and your local NR software repo set up, you +are able to use the +./generate script in the NR documentation repo directory to generate documents +from the 'page' files. The first time you run the script, you will be asked to +enter the paths of three different variables, POCO_BASE, DOC_BASE and NR_BASE, +according to wherever you've put the POCO files, the NR documentation repo, and +the NR software repo. This will create a file in the same directory called +<*paths.txt*> that stores the paths you entered. You can later use a text editor +to open this file and make any necessary changes, or if you delete this file, +you will be prompted to enter the paths again the next time you run the script. +Once you've entered the correct paths you can use a terminal window and enter +the directory where you cloned the documentation repo (using the <*cd*> command +as shown above) and run the script from there with the following command: ./generate [cfg file] ---- -Where [cfg file] is the name of the config file to use, excluding the file ending. +Where [cfg file] is the name of the config file to use, excluding the file +ending. For instance, to use cfg/DevDocs.xml, just run ./generate DevDocs ---- -Once you've successfully run the script, you should find the HTML files that were generated in the 'doc' folder, and can open them in a web browser to see what they look like, which is helpful for testing purposes. If you only want to generate documents from 'page' files (it will take less time to run the script, and may be all you need), you can use the 'PagesOnly' config file instead of 'DevDocs' when running the script. +Once you've successfully run the script, you should find the HTML files that +were generated in the 'doc' folder, and can open them in a web browser to see +what they look like, which is helpful for testing purposes. If you only want to +generate documents from 'page' files (it will take less time to run the script, +and may be all you need), you can use the 'PagesOnly' config file instead of +'DevDocs' when running the script. !!!Troubleshooting -If you are having problems with getting set up to help contribute to the documentation or have related questions, please [[mailto:res...@li... let us know]], and we'll do our best to help you figure things out. This dialogue may also help us know how we can improve the information and instructions on this page. +If you are having problems with getting set up to help contribute to the +documentation or have related questions, please +[[mailto:res...@li... let us know]], and we'll do +our best to help you figure things out. This dialogue may also help us know how +we can improve the information and instructions on this page. Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-10-20 15:55:07
|
1 new commit in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/8271ca0de2b1/ changeset: 8271ca0de2b1 user: duststuff date: 2012-10-20 06:24:13 summary: Made minor edits to en_EN.xml translation locale files. affected #: 2 files diff -r b37e613fa91dbc6b967c0b72c4b6034866a6ffa4 -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 locale/en_EN.xml --- a/locale/en_EN.xml +++ b/locale/en_EN.xml @@ -2,6 +2,11 @@ <locale language="en_EN"><translator> + <name>Dustin Miller</name> + <email>du...@gm...</email> + <nrVersion>3.1</nrVersion> + </translator> + <translator><name>Robert Rosman</name><email>rob...@gm...</email><nrVersion>3.1</nrVersion> @@ -163,7 +168,7 @@ - <!-- Do not edit the following entries, unless you really now what you're doing! --> + <!-- Do not edit the following entries, unless you really know what you're doing! --><test><![CDATA[ diff -r b37e613fa91dbc6b967c0b72c4b6034866a6ffa4 -r 8271ca0de2b10063e02d35977bac8d27429a5bb6 plugins/DefaultReport/locale/en_EN.xml --- a/plugins/DefaultReport/locale/en_EN.xml +++ b/plugins/DefaultReport/locale/en_EN.xml @@ -2,6 +2,11 @@ <locale language="en_EN"><translator> + <name>Dustin Miller</name> + <email>du...@gm...</email> + <nrVersion>3.1</nrVersion> + </translator> + <translator><name>Robert Rosman</name><email>rob...@gm...</email><nrVersion>3.1</nrVersion> @@ -53,13 +58,13 @@ <visitWebsite>Visit www.netresponsibility.com</visitWebsite></options> - <javascriptError>JavaScript has to be enabled. It seems to be blocked by your browser or email host, or anything else. Please allow JavaScript to see this page correctly.</javascriptError> + <javascriptError>JavaScript has to be enabled. It seems to be blocked by your browser, email host, or something else. Please allow JavaScript in order to see this page correctly.</javascriptError> - <!-- Do not edit the following entries, unless you really now what you're doing! --> + <!-- Do not edit the following entries, unless you really know what you're doing! --><header><![CDATA[ Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-10-20 05:40:15
|
1 new commit in net-responsibility-documentation: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/7e40d82e7627/ changeset: 7e40d82e7627 user: duststuff date: 2012-10-20 07:36:59 summary: Updated documents to reflect the switch from Subversion to Mercurial as a version control system, the switch from SourceForge to BitBucket as a code hosting service, and the website changes that have been made thus far. Also made a few other miscellaneous edits/updates. affected #: 20 files Diff too large to display. Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-10-16 16:45:58
|
3 new commits in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/cfb0efad1709/ changeset: cfb0efad1709 user: roggan87 date: 2012-10-16 17:23:34 summary: Fixed a bug in the locale file. The elements were badly nested. affected #: 2 files diff -r 027bbfb4e7b98b42ff3df4960873280bb20070dd -r cfb0efad1709400615f93bfaa721925739bfe805 locale/en_EN.xml --- a/locale/en_EN.xml +++ b/locale/en_EN.xml @@ -9,18 +9,16 @@ <bypass><unknown>Net Responsibility seems to have been bypassed</unknown> - <shutdown> - Net Responsibility was shutdown - - <details> - <manually>Manually it seems</manually> - <downTime>It was down for ${bypass.shutdown.minutes} minutes</downTime> - <downtimeHours>It was down for ${bypass.shutdown.hours} hours and ${bypass.shutdown.minutes} minutes</downtimeHours> - </details> - - </shutdown> + <shutdown>Net Responsibility was shutdown</shutdown><missingFile>An important file was deleted</missingFile><modifiedFile>An important file was modified</modifiedFile> + <details> + <shutdown> + <manually>Manually it seems</manually> + <downtime>It was down for ${bypass.details.shutdown.minutes} minutes</downtime> + <downtimeHours>It was down for ${bypass.details.shutdown.hours} hours and ${bypass.details.shutdown.minutes} minutes</downtimeHours> + </shutdown> + </details></bypass> @@ -117,7 +115,7 @@ </initializingSubsystem><bypass> - <shutdown>Bypass: ${bypass.shutdown.msg}</shutdown> + <shutdown>Bypass: ${bypass.details.shutdown.msg}</shutdown></bypass><report> diff -r 027bbfb4e7b98b42ff3df4960873280bb20070dd -r cfb0efad1709400615f93bfaa721925739bfe805 src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -189,22 +189,22 @@ string downtime; if (gap == 0) { - msg = _options->getString("bypass.shutdown.details.manually"); + msg = _options->getString("bypass.details.shutdown.manually"); } else { if (gap > 3600) { int hours = gap / 3600; gap = gap % 3600; - _options->setInt("bypass.shutdown.hours", hours); - downtime = "bypass.shutdown.details.downtimeHours"; + _options->setInt("bypass.details.shutdown.hours", hours); + downtime = "bypass.details.shutdown.downtimeHours"; } else - downtime = "bypass.shutdown.details.downtime"; + downtime = "bypass.details.shutdown.downtime"; int minutes = gap / 60; - _options->setInt("bypass.shutdown.minutes", minutes); + _options->setInt("bypass.details.shutdown.minutes", minutes); msg = _options->getString(downtime); - _options->setString("bypass.shutdown.msg", msg); + _options->setString("bypass.details.shutdown.msg", msg); } logBypass(BYPASS_SHUTDOWN, msg, datetime); https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/2f3603d750e0/ changeset: 2f3603d750e0 user: roggan87 date: 2012-10-16 17:24:47 summary: Changed the format of improvement data sent to the server. This commit closes feature #20 and #21. affected #: 2 files diff -r cfb0efad1709400615f93bfaa721925739bfe805 -r 2f3603d750e0a07d1c3d6e6e6501bf71e3f1251d src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -182,32 +182,39 @@ void ReportBase::sendImprovementData() { Warnings warnings = _db->getWarnings(); - if (_options->doSendImprovementData() && warnings.size() > 0) { - string impData = ""; - stringstream strength; - vector<BlacklistKeyword> keywords; + if (_options->getBool("improveData", false) && warnings.size() > 0) { + stringstream impData; + int i = 0; while (warnings.hasMore()) { - keywords = warnings.getKeywords(); + vector<BlacklistKeyword> keywords = warnings.getKeywords(); + string joinedKeywords = ""; for(vector<BlacklistKeyword>::iterator it = keywords.begin(); it != keywords.end(); it++) { - impData += it->category + "¤" + it->asString + "¤"; - URI::encode(warnings.getBoldUrl(), "&'\"<>", impData); - impData += "¤"; - URI::encode(warnings.getUrl(), "&'\"<>", impData); - impData += "¤"; - URI::encode(warnings.getAbbrUrl(), "&'\"<>", impData); - strength.str(""); - strength <<"¤" <<warnings.getStrength(); - impData += strength.str(); + // Format the keywords like this: + // keyword <category>; keyword <category>; keyword <category> + joinedKeywords += it->asString + " <" + it->category + ">"; if (it + 1 != keywords.end()) - impData += "\n"; - } + joinedKeywords += "; "; + } + + // Do we still need to encode the urls? + impData <<"#" <<i++ <<endl + <<"url: " <<warnings.getUrl() <<endl + <<"boldUrl: " <<warnings.getBoldUrl() <<endl + <<"abbrUrl: " <<warnings.getAbbrUrl() <<endl + <<"strength: " <<warnings.getStrength() <<endl + <<"keywords: " <<joinedKeywords <<endl + <<endl + <<endl + <<endl; + warnings.next(); - if (warnings.hasMore()) - impData += "\n"; } - _logger->information(Request::sendImprovementData(_options, impData)); + + // TODO: Make the return message dynamic by using the locale files! + string returnValue = Request::sendImprovementData(_options, impData.str()); + _logger->information(returnValue); } } diff -r cfb0efad1709400615f93bfaa721925739bfe805 -r 2f3603d750e0a07d1c3d6e6e6501bf71e3f1251d src/Request.cpp --- a/src/Request.cpp +++ b/src/Request.cpp @@ -60,8 +60,35 @@ string Request::sendImprovementData(Options *options, string impData) { - impData = "warnings=" + impData; - return send(options, "/request/add_improve_data.php", "", impData); + // We don't want to send this request as + // application/x-www-form-urlencoded, so we customize this one. + while (true) { + try { + URI uri("http://" + options->get<string>("server.hostname") + + "/request/add_improve_data.php" + + "?version=" + options->getString("program.version")); + + string path(uri.getPathAndQuery()); + HTTPClientSession session(uri.getHost(), uri.getPort()); + HTTPRequest req(HTTPRequest::HTTP_POST, path); + req.setContentType("text/plain"); + req.setContentLength(impData.length()); + session.sendRequest(req) <<impData; + HTTPResponse res; + istream& rs = session.receiveResponse(res); + + if (res.getStatus() == 200) { + string s((istreambuf_iterator<char>(rs)), istreambuf_iterator<char>()); + return s; + } + // TODO: delete this stupid message! + return "FAIL! Improvement data"; + } + catch (Exception& exc) { + MyLogger::instance().debug(exc.displayText()); + ::Poco::Thread::sleep(20000); + } + } } https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/b37e613fa91d/ changeset: b37e613fa91d user: roggan87 date: 2012-10-16 18:45:27 summary: Made improvement data response dynamic by putting it in the locale file affected #: 3 files diff -r 2f3603d750e0a07d1c3d6e6e6501bf71e3f1251d -r b37e613fa91dbc6b967c0b72c4b6034866a6ffa4 locale/en_EN.xml --- a/locale/en_EN.xml +++ b/locale/en_EN.xml @@ -74,6 +74,18 @@ <config>Downloading configuration file</config><blacklists>Downloading blacklists</blacklists></downloading> + + <improvementData> + <!-- Here ${return.improvementData} is (stored/sent) like (4/10) --> + <saved>Saved the improvement data ${return.improvementData}</saved> + + <!-- Here ${return.improvementData} is a version number, such as 3.1 --> + <upgrade>Will only save improvement data from version ${return.improvementData} or later</upgrade> + + <empty>No improvement data received</empty> + <disabled>The improvement data collector is currently disabled on the server</disabled> + <failure>Failed to send improvement data</failure> + </improvementData></information><debug> diff -r 2f3603d750e0a07d1c3d6e6e6501bf71e3f1251d -r b37e613fa91dbc6b967c0b72c4b6034866a6ffa4 src/ReportBase.cpp --- a/src/ReportBase.cpp +++ b/src/ReportBase.cpp @@ -212,9 +212,18 @@ warnings.next(); } - // TODO: Make the return message dynamic by using the locale files! - string returnValue = Request::sendImprovementData(_options, impData.str()); - _logger->information(returnValue); + string retMsg = Request::sendImprovementData(_options, impData.str()); + + // Split the retMsg by the first space. The first word is used to access + // the correct locale message, and the rest is stored as data. + size_t pos = retMsg.find(' '); + string msg = retMsg.substr(0, pos); + if (pos != string::npos) { + string data = retMsg.substr(pos + 1); + _options->setString("return.improvementData", data); + } + + _logger->information("improvementData." + msg); } } diff -r 2f3603d750e0a07d1c3d6e6e6501bf71e3f1251d -r b37e613fa91dbc6b967c0b72c4b6034866a6ffa4 src/Request.cpp --- a/src/Request.cpp +++ b/src/Request.cpp @@ -80,9 +80,8 @@ if (res.getStatus() == 200) { string s((istreambuf_iterator<char>(rs)), istreambuf_iterator<char>()); return s; - } - // TODO: delete this stupid message! - return "FAIL! Improvement data"; + } + return "failure"; } catch (Exception& exc) { MyLogger::instance().debug(exc.displayText()); Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-10-15 19:23:49
|
1 new commit in net-responsibility: https://bitbucket.org/netresponsibilityteam/net-responsibility/changeset/027bbfb4e7b9/ changeset: 027bbfb4e7b9 user: roggan87 date: 2012-10-15 21:23:14 summary: Restructured the locale files to make them as easy as possible to translate. This means that I've tried to separate all messages from the code. affected #: 8 files diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd include/Database.h --- a/include/Database.h +++ b/include/Database.h @@ -185,7 +185,8 @@ string _hostname; string _path; string _keyword; - string _category; + string _category; + Options *_options; MyLogger *_logger; BootHistory *_bootHistory; BlacklistMatch _blacklistMatch; diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd include/ReportSubsystem.h --- a/include/ReportSubsystem.h +++ b/include/ReportSubsystem.h @@ -71,6 +71,7 @@ protected: MyLogger *_logger; + Options *_options; void initialize(Application& self); /// Run the Subsystem diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd include/SnifferSubsystem.h --- a/include/SnifferSubsystem.h +++ b/include/SnifferSubsystem.h @@ -62,6 +62,7 @@ protected: MyLogger *_logger; + Options *_options; void initialize(Application& self); void uninitialize(); bool isOnlyInstance(); diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd locale/en_EN.xml --- a/locale/en_EN.xml +++ b/locale/en_EN.xml @@ -1,49 +1,28 @@ <?xml version="1.0" encoding="UTF-8"?> -<txt> +<locale language="en_EN"> + <translator> + <name>Robert Rosman</name> + <email>rob...@gm...</email> + <nrVersion>3.1</nrVersion> + </translator> + <bypass><unknown>Net Responsibility seems to have been bypassed</unknown> - <shutdown>Net Responsibility was shutdown</shutdown> + <shutdown> + Net Responsibility was shutdown + + <details> + <manually>Manually it seems</manually> + <downTime>It was down for ${bypass.shutdown.minutes} minutes</downTime> + <downtimeHours>It was down for ${bypass.shutdown.hours} hours and ${bypass.shutdown.minutes} minutes</downtimeHours> + </details> + + </shutdown><missingFile>An important file was deleted</missingFile><modifiedFile>An important file was modified</modifiedFile></bypass> - <report> - <subject> - <normal>${name}'s Net Responsibility Report</normal> - <test>${name}'s Test Report</test> - <install>${name} has installed Net Responsibility</install> - <uninstall>${name} has uninstalled Net Responsibility</uninstall> - </subject> - <test> - <![CDATA[ - <html> - <body> - This is a test report generated by ${name} using Net Responsibility. The fact you're reading this is a good sign that it's probably working.<br /> - For more information please visit <a href="http://www.netresponsibility.com">www.netresponsibility.com</a> - </body> - </html> - ]]> - </test> - <install> - <![CDATA[ - <html> - <body> - ${name} has installed Net Responsibility on his or her computer. If this isn't the first time you should ask if it's an attempt to clear the history. - </body> - </html> - ]]> - </install> - <uninstall> - <![CDATA[ - <html> - <body> - ${name} has uninstalled Net Responsibility on his or her computer. If you haven't agreed on this you should ask if it's an attempt to bypass the software. - </body> - </html> - ]]> - </uninstall> - </report><!--Logger messages--><logger> @@ -104,6 +83,10 @@ <database>Database path: ${path.database}</database><txt>Txt path: ${path.txt}</txt><config>Config path: ${path.config}</config> + <plugin> + <sniffer>Sniffer plugin path: ${path.plugin.sniffer}</sniffer> + <report>Report plugin path: ${path.plugin.report}</report> + </plugin></printPath><dbLockRetry> @@ -132,7 +115,78 @@ <initializingSubsystem><report>Initializing subsystem: Report Subsystem</report></initializingSubsystem> + + <bypass> + <shutdown>Bypass: ${bypass.shutdown.msg}</shutdown> + </bypass> + + <report> + <retryIn20>Retrying to send report in 20 seconds</retryIn20> + </report></debug></logger> -</txt> + + <report> + <subject> + <normal>${name}'s Net Responsibility Report</normal> + <test>${name}'s Test Report</test> + <install>${name} has installed Net Responsibility</install> + <uninstall>${name} has uninstalled Net Responsibility</uninstall> + </subject> + <information> + <test> + This is a test report generated by ${name} using Net Responsibility. The fact you're reading this is a good sign that it's probably working. + </test> + <moreInfoLink> + For more information please visit ${report.website} + </moreInfoLink> + <install> + ${name} has installed Net Responsibility on his or her computer. If this isn't the first time you should ask if it's an attempt to clear the history. + </install> + <uninstall> + ${name} has uninstalled Net Responsibility on his or her computer. If you haven't agreed on this you should ask if it's an attempt to bypass the software. + </uninstall> + </information> + + + + + + <!-- Do not edit the following entries, unless you really now what you're doing! --> + + <test> + <![CDATA[ + <html> + <body> + ${report.information.test}<br /> + ${report.information.moreInfoLink} + </body> + </html> + ]]> + </test> + <install> + <![CDATA[ + <html> + <body> + ${report.information.install} + </body> + </html> + ]]> + </install> + <uninstall> + <![CDATA[ + <html> + <body> + ${report.information.uninstall} + </body> + </html> + ]]> + </uninstall> + <website> + <![CDATA[ + <a href="http://www.netresponsibility.com">www.netresponsibility.com</a> + ]]> + </website> + </report> +</locale> diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd plugins/DefaultReport/locale/en_EN.xml --- a/plugins/DefaultReport/locale/en_EN.xml +++ b/plugins/DefaultReport/locale/en_EN.xml @@ -1,17 +1,35 @@ <?xml version="1.0" encoding="UTF-8"?> -<txt> +<locale language="en_EN"> + + <translator> + <name>Robert Rosman</name> + <email>rob...@gm...</email> + <nrVersion>3.1</nrVersion> + </translator> + + <!-- Format of date and time --> + <dateTimeFormat>%d/%m - %H:%M:%S</dateTimeFormat><report> - <generatedBy>This report was generated by <![CDATA[<a href='http://www.netresponsibility.com'>Net Responsibility.</a>]]></generatedBy> - <troubleshooting>For more information and troubleshooting, <![CDATA[<a href='http://www.netresponsibility.com/help.php#AccountabilityPartnerGuide'>click here.</a>]]></troubleshooting> - <noReply>Please do not reply to this address (re...@ne...).</noReply> - <suspiciousInfo> - <![CDATA[<ol> - <li><b>Don't panic!</b> Things that look suspicious may actually be innocuous. Look at everything in context and be sure to talk to the account user about anything that you don't understand.</li> - <li><b>Be safe!</b> Only links that look like this: [<a href='#'>go to URL</a>] will take you to another web page. These links are listed <i>because</i> they are suspicious so be especially cautious clicking on them.</li> - <li><b>Get help!</b></li> - </ol>]]> - </suspiciousInfo> + <generatedBy>This report was generated by ${report.links.netResponsibility}.</generatedBy> + <troubleshooting>For more information and troubleshooting, please read the ${report.links.documentation}.</troubleshooting> + <noReply>Replies to this email will go to ${name}.</noReply> + + <suspicious> + <dontPanic> + <header>Don't panic!</header> + <description>Things that look suspicious may actually be innocuous. Look at everything in context and be sure to talk to the account user about anything that you don't understand.</description> + </dontPanic> + <beSafe> + <header>Be safe!</header> + <description>Only links that look like this: ${report.links.goToUrl} will take you to another web page. These links are listed because they are suspicious so be especially cautious clicking on them.</description> + </beSafe> + <getHelp> + <header>Get help!</header> + <description></description> + </getHelp> + </suspicious> + <noWarnings>No warnings</noWarnings><noWhitelist>No whitelist matches</noWhitelist><noHistory>Found no recorded history</noHistory> @@ -21,8 +39,28 @@ <warningsTitle>Warnings</warningsTitle><whitelistTitle>Whitelist</whitelistTitle><historyTitle>History</historyTitle> + + <documentation>documentation</documentation><attached> + + <defaultTitle>Net Responsibility Report</defaultTitle> + + <options> + <header>Options:</header> + <displayTime>Display time</displayTime> + <expandAllNodes>Expand all nodes</expandAllNodes> + <visitWebsite>Visit www.netresponsibility.com</visitWebsite> + </options> + + <javascriptError>JavaScript has to be enabled. It seems to be blocked by your browser or email host, or anything else. Please allow JavaScript to see this page correctly.</javascriptError> + + + + + + <!-- Do not edit the following entries, unless you really now what you're doing! --> + <header><![CDATA[ <html> @@ -52,21 +90,20 @@ ----------------------------------------------------------------><meta http-equiv="content-type" content="text/html; charset=utf-8"> - <title>Net Responsibility Report</title> + <title>${report.attached.defaultTitle}</title><link rel="stylesheet" type="text/css" href="http://www.netresponsibility.com/lib/jsTree/jsTree.css"><script src="http://www.netresponsibility.com/lib/jsTree/jsTree.js" type="text/javascript" language="JavaScript"></script></head><body onload="renderTree();"> - <h1>Net Responsibility Report</h1> - Options: - <a href="javascript:displayTime(true)" id="displayTimeLink">Display time</a> | - <a href="javascript:expandAll()">Expand all nodes</a> | - <a href="http://www.netresponsibility.com">Visit www.netresponsibility.com</a> + <h1>${report.attached.defaultTitle}</h1> + ${report.attached.options.header} + <a href="javascript:displayTime(true)" id="displayTimeLink">${report.attached.options.displayTime}</a> | + <a href="javascript:expandAll()">${report.attached.options.expandAllNodes}</a> | + <a href="http://www.netresponsibility.com">${report.attached.options.visitWebsite}</a><br><br> - <div id="treeContainer">JavaScript has to be enabled. It seems to be blocked by your browser or email host, or anything else.<br> - Please allow JavaScript to see this page correctly. + <div id="treeContainer">${report.attached.javascriptError} </div><form id="ajaxForm" action="http://www.netresponsibility.com/lib/ajax/improve_data.php" method="POST" target="ratingIframe"> @@ -96,9 +133,35 @@ ]]></footer></attached> + + <suspiciousInfo> + <![CDATA[ + <ol> + <li><b>${report.suspicious.dontPanic.header}</b> ${report.suspicious.dontPanic.description}</li> + <li><b>${report.suspicious.beSafe.header}</b> ${report.suspicious.beSafe.description}</li> + <li><b>${report.suspicious.getHelp.header}</b> ${report.suspicious.getHelp.description}</li> + </ol> + ]]> + </suspiciousInfo> + + <links> + <netResponsibility> + <![CDATA[ + <a href='http://www.netresponsibility.com'>Net Responsibility</a> + ]]> + </netResponsibility> + <documentation> + <![CDATA[ + <a href='http://www.netresponsibility.com/documentation.php'>${report.documentation}</a> + ]]> + </documentation> + <goToUrl> + <![CDATA[ + [<a href='#'>${report.goToUrl}</a>] + ]]> + </goToUrl> + </links> + </report> - - <!--Formatting--> - <dateTimeFormat>%d/%m - %H:%M:%S</dateTimeFormat> -</txt> +</locale> diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd src/Database.cpp --- a/src/Database.cpp +++ b/src/Database.cpp @@ -30,13 +30,13 @@ _logger->information("connectingToDatabase"); _logger->debug("printPath.database"); - Options *options = &Options::instance(); + _options = &Options::instance(); const int FINISHED = 20; for (int i = 0; i <= FINISHED; i++) { try { SQLite::Connector::registerConnector(); - _session = new Session("SQLite", options->get<string>("path.database")); + _session = new Session("SQLite", _options->get<string>("path.database")); *_session <<"CREATE TABLE IF NOT EXISTS urls " <<"(hostname TEXT, path TEXT, date DATE, time TIME)", now; *_session <<"CREATE TABLE IF NOT EXISTS warnings " @@ -66,7 +66,7 @@ } setStatements(); - logInitBypasses(options->getInitBypasses()); + logInitBypasses(_options->getInitBypasses()); _bootHistory = new BootHistory(); processPreviousSessions(); } @@ -185,22 +185,30 @@ void Database::logBypassShutdown(int datetime, int gap) { - stringstream msg; - // Put the following message in txt.xml instead + string msg; + string downtime; + if (gap == 0) { - msg <<"Manually it seems"; + msg = _options->getString("bypass.shutdown.details.manually"); } else { - msg <<"It was down for "; if (gap > 3600) { - msg <<gap / 3600 <<" hour(s) and "; + int hours = gap / 3600; gap = gap % 3600; + _options->setInt("bypass.shutdown.hours", hours); + downtime = "bypass.shutdown.details.downtimeHours"; } - msg <<gap / 60 <<" minute(s)."; + else + downtime = "bypass.shutdown.details.downtime"; + + int minutes = gap / 60; + _options->setInt("bypass.shutdown.minutes", minutes); + msg = _options->getString(downtime); + _options->setString("bypass.shutdown.msg", msg); } - logBypass(BYPASS_SHUTDOWN, msg.str(), datetime); - _logger->debug("Bypass: " + msg.str()); + logBypass(BYPASS_SHUTDOWN, msg, datetime); + _logger->debug("bypass.shutdown"); } diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd src/ReportSubsystem.cpp --- a/src/ReportSubsystem.cpp +++ b/src/ReportSubsystem.cpp @@ -37,12 +37,15 @@ void ReportSubsystem::initialize(Application& app) { _logger = &MyLogger::instance(); - _logger->debug("initializingSubsystem.report"); - int type = Options::instance().getInt("arg.report", REPORT_FALSE); + _logger->debug("initializingSubsystem.report"); + _options = &Options::instance(); + int type = _options->getInt("arg.report", REPORT_FALSE); setScheduledReport(type); if (type != REPORT_FALSE) { ClassLoader<ReportBase> loader; - string lib = Options::instance().getPluginPath("report"); + string lib = _options->getPluginPath("report"); + _options->setString("path.plugin.report", lib); + _logger->debug("printPath.plugin.report"); try { loader.loadLibrary(lib); ReportBase* report = loader.create("NetResponsibility::Report"); @@ -62,14 +65,14 @@ _logger->notice("sendingReport"); int errorCode = report->send(); while (errorCode == 1) { - _logger->debug("Retrying to send report in 20 seconds"); + _logger->debug("report.retryIn20"); ::Poco::Thread::sleep(20000); errorCode = report->send(); } if (errorCode == 0) { _logger->notice("reportFinished"); report->logFinish(); - Options::instance().setInt("arg.report", REPORT_FALSE); + _options->setInt("arg.report", REPORT_FALSE); } else { _logger->warning("reportNotSent"); @@ -95,7 +98,7 @@ void ReportSubsystem::setScheduledReport(int &type) { - int frequency = Options::instance().get<int>("reportFrequency"); + int frequency = _options->get<int>("reportFrequency"); if (type != REPORT_INSTALL && type != REPORT_UNINSTALL && Database::instance().isReportTime(frequency)) { diff -r e83e1ce650cc1b148f9dd281e33973c6ff080936 -r 027bbfb4e7b98b42ff3df4960873280bb20070dd src/SnifferSubsystem.cpp --- a/src/SnifferSubsystem.cpp +++ b/src/SnifferSubsystem.cpp @@ -34,12 +34,14 @@ void SnifferSubsystem::initialize(Application& app) { _logger = &MyLogger::instance(); - if (Options::instance().getBool("arg.sniffer", true) && isOnlyInstance()) { + _options = &Options::instance(); + if (_options->getBool("arg.sniffer", true) && isOnlyInstance()) { _logger->notice("startingSniffer"); try { ClassLoader<Plugin> loader; - string path = Options::instance().getPluginPath("sniffer"); - _logger->debug("Sniffer plugin path: " + path); + string path = _options->getPluginPath("sniffer"); + _options->setString("path.plugin.sniffer", path); + _logger->debug("printPath.plugin.sniffer"); loader.loadLibrary(path); Plugin* sniffer = loader.create("NetResponsibility::Sniffer"); sniffer->run(); @@ -60,7 +62,7 @@ bool SnifferSubsystem::isOnlyInstance() { - string pidfile = Options::instance().get<string>("path.pid"); + string pidfile = _options->get<string>("path.pid"); int currentPid = ::Poco::Process::id(), oldPid = currentPid; if (File(pidfile).exists()) { @@ -70,7 +72,7 @@ } #if defined(POCO_OS_FAMILY_UNIX) if (oldPid != currentPid && kill(oldPid, 0) == 0) { - if (Options::instance().getBool("arg.force-sniffer", false)) { + if (_options->getBool("arg.force-sniffer", false)) { kill(oldPid, SIGINT); _logger->warning("onlyInstanceRunning"); // Give time to shut down the old instance. Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: Bitbucket <com...@bi...> - 2012-10-15 15:21:07
|
1 new commit in net-responsibility-documentation: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/changeset/3315fd0e25b5/ changeset: 3315fd0e25b5 user: roggan87 date: 2012-10-15 17:20:38 summary: Added an initial Translations page affected #: 1 file diff -r ec5fd8dd56a18d1bac811c70f70cc60971ba9ec0 -r 3315fd0e25b55a4e5c498202c560e11d7b58da3b pages/5035-Translations.page --- /dev/null +++ b/pages/5035-Translations.page @@ -0,0 +1,187 @@ +Translations +A50NR_DevIntro + +!!!The importance of good translations + +Translations are important for some people, while some are doing just fine +with the deafult language, English. Even if you're falling into the latter +group of people, a translation to your language may help others a lot. + +Compared to several other pieces of software, Net Responsibility has pretty +small translation files, which shouldn't take very long to translate. The +important thing to remember is that good translation files should stay updated +to avoid any discrepancy compared to the default language. For this reason we +need translators to commit themselves to update the files before each release +of the software. More details on this later on. + + +!!!Get started + +<*Note*> that versions prior to 3.1 do not have multilingual support. It's +perfectly possible to create translations without having 3.1 or later installed, +but not to try them out live. + +The translations, like the rest of the source code, is handled by the version +control system Mercurial. More information about how to work with the version +control system is found in +the guide [[5007-SourceCodeManagement.html Source Code Management]]. There it +is also described how to commit changes. The same technique applies to the +translations. + +Net Responsibility is designed to make use of different plugins, so each plugin +has got it's own locale (translation) file. The files to look for are found +in these paths, relative to the source code root directory: + + locale/en_EN.xml + plugins/*/locale/en_EN.xml +---- + +The asterisk may be replaced with any folder found in the plugins directory. + + +!!!Crash course in XML + +Let's first quickly go through the basics of XML. Assume we have a file looking +like this: + + <root> + <name>Robert</name> + + <messages> + <welcome>Hello ${name}! Nice to meet you.</welcome> + <goodbye>Goodbye ${name}</goodbye> + </messages> + + <!-- This is only a comment --> + </root> +---- + +Every element has got the structure <tag>Content</tag>, where tag can be +anything. Notice how it's opened by <tag> and closed with </tag>. The only +difference is the slash. So everything is wrapped up inside elements, and +each element may contain other elements. It's also important that all elements +are wrapped up inside a root element. + +Also note the occurence of ${name}. Let's call it a variable replacement. +It will be replaced by the content of the +name element. In this example it means that the welcome message will be: + + Hello Robert! Nice to meet you. +---- + +${name} may be replaced by any element, even nested ones. Reference to the +goodbye message looks like ${messages.goodbye}. You may understand it as +"the goodbye element inside the messages element". The root element is omitted +in variable replacements, otherwise all parents must be specified. This means +that the goodbye message <*may not*> be specified as ${goodbye} or +${root.messages.goodbye}. + +The variable replacements may refer to any element in any locale file, or even +the configuration file. You will find that the +variable replacements are pretty useful and common in the locale files. When +editing a message, keep the variable replacements intact, try to understand +what value that will be inserted, and create a meaningful message out of it. + +The last element to look at is the comment. Comments always begin with <{<}>!-- +and end with -->. Anything in between is neglected by Net Responsibility. +These messages are there to help you understand the structure, but you don't +need to translate them unless you want to. + +As a translator, you should never change the XML structure, but it's useful to +have a basic understanding of it. + + +!!!Create your first translation + +So open locale/en_EN.xml in your favorite text editor. It is recommended to use +one with syntax highlighting, since it will make it easier to determine the +structure. + +The first lines you'll notice looks like this, more or less: + + <?xml version="1.0" encoding="UTF-8"?> + <locale language="en_EN"> + + <translator> + <name>Robert Rosman</name> + <email>rob...@gm...</email> + <nrVersion>3.1</nrVersion> + </translator> +---- + +!!Locale codes + +Never mind the very first line. Use your text editor to set the document's +encoding to UTF-8, and you're all good. + +The next line is the root element. The only thing to edit is en_EN. Change it +to the locale code you're translating to. If you're uncertain what this code is, +you can start by running these commands in a terminal: + + echo $LANG + locale -a +---- + +The first command prints the locale used by your system, the other shows all +installed locales on your computer. On my system the first command prints +"sv_SE.UTF-8". Note that only sv_SE should be used here. +If none of the locales printed by the commands are correct, either google it or +ask us for advice. + +Note that the same code should be used when saving the file. The filename should +follow the pattern xx_ZZ.xml, where xx_ZZ is your locale code. + + +!!Personal information + +Next comes the <translator> tag. Here's some information about who you are. +This is very useful when we're about to make a new release and need to update +the translations. By then we need to be able to contact you. + +The <nrVersion> element specifies which version of Net Responsibility this +translation applies to. Again, this is useful to understand if the locale is +outdated. + +If you only add or edit a present translation, with an existing translator +tag, please copy it and add a new one. The result would be: + + <translator> + <name>Your name</name> + <email>you...@ex...</email> + <nrVersion>3.2</nrVersion> + </translator> + <translator> + <name>Robert Rosman</name> + <email>rob...@gm...</email> + <nrVersion>3.1</nrVersion> + </translator> +---- + + +!!Net Responsibility messages + +Now you're about to edit the real Net Responsibility messages. Your task is to +replace all the readable content between the opening and closing tags, with +translated messages. Please keep the variable replacements intact. + +At one point you will reach a comment looking like this: + + <!-- Do not edit the following entries, unless you really now what you're doing! --> +---- + +Follow the advice and stop editing any entries below. + + +!!!Double check your translation + +When you think you're done, please read through it once again to avoid typos +or bad grammar. + + +!!!Submit your piece of art + +The very last step would be to send your translation to us, so that we can +include it in the next release. This is done as described in the guide +[[5007-SourceCodeManagement.html Source Code Management]]. + +Good luck with the translations, and thanks for your efforts! Repository URL: https://bitbucket.org/netresponsibilityteam/net-responsibility-documentation/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |
From: <mpn...@us...> - 2012-07-14 01:15:37
|
Revision: 332 http://responsibility.svn.sourceforge.net/responsibility/?rev=332&view=rev Author: mpnordland Date: 2012-07-14 01:15:31 +0000 (Sat, 14 Jul 2012) Log Message: ----------- removing troublesome layout file for the linux code::blocks project. This shouldn't cause problems. Removed Paths: ------------- branches/multiuser/projectFiles/linux/net-responsibility.layout Deleted: branches/multiuser/projectFiles/linux/net-responsibility.layout =================================================================== --- branches/multiuser/projectFiles/linux/net-responsibility.layout 2012-07-12 02:06:38 UTC (rev 331) +++ branches/multiuser/projectFiles/linux/net-responsibility.layout 2012-07-14 01:15:31 UTC (rev 332) @@ -1,151 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -<CodeBlocks_layout_file> - <ActiveTarget name="all" /> - <File name="../../config.h" open="0" top="0" tabpos="11"> - <Cursor position="879" topLine="0" /> - </File> - <File name="../../include/Blacklist.h" open="1" top="0" tabpos="41"> - <Cursor position="3787" topLine="50" /> - </File> - <File name="../../include/Bypasses.h" open="1" top="0" tabpos="23"> - <Cursor position="2114" topLine="34" /> - </File> - <File name="../../include/ConfigSubsystem.h" open="1" top="0" tabpos="36"> - <Cursor position="0" topLine="15" /> - </File> - <File name="../../include/ConnectionCache.h" open="1" top="0" tabpos="33"> - <Cursor position="826" topLine="19" /> - </File> - <File name="../../include/ConnectionCacheUpdateThread.h" open="1" top="0" tabpos="35"> - <Cursor position="525" topLine="0" /> - </File> - <File name="../../include/Database.h" open="1" top="0" tabpos="28"> - <Cursor position="1310" topLine="11" /> - </File> - <File name="../../include/Filter.h" open="1" top="0" tabpos="19"> - <Cursor position="897" topLine="9" /> - </File> - <File name="../../include/HTTPHit.h" open="1" top="0" tabpos="31"> - <Cursor position="1351" topLine="14" /> - </File> - <File name="../../include/HTTPHitHandler.h" open="1" top="0" tabpos="40"> - <Cursor position="290" topLine="0" /> - </File> - <File name="../../include/History.h" open="1" top="0" tabpos="30"> - <Cursor position="0" topLine="60" /> - </File> - <File name="../../include/MainApplication.h" open="1" top="0" tabpos="21"> - <Cursor position="2876" topLine="74" /> - </File> - <File name="../../include/MyXml.h" open="1" top="0" tabpos="25"> - <Cursor position="1051" topLine="14" /> - </File> - <File name="../../include/Options.h" open="1" top="0" tabpos="22"> - <Cursor position="2965" topLine="93" /> - </File> - <File name="../../include/Plugin.h" open="1" top="0" tabpos="34"> - <Cursor position="792" topLine="87" /> - </File> - <File name="../../include/PluginBase.h" open="1" top="0" tabpos="33"> - <Cursor position="67" topLine="0" /> - </File> - <File name="../../include/Report.h" open="1" top="0" tabpos="22"> - <Cursor position="1885" topLine="49" /> - </File> - <File name="../../include/ReportBase.h" open="1" top="0" tabpos="22"> - <Cursor position="1817" topLine="28" /> - </File> - <File name="../../include/ReportSubsystem.h" open="1" top="0" tabpos="24"> - <Cursor position="1141" topLine="28" /> - </File> - <File name="../../include/Request.h" open="1" top="0" tabpos="20"> - <Cursor position="1635" topLine="35" /> - </File> - <File name="../../include/Sniffer.h" open="1" top="0" tabpos="11"> - <Cursor position="2395" topLine="60" /> - </File> - <File name="../../include/SnifferSubsystem.h" open="1" top="0" tabpos="37"> - <Cursor position="1364" topLine="17" /> - </File> - <File name="../../include/SnifferThread.h" open="1" top="0" tabpos="26"> - <Cursor position="2909" topLine="92" /> - </File> - <File name="../../include/UID.h" open="0" top="0" tabpos="33"> - <Cursor position="1147" topLine="11" /> - </File> - <File name="../../include/Warnings.h" open="1" top="0" tabpos="29"> - <Cursor position="428" topLine="7" /> - </File> - <File name="../../src/Bypasses.cpp" open="1" top="0" tabpos="15"> - <Cursor position="3150" topLine="151" /> - </File> - <File name="../../src/ConfigSubsystem.cpp" open="1" top="0" tabpos="10"> - <Cursor position="1586" topLine="29" /> - </File> - <File name="../../src/ConnectionCache.cpp" open="1" top="0" tabpos="34"> - <Cursor position="70" topLine="0" /> - </File> - <File name="../../src/ConnectionCacheUpdateThread.cpp" open="1" top="0" tabpos="38"> - <Cursor position="292" topLine="12" /> - </File> - <File name="../../src/Database.cpp" open="1" top="0" tabpos="2"> - <Cursor position="3383" topLine="81" /> - </File> - <File name="../../src/Filter.cpp" open="1" top="0" tabpos="6"> - <Cursor position="2629" topLine="5" /> - </File> - <File name="../../src/HTTPHit.cpp" open="1" top="0" tabpos="32"> - <Cursor position="539" topLine="0" /> - </File> - <File name="../../src/HTTPHitHandler.cpp" open="1" top="0" tabpos="39"> - <Cursor position="549" topLine="0" /> - </File> - <File name="../../src/History.cpp" open="1" top="0" tabpos="5"> - <Cursor position="723" topLine="113" /> - </File> - <File name="../../src/MainApplication.cpp" open="1" top="0" tabpos="13"> - <Cursor position="7843" topLine="256" /> - </File> - <File name="../../src/MyXml.cpp" open="1" top="0" tabpos="18"> - <Cursor position="3782" topLine="108" /> - </File> - <File name="../../src/Options.cpp" open="1" top="0" tabpos="8"> - <Cursor position="1994" topLine="85" /> - </File> - <File name="../../src/Plugin.cpp" open="1" top="0" tabpos="16"> - <Cursor position="792" topLine="6" /> - </File> - <File name="../../src/PluginBase.cpp" open="1" top="0" tabpos="22"> - <Cursor position="0" topLine="0" /> - </File> - <File name="../../src/Report.cpp" open="1" top="1" tabpos="3"> - <Cursor position="2301" topLine="186" /> - </File> - <File name="../../src/ReportBase.cpp" open="1" top="0" tabpos="17"> - <Cursor position="1689" topLine="172" /> - </File> - <File name="../../src/ReportSubsystem.cpp" open="1" top="0" tabpos="9"> - <Cursor position="1078" topLine="4" /> - </File> - <File name="../../src/Request.cpp" open="1" top="0" tabpos="4"> - <Cursor position="1830" topLine="0" /> - </File> - <File name="../../src/Sniffer.cpp" open="1" top="0" tabpos="12"> - <Cursor position="1591" topLine="6" /> - </File> - <File name="../../src/SnifferSubsystem.cpp" open="1" top="0" tabpos="14"> - <Cursor position="1886" topLine="0" /> - </File> - <File name="../../src/SnifferThread.cpp" open="1" top="0" tabpos="27"> - <Cursor position="2302" topLine="63" /> - </File> - <File name="../../src/UID.cpp" open="0" top="0" tabpos="34"> - <Cursor position="2770" topLine="50" /> - </File> - <File name="../../src/Warnings.cpp" open="1" top="0" tabpos="7"> - <Cursor position="627" topLine="0" /> - </File> - <File name="../../src/main.cpp" open="1" top="0" tabpos="1"> - <Cursor position="727" topLine="0" /> - </File> -</CodeBlocks_layout_file> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpn...@us...> - 2012-07-12 02:06:45
|
Revision: 331 http://responsibility.svn.sourceforge.net/responsibility/?rev=331&view=rev Author: mpnordland Date: 2012-07-12 02:06:38 +0000 (Thu, 12 Jul 2012) Log Message: ----------- Commiting some fixes that apparently didn't make it. Modified Paths: -------------- branches/multiuser/DEVELOPERS branches/multiuser/include/Database.h branches/multiuser/include/Filter.h branches/multiuser/include/Sniffer.h branches/multiuser/include/SnifferThread.h Modified: branches/multiuser/DEVELOPERS =================================================================== --- branches/multiuser/DEVELOPERS 2012-07-08 23:06:56 UTC (rev 330) +++ branches/multiuser/DEVELOPERS 2012-07-12 02:06:38 UTC (rev 331) @@ -89,7 +89,7 @@ EMAIL ADDRESSES: rob...@gm... - Robert, main developer and organizer. -mp...@gm... - Micah, Proxy, GUI, multi-users, and sundry other things +mp...@gm... - Micah, multi-users, and content reporting cor...@gm... - Corey, website developer. [Fill in more] Modified: branches/multiuser/include/Database.h =================================================================== --- branches/multiuser/include/Database.h 2012-07-08 23:06:56 UTC (rev 330) +++ branches/multiuser/include/Database.h 2012-07-12 02:06:38 UTC (rev 331) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Database +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -23,77 +28,176 @@ #include "Poco/Data/SQLite/Connector.h" #include "Poco/Data/SQLite/SQLiteException.h" #include "Poco/Exception.h" -#include "Poco/Timestamp.h" +#include "Poco/Timestamp.h" +#include "Poco/Tuple.h" #include "Poco/Logger.h" -#include "Poco/Util/ServerApplication.h" -#include "Poco/Net/HTTPRequest.h" -#include "Poco/Thread.h" +#include "Poco/Util/ServerApplication.h" +#include "HTTPHit.h" +#include "Poco/Thread.h" +#include "Poco/Process.h" #include "Blacklist.h" #include "Options.h" #include "History.h" #include "Warnings.h" #include "Bypasses.h" -#include "HTTPHit.h" +#include "BootHistory.h" -#include <iostream> -#include <vector> +#include <iostream> +#include <sstream> +#include <vector> +#include <set> + -using Poco::Timestamp; -using Poco::Exception; -using Poco::Data::SQLite::DBLockedException; -using Poco::Thread; -using Poco::Net::HTTPRequest; -using namespace Poco::Data; -using namespace std; + +namespace NetResponsibility { + +using ::Poco::Timestamp; +using ::Poco::Tuple; +using ::Poco::Exception; +using ::Poco::Data::SQLite::DBLockedException; +using ::Poco::Thread; +using ::Poco::Net::HTTPRequest; +using namespace ::Poco::Data; +using namespace ::std; + +class HTTPHitHandler; -class Database +class Database + /// Database handles all connections to the SQLite database. The Database + /// object is instanciated in by MainApplication, and may be accessed by the + /// static method &MainApplication::getDatabase(). + /// + /// The only class allowed to actually store any entries in the database is + /// Sniffer. Other classes may only load data from it. + /// + /// There is no method to write any custom SQLite query. Instead the queries + /// are a little more limited. Most methods that returns data from the + /// database also takes the arguments where and orderBy. With these you may + /// customize the return values. + /// + /// Queries that are done repeatedly are stored inside Statements. This will + /// enchance their speed. { public: Database(); - Database(Options&); - ~Database(); - bool isReportTime(int); - int getCount(string) const, - getLastRowId() const; - vector<string> getDistinctHostnames(string - = "hostname <> ''", string = "hostname ASC") const; - Bypasses getBypasses(string = "", string = "date, time ASC") const; - History getHistory(string = "hostname <> ''", string - = "hostname ASC") const; - Warnings getWarnings(string = "", string - = "u.hostname ASC", bool = false) const, - getWhitelist(string = "", string = "u.hostname ASC") const; - void logBypass(int, string = ""), - logInitBypasses(Bypasses&), - logReportStart(int&), - logReportFinish(int), - rotateLog(int); - friend class Sniffer; + Database(Options& options); + ~Database(); + bool isReportTime(int frequency); + /// Check if it's time to send a scheduled report, depending on + /// 'frequency'. + + int getCount(string from) const; + /// Return the number of rows found in the table 'from'. + + int getLastRowId() const; + + vector<string> getDistinctHostnames(string where + = "hostname <> ''", string orderBy = "hostname ASC") const; + /// Return all unique hostnames in a simple vector. By default + /// it will not return hostnames that are empty + /// entries (if found), and the hostnames will be ordered by name. + + Bypasses getBypasses(string where = "", string orderBy + = "date, time ASC") const; + /// Return all Bypasses found, in a Bypasses object. + + History getHistory(string where = "hostname <> ''", string orderBy + = "hostname ASC") const; + /// Return all History. + + Warnings getWarnings(string where = "", string orderBy + = "u.hostname ASC", bool = false) const; + /// Return all Warnings found. + + Warnings getWhitelist(string where = "", string orderBy = "u.hostname ASC") const; + /// Return all matches that are whitelisted for some reason. This + /// is wrapped up in a Warnings object, since it's actually + /// the same thing, but the matches are also considered clean. + + void logBypass(int type, string details = "", int datetime = 0); + /// Log attempts to bypass the software. You'll need to enter + /// the type (BYPASS_TYPE), and optionally more verbose details. + /// The int datetime is a unix timestamp of when the bypass happened. + /// If 0 the current timestamp will be used. + + void logInitBypasses(Bypasses& bypasses); + /// During startup the software makes several sanity checks, to make + /// sure it hasn't been bypassed. Even attempts that fails will be + /// reported. This may be discussed however, if they are redundant + /// and confusing for the accountability partners? + + void logReportStart(int& id); + /// Log that the reporting process have started. You'll need the id + /// later to properly "close" the report. + + void logReportFinish(int id); + /// Log that the report finished successfully. You'll need to enter the + /// id given by logReportStart(). + + void logSessionStart(); + /// Log that this current instance started. This info is used to process + /// if Net Responsibility has been bypassed by shutting it down or + /// omitting it at boot time. The boot time of this specific session is + /// also stored. + + void logSessionStop(); + /// Log that the current instance stopped. + + void rotateLog(int reportId); + /// This method rotated the database, to clean up everything that have + /// been included. Only entries older than the time for the report with + /// reportId will be deleted. The reportId was given by logReportStart(). + + //friend class HTTPHitHandler; + + protected: + void setStatements(); + + void logUrl(HTTPHit& hit); + /// Log a URL that's visited. This may only be done by the HTTPHitHandler class. + // This will later be replaced by HTTPHit. + + void logWarning(BlacklistMatch match); + /// Log a Warning that is flagged by the Filter. It is connected to + /// the last URL inserted. + + void logMatch(BlacklistMatch match); + + void logBypassShutdown(int datetime, int gap = 0); + + void getMatches(vector<int> urlId, vector<BlacklistMatch>& bm) const; + + void processPreviousSessions(); + /// Process the previous sessions, and log any attempts to bypass NR. + friend class HTTPHitHandler; + private: Session *_session; Timestamp _timestamp; - int _lastRowId, - _strength, - _date, - _time; - string _hostname, - _path, - _keyword, - _category; - Logger *_logger; - BlacklistMatch _blacklistMatch; + int _lastRowId; + int _sessionRowId; + int _strength; + int _date; + int _time; int _uid; - Statement *_getLastRowId, - *_logUrlStatement, - *_logWarningStatement, - *_logMatchStatement; - void setStatements(), - logMatch(BlacklistMatch), - logUrl(HTTPRequest&), - logWarning(BlacklistMatch, int), - getMatches(vector<int>, vector<BlacklistMatch>&) const; + string _hostname; + string _path; + string _keyword; + string _category; + Logger *_logger; + BootHistory *_bootHistory; + BlacklistMatch _blacklistMatch; + Statement *_getLastRowId; + Statement *_logUrlStatement; + Statement *_logWarningStatement; + Statement *_logMatchStatement; + + }; + + +} // namespace NetResponsibility #endif // DATABASE_H Modified: branches/multiuser/include/Filter.h =================================================================== --- branches/multiuser/include/Filter.h 2012-07-08 23:06:56 UTC (rev 330) +++ branches/multiuser/include/Filter.h 2012-07-12 02:06:38 UTC (rev 331) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Filter +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -19,8 +24,7 @@ #define FILTER_H #include "Blacklist.h" -#include "MyXml.h" -#include "HTTPHit.h" +#include "MyXml.h" #include <iostream> #include <fstream> @@ -29,45 +33,72 @@ #include "Poco/RegularExpression.h" #include "Poco/SharedPtr.h" #include "Poco/Exception.h" -#include "Poco/URI.h" -#include "Poco/Net/HTTPRequest.h" -#include "Poco/Util/Application.h" - -using Poco::RegularExpression; -using Poco::SharedPtr; -using Poco::Net::HTTPRequest; -using Poco::Util::Application; -using namespace std; +#include "Poco/URI.h" +#include "HTTPHit.h" +#include "Poco/Util/Application.h" +namespace NetResponsibility { + +using ::Poco::RegularExpression; +using ::Poco::SharedPtr; +using ::Poco::Net::HTTPRequest; +using ::Poco::Util::Application; +using namespace ::std; + class Options; class Database; -class Filter +class Filter + /// This class will run all test to find out if the URLs are appropriate or + /// not. It is done by initially loading the blacklists, and then testing + /// each URL against them. When keywords are found within the given text, + /// Filter thries to determine how strong the match is. This means every + /// match will be given an individual strength to indicate how likely it is + /// to be an inappropriate site. (The higher number, the more likely). + /// + /// The URLs are filtered instantly, rather than at report time, as done in + /// several previous versions. { public: Filter(); - Filter(string); - Filter(Options*, Database*); - bool isMatch(HTTPHit&, BlacklistMatch&), - isUrlMatch(HTTPHit&, BlacklistMatch&), - isTokenMatch(HTTPHit&, BlacklistMatch&); - void loadBlacklist(string); - void loadBlacklist(Options*, Database*); + Filter(string blacklistFile); + /// Load the Filter, given the path to the blacklist. This is + /// especially useful when improvign the algorithms. + + Filter(Options* options, Database* db); + /// Load the Filter, given both the options and database. + bool isMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch); + /// This is the method used for running a complete scan on the URL. + /// The URL is given as a HTTPRequest, and the result with a formatted + /// URL, strength etc. is returned in blacklistMatch. The return value + /// is true if the URL is considered suspicious, otherwise false. + + bool isUrlMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch); + + bool isTokenMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch); + + void loadBlacklist(string path); + + void loadBlacklist(Options* options, Database* db); + private: Blacklist _blacklist; Extensions _extensions; - SharedPtr<RegularExpression> _splitToken, - _splitExtension, - _wordDelimiter; + SharedPtr<RegularExpression> _splitToken; + SharedPtr<RegularExpression> _splitExtension; + SharedPtr<RegularExpression> _wordDelimiter; - string abbrUrl(string); + string abbrUrl(string boldUrl); void setRegexps(); - float getExtensionFactor(string); + float getExtensionFactor(string url); -}; +}; +} // namespace NetResponsibility + #include "Database.h" #include "Request.h" -#include "Options.h" +#include "Options.h" + #endif // FILTER_H Modified: branches/multiuser/include/Sniffer.h =================================================================== --- branches/multiuser/include/Sniffer.h 2012-07-08 23:06:56 UTC (rev 330) +++ branches/multiuser/include/Sniffer.h 2012-07-12 02:06:38 UTC (rev 331) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Sniffer +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -39,17 +44,13 @@ #include "Poco/ThreadPool.h" #include "Poco/Logger.h" #include "Poco/LogStream.h" -#include "Poco/Net/HTTPRequest.h" -#include "Database.h" -#include "Options.h" -#include "Filter.h" -#include "Blacklist.h" -#include "SnifferThread.h" -#include "HTTPHitHandler.h" + #include "ConnectionCache.h" -#include "ConnectionCacheUpdateThread.h" +#include "ConnectionCacheUpdateThread.h" + + #include <pcap.h> #if defined(POCO_OS_FAMILY_WINDOWS) @@ -59,35 +60,44 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> -#endif //POCO_OS_FAMILY_ +#endif //POCO_OS_FAMILY_ +class HTTPHitHandler; + +namespace NetResponsibility { + +using ::Poco::RegularExpression; +using ::Poco::SharedPtr; +using ::Poco::ThreadPool; +using ::Poco::Logger; +using ::Poco::LogStream; +using ::Poco::Net::HTTPRequest; +using namespace ::std; + +struct sniff_ethernet; +struct sniff_ip; +struct sniff_tcp; -using Poco::RegularExpression; -using Poco::SharedPtr; -using Poco::ThreadPool; -using Poco::Logger; -using Poco::LogStream; -using Poco::Net::HTTPRequest; -using namespace std; -struct sniff_ethernet; -struct sniff_ip; -struct sniff_tcp; -struct ip_info; - class MainApplication; -class SnifferThread; +class SnifferThread; -class Sniffer +class Sniffer + /// Sniffer sets up several SnifferThreads. One SnifferThread for each + /// interface, or only one for the "any" interface if it's found. + /// Much of this code is inspired by examples provided by TCPDump and Winpcap { public: - Sniffer(); - void run(); + Sniffer(); + /// Default constructor + void run(); + /// Run the sniffer + private: LogStream *_logStream; static Sniffer* _instance; char _errbuf[PCAP_ERRBUF_SIZE]; - HTTPHitHandler _hitHandler; + HTTPHitHandler *_hitHandler; ConnectionCache _cache; static HTTPHitHandler& getHTTPHitHandler(); @@ -95,7 +105,10 @@ vector<string> getDevices(); friend class SnifferThread; -}; +}; + +} // namespace NetResponsibility -#include "MainApplication.h" +#include "MainApplication.h" + #endif // SNIFFER_H Modified: branches/multiuser/include/SnifferThread.h =================================================================== --- branches/multiuser/include/SnifferThread.h 2012-07-08 23:06:56 UTC (rev 330) +++ branches/multiuser/include/SnifferThread.h 2012-07-12 02:06:38 UTC (rev 331) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: SnifferThread +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -43,16 +48,16 @@ #include "Poco/Runnable.h" #include "Poco/Logger.h" #include "Poco/LogStream.h" -#include "Poco/Net/HTTPRequest.h" #include "Poco/Exception.h" + +#include "HTTPHit.h" +//#include "HTTPHitHandler.h" +#include "Sniffer.h" + + -#include "Database.h" -#include "Options.h" -#include "Filter.h" -#include "Blacklist.h" -#include "Sniffer.h" -#include "HTTPHit.h" -#include "HTTPHitHandler.h" + + #include <pcap.h> #if defined(POCO_OS_FAMILY_WINDOWS) @@ -82,30 +87,43 @@ #define IP_HL(ip) (((ip)->ip_vhl) & 0x0f) #define IP_V(ip) (((ip)->ip_vhl) >> 4) -/* TCP header */ -typedef u_int tcp_seq; -using Poco::RegularExpression; -using Poco::SharedPtr; -using Poco::Logger; -using Poco::LogStream; -using Poco::Net::HTTPRequest; -using Poco::Exception; -using namespace std; + +namespace NetResponsibility { + +using ::Poco::RegularExpression; +using ::Poco::SharedPtr; +using ::Poco::Logger; +using ::Poco::LogStream; +using ::Poco::Exception; +using namespace ::std; + +/* TCP header */ +typedef u_int tcp_seq; struct sniff_ethernet; struct sniff_ip; struct sniff_tcp; struct ip_info; -class MainApplication; +class MainApplication; +class HTTPHitHandler; -class SnifferThread: public Poco::Runnable +class SnifferThread: public ::Poco::Runnable + /// SnifferThread is a thread that listens for HTTP requests on a specific + /// interface, and makes sure they're getting logged. It is invoked by Sniffer. + /// Much of this code is inspired by examples provided by TCPDump and Winpcap { public: - SnifferThread(); + SnifferThread(); + /// Constructs SnifferThread and sets up some default values + virtual void run(); - int openDevice(string); + /// Run the SnifferThread. + + int openDevice(string device); + /// Open the given device. + private: pcap_t *_fp; char _errbuf[PCAP_ERRBUF_SIZE]; @@ -162,8 +180,12 @@ u_short th_win; /* window */ u_short th_sum; /* checksum */ u_short th_urp; /* urgent pointer */ -}; +}; + + +} // namespace NetResponsibility -#include "MainApplication.h" +#include "MainApplication.h" + #endif // SNIFFERTHREAD_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rog...@us...> - 2012-07-08 23:07:03
|
Revision: 330 http://responsibility.svn.sourceforge.net/responsibility/?rev=330&view=rev Author: roggan87 Date: 2012-07-08 23:06:56 +0000 (Sun, 08 Jul 2012) Log Message: ----------- Major improvements in options handling. Options is now a descendant of Poco::Util::LayeredConfiguration, and inherits all it's methods (e.g. getString, setString). Now all the Application::instance().config() options are accessed through Options. Most of the old getName(), getUsername(), etc. are deleted. Options is now a singleton, so it may be accessed from anywhere, and is limited to have only one object instantiated. It's accessed with Options::instance(), rather than MainApplication::instance().getOptions(). Modified Paths: -------------- branches/splitPlugins/include/MainApplication.h branches/splitPlugins/include/MyXml.h branches/splitPlugins/include/Options.h branches/splitPlugins/plugins/DefaultReport/src/Report.cpp branches/splitPlugins/plugins/DefaultSniffer/src/Sniffer.cpp branches/splitPlugins/plugins/DefaultSniffer/src/SnifferThread.cpp branches/splitPlugins/src/Bypasses.cpp branches/splitPlugins/src/ConfigSubsystem.cpp branches/splitPlugins/src/Database.cpp branches/splitPlugins/src/Filter.cpp branches/splitPlugins/src/MainApplication.cpp branches/splitPlugins/src/MyXml.cpp branches/splitPlugins/src/Options.cpp branches/splitPlugins/src/ReportBase.cpp branches/splitPlugins/src/ReportSubsystem.cpp branches/splitPlugins/src/Request.cpp branches/splitPlugins/src/SnifferSubsystem.cpp Modified: branches/splitPlugins/include/MainApplication.h =================================================================== --- branches/splitPlugins/include/MainApplication.h 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/include/MainApplication.h 2012-07-08 23:06:56 UTC (rev 330) @@ -108,9 +108,6 @@ static MainApplication &instance(); /// A public static method to access this very instance from any class. - - static Options &getOptions(); - /// A public static method to access the Options object from any class. static Database &getDatabase(); /// A public static method to access the Database from any class. Modified: branches/splitPlugins/include/MyXml.h =================================================================== --- branches/splitPlugins/include/MyXml.h 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/include/MyXml.h 2012-07-08 23:06:56 UTC (rev 330) @@ -35,7 +35,8 @@ #include "Poco/RegularExpression.h" #include "Poco/AutoPtr.h" #include "Poco/Exception.h" -#include "Poco/Logger.h" +#include "Poco/Logger.h" +#include "Poco/DynamicAny.h" #include "Blacklist.h" @@ -46,6 +47,7 @@ using ::Poco::Util::Application; using ::Poco::RegularExpression; using ::Poco::Logger; +using ::Poco::DynamicAny; using namespace ::std; class MyXml : public ::Poco::Util::XMLConfiguration @@ -59,13 +61,13 @@ MyXml(string path); /// Load the XML file found at path. - template <class T> T get(const char* property, T value); + template <class T> T get(const char* property) const; /// Use this template to get single values from the XML file. - template <typename T> vector<T> getVector(const char* property); + template <typename T> vector<T> getVector(const char* property) const; /// Use this template to get vectors from the XML file. - template <typename T> map<string, T> getMap(const char* property); + template <typename T> map<string, T> getMap(const char* property) const; /// This template returns all subkeys to property inside /// a map<string, T>, where the first value is the name of /// the subkey and the second value is the value itself. Modified: branches/splitPlugins/include/Options.h =================================================================== --- branches/splitPlugins/include/Options.h 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/include/Options.h 2012-07-08 23:06:56 UTC (rev 330) @@ -35,9 +35,12 @@ #include "Poco/Exception.h" #include "Poco/Environment.h" -#include "Poco/Util/Application.h" +#include "Poco/Util/Application.h" +#include "Poco/Util/LayeredConfiguration.h" #include "Poco/Logger.h" -#include "Poco/SharedLibrary.h" +#include "Poco/SharedLibrary.h" +#include "Poco/DynamicAny.h" +#include "Poco/SingletonHolder.h" //#if HAVE_CONFIG_H #include "config.h" @@ -73,17 +76,48 @@ namespace NetResponsibility { using ::Poco::Logger; +using ::Poco::DynamicAny; +using ::Poco::SingletonHolder; using ::Poco::Util::Application; +using ::Poco::Util::LayeredConfiguration; using namespace ::std; class MainApplication; class Bypasses; -class Options - /// Poco::Util::ServerApplication is already handling configurations and - /// arguments, but it's way too flexible for us. This is where the Options - /// class comes in. It processes the config and txt files, and stores all - /// usable values in class members. +class Options : public ::Poco::Util::LayeredConfiguration + /// Options adds extra functionality to the already built in + /// Poco::Util::LayeredConfiguration. Here we store values given + /// by the preprocessor, as cli arguments and through the config.xml + /// file. There are also some more methods to get some other useful + /// information such as MAC address etc. + /// + /// Options is a singleton, which means only one instance may exist + /// inside the program. To reach this instance, simply type: + /// + /// Options *options = &Options::instance(); + /// + /// To get values from this object, you may use the inherited methods + /// such as getString() and getInt(). See the documentation for + /// Poco::Util::AbstractConfiguration for more information about + /// those. You may also use the provided get templates, like so: + /// + /// string name = options->get<string>("name"); + /// int reportFrequency = options->get<int>("reportFrequency"); + /// vector<string> reportParts = options.getVector<string>("reportParts"); + /// + /// You may even write settings to Options, but they will never + /// override those found in config.xml. To write, use the methods + /// named setString(), setInt(), etc. + /// + /// In terms of priority the config file options are always chosen + /// first, but if no config option with the given key name exists, + /// the custom settings, the preprocessor variables and the cli + /// arguments will be used. If no option with the given key exists + /// in any of these places, the given default value will be + /// returned, or a NotFoundException will be thrown depending on + /// what method you've used. + { public: Options(); @@ -91,10 +125,10 @@ Options(int argc, char* argv[]); /// Deprecated, use the default contructor Options() instead. - virtual ~Options(); + virtual ~Options(); + + bool doSaveHistory() const; - bool doSaveHistory() const; - bool doSendImprovementData() const; /// Returns true if we're supposed to send the improvement data to /// the server. @@ -110,41 +144,23 @@ bool isAccountEnabled() const; /// Returns false if accounts are disabled at compilation time. + + template <class T> T get(const char* property) const; + /// Use this template to get single configurations. Both the + /// cli arguments and the config file are processed. + + template <class T> vector<T> getVector(const char* property) const; + /// Use this template to get vectors from the configurations. + + template <class T> map<string, T> getMap(const char* property) const; + /// This template returns all subkeys to property inside + /// a map<string, T>, where the first value is the name of + /// the subkey and the second value is the value itself. - string getName() const; - /// Returns the name of the user. This name will be used as sender of - /// the reports. - - string getUsername() const; - /// Returns the username, used to communicate with the server. - - string getEmailFrom() const; - /// Returns the user's email address. This will be specified as reply-to - /// in the report header, so that accountability partners will reply - /// directly to the user instead of re...@ne.... - - string getConfigfile() const; - /// The path to the local config file. - - string getServer() const; - /// The server, usually www.netresponsibility.com - string getMacAddress() const; /// Returns the computer's MAC Address. This is used when communicating /// with the server. - string getVersion() const; - /// The current version of Net Responsibility. - - string getDatabasefile() const; - /// The path to the database. - - string getPidfile() const; - /// The path to the pidfile. - - string getBlacklistFile() const; - /// The path to the local blacklist file. - string getTxt(string) const; /// The path to the local txt file. @@ -152,54 +168,23 @@ /// Returns the path to the chosen plugin. The pluginType /// may be "report" or "sniffer". - string getReportDir() const; - /// Returns the path to locally stored reports. - - vector<string> getEmailTo() const; - /// Returns all emails to send reports to. - - vector<string> getReportParts() const; - /// Returns the report parts. - - vector<string> getAttachedReportParts() const; - /// Returns the attached report parts. - - int getReportFrequency() const; - /// Returns the number of days between scheduled reports. - - int getReportStrengthThreshold() const; - /// Returns the report strength threshold. - Bypasses &getInitBypasses() const; void setUsername(string); void loadConfigfile(); /// Load all options from the local configfile, or download a new one - /// if it's corrupt. + /// if it's corrupt. + + static Options& instance(); + /// Use this method to get the one and only instance of Options. - private: - string _databasefile; - string _pidfile; - string _configfile; - string _txtfile; - string _username; - string _name; - string _emailFrom; - string _blacklistFile; - string _version; - string _server; + private: string _pluginSniffer; string _pluginReport; - bool _saveHistory; bool _sendImprovementData; bool _compressAttachedReport; - vector<string> _reportParts; - vector<string> _attachedReportParts; - vector<string> _emailTo; - map<string, string> _txt; - int _reportFrequency; - int _reportStrengthThreshold; + map<string, string> _txt; Logger *_logger; Bypasses *_initBypasses; AutoPtr<MyXml> _xml; Modified: branches/splitPlugins/plugins/DefaultReport/src/Report.cpp =================================================================== --- branches/splitPlugins/plugins/DefaultReport/src/Report.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/plugins/DefaultReport/src/Report.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -88,7 +88,7 @@ key, anchorName; stringstream where; - where <<"strength >= " <<_options->getReportStrengthThreshold(); + where <<"strength >= " <<_options->get<int>("reportStrengthThreshold"); Warnings warnings = _db->getWarnings(where.str()); if (warnings.size() > 0) { map<string, vector<int> > tree; @@ -272,8 +272,8 @@ _attached << _options->getTxt("attachedReportHeader") <<endl <<"var subject = \"" <<_subject <<"\";" <<endl - <<"var version = \"" <<_options->getVersion() <<"\";" <<endl - <<"var arrNodes = [['Report', ['',,'folder'], [" <<endl + <<"var version = \"" <<_options->get<string>("program.version") <<"\";" + <<endl <<"var arrNodes = [['Report', ['',,'folder'], [" <<endl <<attachedContent <<endl @@ -286,7 +286,7 @@ try { string date = DateTimeFormatter::format(Timestamp(), "%Y%m%d"), iStr, - dir = _options->getReportDir(); + dir = _options->get<string>("path.reports"); int i = 0, tempInt; RegularExpression patt("^report_" + date + "_(\\d+)\\.(htm|zip)$", 0, true); Modified: branches/splitPlugins/plugins/DefaultSniffer/src/Sniffer.cpp =================================================================== --- branches/splitPlugins/plugins/DefaultSniffer/src/Sniffer.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/plugins/DefaultSniffer/src/Sniffer.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -32,7 +32,7 @@ _logStream = new LogStream(Application::instance().logger()); _logStream->warning(); _db = &MainApplication::getDatabase(); - _filter = new Filter(&MainApplication::getOptions(), _db); + _filter = new Filter(&Options::instance(), _db); } Modified: branches/splitPlugins/plugins/DefaultSniffer/src/SnifferThread.cpp =================================================================== --- branches/splitPlugins/plugins/DefaultSniffer/src/SnifferThread.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/plugins/DefaultSniffer/src/SnifferThread.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -27,7 +27,7 @@ SnifferThread::SnifferThread() { _logStream = &Sniffer::getLogStream(); - _options = &MainApplication::getOptions(); + _options = &Options::instance(); _filter = &Sniffer::getFilter(); _sniffPattern = (char*)"tcp[20:4] = 0x47455420 or tcp[32:4] = 0x47455420"; } @@ -89,7 +89,7 @@ HTTPRequest request; request.setChunkedTransferEncoding(true); bool isMatch, - isDebugging = Application::instance().config().getBool("debug", false); + isDebugging = _options->getBool("debug", false); while((res = pcap_next_ex( _fp, &header, &pkt_data)) >= 0) { try { Modified: branches/splitPlugins/src/Bypasses.cpp =================================================================== --- branches/splitPlugins/src/Bypasses.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/Bypasses.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -112,7 +112,7 @@ string Bypasses::getTypeString(int index) const { - Options *options = &MainApplication::getOptions(); + Options *options = &Options::instance(); switch(_bypassRows[index].type) { case BYPASS_SHUTDOWN: return options->getTxt("bypassShutdown"); Modified: branches/splitPlugins/src/ConfigSubsystem.cpp =================================================================== --- branches/splitPlugins/src/ConfigSubsystem.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/ConfigSubsystem.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -35,18 +35,18 @@ void ConfigSubsystem::initialize(Application& app) { - if (app.config().getBool("config", false)) { - Options* options = &MainApplication::getOptions(); + Options* options = &Options::instance(); + if (options->getBool("config", false)) { if (options->isAccountEnabled()) { - string username = app.config().getString("username", ""), - password = app.config().getString("password", ""); + string username = options->getString("username", ""), + password = options->getString("password", ""); if ((username == "" || password == "") && MainApplication::instance().isInteractive()) { getLogin(username, password); } else if (username == "") - username = options->getUsername(); + username = options->getString("username", ""); options->setUsername(username); Request::addMac(options, password); } @@ -66,7 +66,7 @@ _logger->information(msg); } options->loadConfigfile(); - app.config().setBool("config", false); + options->setBool("config", false); } } Modified: branches/splitPlugins/src/Database.cpp =================================================================== --- branches/splitPlugins/src/Database.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/Database.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -30,13 +30,13 @@ { _logger = &Application::instance().logger(); _logger->information("Connecting to database"); - _logger->debug("Database file: " + options.getDatabasefile()); + _logger->debug("Database file: " + options.get<string>("path.database")); const int FINISHED = 20; for (int i = 0; i <= FINISHED; i++) { try { SQLite::Connector::registerConnector(); - _session = new Session("SQLite", options.getDatabasefile()); + _session = new Session("SQLite", options.get<string>("path.database")); *_session <<"CREATE TABLE IF NOT EXISTS urls " <<"(hostname TEXT, path TEXT, date DATE, time TIME)", now; *_session <<"CREATE TABLE IF NOT EXISTS warnings " @@ -272,7 +272,7 @@ void Database::logReportStart(int &id) { - int type = ::Poco::Util::Application::instance().config().getInt("report", 0); + int type = Options::instance().getInt("report", 0); const int FINISHED = 30; for (int i = 0; i <= FINISHED; i++) { try { Modified: branches/splitPlugins/src/Filter.cpp =================================================================== --- branches/splitPlugins/src/Filter.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/Filter.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -60,12 +60,12 @@ try { if (options->isAccountEnabled()) { // Update the blacklist if it's modified - bool doUpdate = Application::instance().config().getBool("update-files", false); + bool doUpdate = options->getBool("update-files", false); Request::updateBlacklist(options, doUpdate); } // Load it - AutoPtr<MyXml> xmlBlacklist (new MyXml(options->getBlacklistFile())); + AutoPtr<MyXml> xmlBlacklist (new MyXml(options->get<string>("path.blacklist"))); _blacklist = xmlBlacklist->getBlacklist(); _extensions = xmlBlacklist->getExtensions(); moreTries = 0; Modified: branches/splitPlugins/src/MainApplication.cpp =================================================================== --- branches/splitPlugins/src/MainApplication.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/MainApplication.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -52,12 +52,6 @@ -Options& MainApplication::getOptions() { - return *_instance->_options; -} - - - Database& MainApplication::getDatabase() { return *_instance->_database; } @@ -69,7 +63,7 @@ setupLogger(); checkForRoot(); logger().notice("Starting Net Responsibility"); - _options = new Options(); + _options = &Options::instance(); _database = new Database(*_options); signalHandler(); ServerApplication::initialize(self); @@ -331,7 +325,7 @@ sigaction(SIGINT, &dfl, 0); #endif if (deletePidfile) - File(_instance->_options->getPidfile()).remove(); + File(_instance->_options->get<string>("path.pid")).remove(); _instance->uninitialize(); terminate(); } Modified: branches/splitPlugins/src/MyXml.cpp =================================================================== --- branches/splitPlugins/src/MyXml.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/MyXml.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -37,45 +37,46 @@ template <class T> -T MyXml::get(const char* property, T value) { - // Try to parse it or not? - return value; +T MyXml::get(const char* property) const { + DynamicAny any = this->getString(property); + return any.convert<T>(); } -template <> bool MyXml::get(const char* property, bool value) { - return this->getBool(property, value); +template <> bool MyXml::get(const char* property) const { + return this->getBool(property); } -template <> int MyXml::get(const char* property, int value) { - return this->getInt(property, value); +template <> int MyXml::get(const char* property) const { + return this->getInt(property); } -template <> double MyXml::get(const char* property, double value) { - return this->getDouble(property, value); +template <> double MyXml::get(const char* property) const { + return this->getDouble(property); } -template <> string MyXml::get(const char* property, string value) { - return this->getString(property, value); +template <> string MyXml::get(const char* property) const { + return this->getString(property); } template <typename T> -vector<T> MyXml::getVector(const char* property) { +vector<T> MyXml::getVector(const char* property) const { vector<T> vec; vector<string> subkeys; - vector<string>::iterator it; + vector<string>::iterator it; + string prefix = (property == "" ? "" : string(property) + string(".")); this->keys(property, subkeys); for (it = subkeys.begin(); it != subkeys.end(); ++it) { - string p = property + '.' + *it; - vec.push_back(this->get<T>(p.c_str(), T())); + string p = prefix + *it; + vec.push_back(this->get<T>(p.c_str())); } return vec; } @@ -83,14 +84,16 @@ template <typename T> -map<string, T> MyXml::getMap(const char* property) { +map<string, T> MyXml::getMap(const char* property) const { map<string, T> m; - vector<string> subkeys; + vector<string> subkeys; + string prefix = (property == "" ? "" : string(property) + string(".")); this->keys(property, subkeys); for (vector<string>::iterator it = subkeys.begin(); it != subkeys.end(); ++it) - { - m[*it] = this->get<T>(it->c_str(), T()); + { + string p = prefix + *it; + m[*it] = this->get<T>(p.c_str()); } return m; } @@ -213,16 +216,16 @@ } -// Instantiate some templates -template vector<bool> MyXml::getVector<bool>(const char*); -template vector<double> MyXml::getVector<double>(const char*); -template vector<int> MyXml::getVector<int>(const char*); -template vector<string> MyXml::getVector<string>(const char*); +// Explicitly instantiate some templates +template vector<bool> MyXml::getVector<bool>(const char*) const; +template vector<double> MyXml::getVector<double>(const char*) const; +template vector<int> MyXml::getVector<int>(const char*) const; +template vector<string> MyXml::getVector<string>(const char*) const; -template map<string, bool> MyXml::getMap<bool>(const char*); -template map<string, double> MyXml::getMap<double>(const char*); -template map<string, int> MyXml::getMap<int>(const char*); -template map<string, string> MyXml::getMap<string>(const char*); +template map<string, bool> MyXml::getMap<bool>(const char*) const; +template map<string, double> MyXml::getMap<double>(const char*) const; +template map<string, int> MyXml::getMap<int>(const char*) const; +template map<string, string> MyXml::getMap<string>(const char*) const; } // namespace NetResponsibility Modified: branches/splitPlugins/src/Options.cpp =================================================================== --- branches/splitPlugins/src/Options.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/Options.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -27,12 +27,13 @@ { _initBypasses = new Bypasses(); _logger = &Application::instance().logger(); - _logger->information("Loading options"); + _logger->information("Loading options"); + this->addWriteable(&Application::instance().config(), 1); loadDefaultValues(); - _logger->debug("Config file: " + _configfile); - if (!Application::instance().config().getBool("config", false)) + _logger->debug("Config file: " + this->getString("path.config")); + if (!this->getBool("config", false)) loadConfigfile(); - _logger->debug("Txt file: " + _txtfile); + _logger->debug("Txt file: " + this->getString("path.txt")); loadTxt(); } @@ -50,15 +51,16 @@ { //dtor } + + + +bool Options::doSaveHistory() const { + return isAttachedReportPart("history_hostnames") + || isAttachedReportPart("history_paths"); +} + - -bool Options::doSaveHistory() const { - return _saveHistory; -} - - - bool Options::doSendImprovementData() const { return _sendImprovementData; } @@ -71,18 +73,20 @@ -bool Options::isReportPart(string part) const { +bool Options::isReportPart(string part) const { + vector<string> parts = this->getVector<string>("reportParts"); vector<string>::const_iterator it; - it = find (_reportParts.begin(), _reportParts.end(), part); - return it != _reportParts.end(); + it = find (parts.begin(), parts.end(), part); + return it != parts.end(); } -bool Options::isAttachedReportPart(string part) const { +bool Options::isAttachedReportPart(string part) const { + vector<string> parts = this->getVector<string>("attachedReportParts"); vector<string>::const_iterator it; - it = find (_attachedReportParts.begin(), _attachedReportParts.end(), part); - return it != _attachedReportParts.end(); + it = find (parts.begin(), parts.end(), part); + return it != parts.end(); } @@ -90,72 +94,83 @@ bool Options::isAccountEnabled() const { return !(bool)DISABLE_ACCOUNT; } + + + +template <class T> +T Options::get(const char* property) const { + DynamicAny any = this->getString(property); + return any.convert<T>(); +} + + + +template <> bool Options::get(const char* property) const { + return this->getBool(property); +} + + + +template <> int Options::get(const char* property) const { + return this->getInt(property); +} + + + +template <> double Options::get(const char* property) const { + return this->getDouble(property); +} + + + +template <> string Options::get(const char* property) const { + return this->getString(property); +} + + + +template <class T> +vector<T> Options::getVector(const char* property) const { + vector<T> vec; + vector<string> subkeys; + vector<string>::iterator it; + string prefix = (property == "" ? "" : string(property) + string(".")); + this->keys(property, subkeys); + for (it = subkeys.begin(); it != subkeys.end(); ++it) { + string p = prefix + *it; + vec.push_back(this->get<T>(p.c_str())); + } + return vec; +} + + +template <class T> +map<string, T> Options::getMap(const char* property) const { + map<string, T> m; + vector<string> subkeys; + string prefix = (property == "" ? "" : string(property) + string(".")); + this->keys(property, subkeys); + for (vector<string>::iterator it = subkeys.begin(); + it != subkeys.end(); ++it) + { + string p = prefix + *it; + m[*it] = this->get<T>(p.c_str()); + } + return m; +} + -string Options::getName() const { - return _name; -} - - - -string Options::getUsername() const { - return _username; -} - - - -string Options::getEmailFrom() const { - return _emailFrom; -} - - - -string Options::getConfigfile() const { - return _configfile; -} - - - -string Options::getServer() const { - return _server; -} - - - string Options::getMacAddress() const { // Compute the MAC address every time, since it will be 00:00:00:00:00:00 // if no internet connection is found. Then we have to reload it when the // internet connection is established. return ::Poco::Environment::nodeId(); } + - -string Options::getVersion() const { - return _version; -} - - - -string Options::getDatabasefile() const { - return _databasefile; -} - - - -string Options::getPidfile() const { - return _pidfile; -} - - - -string Options::getBlacklistFile() const { - return _blacklistFile; -} - - - string Options::getTxt(string key) const { if (_txt.find(key) != _txt.end()) return _txt.find(key)->second; @@ -167,50 +182,18 @@ string Options::getPluginPath(string pluginType) const { string path(PLUGIN_DIR); - // Get the plugin name from the config file. Temporarily fixed hardcoded like this: - path += (pluginType == "report" ? _pluginReport : _pluginSniffer); + if (pluginType == "report") + path += this->getString + ("plugin[@type='report'][@selected='true'][@name]", "DefaultReport"); + else + path += this->getString + ("plugin[@type='sniffer'][@selected='true'][@name]", "DefaultSniffer"); path += ::Poco::SharedLibrary::suffix(); return path; } - - - -string Options::getReportDir() const { - return REPORT_DIR; -} - - - -vector<string> Options::getEmailTo() const { - return _emailTo; -} - - - -vector<string> Options::getReportParts() const { - return _reportParts; -} - - - -vector<string> Options::getAttachedReportParts() const { - return _attachedReportParts; -} -int Options::getReportFrequency() const { - return _reportFrequency; -} - - - -int Options::getReportStrengthThreshold() const { - return _reportStrengthThreshold; -} - - - Bypasses &Options::getInitBypasses() const { return *_initBypasses; } @@ -218,53 +201,39 @@ void Options::setUsername(string username) { - _username = username; + this->setString("username", username); } -void Options::loadDefaultValues() { - _configfile = CONFIGFILE; - _databasefile = DATABASEFILE; - _pidfile = PIDFILE; - _blacklistFile = BLACKLISTFILE; - _server = SERVER; - _txtfile = TXTFILE; - _version = VERSION; - _saveHistory = true; - _username = ""; - _logger->debug("Version " + _version); +void Options::loadDefaultValues() { + this->setString("path.config", CONFIGFILE); + this->setString("path.database", DATABASEFILE); + this->setString("path.pid", PIDFILE); + this->setString("path.blacklist", BLACKLISTFILE); + this->setString("path.txt", TXTFILE); + this->setString("path.reports", REPORT_DIR); + this->setString("server.hostname", SERVER); + this->setString("program.version", VERSION); + this->setInt("reportFrequency", 7); + this->setInt("reportStrengthThreshold", 0); + this->setBool("improveData", false); + this->setBool("compressAttachedReport", false); + _logger->debug("Version " VERSION); } void Options::loadConfigfile() { - bool doUpdate = Application::instance().config().getBool("update-files", false); + bool doUpdate = this->getBool("update-files", false); for (int moreTries = 3; moreTries > 0; moreTries--) { try { - AutoPtr<MyXml> xmlConfig (new MyXml(_configfile)); - _username = xmlConfig->get<string>("username", ""); - _emailFrom = xmlConfig->get<string>("emailFrom", ""); - _name = xmlConfig->get<string>("name", ""); - _pluginSniffer = xmlConfig->get<string>("plugin[@type='sniffer'][@selected='true'][@name]", "DefaultSniffer"); - _pluginReport = xmlConfig->get<string>("plugin[@type='report'][@selected='true'][@name]", "DefaultReport"); + _xml = new MyXml(this->getString("path.config")); - _logger->debug("Selected sniffer: " + _pluginSniffer); - _logger->debug("Selected report: " + _pluginReport); - - _sendImprovementData = xmlConfig->get<bool>("improveData", false); - _compressAttachedReport = xmlConfig->get<bool>("compressAttachedReport", false); - - _emailTo = xmlConfig->getVector<string>("emailTo"); - _reportParts = xmlConfig->getVector<string>("reportParts"); - _attachedReportParts = xmlConfig->getVector<string>("attachedReportParts"); + // Add the configurations from our XML file to the LayeredConfiguration. + // This is top priority. + this->add(_xml, 0); - _reportFrequency = xmlConfig->get<int>("reportFrequency", 7); - _reportStrengthThreshold = xmlConfig->get<int>("reportStrengthThreshold", 0); - - _saveHistory = isAttachedReportPart("history_hostnames") - || isAttachedReportPart("history_paths"); - // If the account is enabled, update and retry if needed. if (!this->isAccountEnabled() || !Request::updateConfig(this, doUpdate)) moreTries = 0; @@ -272,7 +241,7 @@ doUpdate = false; } catch (::Poco::FileNotFoundException &err) { - Application::instance().config().setBool("config", true); + this->setBool("config", true); _initBypasses->addRow(BYPASS_MISSING_FILE, "Config file"); moreTries = 0; } @@ -282,12 +251,12 @@ if (moreTries == 3) _initBypasses->addRow(BYPASS_MODIFIED_FILE, "Config file"); else if (moreTries == 1) - Application::instance().config().setBool("config", true); + this->setBool("config", true); if (this->isAccountEnabled()) Request::downloadConfig(this); else { - Application::instance().config().setBool("config", true); + this->setBool("config", true); moreTries = 0; } } @@ -298,7 +267,7 @@ void Options::loadTxt() { try { - AutoPtr<MyXml> xmlTxt (new MyXml(_txtfile)); + AutoPtr<MyXml> xmlTxt (new MyXml(this->get<string>("path.txt"))); _txt = xmlTxt->getMap<string>(""); } catch (::Poco::Exception &err) { @@ -306,7 +275,27 @@ _initBypasses->addRow(BYPASS_MODIFIED_FILE, "Txt file"); } } - + +Options& Options::instance() { + static SingletonHolder<Options> sh; + return *sh.get(); +} + + + +// Explicitly instantiate some templates +template vector<bool> Options::getVector<bool>(const char*) const; +template vector<double> Options::getVector<double>(const char*) const; +template vector<int> Options::getVector<int>(const char*) const; +template vector<string> Options::getVector<string>(const char*) const; + +template map<string, bool> Options::getMap<bool>(const char*) const; +template map<string, double> Options::getMap<double>(const char*) const; +template map<string, int> Options::getMap<int>(const char*) const; +template map<string, string> Options::getMap<string>(const char*) const; + + + } // namespace NetResponsibility Modified: branches/splitPlugins/src/ReportBase.cpp =================================================================== --- branches/splitPlugins/src/ReportBase.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/ReportBase.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -28,9 +28,9 @@ { _logger = &Application::instance().logger(); _db = &MainApplication::getDatabase(); - _options = &MainApplication::getOptions(); + _options = &Options::instance(); _contentType = "text/plain"; - _subject = _options->getName() + "'s Net Responsibility Report"; + _subject = _options->get<string>("name") + "'s Net Responsibility Report"; _db->logReportStart(_reportId); } @@ -75,7 +75,7 @@ void ReportBase::logFinish() { - if (Application::instance().config().getBool("rotate", true)) + if (_options->getBool("rotate", true)) _db->rotateLog(_reportId); _db->logReportFinish(_reportId); } @@ -84,9 +84,10 @@ void ReportBase::install() { string txt = _options->getTxt("reportInstall"); - replaceVar(txt, "name", _options->getName()); + string name = _options->get<string>("name"); + replaceVar(txt, "name", name); _body << txt; - _subject = _options->getName() + " has installed Net Responsibility"; + _subject = name + " has installed Net Responsibility"; _contentType = "text/html"; } @@ -94,9 +95,10 @@ void ReportBase::uninstall() { string txt = _options->getTxt("reportUninstall"); - replaceVar(txt, "name", _options->getName()); + string name = _options->get<string>("name"); + replaceVar(txt, "name", name); _body << txt; - _subject = _options->getName() + " has uninstalled Net Responsibility"; + _subject = name + " has uninstalled Net Responsibility"; _contentType = "text/html"; } @@ -105,11 +107,11 @@ int ReportBase::send(bool receiveCopy) { try { MailMessage message; - message.setSender(_options->getName() + " <re...@ne...>"); - message.set("Reply-To", _options->getEmailFrom()); - vector<string> recipients = _options->getEmailTo(); + message.setSender(_options->get<string>("name") + " <re...@ne...>"); + message.set("Reply-To", _options->get<string>("emailFrom")); + vector<string> recipients = _options->getVector<string>("emailTo"); if (receiveCopy) - recipients.push_back(_options->getEmailFrom()); + recipients.push_back(_options->get<string>("emailFrom")); for (vector<string>::iterator it = recipients.begin(); it != recipients.end(); it++) { @@ -174,9 +176,10 @@ void ReportBase::test() { string txt = _options->getTxt("reportTest"); - replaceVar(txt, "name", _options->getName()); + string name = _options->get<string>("name"); + replaceVar(txt, "name", name); _body << txt; - _subject = _options->getName() + "'s Test Report"; + _subject = name + "'s Test Report"; _contentType = "text/html"; send(true); } Modified: branches/splitPlugins/src/ReportSubsystem.cpp =================================================================== --- branches/splitPlugins/src/ReportSubsystem.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/ReportSubsystem.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -38,11 +38,11 @@ void ReportSubsystem::initialize(Application& app) { _logger = &Application::instance().logger(); _logger->debug("Initializing subsystem: Report Subsystem"); - int type = app.config().getInt("report", REPORT_FALSE); + int type = Options::instance().getInt("report", REPORT_FALSE); setScheduledReport(type); if (type != REPORT_FALSE) { ClassLoader<ReportBase> loader; - string lib = MainApplication::getOptions().getPluginPath("report"); + string lib = Options::instance().getPluginPath("report"); try { loader.loadLibrary(lib); ReportBase* report = loader.create("NetResponsibility::Report"); @@ -69,7 +69,7 @@ if (errorCode == 0) { _logger->notice("Report finished"); report->logFinish(); - app.config().setInt("report", REPORT_FALSE); + Options::instance().setInt("report", REPORT_FALSE); } else { _logger->warning("Report could not be sent"); @@ -95,7 +95,7 @@ void ReportSubsystem::setScheduledReport(int &type) { - int frequency = MainApplication::getOptions().getReportFrequency(); + int frequency = Options::instance().get<int>("reportFrequency"); if (type != REPORT_INSTALL && type != REPORT_UNINSTALL && MainApplication::getDatabase().isReportTime(frequency)) { Modified: branches/splitPlugins/src/Request.cpp =================================================================== --- branches/splitPlugins/src/Request.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/Request.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -29,9 +29,9 @@ void Request::addMac(Options *options, string password) { Application::instance().logger().information("Downloading configuration file"); if (password == "") - send(options, "/request/add_mac.php", options->getConfigfile()); + send(options, "/request/add_mac.php", options->get<string>("path.config")); else - send(options, "/request/add_mac.php", options->getConfigfile(), + send(options, "/request/add_mac.php", options->get<string>("path.config"), "online_password=" + password); setDownloadedTime(options); } @@ -41,9 +41,9 @@ void Request::downloadConfig(Options *options, string password) { Application::instance().logger().information("Downloading configuration file"); if (password == "") - send(options, "/request/config.php", options->getConfigfile()); + send(options, "/request/config.php", options->get<string>("path.config")); else - send(options, "/request/config.php", options->getConfigfile(), + send(options, "/request/config.php", options->get<string>("path.config"), "online_password=" + password); setDownloadedTime(options); } @@ -52,7 +52,7 @@ void Request::downloadBlacklist(Options *options) { Application::instance().logger().information("Downloading blacklists"); - send(options, "/request/blacklist.php", options->getBlacklistFile()); + send(options, "/request/blacklist.php", options->get<string>("path.blacklist")); setDownloadedTime(options); } @@ -71,7 +71,7 @@ setDownloadedTime(options); // Determine what time the config file was edited last - Timestamp ft = File(options->getConfigfile()).getLastModified(); + Timestamp ft = File(options->get<string>("path.config")).getLastModified(); if (ft.epochTime() > (configDownloaded + 15)) { downloadConfig(options); options->getInitBypasses().addRow(BYPASS_MODIFIED_FILE, "Config file"); @@ -98,7 +98,7 @@ setDownloadedTime(options); // Determine what time the blacklist file was edited last - Timestamp ft = File(options->getBlacklistFile()).getLastModified(); + Timestamp ft = File(options->get<string>("path.blacklist")).getLastModified(); if (ft.epochTime() > (blacklistDownloaded + 15)) { downloadBlacklist(options); // This won't get caught as a bypass, but maybe it doesn't have to @@ -126,7 +126,7 @@ { while (true) { try { - string uriString = "http://" + options->getServer() + uriPath; + string uriString = "http://" + options->get<string>("server.hostname") + uriPath; URI uri(uriString); string path(uri.getPathAndQuery()); if (path.empty()) @@ -136,9 +136,9 @@ HTTPRequest req(HTTPRequest::HTTP_POST, path); req.setContentType("application/x-www-form-urlencoded"); string reqBody = ""; - reqBody += "online_user=" + options->getUsername() + reqBody += "online_user=" + options->getString("username", "") + "&mac=" + options->getMacAddress() - + "&version=" + options->getVersion(); + + "&version=" + options->getString("program.version"); if (morePostVars != "") reqBody += "&" + morePostVars; req.setContentLength(reqBody.length()); Modified: branches/splitPlugins/src/SnifferSubsystem.cpp =================================================================== --- branches/splitPlugins/src/SnifferSubsystem.cpp 2012-07-07 16:36:20 UTC (rev 329) +++ branches/splitPlugins/src/SnifferSubsystem.cpp 2012-07-08 23:06:56 UTC (rev 330) @@ -34,11 +34,11 @@ void SnifferSubsystem::initialize(Application& app) { _logger = &app.logger(); - if (app.config().getBool("sniffer", true) && isOnlyInstance()) { + if (Options::instance().getBool("sniffer", true) && isOnlyInstance()) { _logger->information("Starting sniffer"); try { ClassLoader<Plugin> loader; - string path = MainApplication::getOptions().getPluginPath("sniffer"); + string path = Options::instance().getPluginPath("sniffer"); _logger->debug("Sniffer plugin path: " + path); loader.loadLibrary(path); Plugin* sniffer = loader.create("NetResponsibility::Sniffer"); @@ -60,7 +60,7 @@ bool SnifferSubsystem::isOnlyInstance() { - string pidfile = MainApplication::getOptions().getPidfile(); + string pidfile = Options::instance().get<string>("path.pid"); int currentPid = ::Poco::Process::id(), oldPid = currentPid; if (File(pidfile).exists()) { @@ -70,7 +70,7 @@ } #if defined(POCO_OS_FAMILY_UNIX) if (oldPid != currentPid && kill(oldPid, 0) == 0) { - if (Application::instance().config().getBool("force-sniffer", false)) { + if (Options::instance().getBool("force-sniffer", false)) { kill(oldPid, SIGINT); _logger->warning("NOTE: This instance is the only one running. When " "you end this, no sniffer will be running."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpn...@us...> - 2012-07-07 16:36:29
|
Revision: 329 http://responsibility.svn.sourceforge.net/responsibility/?rev=329&view=rev Author: mpnordland Date: 2012-07-07 16:36:20 +0000 (Sat, 07 Jul 2012) Log Message: ----------- Execpt for a missing Plugin.h, everything now compiles. Most of the new classes have been added to the NetResponsibility namespace. Modified Paths: -------------- branches/multiuser/Makefile.am branches/multiuser/configure.ac branches/multiuser/include/Blacklist.h branches/multiuser/include/Bypasses.h branches/multiuser/include/ConfigSubsystem.h branches/multiuser/include/ConnectionCache.h branches/multiuser/include/ConnectionCacheUpdateThread.h branches/multiuser/include/HTTPHit.h branches/multiuser/include/HTTPHitHandler.h branches/multiuser/include/History.h branches/multiuser/include/MainApplication.h branches/multiuser/include/MyXml.h branches/multiuser/include/Options.h branches/multiuser/include/Report.h branches/multiuser/include/ReportBase.h branches/multiuser/include/ReportSubsystem.h branches/multiuser/include/Request.h branches/multiuser/include/SnifferSubsystem.h branches/multiuser/include/Warnings.h branches/multiuser/projectFiles/linux/net-responsibility.cbp branches/multiuser/projectFiles/linux/net-responsibility.depend branches/multiuser/projectFiles/windows/net-responsibility.cbp branches/multiuser/projectFiles/windows/net-responsibility.layout branches/multiuser/src/Bypasses.cpp branches/multiuser/src/ConfigSubsystem.cpp branches/multiuser/src/ConnectionCache.cpp branches/multiuser/src/ConnectionCacheUpdateThread.cpp branches/multiuser/src/Database.cpp branches/multiuser/src/Filter.cpp branches/multiuser/src/HTTPHit.cpp branches/multiuser/src/HTTPHitHandler.cpp branches/multiuser/src/History.cpp branches/multiuser/src/MainApplication.cpp branches/multiuser/src/MyXml.cpp branches/multiuser/src/Options.cpp branches/multiuser/src/Plugin.cpp branches/multiuser/src/Report.cpp branches/multiuser/src/ReportBase.cpp branches/multiuser/src/ReportSubsystem.cpp branches/multiuser/src/Request.cpp branches/multiuser/src/Sniffer.cpp branches/multiuser/src/SnifferSubsystem.cpp branches/multiuser/src/Warnings.cpp branches/multiuser/src/main.cpp Added Paths: ----------- branches/multiuser/include/BootHistory.h branches/multiuser/src/BootHistory.cpp Property Changed: ---------------- branches/multiuser/ Property changes on: branches/multiuser ___________________________________________________________________ Added: svn:mergeinfo + /trunk:230-323 Modified: branches/multiuser/Makefile.am =================================================================== --- branches/multiuser/Makefile.am 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/Makefile.am 2012-07-07 16:36:20 UTC (rev 329) @@ -20,7 +20,7 @@ @top_srcdir@/src/SnifferSubsystem.cpp\ @top_srcdir@/src/SnifferThread.cpp\ @top_srcdir@/src/Warnings.cpp -libNetResponsibility_la_CPPFLAGS = $(cppFlags) +libNetResponsibility_la_CPPFLAGS = $(cppFlags) -std=c++0x libNetResponsibility_la_LDFLAGS = -no-undefined $(ldFlags) # Minimal executable Modified: branches/multiuser/configure.ac =================================================================== --- branches/multiuser/configure.ac 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/configure.ac 2012-07-07 16:36:20 UTC (rev 329) @@ -3,7 +3,7 @@ AC_PREREQ(2.58) LT_PREREQ([2.2]) -AC_INIT([Net Responsibility],[3.0b3],[co...@ne...]) +AC_INIT([Net Responsibility],[3.0.1],[co...@ne...]) AM_INIT_AUTOMAKE([subdir-objects]) LT_INIT([shared]) AC_SUBST([LIBTOOL_DEPS]) Modified: branches/multiuser/include/Blacklist.h =================================================================== --- branches/multiuser/include/Blacklist.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/Blacklist.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Blacklist +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -28,63 +33,107 @@ #include "Poco/Data/Common.h" #include "Poco/Data/Connector.h" #include "Poco/Data/SQLite/Connector.h" + +namespace NetResponsibility { + +using ::Poco::Timestamp; +using ::Poco::SharedPtr; +using ::Poco::RegularExpression; +using namespace ::Poco::Data; +using namespace ::std; -using Poco::Timestamp; -using namespace Poco::Data; -using Poco::SharedPtr; -using Poco::RegularExpression; -using namespace std; - -struct BlacklistKeyword +struct BlacklistKeyword + /// This is a small struct to hold each keyword, as a string, compiled as + /// separate regular expressions and the adherent strength. { - int strength; - string asString, - category; - vector< SharedPtr<RegularExpression> > re; + int strength; + /// The strength of this keyword. 100 is default. + + string asString; + /// The keyword displayed as a string. + + string category; + + vector< SharedPtr<RegularExpression> > re; + /// The keyword splitted and compiled as a regular expression. }; -struct BlacklistCategory +struct BlacklistCategory + /// This struct holds each specific category. { - string name; - vector<BlacklistKeyword> keyword; + string name; + /// The name of the category. + + vector<BlacklistKeyword> keyword; // Change to keywords since its more than one + /// All the keywords. }; -struct BlacklistMatch +struct BlacklistMatch + /// If the filter catches a match, in other words a suspicious URL, it's + /// stored inside a BlacklistMatch. Here we have all the important + /// information related to the match. { - string boldUrl, - abbrUrl; - int strength; - bool whitelist; - vector<BlacklistKeyword> keyword; + string boldUrl; + /// The URL with every suspicious word in bold. + + string abbrUrl; + /// The same as boldUrl, but abbreviated to be easier to read and save + /// some space. + + int strength; + /// The total strength of the match. This is displayed in the reports + /// if this strength is lower than reportStrengthThreshold. + + bool whitelist; + /// This bool is set to true if it is a whitelist match. In that case it + /// will show up in the whitelist section of the report. + + vector<BlacklistKeyword> keyword; // Change to keywords, more than one. + /// The keywords that are found in the URL. }; -typedef vector<BlacklistCategory> Blacklist; +typedef vector<BlacklistCategory> Blacklist; + /// Blacklist is the top-level container for all the blacklists. + // Change this typedef to: + // typedef map<string, vector<BlacklistKeyword> > Blacklist; + // This way we can skip BlacklistCategory. struct Extension { + /// The strength of the BlacklistMatch will also take the type of the URL in + /// consideration. If it's an image or video it will be much stronger than + /// if it is a script. This class holds different extensions and their + /// associated types. public: int strength; + /// The strength of this specific extension. + string group; + /// What kind of type it is. Image/Video etc. + SharedPtr<RegularExpression> re; + /// The regular expression to compare to the extension of the URL. }; typedef vector<Extension> Extensions; +} // namespace NetResponsibility + namespace Poco { -namespace Data { +namespace Data { template <> -class TypeHandler<class BlacklistMatch> +class TypeHandler<class ::NetResponsibility::BlacklistMatch> { public: static size_t size() @@ -92,34 +141,34 @@ return 4; // we handle four columns of the Table! } - static void bind(size_t pos, const BlacklistMatch& obj, + static void bind(size_t pos, const ::NetResponsibility::BlacklistMatch& obj, AbstractBinder* pBinder) { poco_assert_dbg (pBinder != 0); - TypeHandler<string>::bind(pos++, obj.boldUrl, pBinder); - TypeHandler<string>::bind(pos++, obj.abbrUrl, pBinder); + TypeHandler<std::string>::bind(pos++, obj.boldUrl, pBinder); + TypeHandler<std::string>::bind(pos++, obj.abbrUrl, pBinder); TypeHandler<int>::bind(pos++, obj.strength, pBinder); TypeHandler<int>::bind(pos++, (int)obj.whitelist, pBinder); } - static void prepare(size_t pos, const BlacklistMatch& obj, + static void prepare(size_t pos, const ::NetResponsibility::BlacklistMatch& obj, AbstractPreparation* pPrepare) { poco_assert_dbg (pBinder != 0); - TypeHandler<string>::prepare(pos++, obj.boldUrl, pPrepare); - TypeHandler<string>::prepare(pos++, obj.abbrUrl, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.boldUrl, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.abbrUrl, pPrepare); TypeHandler<int>::prepare(pos++, obj.strength, pPrepare); TypeHandler<int>::prepare(pos++, (int)obj.whitelist, pPrepare); } - static void extract(size_t pos, BlacklistMatch& obj, - const BlacklistMatch& defVal, AbstractExtractor* pExt) + static void extract(size_t pos, ::NetResponsibility::BlacklistMatch& obj, + const ::NetResponsibility::BlacklistMatch& defVal, AbstractExtractor* pExt) /// obj will contain the result, defVal contains values we should use when one column is NULL { poco_assert_dbg (pExt != 0); int w; - TypeHandler<string>::extract(pos++, obj.boldUrl, defVal.boldUrl, pExt); - TypeHandler<string>::extract(pos++, obj.abbrUrl, defVal.abbrUrl, pExt); + TypeHandler<std::string>::extract(pos++, obj.boldUrl, defVal.boldUrl, pExt); + TypeHandler<std::string>::extract(pos++, obj.abbrUrl, defVal.abbrUrl, pExt); TypeHandler<int>::extract(pos++, obj.strength, defVal.strength, pExt); TypeHandler<int>::extract(pos++, w, defVal.whitelist, pExt); obj.whitelist = (w != 0); @@ -128,7 +177,7 @@ template <> -class TypeHandler<class BlacklistKeyword> +class TypeHandler<class ::NetResponsibility::BlacklistKeyword> { public: static size_t size() @@ -136,31 +185,31 @@ return 3; // we handle four columns of the Table! } - static void bind(size_t pos, const BlacklistKeyword& obj, + static void bind(size_t pos, const ::NetResponsibility::BlacklistKeyword& obj, AbstractBinder* pBinder) { poco_assert_dbg (pBinder != 0); - TypeHandler<string>::bind(pos++, obj.asString, pBinder); - TypeHandler<string>::bind(pos++, obj.category, pBinder); + TypeHandler<std::string>::bind(pos++, obj.asString, pBinder); + TypeHandler<std::string>::bind(pos++, obj.category, pBinder); TypeHandler<int>::bind(pos++, obj.strength, pBinder); } - static void prepare(size_t pos, const BlacklistKeyword& obj, + static void prepare(size_t pos, const ::NetResponsibility::BlacklistKeyword& obj, AbstractPreparation* pPrepare) { poco_assert_dbg (pBinder != 0); - TypeHandler<string>::prepare(pos++, obj.asString, pPrepare); - TypeHandler<string>::prepare(pos++, obj.category, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.asString, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.category, pPrepare); TypeHandler<int>::prepare(pos++, obj.strength, pPrepare); } - static void extract(size_t pos, BlacklistKeyword& obj, - const BlacklistKeyword& defVal, AbstractExtractor* pExt) + static void extract(size_t pos, ::NetResponsibility::BlacklistKeyword& obj, + const ::NetResponsibility::BlacklistKeyword& defVal, AbstractExtractor* pExt) /// obj will contain the result, defVal contains values we should use when one column is NULL { poco_assert_dbg (pExt != 0); - TypeHandler<string>::extract(pos++, obj.asString, defVal.asString, pExt); - TypeHandler<string>::extract(pos++, obj.category, defVal.category, pExt); + TypeHandler<std::string>::extract(pos++, obj.asString, defVal.asString, pExt); + TypeHandler<std::string>::extract(pos++, obj.category, defVal.category, pExt); TypeHandler<int>::extract(pos++, obj.strength, defVal.strength, pExt); } }; Copied: branches/multiuser/include/BootHistory.h (from rev 323, trunk/include/BootHistory.h) =================================================================== --- branches/multiuser/include/BootHistory.h (rev 0) +++ branches/multiuser/include/BootHistory.h 2012-07-07 16:36:20 UTC (rev 329) @@ -0,0 +1,160 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: BootHistory +// +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <BootHistory> processes the computers boot history to determine whether or +// not Net Responsibility have been shut down manually. +// Almost all code is taken from the Linux command "last", so credit goes to +// Miquel van Smoorenburg, mi...@ci... + +#ifndef BOOTHISTORY_H +#define BOOTHISTORY_H + +#include "Poco/Environment.h" +#include <map> +#include <set> + +#if defined(POCO_OS_FAMILY_UNIX) + +#include <time.h> +#include <utmp.h> +#include <errno.h> +#include <malloc.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> + +#include "Poco/Timestamp.h" +#include "Poco/Logger.h" +#include "Poco/Util/Application.h" + +#define OLD_LINESIZE 12 +#define OLD_NAMESIZE 8 +#define OLD_HOSTSIZE 16 + + +#ifndef SHUTDOWN_TIME +# define SHUTDOWN_TIME 254 +#endif + +#define CHOP_DOMAIN 0 /* Define to chop off local domainname. */ +#define NEW_UTMP 1 /* Fancy & fast utmp read code. */ +#define UCHUNKSIZE 16384 /* How much we read at once. */ + +/* Types of listing */ +#define R_CRASH 1 /* No logout record, system boot in between */ +#define R_DOWN 2 /* System brought down in decent way */ +#define R_NORMAL 3 /* Normal */ +#define R_NOW 4 /* Still logged in */ +#define R_REBOOT 5 /* Reboot record. */ +#define R_PHANTOM 6 /* No logout record but session is stale. */ +#define R_TIMECHANGE 7 /* NEW_TIME or OLD_TIME */ + +namespace NetResponsibility { + +using ::Poco::Timestamp; +using ::Poco::Logger; +using ::Poco::Util::Application; +using namespace ::std; + +struct utmplist { + /// Double linked list of struct utmp's + struct utmp ut; + struct utmplist *next; + struct utmplist *prev; +}; + +struct oldutmp { + short ut_type; + int ut_pid; + char ut_line[OLD_LINESIZE]; + char ut_id[4]; + long ut_oldtime; + char ut_user[OLD_NAMESIZE]; + char ut_host[OLD_HOSTSIZE]; + long ut_oldaddr; +}; + + +class BootHistory + /// BootHistory processes the computer's boot history to determine whether or + /// not Net Responsibility have been shut down manually. + /// + /// Almost all code is taken from the Linux command "last", so credit goes to + /// Miquel van Smoorenburg, mi...@ci... +{ + public: + BootHistory(); + int getBootTime(); + /// Get the unix timestamp of when the current session booted. + + int getHaltTime(int bootTime); + /// Get the unix timestamp of when the session with the given bootTime + /// halted or 0 on failure. + + map<int, int> getOmittedSessions(set<int> logged); + /// Returns all sessions that are not logged for some reason. + /// Only the sessions with a boot time later than the first element + /// of logged. + + private: + + void readFile(char*); + void uconv(struct oldutmp *oldut, struct utmp *utn); + int uread(FILE *fp, struct utmp *u, int *quit); + int pushBoot(struct utmp *p, time_t haltTime, int what); + + + int _oldfmt; /* Use old libc5 format? */ + time_t _lastdate; /* Last date we've seen */ + char *_show; + map<time_t, time_t> _boots; + Logger *_logger; + + +}; + +#else // NOT UNIX +//This is only a fake class for Windows and other platforms, not yet implemented +class BootHistory + /// BootHistory processes the computer's boot history to determine whether or + /// not Net Responsibility have been shut down manually. + /// + /// Almost all code is taken from the Linux command "last", so credit goes to + /// Miquel van Smoorenburg, mi...@ci... +{ + public: + BootHistory() {} + int getBootTime() { return 0; } + /// Get the unix timestamp of when the current session booted. + + int getHaltTime(int bootTime) { return 0; } + /// Get the unix timestamp of when the session with the given bootTime + /// halted. + + map<int, int> getOmittedSessions(set<int> logged) { return map<int, int>; } + /// Returns all sessions that are not logged for some reason. + /// Only the sessions with a boot time later than the first element + /// of logged. +}; +#endif // UNIX + + +} // namespace NetResponsibility +#endif // BOOTHISTORY_H Modified: branches/multiuser/include/Bypasses.h =================================================================== --- branches/multiuser/include/Bypasses.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/Bypasses.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,7 +1,8 @@ -#ifndef BYPASSES_H -#define BYPASSES_H - - +// +// Library: Net Responsibility +// Package: Core +// Module: Bypasses +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -20,8 +21,10 @@ // <Bypasses> is able to store all useful information about attempts to bypass // the software +#ifndef BYPASSES_H +#define BYPASSES_H -#include "Poco/Timestamp.h" +#include "Poco/Timestamp.h" #include "Poco/Data/Common.h" #include "Poco/Data/Connector.h" #include "Poco/Data/SQLite/Connector.h" @@ -29,15 +32,18 @@ #include <iostream> #include <vector> - -using Poco::Timestamp; -using Poco::DateTimeFormatter; -using namespace Poco::Data; -using namespace std; +namespace NetResponsibility { + +using ::Poco::Timestamp; +using ::Poco::DateTimeFormatter; +using namespace ::Poco::Data; +using namespace ::std; + class Database; enum BypassType + /// What kind of bypass is it? { BYPASS_UNKNOWN, BYPASS_SHUTDOWN, @@ -45,58 +51,88 @@ BYPASS_MODIFIED_FILE }; -struct BypassRow { +struct BypassRow + /// A simple class to contain each Bypass. +{ public: - int type; - Timestamp date, - time, - dateTime; - string details; + int type; + /// Type of the bypass, given as BypassType. + + Timestamp date; + Timestamp time; + Timestamp dateTime; + string details; + /// Additional details about the bypass. Could be which file that was + /// deleted, how Net Responsibility was shutdown etc. }; class Bypasses + /// Bypasses is able to store all useful information about attempts to bypass + /// the software. All Bypasses will show up in the bypass section in the report. + /// + /// Bypasses is iterated through in a similar manner as History. { public: Bypasses(); virtual ~Bypasses(); - void setRows(vector<BypassRow, allocator<BypassRow> > &rows), - addRow(BypassRow), - addRow(int, string); - int getIndex() const, - getType() const, - getType(int) const, - size() const; - string getDateTime(string) const, - getDateTime(string, int) const, - getDetails() const, - getDetails(int) const, - getTypeString() const, - getTypeString(int) const; - Timestamp getDate() const, - getDate(int) const, - getTime() const, - getTime(int) const, - getDateTime() const, - getDateTime(int) const; - vector<BypassRow> getRows() const; + void setRows(vector<BypassRow, allocator<BypassRow> > &rows); + void addRow(BypassRow); + void addRow(int type, string details = ""); + /// Add a row by giving its BypassType and details. - bool hasMore() const; - void previous(), - next(), - clear(); + int getIndex() const; + /// Returns the index of the current BypassRow. This may be used to + /// access this specific element later. + + int getType() const; + /// Returns the type given as BypassType. + + int getType(int index) const; + int size() const; + string getDateTime(string fmt) const; + /// Returns a DateTime string formatted as specified in fmt. + string getDateTime(string fmt, int index) const; + string getDetails() const; + string getDetails(int index) const; + string getTypeString() const; + /// Returns a message that tries to explain what type of bypass it is. + /// These messages are loaded from the txtfile. + + string getTypeString(int index) const; + Timestamp getDate() const; + Timestamp getDate(int index) const; + Timestamp getTime() const; + Timestamp getTime(int index) const; + Timestamp getDateTime() const; + Timestamp getDateTime(int index) const; + vector<BypassRow> getRows() const; + /// Get all _bypassRows inside a vector. + + bool hasMore() const; + /// Returns true if Bypasses contains more elements to iterate through. + + void previous(); + void next(); + void clear(); + /// Clear out all _bypassRows. + protected: - vector<BypassRow, allocator<BypassRow> > _bypassRows; - int _index; + vector<BypassRow, allocator<BypassRow> > _bypassRows; + /// All BypassRows stored in a vector. + + int _index; + /// The current index. }; + +} // namespace NetResponsibility - namespace Poco { namespace Data { template <> -class TypeHandler<class BypassRow> +class TypeHandler<class ::NetResponsibility::BypassRow> { public: static size_t size() @@ -104,27 +140,27 @@ return 4; // we handle four columns of the Table! } - static void bind(size_t pos, const BypassRow& obj, AbstractBinder* pBinder) + static void bind(size_t pos, const ::NetResponsibility::BypassRow& obj, AbstractBinder* pBinder) { poco_assert_dbg (pBinder != 0); TypeHandler<int>::bind(pos++, obj.type, pBinder); TypeHandler<Poco::Int64>::bind(pos++, obj.date.epochTime(), pBinder); TypeHandler<Poco::Int64>::bind(pos++, obj.time.epochTime(), pBinder); - TypeHandler<string>::bind(pos++, obj.details, pBinder); + TypeHandler<std::string>::bind(pos++, obj.details, pBinder); } - static void prepare(size_t pos, const BypassRow& obj, + static void prepare(size_t pos, const ::NetResponsibility::BypassRow& obj, AbstractPreparation* pPrepare) { poco_assert_dbg (pBinder != 0); TypeHandler<int>::prepare(pos++, obj.type, pPrepare); TypeHandler<Poco::Int64>::prepare(pos++, obj.date.epochTime(), pPrepare); TypeHandler<Poco::Int64>::prepare(pos++, obj.time.epochTime(), pPrepare); - TypeHandler<string>::prepare(pos++, obj.details, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.details, pPrepare); } - static void extract(size_t pos, BypassRow& obj, - const BypassRow& defVal, AbstractExtractor* pExt) + static void extract(size_t pos, ::NetResponsibility::BypassRow& obj, + const ::NetResponsibility::BypassRow& defVal, AbstractExtractor* pExt) /// obj will contain the result, defVal contains values we should use when one column is NULL { poco_assert_dbg (pExt != 0); @@ -132,7 +168,7 @@ TypeHandler<int>::extract(pos++, obj.type, defVal.type, pExt); TypeHandler<Int64>::extract(pos++, d, defVal.date.epochTime(), pExt); TypeHandler<Int64>::extract(pos++, t, defVal.time.epochTime(), pExt); - TypeHandler<string>::extract(pos++, obj.details, defVal.details, pExt); + TypeHandler<std::string>::extract(pos++, obj.details, defVal.details, pExt); dt = d + (t % 86400); obj.date = Timestamp::fromEpochTime(d); obj.time = Timestamp::fromEpochTime(t); @@ -143,5 +179,6 @@ } } // namespace Poco::Data #include "Options.h" -#include "MainApplication.h" +#include "MainApplication.h" + #endif // BYPASSES_H Modified: branches/multiuser/include/ConfigSubsystem.h =================================================================== --- branches/multiuser/include/ConfigSubsystem.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/ConfigSubsystem.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: ConfigSubsystem +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -30,26 +35,34 @@ #include "Poco/Thread.h" #include <iostream> -class MainApplication; + +namespace NetResponsibility { -using Poco::Util::Application; -using Poco::Util::Subsystem; -using Poco::Logger; -using namespace std; - - -class ConfigSubsystem: public Subsystem +using ::Poco::Util::Application; +using ::Poco::Logger; +using namespace ::std; + +class MainApplication; + +class ConfigSubsystem: public ::Poco::Util::Subsystem + /// ConfigSubsystem is a Subsystem that takes care of the configuration. + /// It will only do anything if one of the arguments --config or --install + /// is specified. { public: const char* name() const; - void reinitialize(Application& app); + void reinitialize(Application &app); protected: Logger *_logger; - void initialize(Application& self), - uninitialize(), - getLogin(string&, string&); + void initialize(Application &self); + void uninitialize(); + void getLogin(string &username, string &password); + /// Get the username and password through std::cin. This is not + /// neccessary if --username=X and --password=Y are given as arguments. }; -#include "MainApplication.h" +#include "MainApplication.h" + +} // namespace NetResponsibility #endif // CONFIGSUBSYSTEM_H Modified: branches/multiuser/include/ConnectionCache.h =================================================================== --- branches/multiuser/include/ConnectionCache.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/ConnectionCache.h 2012-07-07 16:36:20 UTC (rev 329) @@ -12,10 +12,9 @@ #include "Poco/Timestamp.h" #include <libmnl/libmnl.h> #include <arpa/inet.h> -#include "Sniffer.h" using namespace std; -/* Already defined + enum { SS_UNKNOWN, SS_ESTABLISHED, @@ -31,9 +30,9 @@ SS_CLOSING, SS_MAX }; -*/ -#define SS_ALL ((1<<SS_MAX)-1) + + struct TCPConnection { unsigned int destAddress; @@ -46,7 +45,7 @@ { public: ConnectionCache(); - int getUID(); + int getUID(unsigned int destAddress, unsigned int srcAddress); static ConnectionCache& getCache(); private: Modified: branches/multiuser/include/ConnectionCacheUpdateThread.h =================================================================== --- branches/multiuser/include/ConnectionCacheUpdateThread.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/ConnectionCacheUpdateThread.h 2012-07-07 16:36:20 UTC (rev 329) @@ -5,6 +5,9 @@ #include <unistd.h> #include "Poco/Runnable.h" #include "Poco/Timestamp.h" + +#define SS_ALL ((1<<SS_MAX)-1) + using namespace std; using Poco::Timestamp; @@ -15,13 +18,13 @@ ConnectionCacheUpdateThread(); virtual void run(); private: - vector<TCPConnection> _cache; + ConnectionCache *_cache; bool _timeToEnd; int getTcpFromNetlink(); static int addToConnectionCache(const struct nlmsghdr *nlh, void *data); int removeStale(); - int endThread(); + void endThread(); }; #endif // CONNECTIONCACHEUPDATETHREAD_H Modified: branches/multiuser/include/HTTPHit.h =================================================================== --- branches/multiuser/include/HTTPHit.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/HTTPHit.h 2012-07-07 16:36:20 UTC (rev 329) @@ -26,11 +26,13 @@ #include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPMessage.h" -using Poco::Net::HTTPMessage; -using Poco::Net::HTTPRequest; -using Poco::Net::HTTPResponse; -using namespace std; +namespace NetResponsibility{ +using ::Poco::Net::HTTPMessage; +using ::Poco::Net::HTTPRequest; +using ::Poco::Net::HTTPResponse; +using namespace ::std; + class HTTPHit { @@ -46,11 +48,11 @@ string _url; protected: - HTTPRequest _request; - HTTPResponse _response; - + HTTPRequest *_request; + HTTPResponse *_response; int _uid; }; +} //NetResponsibility #endif //HTTPHIT_H Modified: branches/multiuser/include/HTTPHitHandler.h =================================================================== --- branches/multiuser/include/HTTPHitHandler.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/HTTPHitHandler.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,31 +1,37 @@ #ifndef HTTPHITHANDLER_H #define HTTPHITHANDLER_H -//HTTPHitHandler.h #include <vector> -#include "ConnectionCache.h" -#include "Poco/Runnable.h" -#include "HTTPHit.h" #include "Database.h" #include "Filter.h" #include "Blacklist.h" -#include "Sniffer.h" -#include "Options.h" +#include "ConnectionCache.h" +#include "Poco/LogStream.h" +#include "HTTPHit.h" +namespace NetResponsibility{ + using namespace std; +using namespace NetResponsibility; +using Poco::LogStream; -class MainApplication; class HTTPHitHandler { public: - HTTPHitHandler(); - int handleHit(HTTPHit hit); + HTTPHitHandler(LogStream* logStream); + void handleHit(HTTPHit hit); protected: - static void logUrl(HTTPRequest&); + static void logUrl(HTTPHit&); static void logWarning(BlacklistMatch); ConnectionCache *_cache; Filter *_filter; Database *_db; + LogStream *_logStream; + static HTTPHitHandler *_instance; }; +} //NetResponsibilty + +#include "MainApplication.h" + #endif // HTTPHITHANDLER_H Modified: branches/multiuser/include/History.h =================================================================== --- branches/multiuser/include/History.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/History.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: History +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -28,60 +33,134 @@ #include <iostream> #include <vector> + +namespace NetResponsibility { + +using ::Poco::Timestamp; +using ::Poco::DateTimeFormatter; +using namespace ::Poco::Data; +using namespace ::std; -using Poco::Timestamp; -using Poco::DateTimeFormatter; -using namespace Poco::Data; -using namespace std; - -struct HistoryRow { +struct HistoryRow + /// A struct that contains each row of the urls table. It is actually nothing + /// more than the URL split up in hostname and path, as well as the time, + /// divided in time, date and datetime. +{ public: - string hostname, - path; - Timestamp date, - time, - dateTime; + string hostname; + string path; + Timestamp date; + Timestamp time; + Timestamp dateTime; }; -class History +class History + /// The History class is especially important to understand if you're writing + /// a report plugin. When running Database.getHistory(), you'll get the return + /// as a History object. It is designed to be easy to iterate through and + /// holds every URL with some additional info about it. + /// + /// The following is an example of how the History object may be used to + /// iterate through: + /// History history = _db->getHistory(); + /// while (history.hasMore()) { + /// _body <<history.getDateTime("%d/%m - %H:%M:%S")) + /// <<" - " <<history.getUrl() <<endl; + /// history.next(); + /// } + /// + /// Pay extra attention to how the History is recieved from the database, + /// used in a while loop, and the next object is accessed by the next() + /// method. + /// + /// You may also access information about any row in the History object + /// if you have its index. You can get the index of the current URL with + /// the method getIndex(). + { public: History(); virtual ~History(); - void setRows(vector<HistoryRow, allocator<HistoryRow> > &rows), - addRow(HistoryRow); - int getIndex() const; - string getHostname() const, - getHostname(int) const, - getPath() const, - getPath(int) const, - getUrl() const, - getUrl(int) const, - getDateTime(string) const, - getDateTime(string, int) const; - Timestamp getDate() const, - getDate(int) const, - getTime() const, - getTime(int) const, - getDateTime() const, - getDateTime(int) const; + void setRows(vector<HistoryRow, allocator<HistoryRow> > &rows); + /// This method is used to add all the HistoryRows to History. - bool hasMore() const; - void previous(), - next(); + void addRow(HistoryRow); + /// Use this method to only add a single HistoryRow. + int getIndex() const; + /// Returns the index of the current row. The index may be used to + /// access a row at any time, without having to use next() and + /// previous(). + + string getHostname() const; + /// Returns the current hostname as a string. + + string getHostname(int index) const; + /// Returns the hostname of index as a string. + + string getPath() const; + /// Returns the current path as a string. In the URL + /// "www.netresponsibility.com/dev/docs", "/dev/docs" is the path. + + string getPath(int index) const; + /// Same as getPath() but for the given index. + + string getUrl() const; + /// Returns the current URL (both hostname and path) as a string. + + string getUrl(int index) const; + /// Returns the URL of index as a string. + + string getDateTime(string fmt) const; + /// Returns a formatted date and time as a string. fmt is the format + /// you wish to return. See Poco::DateTimeFormatter::format() for + /// more information on exactly how the format may be written. + + string getDateTime(string fmt, int index) const; + + Timestamp getDate() const; + /// Get the current date as a Timestamp. + + Timestamp getDate(int index) const; + /// Get the date of index as a Timestamp. + + Timestamp getTime() const; + /// Get the current time as a Timestamp. + + Timestamp getTime(int index) const; + /// Get the time of index as a Timestamp. + + Timestamp getDateTime() const; + /// Get the current date and time as a Timestamp. + + Timestamp getDateTime(int index) const; + /// Get the date and time of index as a Timestamp. + + bool hasMore() const; + /// Returns true if there are any more rows to iterate through. Very + /// useful to put inside a while condition e.g. + + void previous(); + /// Go to the previous row. + + void next(); + /// Go to the next row. Useful to put in the end of a while loop. + // Also add the ++ and -- operators to History + protected: vector<HistoryRow, allocator<HistoryRow> > _historyRows; int _index; -}; +}; + +} // namespace NetResponsibility namespace Poco { namespace Data { template <> -class TypeHandler<class HistoryRow> +class TypeHandler<class ::NetResponsibility::HistoryRow> { public: static size_t size() @@ -89,33 +168,33 @@ return 4; // we handle four columns of the Table! } - static void bind(size_t pos, const HistoryRow& obj, AbstractBinder* pBinder) + static void bind(size_t pos, const ::NetResponsibility::HistoryRow& obj, AbstractBinder* pBinder) { poco_assert_dbg (pBinder != 0); - TypeHandler<string>::bind(pos++, obj.hostname, pBinder); - TypeHandler<string>::bind(pos++, obj.path, pBinder); + TypeHandler<std::string>::bind(pos++, obj.hostname, pBinder); + TypeHandler<std::string>::bind(pos++, obj.path, pBinder); TypeHandler<Int64>::bind(pos++, obj.date.epochTime(), pBinder); TypeHandler<Int64>::bind(pos++, obj.time.epochTime(), pBinder); } - static void prepare(size_t pos, const HistoryRow& obj, + static void prepare(size_t pos, const ::NetResponsibility::HistoryRow& obj, AbstractPreparation* pPrepare) { poco_assert_dbg (pBinder != 0); - TypeHandler<string>::prepare(pos++, obj.hostname, pPrepare); - TypeHandler<string>::prepare(pos++, obj.path, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.hostname, pPrepare); + TypeHandler<std::string>::prepare(pos++, obj.path, pPrepare); TypeHandler<Int64>::prepare(pos++, obj.date.epochTime(), pPrepare); TypeHandler<Int64>::prepare(pos++, obj.time.epochTime(), pPrepare); } - static void extract(size_t pos, HistoryRow& obj, - const HistoryRow& defVal, AbstractExtractor* pExt) + static void extract(size_t pos, ::NetResponsibility::HistoryRow& obj, + const ::NetResponsibility::HistoryRow& defVal, AbstractExtractor* pExt) /// obj will contain the result, defVal contains values we should use when one column is NULL { poco_assert_dbg (pExt != 0); Int64 d, t, dt; - TypeHandler<string>::extract(pos++, obj.hostname, defVal.hostname, pExt); - TypeHandler<string>::extract(pos++, obj.path, defVal.path, pExt); + TypeHandler<std::string>::extract(pos++, obj.hostname, defVal.hostname, pExt); + TypeHandler<std::string>::extract(pos++, obj.path, defVal.path, pExt); TypeHandler<Int64>::extract(pos++, d, defVal.date.epochTime(), pExt); TypeHandler<Int64>::extract(pos++, t, defVal.time.epochTime(), pExt); dt = d + (t % 86400); @@ -126,5 +205,6 @@ }; } } // namespace Poco::Data + #endif // HISTORY_H Modified: branches/multiuser/include/MainApplication.h =================================================================== --- branches/multiuser/include/MainApplication.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/MainApplication.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: MainApplication +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -59,58 +64,118 @@ #if defined(POCO_OS_FAMILY_UNIX) #include "unistd.h" #include "signal.h" -#include "Poco/SyslogChannel.h" -using Poco::SyslogChannel; -#endif +#include "Poco/SyslogChannel.h" +namespace NetResponsibility { + using ::Poco::SyslogChannel; +} +#endif -using Poco::Logger; -using Poco::FileChannel; -using Poco::ConsoleChannel; -using Poco::SplitterChannel; -using Poco::FormattingChannel; -using Poco::PatternFormatter; -using Poco::Util::Application; -using Poco::Util::ServerApplication; -using Poco::Util::Subsystem; -using Poco::Util::Option; -using Poco::Util::OptionSet; -using Poco::Util::OptionCallback; -using Poco::Util::HelpFormatter; -using Poco::DateTimeFormatter; -using Poco::AutoPtr; -using Poco::Process; -using Poco::ProcessHandle; -using namespace std; +namespace NetResponsibility { + +using ::Poco::Logger; +using ::Poco::FileChannel; +using ::Poco::ConsoleChannel; +using ::Poco::SplitterChannel; +using ::Poco::FormattingChannel; +using ::Poco::PatternFormatter; +using ::Poco::Util::Application; +using ::Poco::Util::ServerApplication; +using ::Poco::Util::Subsystem; +using ::Poco::Util::Option; +using ::Poco::Util::OptionSet; +using ::Poco::Util::OptionCallback; +using ::Poco::Util::HelpFormatter; +using ::Poco::DateTimeFormatter; +using ::Poco::AutoPtr; +using ::Poco::Process; +using ::Poco::ProcessHandle; +using namespace ::std; -class MainApplication: public ServerApplication +class MainApplication: public ::Poco::Util::ServerApplication + /// MainApplication is the skeleton of Net Responsibility. This is where all + /// Options are processed, the Database loaded, the Logger set up, the signals + /// handled and the Subsystems called. + /// + /// MainApplication is derived from Poco::Util::ServerApplication, which + /// also takes care of making the instance a daemon or service, if requested. { public: MainApplication(); + /// Default constructor. Sets some class variables and registers the + /// Subsystems that are to be invoked. + ~MainApplication(); static MainApplication &instance(); - static Options &getOptions(); + /// A public static method to access this very instance from any class. + + static Options &getOptions(); + /// A public static method to access the Options object from any class. + static Database &getDatabase(); - static void terminateNicely(bool = false); + /// A public static method to access the Database from any class. + static void terminateNicely(bool deletePidfile= false); + /// Terminate Net Responsibility nicely. This unmasks all singals, + /// deleted the pidfile if told to, and tells the instance to shut down. + protected: - void initialize(Application&), - uninitialize(), - setupLogger(), - defineOptions(OptionSet&), - handleHelp(const string&, const string&), - setOption(const string&, const string&), - displayHelp(), - checkForRoot(); - static void signalHandler(int = -1); - static bool isHalting(); - int main(const vector<string>&); + void initialize(Application& self); + /// Invokes a set of methods and constructs Options and Database. + /// A short glimpse of the actual code will reveal pretty much what it + /// does. + void uninitialize(); + + void setupLogger(); + /// Sets up the Logger. This is done differently on on different + /// platforms. Unix platforms will talk to syslog by default. If the + /// instance is not running as a daemon/service, all messages will be + /// sent to stdout instead. If a specific logfile is specified, the + /// messages will go there. + + void defineOptions(OptionSet& options); + /// Defines all arguments that are accepted. These must be entered + /// the Unix style: --argument=value or -avalue. + + void handleHelp(const string& name, const string& value); + /// This method is called if the --help argument is specified. It will + /// only print out all available arguments with displayHelp() and exit. + + void setOption(const string& name, const string& value); + /// The default way that Poco handles configurations is not ideal for + /// our purposes. It's way to flexible for accountability softwares. + /// Therefor the options are processed in Options. However, some global + /// values are specified in the default config system. This is because + /// they're easliy reached from any class. setOption() is used to store + /// these global values. + + void displayHelp(); + + void displayVersion(const string& name, const string& value); + + void checkForRoot(); + /// Checks if the user who started the program is having enough + /// priviligues. In Linux you'll need to be running Net Responsibility + /// as root. + + static void signalHandler(int sig = -1); + /// The signal handler. Masks all possible signals, and catches them + /// properly, by logging the shutdown in the Database. + + int main(const vector<string>& args); + /// The main method invoked after the Subsystems are run. At this + /// moment it is more or less redundent, since all the actual code + /// is run inside the Subsystems. + private: bool _helpRequested; static MainApplication *_instance; Options *_options; Database *_database; -}; +}; + + +} // namespace NetResponsibility #endif // MAINAPPLICATION_H Modified: branches/multiuser/include/MyXml.h =================================================================== --- branches/multiuser/include/MyXml.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/MyXml.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: MyXml +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -19,6 +24,8 @@ #ifndef MYXML_H #define MYXML_H + + #include <iostream> #include <vector> @@ -31,26 +38,44 @@ #include "Poco/Logger.h" #include "Blacklist.h" + +namespace NetResponsibility { + +using ::Poco::AutoPtr; +using ::Poco::Util::XMLConfiguration; +using ::Poco::Util::Application; +using ::Poco::RegularExpression; +using ::Poco::Logger; +using namespace ::std; -using Poco::AutoPtr; -using Poco::Util::XMLConfiguration; -using Poco::Util::Application; -using Poco::RegularExpression; -using Poco::Logger; -using namespace std; - -class MyXml : public XMLConfiguration +class MyXml : public ::Poco::Util::XMLConfiguration + /// MyXml inherits XMLConfiguration and adds some extra functionality to it. + /// It's most important task is to extract and compile the blacklists, as + /// well as the txtfile. { public: - MyXml(); - MyXml(string path); - ~MyXml() {} - vector<string> getStringVector(string) const; - map<string, string> getStringMap() const; + MyXml(); + + MyXml(string path); + /// Load the XML file found at path. + + vector<string> getStringVector(string key) const; + /// Returns a string vector with the values found at "key". + + map<string, string> getStringMap() const; + /// Returns a map<string, string> with all values found in the document. + Blacklist getBlacklist(); + /// Extracts and compiles the keywords in the blacklist file. + Extensions getExtensions(); + /// Extracts every Extension shipped with the blacklists. + protected: Logger* _logger; }; + + +} // namespace NetResponsibility #endif // MYXML_H Modified: branches/multiuser/include/Options.h =================================================================== --- branches/multiuser/include/Options.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/Options.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Options +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -60,74 +65,138 @@ #ifndef VERSION #define VERSION "0" #endif //VERSION - -using Poco::Logger; -using Poco::Util::Application; -using namespace std; +namespace NetResponsibility { + +using ::Poco::Logger; +using ::Poco::Util::Application; +using namespace ::std; + class MainApplication; class Bypasses; -class Options +class Options + /// Poco::Util::ServerApplication is already handling configurations and + /// arguments, but it's way too flexible for us. This is where the Options + /// class comes in. It processes the config and txt files, and stores all + /// usable values in class members. { public: - Options(); - Options(int argc, char* argv[]); + Options(); + + Options(int argc, char* argv[]); + /// Deprecated, use the default contructor Options() instead. + virtual ~Options(); - bool doSaveHistory() const, - doSendImprovementData() const, - doCompressAttachedReport() const, - isReportPart(string) const, - isAttachedReportPart(string) const; - string getName() const, - getUsername() const, - getEmailFrom() const, - getConfigfile() const, - getServer() const, - getMacAddress() const, - getVersion() const, - getDatabasefile() const, - getPidfile() const, - getBlacklistFile() const, - getTxt(string) const, - getReportModule() const; - vector<string> getEmailTo() const, - getReportParts() const, - getAttachedReportParts() const; - int getReportFrequency() const, - getReportStrengthThreshold() const; + bool doSaveHistory() const; + + bool doSendImprovementData() const; + /// Returns true if we're supposed to send the improvement data to + /// the server. + + bool doCompressAttachedReport() const; + /// Returns true if the report should be zipped. + + bool isReportPart(string part) const; + /// Returns true if the given part should be included in the regular report. + + bool isAttachedReportPart(string part) const; + /// Returns true if the given part should be included in the attached report. + + string getName() const; + /// Returns the name of the user. This name will be used as sender of + /// the reports. + + string getUsername() const; + /// Returns the username, used to communicate with the server. + + string getEmailFrom() const; + /// Returns the user's email address. This will be specified as reply-to + /// in the report header, so that accountability partners will reply + /// directly to the user instead of re...@ne.... + + string getConfigfile() const; + /// The path to the local config file. + + string getServer() const; + /// The server, usually www.netresponsibility.com + + string getMacAddress() const; + /// Returns the computer's MAC Address. This is used when communicating + /// with the server. + + string getVersion() const; + /// The current version of Net Responsibility. + + string getDatabasefile() const; + /// The path to the database. + + string getPidfile() const; + /// The path to the pidfile. + + string getBlacklistFile() const; + /// The path to the local blacklist file. + + string getTxt(string) const; + /// The path to the local txt file. + + string getReportModule() const; + /// The path to the report module. + + vector<string> getEmailTo() const; + /// Returns all emails to send reports to. + + vector<string> getReportParts() const; + /// Returns the report parts. + + vector<string> getAttachedReportParts() const; + /// Returns the attached report parts. + + int getReportFrequency() const; + /// Returns the number of days between scheduled reports. + + int getReportStrengthThreshold() const; + /// Returns the report strength threshold. + Bypasses &getInitBypasses() const; - void setUsername(string), - loadConfigfile(); + + void setUsername(string); + + void loadConfigfile(); + /// Load all options from the local configfile, or download a new one + /// if it's corrupt. private: - string _databasefile, - _pidfile, - _configfile, - _txtfile, - _username, - _name, - _emailFrom, - _blacklistFile, - _version, - _server, - _reportModule; - bool _saveHistory, - _sendImprovementData, - _compressAttachedReport; - vector<string> _reportParts, - _attachedReportParts, - _emailTo; + string _databasefile; + string _pidfile; + string _configfile; + string _txtfile; + string _username; + string _name; + string _emailFrom; + string _blacklistFile; + string _version; + string _server; + string _reportModule; + bool _saveHistory; + bool _sendImprovementData; + bool _compressAttachedReport; + vector<string> _reportParts; + vector<string> _attachedReportParts; + vector<string> _emailTo; map<string, string> _txt; - int _reportFrequency, - _reportStrengthThreshold; + int _reportFrequency; + int _reportStrengthThreshold; Logger *_logger; Bypasses *_initBypasses; - void loadDefaultValues(), - loadTxt(); + void loadDefaultValues(); + void loadTxt(); }; + +} // namespace NetResponsibility -#include "Bypasses.h" +#include "Bypasses.h" + #endif // OPTIONS_H Modified: branches/multiuser/include/Report.h =================================================================== --- branches/multiuser/include/Report.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/Report.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Report +// Module: Report +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -41,20 +46,31 @@ #include "Poco/Path.h" #include "Poco/File.h" #include "Poco/NumberFormatter.h" + +namespace NetResponsibility { + +using ::Poco::RegularExpression; +using ::Poco::DirectoryIterator; +using ::Poco::Zip::Compress; +using ::Poco::Path; +using ::Poco::File; -using Poco::RegularExpression; -using Poco::DirectoryIterator; -using Poco::Zip::Compress; -using Poco::Path; -using Poco::File; - -class Report: public ReportBase +class Report: public ReportBase + /// This class is generating the reports. It may also override ReportBase's + /// send method to send the reports another way than usual. Report is written + /// as a plugin, so one may extend Net Responsibility with different types + /// of reports. So far this is the only existing plugin. { public: - Report(): ReportBase() {} - string name() const; - void generate(); + Report(): ReportBase() {} + /// The default constructor, only uses ReportBase's regular constructor. + string name() const; + /// Returns the name of the class + + void generate(); + /// Generates the report. This method invokes a number of other methods + protected: /*Inherited: stringstream _body; @@ -69,21 +85,23 @@ private: stringstream _attached; - void makeBypassesSection(), - makeWarningsSection(string&), - makeWhitelistSection(), - makeHistorySection(), - addTemplate(string suspicious = ""), - saveAttachedReport(); - string jsContent(string), - makeColoredStrength(int), - makeTableBranch(string, string, string anchorName = ""), - makeJavascriptBranch(string, string); + void makeBypassesSection(); + void makeWarningsSection(string&); + void makeWhitelistSection(); + void makeHistorySection(); + void addTemplate(string suspicious = ""); + void saveAttachedReport(); + string jsContent(string); + string makeColoredStrength(int); + string makeTableBranch(string, string, string anchorName = ""); + string makeJavascriptBranch(string, string); }; + +} // namespace NetResponsibility - -POCO_BEGIN_MANIFEST(ReportBase) -POCO_EXPORT_CLASS(Report) +POCO_BEGIN_MANIFEST(NetResponsibility::ReportBase) +POCO_EXPORT_CLASS(NetResponsibility::Report) POCO_END_MANIFEST + #endif // REPORT_H Modified: branches/multiuser/include/ReportBase.h =================================================================== --- branches/multiuser/include/ReportBase.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/ReportBase.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: ReportBase +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -45,55 +50,108 @@ #include "Poco/Logger.h" #include "Poco/URI.h" #include "Poco/Path.h" + +namespace NetResponsibility { +using ::Poco::Timestamp; +using ::Poco::DateTimeFormatter; +using ::Poco::Net::MailMessage; +using ::Poco::Net::MailRecipient; +using ::Poco::Net::SMTPClientSession; +using ::Poco::Net::StringPartSource; +using ::Poco::Net::FilePartSource; +using ::Poco::Net::NoAddressFoundException; +using ::Poco::Util::Application; +using ::Poco::Exception; +using ::Poco::Logger; +using ::Poco::Path; -using Poco::Timestamp; -using Poco::DateTimeFormatter; -using Poco::Net::MailMessage; -using Poco::Net::MailRecipient; -using Poco::Net::SMTPClientSession; -using Poco::Net::StringPartSource; -using Poco::Net::FilePartSource; -using Poco::Net::NoAddressFoundException; -using Poco::Util::Application; -using Poco::Exception; -using Poco::Logger; -using Poco::Path; - class MainApplication; -class ReportBase +class ReportBase + /// ReportBase provides basic functionality for making and sending reports, + /// but must be inherited by Report. { public: - ReportBase(); - ReportBase(const ReportBase&); - virtual ~ReportBase(); - string getBody() const, - getSubject() const, - getContentType() const; - void logFinish(), - sendImprovementData(), - install(), - uninstall(); - virtual int send(bool = false); + ReportBase(); + /// Default constructor. Assigns some default values and logs that the + /// creating of a report started. + + ReportBase(const ReportBase&); + /// Copy constructor + + virtual ~ReportBase(); + + string getBody() const; + /// Returns the content of the reports body + + string getSubject() const; + /// Returns the email's subject + + string getContentType() const; + /// Returns what content-type the email consist of. By default it is + /// "text/plain". + + void logFinish(); + /// Logs that the report was successfully created and sent + + void sendImprovementData(); + /// Sends improvement data to the servers. This is optional for every + /// user. + + void install(); + /// Call this function if it is an install report + + void uninstall(); + /// Call this function if it is an uninstall report + + virtual int send(bool receiveCopy = false); + /// Send the report. Set receiveCopy to true if you wish to send a + /// report to the user as well as the Accountability Partners. + virtual void sendCout(); - virtual void sendToFile(char*); - virtual void test(); - virtual void generate() = 0; - virtual string name() const = 0; + /// Write the report to stdout instead of mailing it. Useful for + /// debugging but really nothing else. + + virtual void sendToFile(char* filename); + /// Write the report to filename instead of mailing it. Useful for + /// debugging but really nothing else. + + virtual void test(); + /// Call this function if it is an test report + virtual void generate() = 0; + /// Override this method in Report to generate nicely formatted reports + + virtual string name() const = 0; + /// Override this method in Report. Should actually only return the + /// class name, which is "Report". + protected: Options *_options; Database *_db; Logger *_logger; - stringstream _body; - vector<Path> _attachments; - string _contentType, - _subject; + stringstream _body; + /// The body of the report. Use it to build your Report. + + vector<Path> _attachments; + /// Attachments to the report. Each Path will be included. + + string _contentType; + /// The content-type of the report. You may change it to "text/html" or + /// whatever suits your purpose. + + string _subject; + /// The subject to be shown in the subject line. + int _reportId; - void replaceVar(string&, string, string); -}; + void replaceVar(string &subject, string var, string replacement); + /// Replace {var} with replacement in subject +}; + +} // namespace NetResponsibility -#include "MainApplication.h" +#include "MainApplication.h" + #endif // REPORTBASE_H Modified: branches/multiuser/include/ReportSubsystem.h =================================================================== --- branches/multiuser/include/ReportSubsystem.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/ReportSubsystem.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: ReportSubsystem +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -32,15 +37,17 @@ #include "Poco/File.h" #include <iostream> #include <fstream> - + +namespace NetResponsibility { + +using ::Poco::Util::Application; +using ::Poco::Util::Subsystem; +using ::Poco::ClassLoader; +using ::Poco::Logger; +using ::Poco::File; +using namespace ::std; + class MainApplication; - -using Poco::Util::Application; -using Poco::Util::Subsystem; -using Poco::ClassLoader; -using Poco::Logger; -using Poco::File; -using namespace std; enum ReportType { @@ -53,18 +60,29 @@ REPORT_UNINSTALL }; -class ReportSubsystem: public Subsystem +class ReportSubsystem: public ::Poco::Util::Subsystem + /// ReportSubsystem is a Poco::Util::Subsystem that determines if we should + /// send a report, and makes sure it's done properly. { public: const char* name() const; + /// Returns the name of the class: "ReportSubsystem" + void reinitialize(Application& app); protected: Logger *_logger; - void initialize(Application& self), - uninitialize(), - setScheduledReport(int&); + void initialize(Application& self); + /// Run the Subsystem + + void uninitialize(); + void setScheduledReport(int& type); + /// Check if it's time to send a scheduled report, and in that case + /// set type to REPORT_SCHEDULED }; + +} // namespace NetResponsibility -#include "MainApplication.h" +#include "MainApplication.h" + #endif // REPORTSUBSYSTEM_H Modified: branches/multiuser/include/Request.h =================================================================== --- branches/multiuser/include/Request.h 2012-07-05 23:01:45 UTC (rev 328) +++ branches/multiuser/include/Request.h 2012-07-07 16:36:20 UTC (rev 329) @@ -1,3 +1,8 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Request +// // This file is part of Net Responsibility. // // Net Responsibility is free software: you can redistribute it and/or modify @@ -41,37 +46,70 @@ #include "Poco/Exception.h" #include "Poco/Thread.h" -using Poco::Net::HTTPClientSession; -using Poco::Net::HTTPRequest; -using Poco::Net::HTTPRes... [truncated message content] |
From: <rog...@us...> - 2012-07-05 23:01:52
|
Revision: 328 http://responsibility.svn.sourceforge.net/responsibility/?rev=328&view=rev Author: roggan87 Date: 2012-07-05 23:01:45 +0000 (Thu, 05 Jul 2012) Log Message: ----------- The basic templates for loading custom data from the config file is implemented. This is done using MyXml::get<T>(property, value), or getVector or getMap. Modified Paths: -------------- branches/splitPlugins/include/MyXml.h branches/splitPlugins/include/Options.h branches/splitPlugins/src/MyXml.cpp branches/splitPlugins/src/Options.cpp Modified: branches/splitPlugins/include/MyXml.h =================================================================== --- branches/splitPlugins/include/MyXml.h 2012-07-05 16:31:59 UTC (rev 327) +++ branches/splitPlugins/include/MyXml.h 2012-07-05 23:01:45 UTC (rev 328) @@ -58,6 +58,17 @@ MyXml(string path); /// Load the XML file found at path. + + template <class T> T get(const char* property, T value); + /// Use this template to get single values from the XML file. + + template <typename T> vector<T> getVector(const char* property); + /// Use this template to get vectors from the XML file. + + template <typename T> map<string, T> getMap(const char* property); + /// This template returns all subkeys to property inside + /// a map<string, T>, where the first value is the name of + /// the subkey and the second value is the value itself. vector<string> getStringVector(string key) const; /// Returns a string vector with the values found at "key". @@ -75,7 +86,6 @@ Logger* _logger; }; - } // namespace NetResponsibility #endif // MYXML_H Modified: branches/splitPlugins/include/Options.h =================================================================== --- branches/splitPlugins/include/Options.h 2012-07-05 16:31:59 UTC (rev 327) +++ branches/splitPlugins/include/Options.h 2012-07-05 23:01:45 UTC (rev 328) @@ -201,7 +201,8 @@ int _reportFrequency; int _reportStrengthThreshold; Logger *_logger; - Bypasses *_initBypasses; + Bypasses *_initBypasses; + AutoPtr<MyXml> _xml; void loadDefaultValues(); void loadTxt(); Modified: branches/splitPlugins/src/MyXml.cpp =================================================================== --- branches/splitPlugins/src/MyXml.cpp 2012-07-05 16:31:59 UTC (rev 327) +++ branches/splitPlugins/src/MyXml.cpp 2012-07-05 23:01:45 UTC (rev 328) @@ -31,10 +31,71 @@ MyXml::MyXml(string path) : XMLConfiguration(path) { _logger = &Application::instance().logger(); + this->getVector<string>("/"); } + + +template <class T> +T MyXml::get(const char* property, T value) { + // Try to parse it or not? + return value; +} + + + +template <> bool MyXml::get(const char* property, bool value) { + return this->getBool(property, value); +} + + + +template <> int MyXml::get(const char* property, int value) { + return this->getInt(property, value); +} + + +template <> double MyXml::get(const char* property, double value) { + return this->getDouble(property, value); +} + + +template <> string MyXml::get(const char* property, string value) { + return this->getString(property, value); +} + + + + +template <typename T> +vector<T> MyXml::getVector(const char* property) { + vector<T> vec; + vector<string> subkeys; + vector<string>::iterator it; + this->keys(property, subkeys); + for (it = subkeys.begin(); it != subkeys.end(); ++it) { + string p = property + '.' + *it; + vec.push_back(this->get<T>(p.c_str(), T())); + } + return vec; +} + + +template <typename T> +map<string, T> MyXml::getMap(const char* property) { + map<string, T> m; + vector<string> subkeys; + this->keys(property, subkeys); + for (vector<string>::iterator it = subkeys.begin(); + it != subkeys.end(); ++it) + { + m[*it] = this->get<T>(it->c_str(), T()); + } + return m; +} + vector<string> MyXml::getStringVector(string key) const { vector<string> vec, subkeys; @@ -152,4 +213,16 @@ } +// Instantiate some templates +template vector<bool> MyXml::getVector<bool>(const char*); +template vector<double> MyXml::getVector<double>(const char*); +template vector<int> MyXml::getVector<int>(const char*); +template vector<string> MyXml::getVector<string>(const char*); + +template map<string, bool> MyXml::getMap<bool>(const char*); +template map<string, double> MyXml::getMap<double>(const char*); +template map<string, int> MyXml::getMap<int>(const char*); +template map<string, string> MyXml::getMap<string>(const char*); + + } // namespace NetResponsibility Modified: branches/splitPlugins/src/Options.cpp =================================================================== --- branches/splitPlugins/src/Options.cpp 2012-07-05 16:31:59 UTC (rev 327) +++ branches/splitPlugins/src/Options.cpp 2012-07-05 23:01:45 UTC (rev 328) @@ -243,21 +243,24 @@ for (int moreTries = 3; moreTries > 0; moreTries--) { try { AutoPtr<MyXml> xmlConfig (new MyXml(_configfile)); - _username = xmlConfig->getString("username"); - _emailFrom = xmlConfig->getString("emailFrom"); - _name = xmlConfig->getString("name"); - _pluginSniffer = xmlConfig->getString("plugin[@type='sniffer'][@selected='true'][@name]", "DefaultSniffer"); - _pluginReport = xmlConfig->getString("plugin[@type='report'][@selected='true'][@name]", "DefaultReport"); + _username = xmlConfig->get<string>("username", ""); + _emailFrom = xmlConfig->get<string>("emailFrom", ""); + _name = xmlConfig->get<string>("name", ""); + _pluginSniffer = xmlConfig->get<string>("plugin[@type='sniffer'][@selected='true'][@name]", "DefaultSniffer"); + _pluginReport = xmlConfig->get<string>("plugin[@type='report'][@selected='true'][@name]", "DefaultReport"); + + _logger->debug("Selected sniffer: " + _pluginSniffer); + _logger->debug("Selected report: " + _pluginReport); - _sendImprovementData = xmlConfig->getBool("improveData", false); - _compressAttachedReport = xmlConfig->getBool("compressAttachedReport", false); + _sendImprovementData = xmlConfig->get<bool>("improveData", false); + _compressAttachedReport = xmlConfig->get<bool>("compressAttachedReport", false); - _emailTo = xmlConfig->getStringVector("emailTo"); - _reportParts = xmlConfig->getStringVector("reportParts"); - _attachedReportParts = xmlConfig->getStringVector("attachedReportParts"); + _emailTo = xmlConfig->getVector<string>("emailTo"); + _reportParts = xmlConfig->getVector<string>("reportParts"); + _attachedReportParts = xmlConfig->getVector<string>("attachedReportParts"); - _reportFrequency = xmlConfig->getInt("reportFrequency", 7); - _reportStrengthThreshold = xmlConfig->getInt("reportStrengthThreshold", 0); + _reportFrequency = xmlConfig->get<int>("reportFrequency", 7); + _reportStrengthThreshold = xmlConfig->get<int>("reportStrengthThreshold", 0); _saveHistory = isAttachedReportPart("history_hostnames") || isAttachedReportPart("history_paths"); @@ -296,7 +299,7 @@ void Options::loadTxt() { try { AutoPtr<MyXml> xmlTxt (new MyXml(_txtfile)); - _txt = xmlTxt->getStringMap(); + _txt = xmlTxt->getMap<string>(""); } catch (::Poco::Exception &err) { _logger->warning("Corrupt txtfile"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rog...@us...> - 2012-07-05 16:32:13
|
Revision: 327 http://responsibility.svn.sourceforge.net/responsibility/?rev=327&view=rev Author: roggan87 Date: 2012-07-05 16:31:59 +0000 (Thu, 05 Jul 2012) Log Message: ----------- Sorry for a big commit, I should've chunked it up in pieces. Now we have more or less full plugin support. The Sniffer and Report is split up in their own separate libraries. plugins/create.sh will set up the basics for a new plugin. Also added the option to disable account support. When running ./configure --disable-account on compilation, NR will be compiled without this feature. That way one will be able to change the config file and blacklists without being auto-updated and reported. Some people may benefit from this, especially developers and people who don't want to create an account. Modified Paths: -------------- branches/splitPlugins/Makefile.am branches/splitPlugins/configure.ac branches/splitPlugins/include/Options.h branches/splitPlugins/include/SnifferSubsystem.h branches/splitPlugins/projectFiles/linux/net-responsibility.cbp branches/splitPlugins/src/ConfigSubsystem.cpp branches/splitPlugins/src/Filter.cpp branches/splitPlugins/src/Options.cpp branches/splitPlugins/src/ReportSubsystem.cpp branches/splitPlugins/src/SnifferSubsystem.cpp Added Paths: ----------- branches/splitPlugins/ branches/splitPlugins/include/Plugin.h branches/splitPlugins/plugins/ branches/splitPlugins/plugins/DefaultReport/ branches/splitPlugins/plugins/DefaultReport/AUTHORS branches/splitPlugins/plugins/DefaultReport/COPYING branches/splitPlugins/plugins/DefaultReport/ChangeLog branches/splitPlugins/plugins/DefaultReport/INSTALL branches/splitPlugins/plugins/DefaultReport/Makefile.am branches/splitPlugins/plugins/DefaultReport/NEWS branches/splitPlugins/plugins/DefaultReport/README branches/splitPlugins/plugins/DefaultReport/configure.ac branches/splitPlugins/plugins/DefaultReport/include/ branches/splitPlugins/plugins/DefaultReport/include/Report.h branches/splitPlugins/plugins/DefaultReport/m4/ branches/splitPlugins/plugins/DefaultReport/src/ branches/splitPlugins/plugins/DefaultReport/src/Report.cpp branches/splitPlugins/plugins/DefaultSniffer/ branches/splitPlugins/plugins/DefaultSniffer/AUTHORS branches/splitPlugins/plugins/DefaultSniffer/COPYING branches/splitPlugins/plugins/DefaultSniffer/ChangeLog branches/splitPlugins/plugins/DefaultSniffer/INSTALL branches/splitPlugins/plugins/DefaultSniffer/Makefile.am branches/splitPlugins/plugins/DefaultSniffer/NEWS branches/splitPlugins/plugins/DefaultSniffer/README branches/splitPlugins/plugins/DefaultSniffer/configure.ac branches/splitPlugins/plugins/DefaultSniffer/include/ branches/splitPlugins/plugins/DefaultSniffer/include/Sniffer.h branches/splitPlugins/plugins/DefaultSniffer/include/SnifferThread.h branches/splitPlugins/plugins/DefaultSniffer/m4/ branches/splitPlugins/plugins/DefaultSniffer/src/ branches/splitPlugins/plugins/DefaultSniffer/src/Sniffer.cpp branches/splitPlugins/plugins/DefaultSniffer/src/SnifferThread.cpp branches/splitPlugins/plugins/Template/ branches/splitPlugins/plugins/Template/AUTHORS branches/splitPlugins/plugins/Template/COPYING branches/splitPlugins/plugins/Template/ChangeLog branches/splitPlugins/plugins/Template/INSTALL branches/splitPlugins/plugins/Template/Makefile.am branches/splitPlugins/plugins/Template/NEWS branches/splitPlugins/plugins/Template/README branches/splitPlugins/plugins/Template/configure.ac branches/splitPlugins/plugins/Template/include/ branches/splitPlugins/plugins/Template/include/Report.h branches/splitPlugins/plugins/Template/include/Sniffer.h branches/splitPlugins/plugins/Template/m4/ branches/splitPlugins/plugins/Template/src/ branches/splitPlugins/plugins/Template/src/Report.cpp branches/splitPlugins/plugins/Template/src/Sniffer.cpp branches/splitPlugins/plugins/create.sh Removed Paths: ------------- branches/splitPlugins/include/Report.h branches/splitPlugins/include/Sniffer.h branches/splitPlugins/include/SnifferThread.h branches/splitPlugins/src/Plugin.cpp branches/splitPlugins/src/Report.cpp branches/splitPlugins/src/Sniffer.cpp branches/splitPlugins/src/SnifferThread.cpp Modified: branches/splitPlugins/Makefile.am =================================================================== --- trunk/Makefile.am 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/Makefile.am 2012-07-05 16:31:59 UTC (rev 327) @@ -1,3 +1,6 @@ +# Additional plugins to include +SUBDIRS = . plugins/DefaultReport plugins/DefaultSniffer + # Main library lib_LTLIBRARIES = libNetResponsibility.la libNetResponsibility_la_SOURCES = \ @@ -13,9 +16,7 @@ @top_srcdir@/src/ReportBase.cpp\ @top_srcdir@/src/ReportSubsystem.cpp\ @top_srcdir@/src/Request.cpp\ - @top_srcdir@/src/Sniffer.cpp\ @top_srcdir@/src/SnifferSubsystem.cpp\ - @top_srcdir@/src/SnifferThread.cpp\ @top_srcdir@/src/Warnings.cpp libNetResponsibility_la_CPPFLAGS = $(cppFlags) libNetResponsibility_la_LDFLAGS = -no-undefined $(ldFlags) @@ -25,13 +26,6 @@ net_responsibility_SOURCES = @top_srcdir@/src/main.cpp net_responsibility_LDADD = -lNetResponsibility -# Report module -pkglib_LTLIBRARIES = report.la -report_la_SOURCES = @top_srcdir@/src/Report.cpp -report_la_LDFLAGS = -module -no-undefined $(ldFlags) -report_la_LIBADD = -lNetResponsibility -report_la_CPPFLAGS = $(cppFlags) - dist_pkgdata_DATA = \ $(top_srcdir)/data/txt.xml\ $(top_srcdir)/COPYING @@ -42,8 +36,6 @@ dist_noinst_DATA = $(top_srcdir)/DEVELOPERS -libpocodir = $(top_srcdir)/lib/poco - AM_LDFLAGS = -L/usr/local/lib -L/usr/lib ACLOCAL_AMFLAGS = -I scripts/m4 @@ -74,9 +66,9 @@ find $(distdir) -type d -name .dep -print0 | xargs -0 rm -rf find $(distdir) -type d -name obj -print0 | xargs -0 rm -rf -install: install-am postinst +install: install-recursive postinst -uninstall: prerm uninstall-am postrm +uninstall: prerm uninstall-recursive postrm postinst: $(top_srcdir)/scripts/postinst $(pkgdatadir) $(initdir) Modified: branches/splitPlugins/configure.ac =================================================================== --- trunk/configure.ac 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/configure.ac 2012-07-05 16:31:59 UTC (rev 327) @@ -1,18 +1,21 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. - AC_PREREQ(2.58) -LT_PREREQ([2.2]) -AC_INIT([Net Responsibility],[3.0.1],[co...@ne...]) -AM_INIT_AUTOMAKE([subdir-objects]) -LT_INIT([shared]) +AC_INIT([Net Responsibility],[3.1r323],[co...@ne...]) AC_SUBST([LIBTOOL_DEPS]) +AC_CONFIG_AUX_DIR([.]) AC_CONFIG_SRCDIR([src/main.cpp]) -AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_SUBDIRS([plugins/DefaultReport plugins/DefaultSniffer]) +AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_MACRO_DIR([scripts/m4]) AC_LANG([C++]) AC_PREFIX_PROGRAM([make]) +AM_INIT_AUTOMAKE([subdir-objects]) + +LT_PREREQ([2.2]) +LT_INIT([shared]) + # Additional arguments for customization. AC_ARG_WITH( [initdir], @@ -42,6 +45,22 @@ [AC_SUBST([piddir], ['/var/run'])] ) +AC_ARG_ENABLE( + [account], + [AS_HELP_STRING( + [--disable-account], + [Use this argument to disable the feature to interact with server accounts to read configurations etc. By default Net Responsibility will require an account.] + )], + [ + if test "x$enableval" = "xno" ; then + AC_DEFINE([DISABLE_ACCOUNT], [1], [Define to 1 if accounts are disabled.]) + else + AC_DEFINE([DISABLE_ACCOUNT], [0], [Define to 1 if accounts are disabled.]) + fi + ], + [AC_DEFINE([DISABLE_ACCOUNT], [0], [Define to 1 if accounts are disabled.])] +) + # Checks for programs. AC_PROG_CXX AC_PROG_INSTALL @@ -55,6 +74,8 @@ AC_CHECK_LIB([PocoUtil], [main],, have_libpoco=no) AC_CHECK_LIB([PocoNet], [main],, have_libpoco=no) +# Checks for header files. +AC_HEADER_STDC # Platform specific checks case $(uname) in @@ -82,9 +103,8 @@ be found at their website: www.pocoproject.org --------------------------------------------------" + exit 1 else - # Checks for header files. - AC_HEADER_STDC AC_CONFIG_FILES([Makefile]) AC_OUTPUT Modified: branches/splitPlugins/include/Options.h =================================================================== --- trunk/include/Options.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/include/Options.h 2012-07-05 16:31:59 UTC (rev 327) @@ -36,11 +36,12 @@ #include "Poco/Exception.h" #include "Poco/Environment.h" #include "Poco/Util/Application.h" -#include "Poco/Logger.h" +#include "Poco/Logger.h" +#include "Poco/SharedLibrary.h" -#if HAVE_CONFIG_H +//#if HAVE_CONFIG_H #include "config.h" -#endif +//#endif #define STRINGIFY(path, file) #path #file #define CONCAT(x, y) STRINGIFY(x, y) @@ -52,6 +53,9 @@ #ifndef PIDDIR #define PIDDIR /var/run #endif +#ifndef DISABLE_ACCOUNT +#define DISABLE_ACCOUNT 0 +#endif #define DATABASEFILE CONCAT(DATABASEDIR, /net-responsibility.db) #define PIDFILE CONCAT(PIDDIR, /net-responsibility.pid) @@ -59,7 +63,7 @@ #define BLACKLISTFILE CONCAT(PKGDATADIR, /blacklist.xml) #define TXTFILE CONCAT(PKGDATADIR, /txt.xml) #define REPORT_DIR CONCAT(PKGDATADIR, /reports/) -#define REPORT_MODULE CONCAT(PKGLIBDIR, /report.so) //Make cross-platform +#define PLUGIN_DIR CONCAT(PKGLIBDIR, /) #define SERVER "www.netresponsibility.com" #ifndef VERSION @@ -103,6 +107,9 @@ bool isAttachedReportPart(string part) const; /// Returns true if the given part should be included in the attached report. + + bool isAccountEnabled() const; + /// Returns false if accounts are disabled at compilation time. string getName() const; /// Returns the name of the user. This name will be used as sender of @@ -141,8 +148,12 @@ string getTxt(string) const; /// The path to the local txt file. - string getReportModule() const; - /// The path to the report module. + string getPluginPath(string pluginType) const; + /// Returns the path to the chosen plugin. The pluginType + /// may be "report" or "sniffer". + + string getReportDir() const; + /// Returns the path to locally stored reports. vector<string> getEmailTo() const; /// Returns all emails to send reports to. @@ -178,7 +189,8 @@ string _blacklistFile; string _version; string _server; - string _reportModule; + string _pluginSniffer; + string _pluginReport; bool _saveHistory; bool _sendImprovementData; bool _compressAttachedReport; Added: branches/splitPlugins/include/Plugin.h =================================================================== --- branches/splitPlugins/include/Plugin.h (rev 0) +++ branches/splitPlugins/include/Plugin.h 2012-07-05 16:31:59 UTC (rev 327) @@ -0,0 +1,56 @@ +// +// Library: Net Responsibility +// Package: Core +// Module: Plugin +// +// This file is part of Net Responsibility. +// +// Net Responsibility is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Net Responsibility is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. +// +// <Plugin> is a template for plugins with only limited functionality. Must be +// inherited by <Sniffer> and possibly more different plugins in the future. + + + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <stdio.h> + +namespace NetResponsibility { + +using namespace ::std; + +class Plugin + /// <Plugin> is a template for plugins with only limited + /// functionality. Must be inherited by <Sniffer> and possibly more + /// different plugins in the future. +{ + public: + Plugin() {} + /// Default constructor. Must not be used by deriving plugins. + + ~Plugin() {} + + virtual void run() = 0; + + virtual string name() const = 0; + /// Override this method in deriving plugins. Must return the + /// name of the particular plugin. +}; + +} // namespace NetResponsibility + + +#endif // PLUGIN_H Deleted: branches/splitPlugins/include/Report.h =================================================================== --- trunk/include/Report.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/include/Report.h 2012-07-05 16:31:59 UTC (rev 327) @@ -1,107 +0,0 @@ -// -// Library: Net Responsibility -// Package: Report -// Module: Report -// -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <Report> generates the reports, and may override <ReportBase>'s send method. - - - -#ifndef REPORT_H -#define REPORT_H - -#include "ReportBase.h" - -#include <map> - -#ifdef _WIN32 - #ifdef BUILD_DLL - #define ADDAPI __declspec(dllexport) - #else - #define ADDAPI __declspec(dllimport) - #endif -#else - #define ADDAPI -#endif - -#include "Poco/RegularExpression.h" -#include "Poco/DirectoryIterator.h" -#include "Poco/ClassLibrary.h" -#include "Poco/Zip/Compress.h" -#include "Poco/Path.h" -#include "Poco/File.h" -#include "Poco/NumberFormatter.h" - -namespace NetResponsibility { - -using ::Poco::RegularExpression; -using ::Poco::DirectoryIterator; -using ::Poco::Zip::Compress; -using ::Poco::Path; -using ::Poco::File; - -class Report: public ReportBase - /// This class is generating the reports. It may also override ReportBase's - /// send method to send the reports another way than usual. Report is written - /// as a plugin, so one may extend Net Responsibility with different types - /// of reports. So far this is the only existing plugin. -{ - public: - Report(): ReportBase() {} - /// The default constructor, only uses ReportBase's regular constructor. - - string name() const; - /// Returns the name of the class - - void generate(); - /// Generates the report. This method invokes a number of other methods - - protected: - /*Inherited: - stringstream _body; - string _subject; - string _contentType; - vector<Path> _attachments; - Options *_options; - Database *_db; - Logger *_logger; - - */ - - private: - stringstream _attached; - void makeBypassesSection(); - void makeWarningsSection(string&); - void makeWhitelistSection(); - void makeHistorySection(); - void addTemplate(string suspicious = ""); - void saveAttachedReport(); - string jsContent(string); - string makeColoredStrength(int); - string makeTableBranch(string, string, string anchorName = ""); - string makeJavascriptBranch(string, string); -}; - -} // namespace NetResponsibility - -POCO_BEGIN_MANIFEST(NetResponsibility::ReportBase) -POCO_EXPORT_CLASS(NetResponsibility::Report) -POCO_END_MANIFEST - - -#endif // REPORT_H Deleted: branches/splitPlugins/include/Sniffer.h =================================================================== --- trunk/include/Sniffer.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/include/Sniffer.h 2012-07-05 16:31:59 UTC (rev 327) @@ -1,115 +0,0 @@ -// -// Library: Net Responsibility -// Package: Core -// Module: Sniffer -// -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <Sniffer> listens for HTTP requests, and makes sure they're getting logged -// Much of this code is inspired by examples provided by TCPDump and Winpcap - - - -#ifndef SNIFFER_H -#define SNIFFER_H - -#ifdef _MSC_VER -/* - * we do not want the warnings about the old deprecated and unsecure CRT functions - * since these examples can be compiled under *nix as well - */ -#define _CRT_SECURE_NO_WARNINGS -#endif - - -#include <iostream> -#include <fstream> -#include <vector> - -#include "Poco/RegularExpression.h" -#include "Poco/SharedPtr.h" -#include "Poco/ThreadPool.h" -#include "Poco/Logger.h" -#include "Poco/LogStream.h" -#include "Poco/Net/HTTPRequest.h" - -#include "Database.h" -#include "Options.h" -#include "Filter.h" -#include "Blacklist.h" -#include "SnifferThread.h" - -#include <pcap.h> - -#if defined(POCO_OS_FAMILY_WINDOWS) -#include <winsock2.h> -#elif defined (POCO_OS_FAMILY_UNIX) -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#endif //POCO_OS_FAMILY_ - -namespace NetResponsibility { - -using ::Poco::RegularExpression; -using ::Poco::SharedPtr; -using ::Poco::ThreadPool; -using ::Poco::Logger; -using ::Poco::LogStream; -using ::Poco::Net::HTTPRequest; -using namespace ::std; - -struct sniff_ethernet; -struct sniff_ip; -struct sniff_tcp; - -class MainApplication; -class SnifferThread; - -class Sniffer - /// Sniffer sets up several SnifferThreads. One SnifferThread for each - /// interface, or only one for the "any" interface if it's found. - /// Much of this code is inspired by examples provided by TCPDump and Winpcap -{ - public: - Sniffer(); - /// Default constructor - - void run(); - /// Run the sniffer - - private: - Filter *_filter; - Database *_db; - LogStream *_logStream; - static Sniffer* _instance; - char _errbuf[PCAP_ERRBUF_SIZE]; - - static Filter& getFilter(); - static LogStream& getLogStream(); - static void logUrl(HTTPRequest&); - static void logWarning(BlacklistMatch); - vector<string> getDevices(); - - friend class SnifferThread; -}; - -} // namespace NetResponsibility - -#include "MainApplication.h" - -#endif // SNIFFER_H Modified: branches/splitPlugins/include/SnifferSubsystem.h =================================================================== --- trunk/include/SnifferSubsystem.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/include/SnifferSubsystem.h 2012-07-05 16:31:59 UTC (rev 327) @@ -25,7 +25,7 @@ #define SNIFFERSUBSYSTEM_H #include "Options.h" -#include "Sniffer.h" +#include "Plugin.h" #include "MainApplication.h" #include <fstream> @@ -41,6 +41,7 @@ #include "Poco/Logger.h" #include "Poco/Process.h" #include "Poco/Thread.h" +#include "Poco/ClassLoader.h" #include <iostream> namespace NetResponsibility { Deleted: branches/splitPlugins/include/SnifferThread.h =================================================================== --- trunk/include/SnifferThread.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/splitPlugins/include/SnifferThread.h 2012-07-05 16:31:59 UTC (rev 327) @@ -1,188 +0,0 @@ -// -// Library: Net Responsibility -// Package: Core -// Module: SnifferThread -// -// This file is part of Net Responsibility. -// -// Net Responsibility is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Net Responsibility is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Net Responsibility. If not, see <http://www.gnu.org/licenses/>. -// -// <SnifferThread> listens for HTTP requests, and makes sure they're getting logged -// Much of this code is inspired by examples provided by TCPDump and Winpcap - - - -#ifndef SNIFFERTHREAD_H -#define SNIFFERTHREAD_H - -#ifdef _MSC_VER -/* - * we do not want the warnings about the old deprecated and unsecure CRT functions - * since these examples can be compiled under *nix as well - */ -#define _CRT_SECURE_NO_WARNINGS -#endif - - -#include <iostream> -#include <fstream> -#include <vector> -#include <stdlib.h> -#include <stdio.h> -#include <ctype.h> -#include <sstream> - -#include "Poco/RegularExpression.h" -#include "Poco/SharedPtr.h" -#include "Poco/Runnable.h" -#include "Poco/Logger.h" -#include "Poco/LogStream.h" -#include "Poco/Net/HTTPRequest.h" -#include "Poco/Exception.h" - -#include "Database.h" -#include "Options.h" -#include "Filter.h" -#include "Blacklist.h" -#include "Sniffer.h" - -#include <pcap.h> - -#if defined(POCO_OS_FAMILY_WINDOWS) -#include <winsock2.h> -#elif defined (POCO_OS_FAMILY_UNIX) -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#endif //POCO_OS_FAMILY_ - - -#define LINE_LEN 32 - -/* default snap length (maximum bytes per packet to capture) */ -#define SNAP_LEN 1518 - -/* ethernet headers are always exactly 14 bytes [1] */ -#define SIZE_ETHERNET 14 - -/* Ethernet addresses are 6 bytes */ -#define ETHER_ADDR_LEN 6 - -/* This TCP header length seems to work. */ -#define SIZE_TCP 22 - -#define IP_HL(ip) (((ip)->ip_vhl) & 0x0f) -#define IP_V(ip) (((ip)->ip_vhl) >> 4) - - - -namespace NetResponsibility { - -using ::Poco::RegularExpression; -using ::Poco::SharedPtr; -using ::Poco::Logger; -using ::Poco::LogStream; -using ::Poco::Net::HTTPRequest; -using ::Poco::Exception; -using namespace ::std; - -/* TCP header */ -typedef u_int tcp_seq; - -struct sniff_ethernet; -struct sniff_ip; -struct sniff_tcp; - -class MainApplication; - -class SnifferThread: public ::Poco::Runnable - /// SnifferThread is a thread that listens for HTTP requests on a specific - /// interface, and makes sure they're getting logged. It is invoked by Sniffer. - /// Much of this code is inspired by examples provided by TCPDump and Winpcap -{ - public: - SnifferThread(); - /// Constructs SnifferThread and sets up some default values - - virtual void run(); - /// Run the SnifferThread. - - int openDevice(string device); - /// Open the given device. - - private: - pcap_t *_fp; - char _errbuf[PCAP_ERRBUF_SIZE]; - char *_sniffPattern; - Options *_options; - Filter *_filter; - LogStream *_logStream; - - void gotPacket(const struct pcap_pkthdr*, const u_char*, HTTPRequest&); -}; - -/* Ethernet header */ -struct sniff_ethernet { - u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */ - u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */ - u_short ether_type; /* IP? ARP? RARP? etc */ -}; - - - -/* IP header */ -struct sniff_ip { - u_char ip_vhl; /* version << 4 | header length >> 2 */ - u_char ip_tos; /* type of service */ - u_short ip_len; /* total length */ - u_short ip_id; /* identification */ - u_short ip_off; /* fragment offset field */ -#define IP_RF 0x8000 /* reserved fragment flag */ -#define IP_DF 0x4000 /* dont fragment flag */ -#define IP_MF 0x2000 /* more fragments flag */ -#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ - u_char ip_ttl; /* time to live */ - u_char ip_p; /* protocol */ - u_short ip_sum; /* checksum */ - struct in_addr ip_src,ip_dst; /* source and dest address */ -}; - -struct sniff_tcp { - u_short th_sport; /* source port */ - u_short th_dport; /* destination port */ - tcp_seq th_seq; /* sequence number */ - tcp_seq th_ack; /* acknowledgement number */ - u_char th_offx2; /* data offset, rsvd */ -#define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4) - u_char th_flags; -#define TH_FIN 0x01 -#define TH_SYN 0x02 -#define TH_RST 0x04 -#define TH_PUSH 0x08 -#define TH_ACK 0x10 -#define TH_URG 0x20 -#define TH_ECE 0x40 -#define TH_CWR 0x80 -#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR) - u_short th_win; /* window */ - u_short th_sum; /* checksum */ - u_short th_urp; /* urgent pointer */ -}; - -} // namespace NetResponsibility - -#include "MainApplication.h" - -#endif // SNIFFERTHREAD_H Added: branches/splitPlugins/plugins/DefaultReport/AUTHORS =================================================================== --- branches/splitPlugins/plugins/DefaultReport/AUTHORS (rev 0) +++ branches/splitPlugins/plugins/DefaultReport/AUTHORS 2012-07-05 16:31:59 UTC (rev 327) @@ -0,0 +1 @@ +Robert Rosman Added: branches/splitPlugins/plugins/DefaultReport/COPYING =================================================================== --- branches/splitPlugins/plugins/DefaultReport/COPYING (rev 0) +++ branches/splitPlugins/plugins/DefaultReport/COPYING 2012-07-05 16:31:59 UTC (rev 327) @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact y... [truncated message content] |
From: <rog...@us...> - 2012-07-02 12:23:42
|
Revision: 326 http://responsibility.svn.sourceforge.net/responsibility/?rev=326&view=rev Author: roggan87 Date: 2012-07-02 12:23:31 +0000 (Mon, 02 Jul 2012) Log Message: ----------- Added include guards in headers to avoid duplicate definitions. Added semicolons where needed. Added the new files to Makefile.am Modified Paths: -------------- branches/multiuser/Makefile.am branches/multiuser/include/ConnectionCache.h branches/multiuser/include/ConnectionCacheUpdateThread.h branches/multiuser/include/HTTPHit.h branches/multiuser/include/HTTPHitHandler.h branches/multiuser/include/Sniffer.h branches/multiuser/src/ConnectionCacheUpdateThread.cpp Modified: branches/multiuser/Makefile.am =================================================================== --- branches/multiuser/Makefile.am 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/Makefile.am 2012-07-02 12:23:31 UTC (rev 326) @@ -3,10 +3,14 @@ libNetResponsibility_la_SOURCES = \ @top_srcdir@/src/MainApplication.cpp\ @top_srcdir@/src/ConfigSubsystem.cpp\ + @top_srcdir@/src/ConnnectionCache.cpp\ + @top_srcdir@/src/ConnnectionCacheUpdateThread.cpp\ @top_srcdir@/src/Bypasses.cpp\ @top_srcdir@/src/Database.cpp\ @top_srcdir@/src/Filter.cpp\ @top_srcdir@/src/History.cpp\ + @top_srcdir@/src/HTTPHit.cpp\ + @top_srcdir@/src/HTTPHitHandler.cpp\ @top_srcdir@/src/MyXml.cpp\ @top_srcdir@/src/Options.cpp\ @top_srcdir@/src/ReportBase.cpp\ Modified: branches/multiuser/include/ConnectionCache.h =================================================================== --- branches/multiuser/include/ConnectionCache.h 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/include/ConnectionCache.h 2012-07-02 12:23:31 UTC (rev 326) @@ -1,3 +1,5 @@ +#ifndef CONNECTIONCACHE_H +#define CONNECTIONCACHE_H #include <cstdlib> #include <iostream> @@ -13,7 +15,7 @@ #include "Sniffer.h" using namespace std; - +/* Already defined enum { SS_UNKNOWN, SS_ESTABLISHED, @@ -29,7 +31,7 @@ SS_CLOSING, SS_MAX }; - +*/ #define SS_ALL ((1<<SS_MAX)-1) struct TCPConnection @@ -44,7 +46,6 @@ { public: ConnectionCache(); - void run(); int getUID(); static ConnectionCache& getCache(); @@ -53,9 +54,9 @@ static ConnectionCache* _instance; int get_uid_from_netlink(unsigned int destAddress, unsigned int srcAddress); - void run(); friend class ConnectionCacheUpdateThread; }; +#endif // CONNECTIONCACHE_H Modified: branches/multiuser/include/ConnectionCacheUpdateThread.h =================================================================== --- branches/multiuser/include/ConnectionCacheUpdateThread.h 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/include/ConnectionCacheUpdateThread.h 2012-07-02 12:23:31 UTC (rev 326) @@ -1,3 +1,6 @@ +#ifndef CONNECTIONCACHEUPDATETHREAD_H +#define CONNECTIONCACHEUPDATETHREAD_H + #include "ConnectionCache.h" #include <unistd.h> #include "Poco/Runnable.h" @@ -13,10 +16,12 @@ virtual void run(); private: vector<TCPConnection> _cache; - bool _timeToEnd = false; + bool _timeToEnd; int getTcpFromNetlink(); static int addToConnectionCache(const struct nlmsghdr *nlh, void *data); - int removeStale() + int removeStale(); int endThread(); -} +}; + +#endif // CONNECTIONCACHEUPDATETHREAD_H Modified: branches/multiuser/include/HTTPHit.h =================================================================== --- branches/multiuser/include/HTTPHit.h 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/include/HTTPHit.h 2012-07-02 12:23:31 UTC (rev 326) @@ -22,9 +22,9 @@ #include <iostream> #include <string> #include <sstream> -#include "/Poco/Net/HTTPRequest.h" -#include "/Poco/Net/HTTPResponse.h" -#include "/Poco/Net/HTTPMessage.h" +#include "Poco/Net/HTTPRequest.h" +#include "Poco/Net/HTTPResponse.h" +#include "Poco/Net/HTTPMessage.h" using Poco::Net::HTTPMessage; using Poco::Net::HTTPRequest; @@ -50,7 +50,7 @@ HTTPResponse _response; int _uid; -} +}; #endif //HTTPHIT_H Modified: branches/multiuser/include/HTTPHitHandler.h =================================================================== --- branches/multiuser/include/HTTPHitHandler.h 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/include/HTTPHitHandler.h 2012-07-02 12:23:31 UTC (rev 326) @@ -1,5 +1,7 @@ +#ifndef HTTPHITHANDLER_H +#define HTTPHITHANDLER_H //HTTPHitHandler.h -#include <vector.h> +#include <vector> #include "ConnectionCache.h" #include "Poco/Runnable.h" #include "HTTPHit.h" @@ -20,8 +22,10 @@ int handleHit(HTTPHit hit); protected: static void logUrl(HTTPRequest&); - static void logWarning(BlacklistMatch, ip_info); + static void logWarning(BlacklistMatch); ConnectionCache *_cache; Filter *_filter; Database *_db; -} +}; + +#endif // HTTPHITHANDLER_H Modified: branches/multiuser/include/Sniffer.h =================================================================== --- branches/multiuser/include/Sniffer.h 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/include/Sniffer.h 2012-07-02 12:23:31 UTC (rev 326) @@ -90,7 +90,7 @@ HTTPHitHandler _hitHandler; ConnectionCache _cache; - static HTTPHitHandler& getHTTPHitHandler() + static HTTPHitHandler& getHTTPHitHandler(); static LogStream& getLogStream(); vector<string> getDevices(); Modified: branches/multiuser/src/ConnectionCacheUpdateThread.cpp =================================================================== --- branches/multiuser/src/ConnectionCacheUpdateThread.cpp 2012-07-02 10:43:41 UTC (rev 325) +++ branches/multiuser/src/ConnectionCacheUpdateThread.cpp 2012-07-02 12:23:31 UTC (rev 326) @@ -5,6 +5,7 @@ _options = &MainApplication::getOptions(); _filter = &Sniffer::getFilter(); _cache = &ConnectionCache::getCache(); + _timeToEnd = false; } void ConnectionCacheUpdateThread::run() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpn...@us...> - 2012-07-02 10:43:48
|
Revision: 325 http://responsibility.svn.sourceforge.net/responsibility/?rev=325&view=rev Author: mpnordland Date: 2012-07-02 10:43:41 +0000 (Mon, 02 Jul 2012) Log Message: ----------- Adding all necessary sniffer and filter changes, along with some database changes. Report, and ReportBase changes are not done yet. Modified Paths: -------------- branches/multiuser/include/ConnectionCache.h branches/multiuser/include/Database.h branches/multiuser/include/Filter.h branches/multiuser/include/HTTPHit.h branches/multiuser/include/HTTPHitHandler.h branches/multiuser/include/Sniffer.h branches/multiuser/include/SnifferThread.h branches/multiuser/projectFiles/linux/net-responsibility.layout branches/multiuser/src/ConnectionCache.cpp branches/multiuser/src/Database.cpp branches/multiuser/src/Filter.cpp branches/multiuser/src/HTTPHitHandler.cpp branches/multiuser/src/Sniffer.cpp branches/multiuser/src/SnifferThread.cpp Modified: branches/multiuser/include/ConnectionCache.h =================================================================== --- branches/multiuser/include/ConnectionCache.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/ConnectionCache.h 2012-07-02 10:43:41 UTC (rev 325) @@ -43,14 +43,15 @@ class ConnectionCache { public: - ConnectionCache(unsigned int srcAddress, unsigned int destAddress); + ConnectionCache(); void run(); + int getUID(); + static ConnectionCache& getCache(); private: vector<TCPConnection> tcpConnectionList; static ConnectionCache* _instance; - static ConnectionCache& getCache(); int get_uid_from_netlink(unsigned int destAddress, unsigned int srcAddress); void run(); Modified: branches/multiuser/include/Database.h =================================================================== --- branches/multiuser/include/Database.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/Database.h 2012-07-02 10:43:41 UTC (rev 325) @@ -33,7 +33,8 @@ #include "Options.h" #include "History.h" #include "Warnings.h" -#include "Bypasses.h" +#include "Bypasses.h" +#include "HTTPHit.h" #include <iostream> #include <vector> Modified: branches/multiuser/include/Filter.h =================================================================== --- branches/multiuser/include/Filter.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/Filter.h 2012-07-02 10:43:41 UTC (rev 325) @@ -19,7 +19,8 @@ #define FILTER_H #include "Blacklist.h" -#include "MyXml.h" +#include "MyXml.h" +#include "HTTPHit.h" #include <iostream> #include <fstream> @@ -47,9 +48,9 @@ Filter(); Filter(string); Filter(Options*, Database*); - bool isMatch(HTTPRequest&, BlacklistMatch&), - isUrlMatch(HTTPRequest&, BlacklistMatch&), - isTokenMatch(HTTPRequest&, BlacklistMatch&); + bool isMatch(HTTPHit&, BlacklistMatch&), + isUrlMatch(HTTPHit&, BlacklistMatch&), + isTokenMatch(HTTPHit&, BlacklistMatch&); void loadBlacklist(string); void loadBlacklist(Options*, Database*); Modified: branches/multiuser/include/HTTPHit.h =================================================================== --- branches/multiuser/include/HTTPHit.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/HTTPHit.h 2012-07-02 10:43:41 UTC (rev 325) @@ -42,11 +42,13 @@ HTTPResponse* getResponse(); int getUser(); void setUser(int uid); + int src, dest; + string _url; protected: HTTPRequest _request; HTTPResponse _response; - string _url; + int _uid; } Modified: branches/multiuser/include/HTTPHitHandler.h =================================================================== --- branches/multiuser/include/HTTPHitHandler.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/HTTPHitHandler.h 2012-07-02 10:43:41 UTC (rev 325) @@ -13,7 +13,7 @@ class MainApplication; -class HTTPHitHandler public: Poco::Runnable +class HTTPHitHandler { public: HTTPHitHandler(); Modified: branches/multiuser/include/Sniffer.h =================================================================== --- branches/multiuser/include/Sniffer.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/Sniffer.h 2012-07-02 10:43:41 UTC (rev 325) @@ -45,7 +45,10 @@ #include "Options.h" #include "Filter.h" #include "Blacklist.h" -#include "SnifferThread.h" +#include "SnifferThread.h" +#include "HTTPHitHandler.h" +#include "ConnectionCache.h" +#include "ConnectionCacheUpdateThread.h" #include <pcap.h> @@ -84,8 +87,10 @@ LogStream *_logStream; static Sniffer* _instance; char _errbuf[PCAP_ERRBUF_SIZE]; - - static Filter& getFilter(); + HTTPHitHandler _hitHandler; + ConnectionCache _cache; + + static HTTPHitHandler& getHTTPHitHandler() static LogStream& getLogStream(); vector<string> getDevices(); Modified: branches/multiuser/include/SnifferThread.h =================================================================== --- branches/multiuser/include/SnifferThread.h 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/include/SnifferThread.h 2012-07-02 10:43:41 UTC (rev 325) @@ -51,7 +51,8 @@ #include "Filter.h" #include "Blacklist.h" #include "Sniffer.h" -#include "UID.h" +#include "HTTPHit.h" +#include "HTTPHitHandler.h" #include <pcap.h> #if defined(POCO_OS_FAMILY_WINDOWS) @@ -109,9 +110,8 @@ pcap_t *_fp; char _errbuf[PCAP_ERRBUF_SIZE]; char *_sniffPattern; - Options *_options; - Filter *_filter; - LogStream *_logStream; + LogStream *_logStream; + HTTPHitHandler *_hitHandler; void gotPacket(const struct pcap_pkthdr*, const u_char*, HTTPRequest&, int&); }; Modified: branches/multiuser/projectFiles/linux/net-responsibility.layout =================================================================== --- branches/multiuser/projectFiles/linux/net-responsibility.layout 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/projectFiles/linux/net-responsibility.layout 2012-07-02 10:43:41 UTC (rev 325) @@ -4,37 +4,40 @@ <File name="../../config.h" open="0" top="0" tabpos="11"> <Cursor position="879" topLine="0" /> </File> - <File name="../../include/Blacklist.h" open="1" top="0" tabpos="22"> - <Cursor position="2485" topLine="136" /> + <File name="../../include/Blacklist.h" open="1" top="0" tabpos="41"> + <Cursor position="3787" topLine="50" /> </File> - <File name="../../include/Bypasses.h" open="1" top="0" tabpos="24"> + <File name="../../include/Bypasses.h" open="1" top="0" tabpos="23"> <Cursor position="2114" topLine="34" /> </File> - <File name="../../include/ConfigSubsystem.h" open="1" top="0" tabpos="38"> + <File name="../../include/ConfigSubsystem.h" open="1" top="0" tabpos="36"> <Cursor position="0" topLine="15" /> </File> - <File name="../../include/ConnectionCache.h" open="1" top="0" tabpos="35"> - <Cursor position="1065" topLine="20" /> + <File name="../../include/ConnectionCache.h" open="1" top="0" tabpos="33"> + <Cursor position="826" topLine="19" /> </File> - <File name="../../include/ConnectionCacheUpdateThread.h" open="1" top="0" tabpos="37"> + <File name="../../include/ConnectionCacheUpdateThread.h" open="1" top="0" tabpos="35"> <Cursor position="525" topLine="0" /> </File> <File name="../../include/Database.h" open="1" top="0" tabpos="28"> - <Cursor position="2738" topLine="56" /> + <Cursor position="1310" topLine="11" /> </File> - <File name="../../include/Filter.h" open="1" top="0" tabpos="18"> - <Cursor position="1342" topLine="30" /> + <File name="../../include/Filter.h" open="1" top="0" tabpos="19"> + <Cursor position="897" topLine="9" /> </File> <File name="../../include/HTTPHit.h" open="1" top="0" tabpos="31"> - <Cursor position="1275" topLine="11" /> + <Cursor position="1351" topLine="14" /> </File> + <File name="../../include/HTTPHitHandler.h" open="1" top="0" tabpos="40"> + <Cursor position="290" topLine="0" /> + </File> <File name="../../include/History.h" open="1" top="0" tabpos="30"> <Cursor position="0" topLine="60" /> </File> <File name="../../include/MainApplication.h" open="1" top="0" tabpos="21"> <Cursor position="2876" topLine="74" /> </File> - <File name="../../include/MyXml.h" open="1" top="0" tabpos="26"> + <File name="../../include/MyXml.h" open="1" top="0" tabpos="25"> <Cursor position="1051" topLine="14" /> </File> <File name="../../include/Options.h" open="1" top="0" tabpos="22"> @@ -46,101 +49,101 @@ <File name="../../include/PluginBase.h" open="1" top="0" tabpos="33"> <Cursor position="67" topLine="0" /> </File> - <File name="../../include/Report.h" open="1" top="0" tabpos="23"> - <Cursor position="1318" topLine="47" /> + <File name="../../include/Report.h" open="1" top="0" tabpos="22"> + <Cursor position="1885" topLine="49" /> </File> <File name="../../include/ReportBase.h" open="1" top="0" tabpos="22"> <Cursor position="1817" topLine="28" /> </File> - <File name="../../include/ReportSubsystem.h" open="1" top="0" tabpos="25"> + <File name="../../include/ReportSubsystem.h" open="1" top="0" tabpos="24"> <Cursor position="1141" topLine="28" /> </File> <File name="../../include/Request.h" open="1" top="0" tabpos="20"> <Cursor position="1635" topLine="35" /> </File> - <File name="../../include/Sniffer.h" open="1" top="0" tabpos="19"> - <Cursor position="2126" topLine="56" /> + <File name="../../include/Sniffer.h" open="1" top="0" tabpos="11"> + <Cursor position="2395" topLine="60" /> </File> - <File name="../../include/SnifferSubsystem.h" open="1" top="0" tabpos="39"> + <File name="../../include/SnifferSubsystem.h" open="1" top="0" tabpos="37"> <Cursor position="1364" topLine="17" /> </File> - <File name="../../include/SnifferThread.h" open="1" top="0" tabpos="27"> - <Cursor position="2765" topLine="94" /> + <File name="../../include/SnifferThread.h" open="1" top="0" tabpos="26"> + <Cursor position="2909" topLine="92" /> </File> - <File name="../../include/UID.h" open="1" top="0" tabpos="33"> + <File name="../../include/UID.h" open="0" top="0" tabpos="33"> <Cursor position="1147" topLine="11" /> </File> <File name="../../include/Warnings.h" open="1" top="0" tabpos="29"> - <Cursor position="428" topLine="5" /> + <Cursor position="428" topLine="7" /> </File> - <File name="../../src/Bypasses.cpp" open="1" top="0" tabpos="14"> + <File name="../../src/Bypasses.cpp" open="1" top="0" tabpos="15"> <Cursor position="3150" topLine="151" /> </File> - <File name="../../src/ConfigSubsystem.cpp" open="1" top="0" tabpos="11"> + <File name="../../src/ConfigSubsystem.cpp" open="1" top="0" tabpos="10"> <Cursor position="1586" topLine="29" /> </File> - <File name="../../src/ConnectionCache.cpp" open="1" top="0" tabpos="36"> - <Cursor position="387" topLine="0" /> + <File name="../../src/ConnectionCache.cpp" open="1" top="0" tabpos="34"> + <Cursor position="70" topLine="0" /> </File> - <File name="../../src/ConnectionCacheUpdateThread.cpp" open="1" top="0" tabpos="40"> + <File name="../../src/ConnectionCacheUpdateThread.cpp" open="1" top="0" tabpos="38"> <Cursor position="292" topLine="12" /> </File> <File name="../../src/Database.cpp" open="1" top="0" tabpos="2"> - <Cursor position="4017" topLine="113" /> + <Cursor position="3383" topLine="81" /> </File> - <File name="../../src/Filter.cpp" open="1" top="0" tabpos="7"> - <Cursor position="1528" topLine="127" /> + <File name="../../src/Filter.cpp" open="1" top="0" tabpos="6"> + <Cursor position="2629" topLine="5" /> </File> <File name="../../src/HTTPHit.cpp" open="1" top="0" tabpos="32"> <Cursor position="539" topLine="0" /> </File> - <File name="../../src/HTTPHitHandler.cpp" open="1" top="0" tabpos="41"> - <Cursor position="0" topLine="0" /> + <File name="../../src/HTTPHitHandler.cpp" open="1" top="0" tabpos="39"> + <Cursor position="549" topLine="0" /> </File> - <File name="../../src/History.cpp" open="1" top="0" tabpos="6"> + <File name="../../src/History.cpp" open="1" top="0" tabpos="5"> <Cursor position="723" topLine="113" /> </File> - <File name="../../src/MainApplication.cpp" open="1" top="0" tabpos="12"> + <File name="../../src/MainApplication.cpp" open="1" top="0" tabpos="13"> <Cursor position="7843" topLine="256" /> </File> - <File name="../../src/MyXml.cpp" open="1" top="0" tabpos="17"> + <File name="../../src/MyXml.cpp" open="1" top="0" tabpos="18"> <Cursor position="3782" topLine="108" /> </File> - <File name="../../src/Options.cpp" open="1" top="0" tabpos="9"> + <File name="../../src/Options.cpp" open="1" top="0" tabpos="8"> <Cursor position="1994" topLine="85" /> </File> - <File name="../../src/Plugin.cpp" open="1" top="0" tabpos="15"> + <File name="../../src/Plugin.cpp" open="1" top="0" tabpos="16"> <Cursor position="792" topLine="6" /> </File> <File name="../../src/PluginBase.cpp" open="1" top="0" tabpos="22"> <Cursor position="0" topLine="0" /> </File> - <File name="../../src/Report.cpp" open="1" top="0" tabpos="3"> - <Cursor position="8934" topLine="197" /> + <File name="../../src/Report.cpp" open="1" top="1" tabpos="3"> + <Cursor position="2301" topLine="186" /> </File> - <File name="../../src/ReportBase.cpp" open="1" top="0" tabpos="16"> + <File name="../../src/ReportBase.cpp" open="1" top="0" tabpos="17"> <Cursor position="1689" topLine="172" /> </File> - <File name="../../src/ReportSubsystem.cpp" open="1" top="0" tabpos="10"> + <File name="../../src/ReportSubsystem.cpp" open="1" top="0" tabpos="9"> <Cursor position="1078" topLine="4" /> </File> - <File name="../../src/Request.cpp" open="1" top="0" tabpos="5"> - <Cursor position="1830" topLine="9" /> + <File name="../../src/Request.cpp" open="1" top="0" tabpos="4"> + <Cursor position="1830" topLine="0" /> </File> - <File name="../../src/Sniffer.cpp" open="1" top="0" tabpos="4"> - <Cursor position="980" topLine="33" /> + <File name="../../src/Sniffer.cpp" open="1" top="0" tabpos="12"> + <Cursor position="1591" topLine="6" /> </File> - <File name="../../src/SnifferSubsystem.cpp" open="1" top="0" tabpos="13"> + <File name="../../src/SnifferSubsystem.cpp" open="1" top="0" tabpos="14"> <Cursor position="1886" topLine="0" /> </File> - <File name="../../src/SnifferThread.cpp" open="1" top="1" tabpos="22"> - <Cursor position="2373" topLine="66" /> + <File name="../../src/SnifferThread.cpp" open="1" top="0" tabpos="27"> + <Cursor position="2302" topLine="63" /> </File> - <File name="../../src/UID.cpp" open="1" top="0" tabpos="34"> + <File name="../../src/UID.cpp" open="0" top="0" tabpos="34"> <Cursor position="2770" topLine="50" /> </File> - <File name="../../src/Warnings.cpp" open="1" top="0" tabpos="8"> - <Cursor position="627" topLine="54" /> + <File name="../../src/Warnings.cpp" open="1" top="0" tabpos="7"> + <Cursor position="627" topLine="0" /> </File> <File name="../../src/main.cpp" open="1" top="0" tabpos="1"> <Cursor position="727" topLine="0" /> Modified: branches/multiuser/src/ConnectionCache.cpp =================================================================== --- branches/multiuser/src/ConnectionCache.cpp 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/src/ConnectionCache.cpp 2012-07-02 10:43:41 UTC (rev 325) @@ -9,12 +9,6 @@ } -// What do we need to do with the threads here? -void ConnectionCache::run() -{ - ConnectionCacheUpdateThread updateThread(); - updateThread.run(); -} int ConnectionCache::getUID (unsigned int destAddress, unsigned int srcAddress) { @@ -32,3 +26,8 @@ return 0; } + +ConnectionCache& ConnectionCache::getCache() +{ + return *_instance; +} Modified: branches/multiuser/src/Database.cpp =================================================================== --- branches/multiuser/src/Database.cpp 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/src/Database.cpp 2012-07-02 10:43:41 UTC (rev 325) @@ -92,13 +92,13 @@ } -void Database::logUrl(HTTPRequest& request) +void Database::logUrl(HTTPHit& hit) { const int FINISHED = 10; for (int i = 0; i <= FINISHED; i++) { try { - _hostname = request.getHost(); - _path = request.getURI(); + _hostname = hit.getRequest().getHost(); + _path = hit.getRequest().getURI(); _timestamp.update(); _date = _time = _timestamp.epochTime(); _logUrlStatement->execute(); Modified: branches/multiuser/src/Filter.cpp =================================================================== --- branches/multiuser/src/Filter.cpp 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/src/Filter.cpp 2012-07-02 10:43:41 UTC (rev 325) @@ -82,17 +82,17 @@ -bool Filter::isMatch(HTTPRequest& request, BlacklistMatch& blacklistMatch) { - return isUrlMatch(request, blacklistMatch) - && isTokenMatch(request, blacklistMatch); +bool Filter::isMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch) { + return isUrlMatch(hit, blacklistMatch) + && isTokenMatch(hit, blacklistMatch); } -bool Filter::isUrlMatch(HTTPRequest& request, BlacklistMatch& blacklistMatch) { +bool Filter::isUrlMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch) { blacklistMatch.keyword.clear(); blacklistMatch.whitelist = false; - string url = request.getHost() + request.getURI(), + string url = hit._url, boldUrl = url; bool isSubMatch, isMatch = false; @@ -136,7 +136,7 @@ -bool Filter::isTokenMatch(HTTPRequest& request, BlacklistMatch& blacklistMatch) { +bool Filter::isTokenMatch(HTTPHit& hit, BlacklistMatch& blacklistMatch) { bool isSubMatch, isMatch = false; RegularExpression::Match m, n; @@ -145,7 +145,7 @@ wordFactor = 0.5; int tokenMatches = 0; unsigned int o = 0; - string url = request.getHost() + request.getURI(), + string url = hit._url, token, decodedUrl = ""; try { Modified: branches/multiuser/src/HTTPHitHandler.cpp =================================================================== --- branches/multiuser/src/HTTPHitHandler.cpp 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/src/HTTPHitHandler.cpp 2012-07-02 10:43:41 UTC (rev 325) @@ -12,12 +12,13 @@ HTTPHitHandler::handleHit(HTTPHit hit) { + BlacklistMatch match; hit._uid = _cache->getUID(hit.src, hit.dest); - isMatch = _filter->isMatch(request, match); - HTTPHitHandler::logUrl(request); + isMatch = _filter->isMatch(hit, match); + HTTPHitHandler::logUrl(hit); if (isMatch) - HTTPHitHandler::logWarning(match); + HTTPHitHandler::logWarning(match, hit.getUser()); if (isDebugging) *_logStream <<isMatch <<endl; Modified: branches/multiuser/src/Sniffer.cpp =================================================================== --- branches/multiuser/src/Sniffer.cpp 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/src/Sniffer.cpp 2012-07-02 10:43:41 UTC (rev 325) @@ -28,7 +28,9 @@ Sniffer::Sniffer() { _instance = this; _logStream = new LogStream(Application::instance().logger()); - _logStream->warning(); + _logStream->warning(); + _hitHandler = new HTTPHitHandler; + _cache = new ConnectionCache; } @@ -42,31 +44,25 @@ threads.pop_back(); else Poco::ThreadPool::defaultPool().start(*(threads.back())); - } + } + Poco::ThreadPool::defaultPool().start(new ConnectionCacheUpdateThread); Poco::ThreadPool::defaultPool().joinAll(); } -Filter& Sniffer::getFilter() { - return *_instance->_filter; -} - LogStream& Sniffer::getLogStream() { return *_instance->_logStream; } +HTTPHitHandler& Sniffer::getHTTPHitHandler() { + return *_instance->_hitHandler; +} - - - - - - vector<string> Sniffer::getDevices() { vector<string> devices; pcap_if_t *alldevs, Modified: branches/multiuser/src/SnifferThread.cpp =================================================================== --- branches/multiuser/src/SnifferThread.cpp 2012-06-23 22:32:27 UTC (rev 324) +++ branches/multiuser/src/SnifferThread.cpp 2012-07-02 10:43:41 UTC (rev 325) @@ -25,9 +25,9 @@ SnifferThread::SnifferThread() { _logStream = &Sniffer::getLogStream(); - _options = &MainApplication::getOptions(); - _filter = &Sniffer::getFilter(); - _sniffPattern = (char*)"tcp[20:4] = 0x47455420 or tcp[32:4] = 0x47455420"; + _sniffPattern = (char*)"tcp[20:4] = 0x47455420 or tcp[32:4] = 0x47455420"; + _hitHandler = &Sniffer::getHTTPHitHandler(); + } @@ -75,10 +75,8 @@ urlId; struct pcap_pkthdr *header; const u_char *pkt_data; - BlacklistMatch match; HTTPHit hit; - int uid; - request.setChunkedTransferEncoding(true); + hit.getRequest().setChunkedTransferEncoding(true); bool isMatch, isDebugging = Application::instance().config().getBool("debug", false); @@ -87,8 +85,8 @@ if (res == 0) continue; - gotPacket(header, pkt_data, request, addrs); - if (request.empty()) + gotPacket(header, pkt_data, hit); + if (hit.getRequest().empty()) throw Poco::Exception("No message found"); } catch (Poco::Exception &err) { @@ -108,20 +106,17 @@ void SnifferThread::gotPacket(const struct pcap_pkthdr *header, - const u_char *packet, HTTPRequest& request, int& uid) + const u_char *packet, HTTPHit& hit) { - request.clear(); + hit.getRequest().clear(); /* declare pointers to packet headers */ const struct sniff_ethernet *ethernet; /* The ethernet header [1] */ const struct sniff_ip *ip; /* The IP header */ const struct sniff_tcp *tcp; /* The TCP header */ const char *payload; /* Packet payload */ - UID int size_ip, size_tcp, size_payload; - src_addr; - dest_addr; /* define ethernet header */ ethernet = (struct sniff_ethernet*)(packet); @@ -152,11 +147,10 @@ payload = (const char*)(packet + SIZE_ETHERNET + size_ip + 10); istringstream istr(payload); - request.read(istr); - src_addr = ip->ip_src.s_addr; - dest_addr = ip->ip_dest.s_addr; - UID uidGet = UID(src_addr, dest_addr); - uid = uidGet.get_int(); + hit.getRequest().read(istr); + hit.src = ip->ip_src.s_addr; + hit.dest = ip->ip_dest.s_addr; + _hitHandler->handleHit(hit); } catch (Poco::Exception &err) { request.clear(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpn...@us...> - 2012-06-23 22:32:34
|
Revision: 324 http://responsibility.svn.sourceforge.net/responsibility/?rev=324&view=rev Author: mpnordland Date: 2012-06-23 22:32:27 +0000 (Sat, 23 Jun 2012) Log Message: ----------- All the new classes necessary are done. This commit should add them. Modified Paths: -------------- branches/multiuser/include/HTTPHit.h branches/multiuser/include/Sniffer.h branches/multiuser/projectFiles/linux/net-responsibility.cbp branches/multiuser/projectFiles/linux/net-responsibility.layout branches/multiuser/src/HTTPHit.cpp branches/multiuser/src/Sniffer.cpp branches/multiuser/src/SnifferThread.cpp Added Paths: ----------- branches/multiuser/include/ConnectionCache.h branches/multiuser/include/ConnectionCacheUpdateThread.h branches/multiuser/include/HTTPHitHandler.h branches/multiuser/src/ConnectionCache.cpp branches/multiuser/src/ConnectionCacheUpdateThread.cpp branches/multiuser/src/HTTPHitHandler.cpp Added: branches/multiuser/include/ConnectionCache.h =================================================================== --- branches/multiuser/include/ConnectionCache.h (rev 0) +++ branches/multiuser/include/ConnectionCache.h 2012-06-23 22:32:27 UTC (rev 324) @@ -0,0 +1,60 @@ + +#include <cstdlib> +#include <iostream> +#include <sys/socket.h> +#include <netinet/in.h> +#include <cstring> +#include <linux/netlink.h> +#include <vector> +#include <linux/inet_diag.h> +#include "Poco/Timestamp.h" +#include <libmnl/libmnl.h> +#include <arpa/inet.h> +#include "Sniffer.h" + +using namespace std; + +enum { + SS_UNKNOWN, + SS_ESTABLISHED, + SS_SYN_SENT, + SS_SYN_RECV, + SS_FIN_WAIT1, + SS_FIN_WAIT2, + SS_TIME_WAIT, + SS_CLOSE, + SS_CLOSE_WAIT, + SS_LAST_ACK, + SS_LISTEN, + SS_CLOSING, + SS_MAX +}; + +#define SS_ALL ((1<<SS_MAX)-1) + +struct TCPConnection +{ + unsigned int destAddress; + unsigned int srcAddress; + Poco::Timestamp timeAdded; + int uid; +}; + +class ConnectionCache +{ + public: + ConnectionCache(unsigned int srcAddress, unsigned int destAddress); + void run(); + + private: + vector<TCPConnection> tcpConnectionList; + static ConnectionCache* _instance; + + static ConnectionCache& getCache(); + int get_uid_from_netlink(unsigned int destAddress, unsigned int srcAddress); + void run(); + + friend class ConnectionCacheUpdateThread; + +}; + Added: branches/multiuser/include/ConnectionCacheUpdateThread.h =================================================================== --- branches/multiuser/include/ConnectionCacheUpdateThread.h (rev 0) +++ branches/multiuser/include/ConnectionCacheUpdateThread.h 2012-06-23 22:32:27 UTC (rev 324) @@ -0,0 +1,22 @@ +#include "ConnectionCache.h" +#include <unistd.h> +#include "Poco/Runnable.h" +#include "Poco/Timestamp.h" +using namespace std; +using Poco::Timestamp; + + +class ConnectionCacheUpdateThread: public Poco::Runnable +{ + public: + ConnectionCacheUpdateThread(); + virtual void run(); + private: + vector<TCPConnection> _cache; + bool _timeToEnd = false; + + int getTcpFromNetlink(); + static int addToConnectionCache(const struct nlmsghdr *nlh, void *data); + int removeStale() + int endThread(); +} Modified: branches/multiuser/include/HTTPHit.h =================================================================== --- branches/multiuser/include/HTTPHit.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/include/HTTPHit.h 2012-06-23 22:32:27 UTC (rev 324) @@ -35,14 +35,19 @@ { public: + HTTPHit(); virtual void read(string); HTTPRequest* getRequest(); HTTPResponse* getResponse(); + int getUser(); + void setUser(int uid); + protected: HTTPRequest _request; HTTPResponse _response; string _url; + int _uid; } Added: branches/multiuser/include/HTTPHitHandler.h =================================================================== --- branches/multiuser/include/HTTPHitHandler.h (rev 0) +++ branches/multiuser/include/HTTPHitHandler.h 2012-06-23 22:32:27 UTC (rev 324) @@ -0,0 +1,27 @@ +//HTTPHitHandler.h +#include <vector.h> +#include "ConnectionCache.h" +#include "Poco/Runnable.h" +#include "HTTPHit.h" +#include "Database.h" +#include "Filter.h" +#include "Blacklist.h" +#include "Sniffer.h" +#include "Options.h" + +using namespace std; + +class MainApplication; + +class HTTPHitHandler public: Poco::Runnable +{ + public: + HTTPHitHandler(); + int handleHit(HTTPHit hit); + protected: + static void logUrl(HTTPRequest&); + static void logWarning(BlacklistMatch, ip_info); + ConnectionCache *_cache; + Filter *_filter; + Database *_db; +} Modified: branches/multiuser/include/Sniffer.h =================================================================== --- branches/multiuser/include/Sniffer.h 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/include/Sniffer.h 2012-06-23 22:32:27 UTC (rev 324) @@ -81,16 +81,12 @@ void run(); private: - Filter *_filter; - Database *_db; LogStream *_logStream; static Sniffer* _instance; char _errbuf[PCAP_ERRBUF_SIZE]; static Filter& getFilter(); static LogStream& getLogStream(); - static void logUrl(HTTPRequest&); - static void logWarning(BlacklistMatch, ip_info); vector<string> getDevices(); friend class SnifferThread; Modified: branches/multiuser/projectFiles/linux/net-responsibility.cbp =================================================================== --- branches/multiuser/projectFiles/linux/net-responsibility.cbp 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/projectFiles/linux/net-responsibility.cbp 2012-06-23 22:32:27 UTC (rev 324) @@ -145,9 +145,12 @@ <Unit filename="../../include/Blacklist.h" /> <Unit filename="../../include/Bypasses.h" /> <Unit filename="../../include/ConfigSubsystem.h" /> + <Unit filename="../../include/ConnectionCache.h" /> + <Unit filename="../../include/ConnectionCacheUpdateThread.h" /> <Unit filename="../../include/Database.h" /> <Unit filename="../../include/Filter.h" /> <Unit filename="../../include/HTTPHit.h" /> + <Unit filename="../../include/HTTPHitHandler.h" /> <Unit filename="../../include/History.h" /> <Unit filename="../../include/MainApplication.h" /> <Unit filename="../../include/MyXml.h" /> @@ -165,9 +168,12 @@ <Unit filename="../../include/Warnings.h" /> <Unit filename="../../src/Bypasses.cpp" /> <Unit filename="../../src/ConfigSubsystem.cpp" /> + <Unit filename="../../src/ConnectionCache.cpp" /> + <Unit filename="../../src/ConnectionCacheUpdateThread.cpp" /> <Unit filename="../../src/Database.cpp" /> <Unit filename="../../src/Filter.cpp" /> <Unit filename="../../src/HTTPHit.cpp" /> + <Unit filename="../../src/HTTPHitHandler.cpp" /> <Unit filename="../../src/History.cpp" /> <Unit filename="../../src/MainApplication.cpp" /> <Unit filename="../../src/MyXml.cpp" /> Modified: branches/multiuser/projectFiles/linux/net-responsibility.layout =================================================================== --- branches/multiuser/projectFiles/linux/net-responsibility.layout 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/projectFiles/linux/net-responsibility.layout 2012-06-23 22:32:27 UTC (rev 324) @@ -10,9 +10,15 @@ <File name="../../include/Bypasses.h" open="1" top="0" tabpos="24"> <Cursor position="2114" topLine="34" /> </File> - <File name="../../include/ConfigSubsystem.h" open="1" top="0" tabpos="22"> - <Cursor position="0" topLine="20" /> + <File name="../../include/ConfigSubsystem.h" open="1" top="0" tabpos="38"> + <Cursor position="0" topLine="15" /> </File> + <File name="../../include/ConnectionCache.h" open="1" top="0" tabpos="35"> + <Cursor position="1065" topLine="20" /> + </File> + <File name="../../include/ConnectionCacheUpdateThread.h" open="1" top="0" tabpos="37"> + <Cursor position="525" topLine="0" /> + </File> <File name="../../include/Database.h" open="1" top="0" tabpos="28"> <Cursor position="2738" topLine="56" /> </File> @@ -20,7 +26,7 @@ <Cursor position="1342" topLine="30" /> </File> <File name="../../include/HTTPHit.h" open="1" top="0" tabpos="31"> - <Cursor position="1350" topLine="8" /> + <Cursor position="1275" topLine="11" /> </File> <File name="../../include/History.h" open="1" top="0" tabpos="30"> <Cursor position="0" topLine="60" /> @@ -53,37 +59,49 @@ <Cursor position="1635" topLine="35" /> </File> <File name="../../include/Sniffer.h" open="1" top="0" tabpos="19"> - <Cursor position="2423" topLine="57" /> + <Cursor position="2126" topLine="56" /> </File> - <File name="../../include/SnifferSubsystem.h" open="1" top="0" tabpos="22"> - <Cursor position="1364" topLine="22" /> + <File name="../../include/SnifferSubsystem.h" open="1" top="0" tabpos="39"> + <Cursor position="1364" topLine="17" /> </File> <File name="../../include/SnifferThread.h" open="1" top="0" tabpos="27"> - <Cursor position="4886" topLine="91" /> + <Cursor position="2765" topLine="94" /> </File> + <File name="../../include/UID.h" open="1" top="0" tabpos="33"> + <Cursor position="1147" topLine="11" /> + </File> <File name="../../include/Warnings.h" open="1" top="0" tabpos="29"> <Cursor position="428" topLine="5" /> </File> <File name="../../src/Bypasses.cpp" open="1" top="0" tabpos="14"> - <Cursor position="3150" topLine="149" /> + <Cursor position="3150" topLine="151" /> </File> <File name="../../src/ConfigSubsystem.cpp" open="1" top="0" tabpos="11"> <Cursor position="1586" topLine="29" /> </File> + <File name="../../src/ConnectionCache.cpp" open="1" top="0" tabpos="36"> + <Cursor position="387" topLine="0" /> + </File> + <File name="../../src/ConnectionCacheUpdateThread.cpp" open="1" top="0" tabpos="40"> + <Cursor position="292" topLine="12" /> + </File> <File name="../../src/Database.cpp" open="1" top="0" tabpos="2"> <Cursor position="4017" topLine="113" /> </File> <File name="../../src/Filter.cpp" open="1" top="0" tabpos="7"> <Cursor position="1528" topLine="127" /> </File> - <File name="../../src/HTTPHit.cpp" open="1" top="1" tabpos="32"> - <Cursor position="306" topLine="0" /> + <File name="../../src/HTTPHit.cpp" open="1" top="0" tabpos="32"> + <Cursor position="539" topLine="0" /> </File> + <File name="../../src/HTTPHitHandler.cpp" open="1" top="0" tabpos="41"> + <Cursor position="0" topLine="0" /> + </File> <File name="../../src/History.cpp" open="1" top="0" tabpos="6"> <Cursor position="723" topLine="113" /> </File> <File name="../../src/MainApplication.cpp" open="1" top="0" tabpos="12"> - <Cursor position="6939" topLine="3" /> + <Cursor position="7843" topLine="256" /> </File> <File name="../../src/MyXml.cpp" open="1" top="0" tabpos="17"> <Cursor position="3782" topLine="108" /> @@ -104,20 +122,23 @@ <Cursor position="1689" topLine="172" /> </File> <File name="../../src/ReportSubsystem.cpp" open="1" top="0" tabpos="10"> - <Cursor position="1078" topLine="28" /> + <Cursor position="1078" topLine="4" /> </File> <File name="../../src/Request.cpp" open="1" top="0" tabpos="5"> <Cursor position="1830" topLine="9" /> </File> <File name="../../src/Sniffer.cpp" open="1" top="0" tabpos="4"> - <Cursor position="1956" topLine="35" /> + <Cursor position="980" topLine="33" /> </File> <File name="../../src/SnifferSubsystem.cpp" open="1" top="0" tabpos="13"> - <Cursor position="1886" topLine="24" /> + <Cursor position="1886" topLine="0" /> </File> - <File name="../../src/SnifferThread.cpp" open="1" top="0" tabpos="22"> - <Cursor position="2793" topLine="53" /> + <File name="../../src/SnifferThread.cpp" open="1" top="1" tabpos="22"> + <Cursor position="2373" topLine="66" /> </File> + <File name="../../src/UID.cpp" open="1" top="0" tabpos="34"> + <Cursor position="2770" topLine="50" /> + </File> <File name="../../src/Warnings.cpp" open="1" top="0" tabpos="8"> <Cursor position="627" topLine="54" /> </File> Added: branches/multiuser/src/ConnectionCache.cpp =================================================================== --- branches/multiuser/src/ConnectionCache.cpp (rev 0) +++ branches/multiuser/src/ConnectionCache.cpp 2012-06-23 22:32:27 UTC (rev 324) @@ -0,0 +1,34 @@ +#include "ConnectionCache.h" +//copied from Sniffer, may need adapting + +ConnectionCache* ConnectionCache::_instance = 0; + +ConnectionCache::ConnectionCache(unsigned int srcAddress, unsigned int destAddress) +{ + _instance = this; + +} + +// What do we need to do with the threads here? +void ConnectionCache::run() +{ + ConnectionCacheUpdateThread updateThread(); + updateThread.run(); +} + +int ConnectionCache::getUID (unsigned int destAddress, unsigned int srcAddress) +{ + vector<TCPConnection>::iterator it; + for (it = this->tcpConnectionList.begin(); it < this->tcpConnectionList.end(); it++) + { + //cout << it->uid << endl; + if (it->destAddress == destAddress && it->srcAddress == srcAddress) + { + cout << "match:" << endl; + cout << it->uitid << endl; + return it->uid; + } + } + return 0; + +} Added: branches/multiuser/src/ConnectionCacheUpdateThread.cpp =================================================================== --- branches/multiuser/src/ConnectionCacheUpdateThread.cpp (rev 0) +++ branches/multiuser/src/ConnectionCacheUpdateThread.cpp 2012-06-23 22:32:27 UTC (rev 324) @@ -0,0 +1,98 @@ + +ConnectionCacheUpdateThread::ConnectionCacheUpdateThread() +{ + _logStream = &Sniffer::getLogStream(); + _options = &MainApplication::getOptions(); + _filter = &Sniffer::getFilter(); + _cache = &ConnectionCache::getCache(); +} + +void ConnectionCacheUpdateThread::run() +{ + while (!_timeToEnd) + { + sleep(1000); + getTcpFromNetlink(); + removeStale(); + } +} + +int ConnectionCacheUpdateThread::addToConnectionCache(const struct nlmsghdr *nlh, void *data) +{ + cout << "adding connection" << endl; + vector<TCPConnection>* connList = (vector<TCPConnection>*)data; + TCPConnection connection; + TimeStamp now(); + struct in_addr addr; + + inet_diag_msg *r = (struct inet_diag_msg*)mnl_nlmsg_get_payload(nlh); + connection.uid = r->idiag_uid; + inet_diag_sockid id = r->id; + connection.destAddress = *id.idiag_dst; + connection.srcAddress = *id.idiag_src; + connection.timeAdded = now; + + addr.s_addr = connection.srcAddress; + cout << inet_ntoa(addr) << endl; + cout << connection.destAddress<< endl; + cout << connection.uid << endl; + connList->push_back(connection); + return MNL_CB_OK; +} + +int ConnectionCacheUpdateThread::getTcpFromNetlink() +{ + //Declarations + int ret; + unsigned int portid; + char buf[MNL_SOCKET_BUFFER_SIZE]; + + //open socket + mnl_socket* sock = mnl_socket_open(NETLINK_INET_DIAG); + mnl_socket_bind(sock, 0, MNL_SOCKET_AUTOPID); + portid = mnl_socket_get_portid(sock); + //Create message + struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf); + nlh->nlmsg_type = TCPDIAG_GETSOCK; + nlh->nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST; + //Add inet_diag specific stuff + struct inet_diag_req *req = (inet_diag_req*)mnl_nlmsg_put_extra_header(nlh, sizeof(*req)); + req->idiag_family = AF_INET; + req->idiag_states = SS_ALL; + req->idiag_ext |= (1<<(INET_DIAG_INFO-1)); + + //send message + if (mnl_socket_sendto(sock, nlh, nlh->nlmsg_len) < 0) { + //This needs to be something different + //We can't just exit if sending the message doesn't work + exit(EXIT_FAILURE); + } + //Receive the response from inet_diag + ret = mnl_socket_recvfrom(sock, buf, sizeof(buf)); + ret = mnl_cb_run(buf, ret, 0, portid, add_to_connection_cache, (void*) &this->_cache); + //close the socket + mnl_socket_close(sock); + return 0; +} + +int ConnectionCacheUpdateThread::removeStale() +{ + vector<TCPConnection>::iterator it; + Poco::TimeDiff fiveSeconds = 5000000; + + for (it = this->_cache.begin(); it < this->_cache.end(); it++) + { + + if (it->timeAdded.elapsed() >= fiveSeconds) + { + this->_cache.erase(it); + } + } + return 0; + +} + +int ConnectionCacheUpdateThread::endThread() +{ + _timeToEnd = true; +} Modified: branches/multiuser/src/HTTPHit.cpp =================================================================== --- branches/multiuser/src/HTTPHit.cpp 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/src/HTTPHit.cpp 2012-06-23 22:32:27 UTC (rev 324) @@ -4,29 +4,40 @@ { } -HTTPHit::read(string message) +void HTTPHit::read(string message) { istringstream inStream(message); if (message.find("HTTP") != message.npos) { //this is a request - this->_request.read(inStream); - this->_url = this->_request.getHost() + this->_request.getURI(); + _request.read(inStream); + _url = _request.getHost() + _request.getURI(); } else: { //this is a response - this->_response.read(inStream); + _response.read(inStream); } } -HTTPHit::getRequest() +HTTPRequest* HTTPHit::getRequest() { return *_request; } -HTTPHit::getResponse() +HTTPResponse* HTTPHit::getResponse() { return *_response; } + +void HTTPHit::setUser(int uid) +{ + _uid = uid; + +} + +int HTTPHit::getUser() +{ + return this->_uid +} Added: branches/multiuser/src/HTTPHitHandler.cpp =================================================================== --- branches/multiuser/src/HTTPHitHandler.cpp (rev 0) +++ branches/multiuser/src/HTTPHitHandler.cpp 2012-06-23 22:32:27 UTC (rev 324) @@ -0,0 +1,32 @@ +//HTTPHitHandler.cpp +#include "HTTPHitHandler.h" + +HTTPHitHandler::HTTPHitHandler() +{ + _db = &MainApplication::getDatabase(); + _filter = new Filter(&MainApplication::getOptions(), _db); + _cache = &ConnectionCache::getCache() + _logStream = &Sniffer::getLogStream(); +} + + +HTTPHitHandler::handleHit(HTTPHit hit) +{ + hit._uid = _cache->getUID(hit.src, hit.dest); + + isMatch = _filter->isMatch(request, match); + HTTPHitHandler::logUrl(request); + if (isMatch) + HTTPHitHandler::logWarning(match); + + if (isDebugging) + *_logStream <<isMatch <<endl; +} + +void HTTPHitHandler::logWarning(BlacklistMatch match) { + _db->logWarning(match); +} + +void HTTPHitHandler::logUrl(HTTPHit& hit) { + _db->logUrl(hit); +} Modified: branches/multiuser/src/Sniffer.cpp =================================================================== --- branches/multiuser/src/Sniffer.cpp 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/src/Sniffer.cpp 2012-06-23 22:32:27 UTC (rev 324) @@ -29,8 +29,6 @@ _instance = this; _logStream = new LogStream(Application::instance().logger()); _logStream->warning(); - _db = &MainApplication::getDatabase(); - _filter = new Filter(&MainApplication::getOptions(), _db); } @@ -62,18 +60,13 @@ -void Sniffer::logUrl(HTTPRequest& request) { - _instance->_db->logUrl(request); -} -void Sniffer::logWarning(BlacklistMatch match, ip_info addrs) { - _instance->_db->logWarning(match, addrs); -} + vector<string> Sniffer::getDevices() { vector<string> devices; pcap_if_t *alldevs, Modified: branches/multiuser/src/SnifferThread.cpp =================================================================== --- branches/multiuser/src/SnifferThread.cpp 2012-06-03 02:09:47 UTC (rev 323) +++ branches/multiuser/src/SnifferThread.cpp 2012-06-23 22:32:27 UTC (rev 324) @@ -76,7 +76,7 @@ struct pcap_pkthdr *header; const u_char *pkt_data; BlacklistMatch match; - HTTPRequest request; + HTTPHit hit; int uid; request.setChunkedTransferEncoding(true); bool isMatch, @@ -89,15 +89,7 @@ gotPacket(header, pkt_data, request, addrs); if (request.empty()) - throw Poco::Exception("No message found"); - - isMatch = _filter->isMatch(request, match); - Sniffer::logUrl(request); - if (isMatch) - Sniffer::logWarning(match, uid); - - if (isDebugging) - *_logStream <<isMatch <<endl; + throw Poco::Exception("No message found"); } catch (Poco::Exception &err) { if (isDebugging) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dus...@us...> - 2012-06-03 02:09:53
|
Revision: 323 http://responsibility.svn.sourceforge.net/responsibility/?rev=323&view=rev Author: dustsource Date: 2012-06-03 02:09:47 +0000 (Sun, 03 Jun 2012) Log Message: ----------- Fixed unintended links in "Rating Improvement Data" guide. Modified Paths: -------------- documentation/doc/net-responsibility-3.0.2-doc.zip Modified: documentation/doc/net-responsibility-3.0.2-doc.zip =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dus...@us...> - 2012-06-03 02:09:21
|
Revision: 322 http://responsibility.svn.sourceforge.net/responsibility/?rev=322&view=rev Author: dustsource Date: 2012-06-03 02:09:13 +0000 (Sun, 03 Jun 2012) Log Message: ----------- Fixed unintended links in "Rating Improvement Data" guide. Modified Paths: -------------- documentation/pages/5050-RateImprovData.page Modified: documentation/pages/5050-RateImprovData.page =================================================================== --- documentation/pages/5050-RateImprovData.page 2012-06-03 01:37:08 UTC (rev 321) +++ documentation/pages/5050-RateImprovData.page 2012-06-03 02:09:13 UTC (rev 322) @@ -2,7 +2,7 @@ A50NR_DevIntro !!!Introduction -There are currently three ways that Net Responsibility (NR) users and their accountability partners (APs) can help improve the accuracy of the <*Warnings*> section of the reports. One way is for the user to make sure they have selected the option 'Provide improvement data' in the <*Tweaks*> section of their [[0301-ConfigurationExplained.html online configuration settings]], which automatically and <*anonymously*> sends all <*Warnings*> items to the NR server where they can then be rated, analyzed, etc. in order to improve NR's filtering methods. A second way is for users and APs to [[0705-UnderstandingReports.html#9 rate individual items]] from the <*Warnings*> section of the reports they receive. This guide describes the third way you can help out, which is by rating the improvement data that has been received from multiple NR users. Please note that, while this is a great way to help out, you also need to be careful in how you go about it, since it is possible that while you are doing this you will see keywords and URLs that will tempt your mind to go in directions you don't want it to. In a later section of this guide, you will find some ideas and tips for protecting yourself as needed. +There are currently three ways that Net Responsibility (NR) users and their accountability partners (APs) can help improve the accuracy of the <*Warni<{}>ngs*> section of the reports. One way is for the user to make sure they have selected the option 'Provide improvement data' in the <*Tweaks*> section of their [[0301-ConfigurationExplained.html online configuration settings]], which automatically and <*anonymously*> sends all <*Warni<{}>ngs*> items to the NR server where they can then be rated, analyzed, etc. in order to improve NR's filtering methods. A second way is for users and APs to [[0705-UnderstandingReports.html#9 rate individual items]] from the <*Warni<{}>ngs*> section of the reports they receive. This guide describes the third way you can help out, which is by rating the improvement data that has been received from multiple NR users. Please note that, while this is a great way to help out, you also need to be careful in how you go about it, since it is possible that while you are doing this you will see keywords and URLs that will tempt your mind to go in directions you don't want it to. In a later section of this guide, you will find some ideas and tips for protecting yourself as needed. All of the improvement data can be viewed and rated by using an online interface hosted on the NR server. [[http://www.netresponsibility.com/dev/improvement_data.php Click here to see what it looks like or begin using it.]] You may find it helpful to have it open in your browser as you read through the rest of this guide, which explains how it works, along with the various options that can be used with it. @@ -25,7 +25,7 @@ - Amount: This refers to the number of times that this identical URL and a particular keyword match was sent to the NR server. Combined with 'Ascending' it will show URLs with the least amount first. This is helpful if you want to focus on rating URLs that are more frequent or less frequent. - Rating: This refers to a number from 0 to 5, which represents the average of how a warning has been rated by users and/or accountability partners. If the number is 0, it means the warning has not yet been rated. The numbers 1, 2, 3, 4, and 5 represent points along a continuum from something that was definitely a false positive (lower number) to something that was definitely an inappropriate site (higher number). Because these are based on an average, you may see numbers with decimals like 1.23 or 3.45, etc., but they will all be within the 1-5 range if they have been rated before. This is helpful if you want to focus on warnings that are currently unrated or warnings that other users have considered to be more or less likely to be inappropriate sites. - Votes: This refers to the number of times that this warning has been rated. This is helpful if you want to focus on warnings that have been rated less or more times by other people. - - Blacklist: This allows you to order the warnings according to the particular blacklist (i.e. 'Models' or 'Porn' or 'Celebrities') they are associated with. This is helpful if you want to focus in on one particular type of warning at a time. + - Black<{}>list: This allows you to order the warnings according to the particular blacklist (i.e. 'Models' or 'Porn' or 'Celebrities') they are associated with. This is helpful if you want to focus in on one particular type of warning at a time. - Keyword: This allows you to order the warnings according to the keywords they are associated with. This is helpful if you want to focus in on warnings for one particular keyword at a time. - Strength: This refers to a number from 0 to 100+, and is the initial value assigned to the warning when NR filtered it the first time, with higher numbers indicating that NR is reporting a greater likelihood of that site being inappropriate. This is helpful if you want to focus on warnings to which NR has assigned either a low strength or a high strength. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dus...@us...> - 2012-06-03 01:37:14
|
Revision: 321 http://responsibility.svn.sourceforge.net/responsibility/?rev=321&view=rev Author: dustsource Date: 2012-06-03 01:37:08 +0000 (Sun, 03 Jun 2012) Log Message: ----------- Made the following edits to the documentation related to rating improvement data: --Added the "Rating Improvement Data" guide. --In the "Configuration Explained" guide: --'Configuration Parts' section, 'Tweaks', 'Provide improvement data': Clarified relationship between this setting and rating warnings in reports. --In the "Understanding the Reports" guide: --'Improving the reports' section: --In the last paragraph (item), clarified relationship between the 'Provide improvement data' setting and rating warnings in reports. --Added a final item linking to new "Rating Improvement Data" guide. --In the "Troubleshooting the Reports" guide: --'Why are there so many false positives?' section: --Adjusted the text to help clarify relationship between the 'Provide improvement data' setting and rating warnings in reports. --Added brief comment about and link to the new "Rating Improvement Data" guide. --In the "Privacy Policy" document: --'What about the improvement data?' section: Clarified relationship between the 'Provide improvement data' setting and rating warnings in reports. Modified Paths: -------------- documentation/doc/net-responsibility-3.0.2-doc.zip Modified: documentation/doc/net-responsibility-3.0.2-doc.zip =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |