From: SomeDude Date: Sun, 3 Feb 2008 09:23:00 +0000 (+0100) Subject: version 0.1.7 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f208e33c29132aacaec448e74341edea1b925a2a;p=fms.git version 0.1.7 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 52233e8..3a14d8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,14 @@ src/freenet/captcha/easybmp/EasyBMP_Font.cpp src/freenet/captcha/easybmp/EasyBMP_Geometry.cpp src/http/httpthread.cpp src/http/ipagehandler.cpp +src/http/pages/addpeerpage.cpp +src/http/pages/announceidentitypage.cpp +src/http/pages/createidentitypage.cpp src/http/pages/homepage.cpp +src/http/pages/localidentitiespage.cpp +src/http/pages/optionspage.cpp +src/http/pages/peertrustpage.cpp +src/http/pages/showcaptchapage.cpp src/nntp/nntpconnection.cpp src/nntp/nntplistener.cpp src/nntp/uwildmat.cpp @@ -66,7 +73,8 @@ src/xyssl/sha1.c ADD_DEFINITIONS(-DTIXML_USE_STL) IF(CMAKE_COMPILER_IS_GNUCXX) - ADD_DEFINITIONS(-fpermissive) + #ADD_DEFINITIONS(-fpermissive) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") ENDIF(CMAKE_COMPILER_IS_GNUCXX) ADD_EXECUTABLE(fms ${FMS_SRC}) @@ -111,9 +119,10 @@ IF(SHTTPD_LIBRARY) TARGET_LINK_LIBRARIES(fms ${SHTTPD_LIBRARY}) ELSE(SHTTPD_LIBRARY) MESSAGE(STATUS "Could not find shttpd library. Will compile from included source.") - ADD_DEFINITIONS(-DEMBEDDED -DNO_GUI) + ADD_DEFINITIONS(-DEMBEDDED) INCLUDE_DIRECTORIES(libs/shttpd/include) IF(WIN32) + ADD_DEFINITIONS(-DNO_GUI) SET(SHTTPD_PLATFORM_SRC libs/shttpd/compat_win32.c) ELSE(WIN32) SET(SHTTPD_PLATFORM_SRC libs/shttpd/compat_unix.c) diff --git a/admin/addpeeridentity.php b/admin/addpeeridentity.php deleted file mode 100644 index 5d24f0c..0000000 --- a/admin/addpeeridentity.php +++ /dev/null @@ -1,51 +0,0 @@ -prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey=?;"); - $st->bindParam(1,$_REQUEST["publickey"]); - $st->execute(); - if($record=$st->fetch()) - { - $message="This peer already exists"; - } - else - { - $st2=$db->prepare("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES(?,?);"); - $st2->bindParam(1,$_REQUEST["publickey"]); - $st2->bindParam(2,gmdate('Y-m-d H:i:s')); - $st2->execute(); - $message="Peer added"; - } -?> -

- -

Add Peer

-
- - Peer Public Key -
- The public key must be a valid SSK public key and include the / at the end -
- -
- \ No newline at end of file diff --git a/admin/config.php b/admin/config.php deleted file mode 100644 index 8f8947e..0000000 --- a/admin/config.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/admin/createidentity.php b/admin/createidentity.php deleted file mode 100644 index 804b4cf..0000000 --- a/admin/createidentity.php +++ /dev/null @@ -1,36 +0,0 @@ -prepare("INSERT INTO tblLocalIdentity(Name,PublishTrustList) VALUES(?,'true');"); - $st->bindParam(1,$_REQUEST["name"]); - $st->execute(); -?> -

Identity Created

- -

Create Identity

-
- - Name : - -
- \ No newline at end of file diff --git a/admin/identitytrust.php b/admin/identitytrust.php deleted file mode 100644 index bdc4718..0000000 --- a/admin/identitytrust.php +++ /dev/null @@ -1,86 +0,0 @@ -prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); - for($i=0; $ibindParam(1,$_REQUEST['newlocalmessagetrust'][$i]); - $st->bindParam(2,$_REQUEST['newlocaltrustlisttrust'][$i]); - $st->bindParam(3,$_REQUEST['identityid'][$i]); - $rval=$st->execute(); - } - } - } - - $st=$db->prepare("SELECT IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey FROM tblIdentity ORDER BY Name;"); - $st->execute(); - ?> -

Identity Trust

- Message Trust is how much you trust the identity to post good messages. Trust List Trust is how much weight you want the trust list of that identity to have when calculating the total. The local trust levels are set by you, and the peer trust levels are calculated by a weighted average using other identities trust lists. -
- - - - - - - - - - fetch()) - { - ?> - - - - - - - - - - - -
PeerLocal Message TrustPeer Message TrustLocal Trust List TrustPeer Trust List Trust
- - - - - - - - - - -
- -
-
- \ No newline at end of file diff --git a/admin/index.php b/admin/index.php deleted file mode 100644 index 12c1653..0000000 --- a/admin/index.php +++ /dev/null @@ -1,17 +0,0 @@ - -

Home

-

- Use these pages to administer your FMS installation. Make sure to set $dblocation correctly in config.php, and that the database is writable to your web service user account. While you should be able to safely use these pages while FMS is running, it is recommended that you shut down FMS prior to make any changes here. -

- \ No newline at end of file diff --git a/admin/introduce.php b/admin/introduce.php deleted file mode 100644 index 216809d..0000000 --- a/admin/introduce.php +++ /dev/null @@ -1,93 +0,0 @@ -prepare("SELECT LocalIdentityID, Name, PublicKey FROM tblLocalIdentity ORDER BY Name;"); - $st->execute(); - - print ""; -} - -function content() -{ - global $dblocation; - - $db=new PDO('sqlite:'.$dblocation); - - if(isset($_REQUEST["formaction"]) && $_REQUEST["formaction"]=="announce" && $_REQUEST["localidentityid"]!="") - { - $st=$db->prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);"); - - for($i=0; $ibindParam(1,$_REQUEST["localidentityid"]); - $st->bindParam(2,$_REQUEST["day"][$i]); - $st->bindParam(3,$_REQUEST["uuid"][$i]); - $st->bindParam(4,$_REQUEST["solution"][$i]); - $st->execute(); - } - } - } - - ?> -

Announce Identity

-
- - Select Identity to announce - Type answers for a few puzzles and submit
"; - - - $st=$db->prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='".gmdate('Y-m-d',strtotime('-1 day'))."' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); - $st->execute(); - - // only show latest captcha for each known identity - $lastid=''; - $shown=0; - while(($record=$st->fetch()) && $shown<30) - { - if($lastid!=$record[2]) - { - $lastid=$record[2]; - print ""; - print ""; - print ""; - print ""; - print "
"; - $shown++; - } - } - - if($shown>0) - { - ?> - - -
- \ No newline at end of file diff --git a/admin/introductionstatus.php b/admin/introductionstatus.php deleted file mode 100644 index c346ef6..0000000 --- a/admin/introductionstatus.php +++ /dev/null @@ -1,42 +0,0 @@ -prepare("SELECT tblLocalIdentity.Name, COUNT(Inserted), tblLocalIdentity.PublicKey FROM tblLocalIdentity LEFT JOIN tblIdentityIntroductionInserts ON tblLocalIdentity.LocalIdentityID=tblIdentityIntroductionInserts.LocalIdentityID WHERE (Inserted='true' OR Inserted IS NULL) GROUP BY tblLocalIdentity.LocalIdentityID;"); - $st->execute(); - - ?> -

Introduction Status

- - - - - - fetch()) - { - ?> - - - - - -
IdentitySuccessful introduction inserts
- - - -
- \ No newline at end of file diff --git a/admin/layout_deneva.css b/admin/layout_deneva.css deleted file mode 100644 index f3a8172..0000000 --- a/admin/layout_deneva.css +++ /dev/null @@ -1,65 +0,0 @@ -body { - width: auto; - margin: 1em; -} -p, div { - margin: 0em 0em 0em 0em; - padding: 0em; -} -h1, h2, h3, h4, h5, h6 { - margin: 0em 0em .2em 0em; - padding: 0em 0em .1em 0em; -} - -.banner { - margin: 0em; - padding: .5em; - -} -.navigation { - margin: 0em 0em 0em 0em; - padding: .3em; -} - -.content_main { - margin: 0em; - padding: 0em; -} - -.content_left { - float: left; - width: 200px; - margin: 1em 0em 0em 0em; - padding: 0em; -} -.content_left .box { - margin: 0em 0em 1em 0em; -} -.content_left .box .header { - padding: .5em; -} -.content_left .box p { - padding: 0em .3em 0em .3em; - margin: .0em 0em .5em 0em; -} - -.content_right { - position:absolute; - left:220px; - margin: 0px 0px 0px 0px; - padding: 1em; -} - -.meta-info { - text-align: right; -} - -.footer { - clear: both; - padding: 1em; - margin: 0em; -} - -.paragraph { - margin-bottom:.5em; - } \ No newline at end of file diff --git a/admin/linkbar.php b/admin/linkbar.php deleted file mode 100644 index 4e80f20..0000000 --- a/admin/linkbar.php +++ /dev/null @@ -1,22 +0,0 @@ - - - \ No newline at end of file diff --git a/admin/localidentities.php b/admin/localidentities.php deleted file mode 100644 index b98f420..0000000 --- a/admin/localidentities.php +++ /dev/null @@ -1,102 +0,0 @@ - - - prepare("UPDATE tblLocalIdentity SET SingleUse=?, PublishTrustList=? WHERE LocalIdentityID=?;"); - for($i=0; $ibindParam(1,$_REQUEST['singleuse'][$_REQUEST['update'][$i]]); - $st->bindParam(2,$_REQUEST['publishtrustlist'][$_REQUEST['update'][$i]]); - $st->bindParam(3,$_REQUEST['localidentityid'][$_REQUEST['update'][$i]]); - $st->execute(); - } - } - } - if($_REQUEST['formaction']=='delete' && isset($_REQUEST['update'])) - { - $st=$db->prepare("DELETE FROM tblLocalIdentity WHERE LocalIdentityID=?;"); - - for($i=0; $ibindParam(1,$_REQUEST['localidentityid'][$_REQUEST['update'][$i]]); - $st->execute(); - } - } - } - } - - $st=$db->prepare("SELECT LocalIdentityID,Name,PublicKey,PublishTrustList,SingleUse,PublishBoardList FROM tblLocalIdentity ORDER BY Name;"); - $st->execute(); - ?> -

Local Identities

-
- - - - - - - - - fetch()) - { - ?> - - - - - - - -
NameSingle UsePublish Trust List
- - - - - - - - -
- - -
- \ No newline at end of file diff --git a/admin/options.php b/admin/options.php deleted file mode 100644 index b4f3757..0000000 --- a/admin/options.php +++ /dev/null @@ -1,58 +0,0 @@ -prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;"); - foreach($_REQUEST as $key=>$val) - { - $st->bindParam(1,$val); - $st->bindParam(2,$key); - $st->execute(); - } - } - -function content() -{ - global $dblocation; - $db=new PDO('sqlite:'.$dblocation); - - $rs=$db->query("SELECT Option, OptionValue, OptionDescription FROM tblOption;"); - -?> -

Options

-
- - - - - - - - fetch()) - { - print ''; - print ''; - print ''; - print ''; - print ''; - } - ?> - - - -
OptionValueDescription
'.$record[0].''.$record[2].'
-
- -
-
- \ No newline at end of file diff --git a/admin/showcaptcha.php b/admin/showcaptcha.php deleted file mode 100644 index 81a01dd..0000000 --- a/admin/showcaptcha.php +++ /dev/null @@ -1,22 +0,0 @@ -prepare("SELECT MimeType,PuzzleData FROM tblIntroductionPuzzleRequests WHERE UUID=?;"); - $st->bindParam(1,$_REQUEST['UUID']); - $st->execute(); - - if($record=$st->fetch()) - { - $data=base64_decode($record[1]); - header("Content-type: ".$record[0]); - header("Content-Length: ".strlen($data)); - print $data; - } - } - -?> \ No newline at end of file diff --git a/admin/style_deneva.css b/admin/style_deneva.css deleted file mode 100644 index ffe4673..0000000 --- a/admin/style_deneva.css +++ /dev/null @@ -1,110 +0,0 @@ -body { - background-color: #FFF; - color: #000; - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 90%; -} -a, a:link, a:active { color: #0000FF; text-decoration: none; } -a:visited { color: #003399; text-decoration: none; } -a:hover { color: #990000; text-decoration: underline; } -p {} -div { -} -h1 {} -h2 { color: #003366;} -h3 { color: #336699; border-bottom: 1px solid #336699;} -h4 { color: #6699CC; border-bottom: 1px solid #6699CC;} -h5 { color: #99CCFF;} - -ul { - padding:0px; - margin-top:5px; - margin-bottom:5px; - margin-left:25px; - } - -.banner { - background-color: #003366; - color: #FFFFFF; - font-weight: bolder; -} -.navigation { - background-color: #CCDDEE; - border: 1px solid #999999; - font-size: 80%; -} -.content_main { background-color: #FFFFFF;} -.content_left { - font-size: 90%; -} -.content_left .box { - border: 1px solid #336699; - background-color: #DDEEFF; - font-size: 85%; -} -.content_left .box .header { - background-color: #003366; - color: #FFFFFF; - font-weight: bold; - font-size: 1em; -} -.content_left .box p { -} -.content_right { -} -.footer { - color: #999; - font-size: smaller; - text-align: center; - border-top: 1px dashed #CCCCCC; -} -.meta-info { - font-size: 80%; -} -.paragraph { - line-height: 1.4em; -} - -.smaller { font-size: 65%; } -.darkest { background-color: #003366; } -.darker { background-color: #336699; } -.dark { background-color: #6699CC; } -.light { background-color: #99CCFF; } -.lighter { background-color: #DDEEFF; } -.lightest { background-color: #FFFFFF; } - -.xml1-attributename { color: #800000; } -.xml1-attributevalue { color: #FF0000; } -.xml1-cdatasection { color: #808000; } -.xml1-comment { color: #808080; font-style: italic; } -.xml1-currentline { color: #000000; } -.xml1-doctypesection { color: #008080; } -.xml1-elementname { color: #000080; } -.xml1-entityreference { color: #0000FF; } -.xml1-matchedbraces { color: #FF0000; } -.xml1-namespaceattributename { color: #008000; } -.xml1-namespaceattributevalue { color: #0000FF; } -.xml1-processinginstruction { color: #000080; } -.xml1-rightedge { color: #C0C0C0; } -.xml1-selection { color: #FFFFFF; } -.xml1-symbol { color: #808080; } -.xml1-text { color: #000000; } -.xml1-whitespace { color: #FFFFFF; } - -.calcheading { - font-weight:bold; - } - -.calcheading td { - padding-left:10px; - padding-right:10px; - } - -.calcrow td { - background-color:#EEEEEE; - text-align:right; - } - -.totalrow td { - text-align:right; - } \ No newline at end of file diff --git a/admin/template.php b/admin/template.php deleted file mode 100644 index 91f308d..0000000 --- a/admin/template.php +++ /dev/null @@ -1,44 +0,0 @@ - - - FMS : Freenet Message System - - - - - - - - - -
- -
- - - -
- -
- - - -
- -
- - - - diff --git a/include/global.h b/include/global.h index cee8ab5..ba2e84f 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ //#include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.1.6" +#define FMS_VERSION "0.1.7" // opens database and creates tables and initial inserts if necessary void SetupDB(); diff --git a/include/http/httpthread.h b/include/http/httpthread.h index ecb61e4..8ebd00d 100644 --- a/include/http/httpthread.h +++ b/include/http/httpthread.h @@ -7,6 +7,7 @@ #include "ipagehandler.h" #include "httpdefs.h" +#include #include class HTTPThread:public PThread::Runnable,public ILogger, public IDatabase diff --git a/include/http/ipagehandler.h b/include/http/ipagehandler.h index 7624c4a..313aa56 100644 --- a/include/http/ipagehandler.h +++ b/include/http/ipagehandler.h @@ -1,13 +1,18 @@ #ifndef _ipagehandler_ #define _ipagehandler_ -#include +#include #include #include +#include +#include class IPageHandler { public: + IPageHandler() {} + IPageHandler(const std::string &templatestr) { m_template=templatestr; } + virtual ~IPageHandler() {} /** \brief Handles request for a page @@ -22,6 +27,12 @@ private: virtual const bool WillHandleURI(const std::string &uri)=0; virtual const std::string GeneratePage(const std::string &method, const std::map &queryvars)=0; +protected: + // converts from basename[#] query args into a vector where the vector pos is the index pos # + void CreateArgArray(const std::map &vars, const std::string &basename, std::vector &args); + + std::string m_template; + }; #endif // _ipagehandler_ diff --git a/include/http/pages/addpeerpage.h b/include/http/pages/addpeerpage.h new file mode 100644 index 0000000..79aedb3 --- /dev/null +++ b/include/http/pages/addpeerpage.h @@ -0,0 +1,18 @@ +#ifndef _addpeerpage_ +#define _addpeerpage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class AddPeerPage:public IPageHandler,public IDatabase +{ +public: + AddPeerPage(const std::string &templatestr):IPageHandler(templatestr) {} + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); + +}; + +#endif // _addpeerpage_ diff --git a/include/http/pages/announceidentitypage.h b/include/http/pages/announceidentitypage.h new file mode 100644 index 0000000..e2817f9 --- /dev/null +++ b/include/http/pages/announceidentitypage.h @@ -0,0 +1,19 @@ +#ifndef _announceidentitypage_ +#define _announceidentitypage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class AnnounceIdentityPage:public IPageHandler,public IDatabase +{ +public: + AnnounceIdentityPage(const std::string &templatestr):IPageHandler(templatestr) {} + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); + + const std::string CreateLocalIdentityDropDown(const std::string &name, const std::string &selected); +}; + +#endif // _announceidentitypage_ diff --git a/include/http/pages/createidentitypage.h b/include/http/pages/createidentitypage.h new file mode 100644 index 0000000..4a5374c --- /dev/null +++ b/include/http/pages/createidentitypage.h @@ -0,0 +1,17 @@ +#ifndef _createidentitypage_ +#define _createidentitypage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class CreateIdentityPage:public IPageHandler,public IDatabase +{ +public: + CreateIdentityPage(const std::string &templatestr):IPageHandler(templatestr) {} + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); +}; + +#endif // _createidentitypage_ diff --git a/include/http/pages/homepage.h b/include/http/pages/homepage.h index 977a015..d8eaa0c 100644 --- a/include/http/pages/homepage.h +++ b/include/http/pages/homepage.h @@ -6,6 +6,7 @@ class HomePage:public IPageHandler { public: + HomePage(const std::string &templatestr):IPageHandler(templatestr) {} private: const bool WillHandleURI(const std::string &uri); diff --git a/include/http/pages/localidentitiespage.h b/include/http/pages/localidentitiespage.h new file mode 100644 index 0000000..bc687e1 --- /dev/null +++ b/include/http/pages/localidentitiespage.h @@ -0,0 +1,19 @@ +#ifndef _localidentitiespage_ +#define _localidentitiespage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class LocalIdentitiesPage:public IPageHandler,public IDatabase +{ +public: + LocalIdentitiesPage(const std::string &templatestr):IPageHandler(templatestr) {} +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); + + const std::string CreateTrueFalseDropDown(const std::string &name, const std::string &selected); + +}; + +#endif // _localidentitiespage_ diff --git a/include/http/pages/optionspage.h b/include/http/pages/optionspage.h new file mode 100644 index 0000000..6ca15db --- /dev/null +++ b/include/http/pages/optionspage.h @@ -0,0 +1,17 @@ +#ifndef _optionspage_ +#define _optionspage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class OptionsPage:public IPageHandler,public IDatabase +{ +public: + OptionsPage(const std::string &templatestr):IPageHandler(templatestr) {} + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); +}; + +#endif // _optionspage_ diff --git a/include/http/pages/peertrustpage.h b/include/http/pages/peertrustpage.h new file mode 100644 index 0000000..b9a5f4e --- /dev/null +++ b/include/http/pages/peertrustpage.h @@ -0,0 +1,18 @@ +#ifndef _peertrustpage_ +#define _peertrustpage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class PeerTrustPage:public IPageHandler,public IDatabase +{ +public: + PeerTrustPage(const std::string &templatestr):IPageHandler(templatestr) {} + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); + +}; + +#endif // _peertrustpage_ diff --git a/include/http/pages/showcaptchapage.h b/include/http/pages/showcaptchapage.h new file mode 100644 index 0000000..121ad9a --- /dev/null +++ b/include/http/pages/showcaptchapage.h @@ -0,0 +1,17 @@ +#ifndef _showcaptchapage_ +#define _showcaptchapage_ + +#include "../ipagehandler.h" +#include "../../idatabase.h" + +class ShowCaptchaPage:public IPageHandler,public IDatabase +{ +public: + +private: + const bool WillHandleURI(const std::string &uri); + const std::string GeneratePage(const std::string &method, const std::map &queryvars); + +}; + +#endif // _showcaptchapage_ diff --git a/src/freenet/fcpv2.cpp b/src/freenet/fcpv2.cpp index 42995f4..fdc83fb 100644 --- a/src/freenet/fcpv2.cpp +++ b/src/freenet/fcpv2.cpp @@ -66,7 +66,7 @@ const bool FCPv2::Connect(const char *host, const int port) struct sockaddr_storage m_serveraddr; std::ostringstream portstring; - addrinfo hint,*result; + addrinfo hint,*result,*current; result=NULL; portstring << port; @@ -80,16 +80,19 @@ const bool FCPv2::Connect(const char *host, const int port) if(result) { - memset(&m_serveraddr,0,sizeof(struct sockaddr_storage)); + for(current=result; current!=NULL && m_serversocket==-1; current=current->ai_next) + { + memset(&m_serveraddr,0,sizeof(struct sockaddr_storage)); - m_serversocket=socket(result->ai_family,result->ai_socktype,result->ai_protocol); + m_serversocket=socket(current->ai_family,current->ai_socktype,current->ai_protocol); - if(m_serversocket!=-1) - { - rval=connect(m_serversocket,result->ai_addr,result->ai_addrlen); - if(rval==-1) + if(m_serversocket!=-1) { - Disconnect(); + rval=connect(m_serversocket,current->ai_addr,current->ai_addrlen); + if(rval==-1) + { + Disconnect(); + } } } diff --git a/src/freenet/trustlistrequester.cpp b/src/freenet/trustlistrequester.cpp index 3d7f129..4eeaf79 100644 --- a/src/freenet/trustlistrequester.cpp +++ b/src/freenet/trustlistrequester.cpp @@ -230,7 +230,7 @@ void TrustListRequester::PopulateIDList() // select identities we want to query (we've seen them today and they are publishing trust list) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending) sql="SELECT IdentityID FROM tblIdentity "; - sql+="WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )"; + sql+="WHERE Name IS NOT NULL AND Name <> '' AND PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen>='"+date.Format("%Y-%m-%d")+"' AND PublishTrustList='true' AND LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust') AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') )"; sql+="ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"; SQLite3DB::Statement st=m_db->Prepare(sql); diff --git a/src/global.cpp b/src/global.cpp index 6430d85..0437eb4 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -204,16 +204,14 @@ void SetupDB() );"); // low / high / message count for each board - db->Execute("DROP VIEW IF EXISTS vwBoardStats; \ - CREATE VIEW IF NOT EXISTS vwBoardStats AS \ + db->Execute("CREATE VIEW IF NOT EXISTS vwBoardStats AS \ SELECT tblBoard.BoardID AS 'BoardID', IFNULL(MIN(MessageID),0) AS 'LowMessageID', IFNULL(MAX(MessageID),0) AS 'HighMessageID', COUNT(MessageID) AS 'MessageCount' \ FROM tblBoard LEFT JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID \ WHERE MessageID>=0 OR MessageID IS NULL \ GROUP BY tblBoard.BoardID;"); // calculates peer trust - db->Execute("DROP VIEW IF EXISTS vwCalculatedPeerTrust; \ - CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \ + db->Execute("CREATE VIEW IF NOT EXISTS vwCalculatedPeerTrust AS \ SELECT TargetIdentityID, \ ROUND(SUM(MessageTrust*(LocalMessageTrust/100.0))/SUM(LocalMessageTrust/100.0),0) AS 'PeerMessageTrust', \ ROUND(SUM(TrustListTrust*(LocalTrustListTrust/100.0))/SUM(LocalTrustListTrust/100.0),0) AS 'PeerTrustListTrust' \ @@ -291,7 +289,7 @@ void SetupDB() // insert SomeDude's public key date.SetToGMTime(); - //db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); + db->Execute("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES('SSK@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw,iXez4j3qCpd596TxXiJgZyTq9o-CElEuJxm~jNNZAuA,AQACAAE/','"+date.Format("%Y-%m-%d %H:%M:%S")+"');"); } @@ -360,7 +358,7 @@ void SetupDefaultOptions() // FCPHost st.Bind(0,"FCPHost"); - st.Bind(1,"localhost"); + st.Bind(1,"127.0.0.1"); st.Bind(2,"Host name or address of Freenet node."); st.Step(); st.Reset(); @@ -421,7 +419,7 @@ void SetupDefaultOptions() st.Reset(); st.Bind(0,"MinPeerMessageTrust"); - st.Bind(1,"25"); + st.Bind(1,"30"); st.Bind(2,"Specifies a peer message trust level that a peer must have before its messages will be downloaded."); st.Step(); st.Reset(); @@ -433,7 +431,7 @@ void SetupDefaultOptions() st.Reset(); st.Bind(0,"MinPeerTrustListTrust"); - st.Bind(1,"25"); + st.Bind(1,"30"); st.Bind(2,"Specifies a peer trust list trust level that a peer must have before its trust list will be included in the weighted average. Any peers below this number will be excluded from the results."); st.Step(); st.Reset(); diff --git a/src/http/httpthread.cpp b/src/http/httpthread.cpp index dd4bd9b..827ce28 100644 --- a/src/http/httpthread.cpp +++ b/src/http/httpthread.cpp @@ -2,6 +2,13 @@ #include "../../include/option.h" #include "../../include/stringfunctions.h" #include "../../include/http/pages/homepage.h" +#include "../../include/http/pages/optionspage.h" +#include "../../include/http/pages/showcaptchapage.h" +#include "../../include/http/pages/createidentitypage.h" +#include "../../include/http/pages/localidentitiespage.h" +#include "../../include/http/pages/announceidentitypage.h" +#include "../../include/http/pages/addpeerpage.h" +#include "../../include/http/pages/peertrustpage.h" #include @@ -11,13 +18,40 @@ HTTPThread::HTTPThread() { - + std::string templatestr; int port; std::string portstr; Option::Instance()->Get("HTTPListenPort",portstr); StringFunctions::Convert(portstr,port); - m_pagehandlers.push_back(new HomePage()); + // set template + templatestr="Home
[CONTENT]"; + FILE *infile=fopen("template.htm","r+b"); + if(infile) + { + fseek(infile,0,SEEK_END); + long len=ftell(infile); + std::vector data(len,0); + fseek(infile,0,SEEK_SET); + fread(&data[0],1,len,infile); + fclose(infile); + templatestr.assign(data.begin(),data.end()); + } + else + { + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"HTTPThread::HTTPThread could not open template.htm"); + } + + // push back page handlers + m_pagehandlers.push_back(new ShowCaptchaPage()); + m_pagehandlers.push_back(new OptionsPage(templatestr)); + m_pagehandlers.push_back(new LocalIdentitiesPage(templatestr)); + m_pagehandlers.push_back(new CreateIdentityPage(templatestr)); + m_pagehandlers.push_back(new AnnounceIdentityPage(templatestr)); + m_pagehandlers.push_back(new AddPeerPage(templatestr)); + m_pagehandlers.push_back(new PeerTrustPage(templatestr)); + // homepage must be last - catch all page handler + m_pagehandlers.push_back(new HomePage(templatestr)); m_ctx=0; m_ctx=shttpd_init(NULL,"listen_ports",portstr.c_str(),NULL); diff --git a/src/http/ipagehandler.cpp b/src/http/ipagehandler.cpp index 230da65..fc77815 100644 --- a/src/http/ipagehandler.cpp +++ b/src/http/ipagehandler.cpp @@ -6,6 +6,31 @@ #include #endif +void IPageHandler::CreateArgArray(const std::map &vars, const std::string &basename, std::vector &args) +{ + for(std::map::const_iterator i=vars.begin(); i!=vars.end(); i++) + { + if((*i).first.find(basename)==0 && (*i).first.find("[")!=std::string::npos && (*i).first.find("]")!=std::string::npos) + { + int index; + std::string indexstr; + std::string::size_type startpos; + std::string::size_type endpos; + startpos=(*i).first.find("["); + endpos=(*i).first.find("]"); + + indexstr=(*i).first.substr(startpos+1,(endpos-startpos)-1); + StringFunctions::Convert(indexstr,index); + + while(args.size()m_indata=new char[len]; + mystate->m_indata=new char[len+1]; + mystate->m_indata[len]=NULL; mystate->m_indatalen=len; mystate->m_indatapos=0; } @@ -45,7 +71,7 @@ const bool IPageHandler::Handle(shttpd_arg *arg) if(arg->in.len>0) { int pos=0; - while(arg->in.num_bytesin.len) + while(posin.len) { mystate->m_indata[mystate->m_indatapos++]=arg->in.buf[pos++]; } @@ -56,7 +82,32 @@ const bool IPageHandler::Handle(shttpd_arg *arg) if(mystate->m_indatalen==mystate->m_indatapos && mystate->m_outdata==NULL) { //TODO parse POST data and any QUERY_STRING before generating page - std::string page=GeneratePage(methodstr,std::map()); + std::map args; + std::vector argparts; + + if(mystate->m_indata) + { + StringFunctions::Split(mystate->m_indata,"&",argparts); + } + if(shttpd_get_env(arg,"QUERY_STRING")) + { + StringFunctions::Split(shttpd_get_env(arg,"QUERY_STRING"),"&",argparts); + } + for(std::vector::iterator argi=argparts.begin(); argi!=argparts.end(); argi++) + { + std::vector parts; + StringFunctions::Split((*argi),"=",parts); + if(parts.size()>0) + { + args[StringFunctions::UriDecode(parts[0])]; + if(parts.size()>1) + { + args[StringFunctions::UriDecode(parts[0])]=StringFunctions::UriDecode(parts[1]); + } + } + } + + std::string page=GeneratePage(methodstr,args); mystate->m_outdata=new char[page.size()]; memcpy(mystate->m_outdata,page.c_str(),page.size()); mystate->m_outdatalen=page.size(); @@ -79,11 +130,11 @@ const bool IPageHandler::Handle(shttpd_arg *arg) { if(mystate->m_indata) { - delete mystate->m_indata; + delete [] mystate->m_indata; } if(mystate->m_outdata) { - delete mystate->m_outdata; + delete [] mystate->m_outdata; } delete mystate; arg->state=NULL; diff --git a/src/http/pages/addpeerpage.cpp b/src/http/pages/addpeerpage.cpp new file mode 100644 index 0000000..7b4d706 --- /dev/null +++ b/src/http/pages/addpeerpage.cpp @@ -0,0 +1,56 @@ +#include "../../../include/http/pages/addpeerpage.h" +#include "../../../include/stringfunctions.h" +#include "../../../include/datetime.h" + +#ifdef XMEM + #include +#endif + +const std::string AddPeerPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + std::string content=""; + + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="add") + { + DateTime date; + std::string publickey=""; + if(queryvars.find("publickey")!=queryvars.end()) + { + publickey=(*queryvars.find("publickey")).second; + } + if(publickey!="" && publickey.find("SSK@")==0 && publickey[publickey.size()-1]=='/') + { + date.SetToGMTime(); + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES(?,?);"); + st.Bind(0,publickey); + st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S")); + st.Step(); + st.Reset(); + } + } + + content+="

Add Peer

"; + content+=""; + content+=""; + content+="Public Key : "; + content+=""; + content+="
"; + content+="The public key must be a valid SSK public key and include the / at the end"; + content+="
"; + content+=""; + content+=""; + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool AddPeerPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("addpeer.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/announceidentitypage.cpp b/src/http/pages/announceidentitypage.cpp new file mode 100644 index 0000000..460302a --- /dev/null +++ b/src/http/pages/announceidentitypage.cpp @@ -0,0 +1,140 @@ +#include "../../../include/http/pages/announceidentitypage.h" +#include "../../../include/stringfunctions.h" +#include "../../../include/datetime.h" + +#ifdef XMEM + #include +#endif + +const std::string AnnounceIdentityPage::CreateLocalIdentityDropDown(const std::string &name, const std::string &selected) +{ + std::string rval=""; + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID, Name, PublicKey FROM tblLocalIdentity ORDER BY Name;"); + st.Step(); + + rval+=""; + return rval; +} + +const std::string AnnounceIdentityPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + DateTime date; + std::string content; + int shown=0; + std::string countstr=""; + std::string uuid; + std::string lastid=""; + std::string thisid=""; + std::string day=""; + + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="announce") + { + SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblIdentityIntroductionInserts(LocalIdentityID,Day,UUID,Solution) VALUES(?,?,?,?);"); + std::string localidentityidstr=""; + int localidentityid=0; + std::vector uuids; + std::vector days; + std::vector solutions; + + if(queryvars.find("localidentityid")!=queryvars.end()) + { + localidentityidstr=(*queryvars.find("localidentityid")).second; + StringFunctions::Convert(localidentityidstr,localidentityid); + } + CreateArgArray(queryvars,"uuid",uuids); + CreateArgArray(queryvars,"day",days); + CreateArgArray(queryvars,"solution",solutions); + + for(int i=0; i"; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + + date.SetToGMTime(); + date.Add(0,0,0,-1); + SQLite3DB::Statement st=m_db->Prepare("SELECT UUID,Day,IdentityID FROM tblIntroductionPuzzleRequests WHERE UUID NOT IN (SELECT UUID FROM tblIdentityIntroductionInserts) AND UUID NOT IN (SELECT UUID FROM tblIntroductionPuzzleInserts) AND Day>='"+date.Format("%Y-%m-%d")+"' AND Found='true' ORDER BY IdentityID, Day DESC, RequestIndex DESC;"); + st.Step(); + + if(st.RowReturned()==false) + { + content+=""; + } + + while(st.RowReturned() && shown<20) + { + st.ResultText(0,uuid); + st.ResultText(1,day); + st.ResultText(2,thisid); + + if(thisid!=lastid) + { + StringFunctions::Convert(shown,countstr); + if(shown>0 && shown%4==0) + { + content+="\r\n"; + } + content+="\r\n"; + thisid=lastid; + shown++; + } + + st.Step(); + } + + content+=""; + content+="
Select Identity : "; + content+=CreateLocalIdentityDropDown("localidentityid",""); + content+="
Type the answers of a few puzzles
You must wait for some puzzles to be downloaded. Check back later.
"; + content+="
"; + content+=""; + content+=""; + content+=""; + content+="
"; + content+=""; + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool AnnounceIdentityPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("announceidentity.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/createidentitypage.cpp b/src/http/pages/createidentitypage.cpp new file mode 100644 index 0000000..2c55c02 --- /dev/null +++ b/src/http/pages/createidentitypage.cpp @@ -0,0 +1,50 @@ +#include "../../../include/http/pages/createidentitypage.h" +#include "../../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +const std::string CreateIdentityPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + std::string content=""; + + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="create") + { + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name,PublishTrustList) VALUES(?,'true');"); + std::string name=""; + + if(queryvars.find("name")!=queryvars.end()) + { + name=(*queryvars.find("name")).second; + } + + st.Bind(0,name); + st.Step(); + + content+="

Created Identity

"; + } + else + { + content+="

Create Identity

"; + content+="
"; + content+=""; + content+="Name : "; + content+=" "; + content+="
"; + } + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool CreateIdentityPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("createidentity.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/homepage.cpp b/src/http/pages/homepage.cpp index 28bfa0f..cbc57e4 100644 --- a/src/http/pages/homepage.cpp +++ b/src/http/pages/homepage.cpp @@ -1,4 +1,5 @@ #include "../../../include/http/pages/homepage.h" +#include "../../../include/stringfunctions.h" #ifdef XMEM #include @@ -6,7 +7,11 @@ const std::string HomePage::GeneratePage(const std::string &method, const std::map &queryvars) { - return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHome"; + std::string content="

Home

"; + content+="

"; + content+="Use these pages to administer your FMS installation."; + content+="

"; + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); } const bool HomePage::WillHandleURI(const std::string &uri) diff --git a/src/http/pages/localidentitiespage.cpp b/src/http/pages/localidentitiespage.cpp new file mode 100644 index 0000000..821339d --- /dev/null +++ b/src/http/pages/localidentitiespage.cpp @@ -0,0 +1,139 @@ +#include "../../../include/http/pages/localidentitiespage.h" +#include "../../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +const std::string LocalIdentitiesPage::CreateTrueFalseDropDown(const std::string &name, const std::string &selected) +{ + std::string rval=""; + + rval+=""; + content+=""; + + SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID,tblLocalIdentity.Name,tblLocalIdentity.PublicKey,tbLLocalIdentity.PublishTrustList,tblLocalIdentity.SingleUse,tblLocalIdentity.PublishBoardList,tblIdentity.IdentityID FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey ORDER BY tblLocalIdentity.Name;"); + st.Step(); + + count=0; + while(st.RowReturned()) + { + StringFunctions::Convert(count,countstr); + std::string id; + std::string name; + std::string publickey; + std::string publishtrustlist; + std::string singleuse; + + st.ResultText(0,id); + st.ResultText(1,name); + st.ResultText(2,publickey); + st.ResultText(3,publishtrustlist); + st.ResultText(4,singleuse); + + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + if(st.ResultNull(6)) + { + content+=""; + } + else + { + content+=""; + } + content+=""; + st.Step(); + count++; + } + + content+=""; + content+="
NameSingle UsePublish Trust ListAnnounced? *
"+name+""+CreateTrueFalseDropDown("singleuse["+countstr+"]",singleuse)+""+CreateTrueFalseDropDown("publishtrustlist["+countstr+"]",publishtrustlist)+"NoYes
"; + content+="

* An identity is considered successfully announced when you have downloaded a trust list from someone that contains the identity.

"; + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool LocalIdentitiesPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("localidentities.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/optionspage.cpp b/src/http/pages/optionspage.cpp new file mode 100644 index 0000000..4c39834 --- /dev/null +++ b/src/http/pages/optionspage.cpp @@ -0,0 +1,78 @@ +#include "../../../include/http/pages/optionspage.h" +#include "../../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +const std::string OptionsPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + std::string content="

Options

\r\n"; + content+="
"; + content+=""; + + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="save") + { + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;"); + std::vector options; + std::vector oldvalues; + std::vector newvalues; + CreateArgArray(queryvars,"option",options); + CreateArgArray(queryvars,"oldvalue",oldvalues); + CreateArgArray(queryvars,"value",newvalues); + + for(int i=0; iPrepare("SELECT Option,OptionValue,OptionDescription FROM tblOption;"); + st.Step(); + + int count=0; + std::string countstr; + while(st.RowReturned()) + { + std::string option; + std::string value; + std::string description; + + st.ResultText(0,option); + st.ResultText(1,value); + st.ResultText(2,description); + + StringFunctions::Convert(count,countstr); + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + st.Step(); + count++; + } + + content+=""; + content+="
OptionValueDescription
"+option+""; + content+=""+description+"
"; + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool OptionsPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("options.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/peertrustpage.cpp b/src/http/pages/peertrustpage.cpp new file mode 100644 index 0000000..a9ac96f --- /dev/null +++ b/src/http/pages/peertrustpage.cpp @@ -0,0 +1,123 @@ +#include "../../../include/http/pages/peertrustpage.h" +#include "../../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +const std::string PeerTrustPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + int count=0; + std::string countstr; + std::string content=""; + + if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="update") + { + std::vector identityids; + std::vector oldlmt; + std::vector lmt; + std::vector oldltlt; + std::vector ltlt; + int localmessagetrust=0; + int localtrustlisttrust=0; + int identityid; + + CreateArgArray(queryvars,"identityid",identityids); + CreateArgArray(queryvars,"oldlocalmessagetrust",oldlmt); + CreateArgArray(queryvars,"localmessagetrust",lmt); + CreateArgArray(queryvars,"oldlocaltrustlisttrust",oldltlt); + CreateArgArray(queryvars,"localtrustlisttrust",ltlt); + + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); + + for(int i=0; i"; + content+=""; + content+=""; + content+=""; + + SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID,Name,LocalMessageTrust,PeerMessageTrust,LocalTrustListTrust,PeerTrustListTrust,PublicKey FROM tblIdentity ORDER BY Name;"); + st.Step(); + + while(st.RowReturned()) + { + std::string identityid; + std::string name; + std::string localmessagetrust; + std::string peermessagetrust; + std::string localtrustlisttrust; + std::string peertrustlisttrust; + std::string publickey; + + StringFunctions::Convert(count,countstr); + + st.ResultText(0,identityid); + st.ResultText(1,name); + st.ResultText(2,localmessagetrust); + st.ResultText(3,peermessagetrust); + st.ResultText(4,localtrustlisttrust); + st.ResultText(5,peertrustlisttrust); + st.ResultText(6,publickey); + + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + content+=""; + st.Step(); + count++; + } + + content+=""; + content+="
NameLocal Message TrustPeer Message TrustLocal Trust List TrustPeer Trust List Trust
"; + content+=""; + if(name!="") + { + content+=name; + } + else + { + content+="[Unknown Name]"; + } + content+=""; + content+=""; + content+=""+peermessagetrust+""; + content+=""; + content+=""+peertrustlisttrust+"
"; + content+=""; + + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"+StringFunctions::Replace(m_template,"[CONTENT]",content); +} + +const bool PeerTrustPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("peertrust.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/http/pages/showcaptchapage.cpp b/src/http/pages/showcaptchapage.cpp new file mode 100644 index 0000000..abd65b3 --- /dev/null +++ b/src/http/pages/showcaptchapage.cpp @@ -0,0 +1,48 @@ +#include "../../../include/http/pages/showcaptchapage.h" +#include "../../../include/base64.h" +#include "../../../include/stringfunctions.h" + +#ifdef XMEM + #include +#endif + +const std::string ShowCaptchaPage::GeneratePage(const std::string &method, const std::map &queryvars) +{ + std::string content="HTTP/1.1 200 OK\r\n"; + if(queryvars.find("UUID")!=queryvars.end()) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT MimeType,PuzzleData FROM tblIntroductionPuzzleRequests WHERE UUID=?;"); + st.Bind(0,(*queryvars.find("UUID")).second); + st.Step(); + + if(st.RowReturned()) + { + std::string mime; + std::string b64data; + std::vector data; + std::string lenstr; + + st.ResultText(0,mime); + st.ResultText(1,b64data); + Base64::Decode(b64data,data); + StringFunctions::Convert(data.size(),lenstr); + + content+="Content-Type: "+mime+"\r\n"; + content+="Content-Length: "+lenstr+"\r\n\r\n"; + content+=std::string(data.begin(),data.end()); + } + } + return content; +} + +const bool ShowCaptchaPage::WillHandleURI(const std::string &uri) +{ + if(uri.find("showcaptcha.")!=std::string::npos) + { + return true; + } + else + { + return false; + } +} diff --git a/src/message.cpp b/src/message.cpp index f4d3a95..dee644d 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -22,7 +22,7 @@ Message::Message(const long messageid) const std::string Message::GetNNTPArticleID() const { - return "<"+m_messageuuid+">"; + return "<"+m_messageuuid+"@freenetproject.org>"; } const std::string Message::GetNNTPBody() const @@ -57,7 +57,7 @@ const std::string Message::GetNNTPHeaders() const { rval+=" "; } - rval+="<"+(*j).second+">"; + rval+="<"+(*j).second+"@freenetproject.org>"; } rval+="\r\n"; } @@ -276,6 +276,18 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) } } m_fromname=StringFunctions::TrimWhitespace(m_fromname); + + // trim off " from beginning and end + if(m_fromname.size()>0 && m_fromname[0]=='\"') + { + m_fromname.erase(0,1); + } + if(m_fromname.size()>0 && m_fromname[m_fromname.size()-1]=='\"') + { + m_fromname.erase(m_fromname.size()-1,1); + } + + m_fromname=StringFunctions::TrimWhitespace(m_fromname); } else { @@ -328,9 +340,15 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) StringFunctions::SplitMultiple(temp,", \t",parts); for(std::vector::reverse_iterator i=parts.rbegin(); i!=parts.rend(); i++) { + // get rid of < and > and any whitespace (*i)=StringFunctions::Replace((*i),"<",""); (*i)=StringFunctions::Replace((*i),">",""); (*i)=StringFunctions::TrimWhitespace((*i)); + // erase @ and everything after + if((*i).find("@")!=std::string::npos) + { + (*i).erase((*i).find("@")); + } if((*i)!="") { m_inreplyto[count++]=(*i); diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index d909c36..d7eaa70 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -636,6 +636,11 @@ const bool NNTPConnection::HandleOverCommand(const NNTPCommand &command) messageuuid=command.m_arguments[0]; messageuuid=StringFunctions::Replace(messageuuid,"<",""); messageuuid=StringFunctions::Replace(messageuuid,">",""); + // get rid of @ and everything after + if(messageuuid.find("@")!=std::string::npos) + { + messageuuid.erase(messageuuid.find("@")); + } } // single article or range else @@ -944,7 +949,7 @@ void NNTPConnection::SendArticleOverInfo(Message &message) { line+=" "; } - line+="<"+(*i).second+">"; + line+="<"+(*i).second+"@freenetproject.org>"; } line+="\t"; } diff --git a/template.htm b/template.htm new file mode 100644 index 0000000..7c4782e --- /dev/null +++ b/template.htm @@ -0,0 +1,221 @@ + + +FMS : Freenet Message System + + + + + + + + +
+ + + +
+ + [CONTENT] + +
+ +
+ + + +