ENDIF(APPLE)\r
OPTION(DO_CHARSET_CONVERSION "Do charset conversion on sent messages to UTF-8. This requires libiconv." ON)\r
OPTION(I_HAVE_READ_THE_README "I have fully read and understood the readme.txt." OFF)\r
+OPTION(ALTERNATE_CAPTCHA "Use alternate captcha. This requires the FreeImage library." OFF)\r
\r
-SET(FMS_SRC \r
+SET(FMS_SRC\r
src/base64.cpp\r
src/bitmapvalidator.cpp\r
src/board.cpp\r
SET(FMS_SRC ${FMS_SRC} src/charsetconverter.cpp)\r
ENDIF(DO_CHARSET_CONVERSION)\r
\r
+IF(ALTERNATE_CAPTCHA)\r
+ SET(FMS_SRC ${FMS_SRC} \r
+ src/freenet/captcha/alternatecaptcha1.cpp\r
+ src/freenet/captcha/freeimage/bitmap.cpp\r
+ src/freenet/captcha/freeimage/font.cpp)\r
+ENDIF(ALTERNATE_CAPTCHA)\r
+\r
IF(NOT I_HAVE_READ_THE_README)\r
MESSAGE(FATAL_ERROR "You must fully read the readme.txt before continuing.")\r
ENDIF(NOT I_HAVE_READ_THE_README)\r
FIND_LIBRARY(POCO_XML_LIBRARY NAMES PocoXML PocoXMLmt)\r
FIND_LIBRARY(PTHREADS_LIBRARY NAMES pthread pthreads pthreadvc2)\r
FIND_LIBRARY(ICONV_LIBRARY NAMES iconv iconv_s libiconv libiconv_s)\r
+IF(ALTERNATE_CAPTCHA)\r
+ FIND_FILE(FREEIMAGE_LIBRARY NAMES libfreeimage.a PATHS /usr/lib/)\r
+ IF(NOT FREEIMAGE_LIBRARY)\r
+ FIND_LIBRARY(FREEIMAGE_LIBRARY NAMES FreeImage libFreeImage libfreeimage)\r
+ ENDIF(NOT FREEIMAGE_LIBRARY)\r
+ENDIF(ALTERNATE_CAPTCHA)\r
\r
IF(POCO_FOUNDATION_LIBRARY)\r
TARGET_LINK_LIBRARIES(fms ${POCO_FOUNDATION_LIBRARY})\r
ENDIF(ICONV_LIBRARY)\r
ENDIF(DO_CHARSET_CONVERSION)\r
\r
+IF(ALTERNATE_CAPTCHA)\r
+ IF(FREEIMAGE_LIBRARY)\r
+ TARGET_LINK_LIBRARIES(fms ${FREEIMAGE_LIBRARY})\r
+ ADD_DEFINITIONS("-DALTERNATE_CAPTCHA")\r
+ ELSE(FREEIMAGE_LIBRARY)\r
+ MESSAGE(FATAL_ERROR "Could not find the FreeImage library. Set the location manually, or turn off the alternate captchas.")\r
+ ENDIF(FREEIMAGE_LIBRARY)\r
+ENDIF(ALTERNATE_CAPTCHA)\r
+\r
# FreeBSD won't find Poco include files without this\r
IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")\r
INCLUDE_DIRECTORIES(AFTER /usr/local/include)\r
--- /dev/null
+#ifndef _alternate_captcha1_\r
+#define _alternate_captcha1_\r
+\r
+#ifdef ALTERNATE_CAPTCHA\r
+\r
+#include <string>\r
+\r
+#include "icaptcha.h"\r
+#include "freeimage/bitmap.h"\r
+#include "freeimage/font.h"\r
+\r
+class AlternateCaptcha1:public ICaptcha\r
+{\r
+public:\r
+ AlternateCaptcha1();\r
+\r
+ void Generate();\r
+\r
+ const bool GetPuzzle(std::vector<unsigned char> &puzzle);\r
+ const bool GetSolution(std::vector<unsigned char> &solution);\r
+\r
+private:\r
+ void LoadFonts();\r
+ const std::string GenerateRandomString(const int len);\r
+\r
+ static bool m_fontsloaded;\r
+ static std::vector<FreeImage::Font> m_fonts;\r
+\r
+ std::vector<unsigned char> m_puzzle;\r
+ std::vector<unsigned char> m_solution;\r
+\r
+};\r
+\r
+#endif // ALTERNATE_CAPTCHA\r
+\r
+#endif // _alternate_captcha1_\r
--- /dev/null
+#ifndef _freeimage_bitmap_\r
+#define _freeimage_bitmap_\r
+\r
+#include <FreeImage.h>\r
+\r
+#include <string>\r
+#include <vector>\r
+\r
+namespace FreeImage\r
+{\r
+\r
+class Bitmap\r
+{\r
+public:\r
+ Bitmap();\r
+ Bitmap(const Bitmap &bmp);\r
+ Bitmap(const std::string &typestr, const std::string &filename);\r
+ Bitmap(FIBITMAP *bmp);\r
+ Bitmap(const int width, const int height, const int bpp);\r
+ ~Bitmap();\r
+\r
+ const bool Create(const int width, const int height, const int bpp);\r
+\r
+ inline const unsigned int Height() const { return m_bmp ? FreeImage_GetHeight(m_bmp) : 0 ; }\r
+ inline const unsigned int Width() const { return m_bmp ? FreeImage_GetWidth(m_bmp) : 0 ; }\r
+ inline const unsigned int BPP() const { return m_bmp ? FreeImage_GetBPP(m_bmp) : 0 ; }\r
+ void ConvertBPP(const int bpp);\r
+\r
+ void Clear(const RGBQUAD color);\r
+ void ClearTransparent();\r
+\r
+ const bool Save(const std::string &filename) const;\r
+ const bool SaveToMemory(const std::string &typestr, std::vector<unsigned char> &data) const;\r
+ const bool Load(const std::string &typestr, const std::string &filename);\r
+ const bool LoadFromMemory(const std::string &typestr, std::vector<unsigned char> &data);\r
+\r
+ void SetTransparent();\r
+ \r
+ void PutPixel(const int x, const int y, RGBQUAD color);\r
+ RGBQUAD GetPixel(const int x, const int y) const;\r
+ const int GetPixelIndex(const int x, const int y) const;\r
+ void Line(const int x1, const int y1, const int x2, const int y2, const RGBQUAD color);\r
+ void FastLine(const int x1, const int y1, const int x2, const int y2, const RGBQUAD color);\r
+ //void Arc(const int cx, const int cy, const int r, const float start, const float end, const RGBQUAD color);\r
+ void Rect(const int x1, const int y1, const int w, const int h, const bool filled, const RGBQUAD color);\r
+ void Rotate(const double angle, const int shiftx, const int shifty, const int originx, const int originy);\r
+ void HorizontalOffset(const int y, const double shift);\r
+ void VerticalOffset(const int x, const double shift);\r
+\r
+ void Blit(const Bitmap &bmp, const int destx, const int desty, const int sourcex, const int sourcey, const int w, const int h, const int alpha);\r
+ void BlitTrans(const Bitmap &bmp, const int destx, const int desty, const int sourcex, const int sourcey, const int w, const int h);\r
+\r
+ Bitmap &operator=(const Bitmap &rhs);\r
+\r
+private:\r
+ void Destroy();\r
+ void AALine(const int x1, const int y1, const int x2, const int y2, const RGBQUAD color);\r
+ double LineFunction(const double slopex, const double slopey, const int startx, const int starty, const double testx, const double texty);\r
+\r
+ FIBITMAP *m_bmp;\r
+\r
+};\r
+\r
+}\r
+\r
+#endif // _freeimage_bitmap_\r
--- /dev/null
+#ifndef _freeimage_font_\r
+#define _freeimage_font_\r
+\r
+#include "bitmap.h"\r
+\r
+namespace FreeImage\r
+{\r
+\r
+class Font\r
+{\r
+public:\r
+ Font();\r
+ Font(const Bitmap &bmp);\r
+ ~Font();\r
+ \r
+ const bool Load(const Bitmap &bmp);\r
+\r
+ const Bitmap &Char(const int num);\r
+\r
+ const int FontWidth() const { return m_fontwidth; }\r
+ const int FontHeight() const { return m_fontheight; }\r
+\r
+private:\r
+ int m_fontwidth;\r
+ int m_fontheight;\r
+ Bitmap m_blank;\r
+ std::vector<Bitmap> m_chars;\r
+\r
+};\r
+\r
+}\r
+\r
+#endif // _freeimage_font_\r
\r
#define VERSION_MAJOR "0"\r
#define VERSION_MINOR "3"\r
-#define VERSION_RELEASE "13"\r
+#define VERSION_RELEASE "14"\r
#define FMS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_RELEASE\r
\r
typedef Poco::ScopedLock<Poco::FastMutex> Guard;\r
to the cmake command. Use of the bundled SQLite3 library is on by default when\r
compiling on a Mac. To turn off charset conversion to UTF-8 when sending\r
messages, add a -D DO_CHARSET_CONVERSION=OFF. Compiling with charset\r
-conversion turned on is recommended.\r
+conversion turned on is recommended. If you would like to compile using the\r
+alternate captchas, add a -D ALTERNATE_CAPTCHA=ON to the cmake command line.\r
+This option requires the FreeImage library to be installed.\r
\r
UPGRADING\r
---------\r
\r
INSTALLATION\r
------------\r
-Place the binary and any templates in a directory of your choice. Windows\r
-users may need to download the runtime DLLs available from the fms Freesite and\r
-place in the fms directory if they are not already installed on the system. On\r
-the first run, a database file will also be created in this directory. Make\r
-sure the user that runs FMS has read/write access to this directory.\r
+Place the binary, any templates, and the fonts directory in a directory of your\r
+choice. Windows users may need to download the runtime DLLs available from the\r
+fms Freesite and place in the fms directory if they are not already installed\r
+on the system. On the first run, a database file will also be created in this\r
+directory. Make sure the user that runs FMS has read/write access to this\r
+directory.\r
\r
RUNNING\r
-------\r
--- /dev/null
+#include "../../../include/freenet/captcha/alternatecaptcha1.h"\r
+\r
+#include <Poco/Path.h>\r
+#include <Poco/DirectoryIterator.h>\r
+\r
+#include <cmath>\r
+\r
+#ifdef ALTERNATE_CAPTCHA\r
+\r
+bool AlternateCaptcha1::m_fontsloaded(false);\r
+std::vector<FreeImage::Font> AlternateCaptcha1::m_fonts;\r
+\r
+AlternateCaptcha1::AlternateCaptcha1()\r
+{\r
+ if(m_fontsloaded==false)\r
+ {\r
+ FreeImage_Initialise(true);\r
+ LoadFonts();\r
+ m_fontsloaded=true;\r
+ }\r
+}\r
+\r
+void AlternateCaptcha1::Generate()\r
+{\r
+ std::string puzzlestring=GenerateRandomString(5);\r
+ FreeImage::Bitmap tempchar(50,50,32);\r
+ tempchar.SetTransparent();\r
+ FreeImage::Bitmap bmp(110,50,32);\r
+ bmp.SetTransparent();\r
+\r
+ m_solution.clear();\r
+ m_puzzle.clear();\r
+\r
+ // draw the text\r
+ if(m_fonts.size()>0)\r
+ {\r
+ for(int i=0; i<puzzlestring.size(); i++)\r
+ {\r
+ RGBQUAD black;\r
+ black.rgbRed=0;\r
+ black.rgbGreen=0;\r
+ black.rgbBlue=0;\r
+ int xoffset=(i*20)-(5+(rand()%5));\r
+ int yoffset=(rand()%20)-10;\r
+ int fontnum=rand()%m_fonts.size();\r
+ FreeImage::Bitmap charbmp=m_fonts[fontnum].Char(puzzlestring[i]);\r
+\r
+ tempchar.SetTransparent();\r
+ tempchar.ClearTransparent();\r
+ tempchar.BlitTrans(charbmp,25-(charbmp.Width()/2),25-(charbmp.Height()/2),0,0,charbmp.Width(),charbmp.Height());\r
+ tempchar.Rotate((rand()%60)-30,0,0,25,25);\r
+\r
+ bmp.BlitTrans(tempchar,xoffset,yoffset,0,0,50,50);\r
+ }\r
+ }\r
+\r
+ //place some random lines\r
+ RGBQUAD white;\r
+ white.rgbRed=255;\r
+ white.rgbGreen=255;\r
+ white.rgbBlue=255;\r
+ white.rgbReserved=255;\r
+ int numlines=(rand()%5)+10;\r
+ for(int i=0; i<numlines; i++)\r
+ {\r
+ // draw 4 short lines very close to each other\r
+ int x1[4];\r
+ int y1[4];\r
+ int x2[4];\r
+ int y2[4];\r
+\r
+ x1[0]=rand()%bmp.Width();\r
+ y1[0]=rand()%bmp.Height();\r
+ x2[0]=x1[0]+(rand()%40)-20;\r
+ y2[0]=y1[0]+(rand()%40)-20;\r
+\r
+ for(int i=1; i<4; i++)\r
+ {\r
+ x1[i]=x1[i-1]+rand()%3-1;\r
+ y1[i]=y1[i-1]+rand()%3-1;\r
+ x2[i]=x2[i-1]+rand()%3-1;\r
+ y2[i]=y2[i-1]+rand()%3-1;\r
+ }\r
+\r
+ for(int i=0; i<4; i++)\r
+ {\r
+ bmp.Line(x1[i],y1[i],x2[i],y2[i],white);\r
+ }\r
+ }\r
+\r
+ int offset=rand()%10000;\r
+ for(int y=0; y<bmp.Height(); y++)\r
+ {\r
+ double shift=sin((double)(y+offset)/3.0);\r
+ bmp.HorizontalOffset(y,shift);\r
+ }\r
+\r
+ m_solution.clear();\r
+ m_solution.insert(m_solution.end(),puzzlestring.begin(),puzzlestring.end());\r
+ m_puzzle.clear();\r
+ bmp.SaveToMemory("bmp",m_puzzle);\r
+\r
+}\r
+\r
+const std::string AlternateCaptcha1::GenerateRandomString(const int len)\r
+{\r
+ // no l,1 O,0 because they look too much alike\r
+ static std::string chars="abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789@#";\r
+ std::string temp="";\r
+ for(int i=0; i<len; i++)\r
+ {\r
+ temp+=chars[rand()%chars.size()];\r
+ }\r
+ return temp;\r
+}\r
+\r
+const bool AlternateCaptcha1::GetPuzzle(std::vector<unsigned char> &puzzle)\r
+{\r
+ puzzle=m_puzzle;\r
+ return true;\r
+}\r
+\r
+const bool AlternateCaptcha1::GetSolution(std::vector<unsigned char> &solution)\r
+{\r
+ solution=m_solution;\r
+ return true;\r
+}\r
+\r
+void AlternateCaptcha1::LoadFonts()\r
+{\r
+ FreeImage::Bitmap bmp;\r
+ Poco::Path path("fonts");\r
+ Poco::DirectoryIterator di(path);\r
+ Poco::DirectoryIterator end;\r
+\r
+ while(di!=end)\r
+ {\r
+ if(di.name().find("bmp")!=std::string::npos)\r
+ {\r
+ bmp.Load("bmp",di.path().toString());\r
+ m_fonts.push_back(FreeImage::Font(bmp));\r
+ }\r
+ ++di;\r
+ }\r
+\r
+}\r
+\r
+#endif // ALTERNATE_CAPTCHA\r
--- /dev/null
+#include "../../../../include/freenet/captcha/freeimage/bitmap.h"\r
+\r
+#include <cmath>\r
+\r
+namespace FreeImage\r
+{\r
+\r
+Bitmap::Bitmap()\r
+{\r
+ m_bmp=0;\r
+}\r
+\r
+Bitmap::Bitmap(const Bitmap &bmp)\r
+{\r
+ m_bmp=0;\r
+ *this=bmp;\r
+}\r
+\r
+Bitmap::Bitmap(const std::string &typestr, const std::string &filename)\r
+{\r
+ m_bmp=0;\r
+ Load(typestr,filename);\r
+}\r
+\r
+Bitmap::Bitmap(FIBITMAP *bmp):m_bmp(bmp)\r
+{\r
+\r
+}\r
+\r
+Bitmap::Bitmap(const int width, const int height, const int bpp)\r
+{\r
+ m_bmp=FreeImage_Allocate(width,height,bpp,0,0,0);\r
+}\r
+\r
+Bitmap::~Bitmap()\r
+{\r
+ Destroy();\r
+}\r
+\r
+void Bitmap::AALine(const int x1, const int y1, const int x2, const int y2, const RGBQUAD color)\r
+{\r
+ RGBQUAD tempcol;\r
+ int height=Height();\r
+ int width=Width();\r
+ int fromx=x1;\r
+ int fromy=y1;\r
+ int tox=x2;\r
+ int toy=y2;\r
+ double sx=x2-x1;\r
+ double sy=y2-y1;\r
+\r
+ if(fabs(sx)<=0.8 && fabs(sy)<=0.8)\r
+ {\r
+ return;\r
+ }\r
+\r
+ double hypot=sqrt((sx*sx)+(sy*sy));\r
+ sx/=hypot;\r
+ sy/=hypot;\r
+\r
+ fromx<0 ? fromx=0 : false;\r
+ fromx>=width ? fromx=width-1 : false;\r
+ tox<0 ? tox=0 : false;\r
+ tox>=width ? tox=width-1 : false;\r
+ fromy<0 ? fromy=0 : false;\r
+ fromy>=height ? fromy=height-1 : false;\r
+ toy<0 ? toy=0 : false;\r
+ toy>=height ? toy=height-1 : false;\r
+\r
+ int lx=fromx;\r
+ int rx=tox;\r
+ if(rx<lx)\r
+ {\r
+ std::swap(rx,lx);\r
+ }\r
+ int ty=fromy;\r
+ int by=toy;\r
+ if(by<ty)\r
+ {\r
+ std::swap(ty,by);\r
+ }\r
+\r
+ for(int i=lx; i<=rx; i++)\r
+ {\r
+ for(int j=ty; j<=by; j++)\r
+ {\r
+ double ii=0;\r
+ double jj=0;\r
+ double dx=0.25;\r
+ double dy=0.25;\r
+ double x=i-1.5*dx;\r
+ double y=j-1.5*dy;\r
+ double temp=0;\r
+ \r
+ for(ii=-2; ii<=1; ii++)\r
+ {\r
+ for(jj=-2; jj<=1; jj++)\r
+ {\r
+ x=i+ii*dx+0.5*dx;\r
+ y=j+jj*dy+0.5*dy;\r
+ double temp1 = LineFunction( sx, sy , fromx, fromy, x,y );\r
+ temp1<=0.5 ? temp1=1.0 : temp1=0.0;\r
+ temp+=temp1;\r
+ }\r
+ }\r
+\r
+ temp/=16.0;\r
+ double minval=0.03125;\r
+\r
+ if(temp>minval)\r
+ {\r
+ FreeImage_GetPixelColor(m_bmp,i,(height-1)-j,&tempcol);\r
+ tempcol.rgbRed=((1.0-temp)*((double)tempcol.rgbRed)+temp*((double)color.rgbRed));\r
+ tempcol.rgbGreen=((1.0-temp)*((double)tempcol.rgbGreen)+temp*((double)color.rgbGreen));\r
+ tempcol.rgbBlue=((1.0-temp)*((double)tempcol.rgbBlue)+temp*((double)color.rgbBlue));\r
+ FreeImage_SetPixelColor(m_bmp,i,(height-1)-j,&tempcol);\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+}\r
+\r
+void Bitmap::Blit(const Bitmap &bmp, const int destx, const int desty, const int sourcex, const int sourcey, const int w, const int h, const int alpha)\r
+{\r
+ if(m_bmp && bmp.m_bmp)\r
+ {\r
+ int width=w;\r
+ int height=h;\r
+ if(destx+width-1>=Width())\r
+ {\r
+ width=Width()-destx+1;\r
+ }\r
+ if(desty+height-1>=Height())\r
+ {\r
+ height=Height()-desty+1;\r
+ }\r
+ FIBITMAP *temp=FreeImage_Copy(bmp.m_bmp,sourcex,sourcey,sourcex+width-1,sourcey+height-1);\r
+ FreeImage_Paste(m_bmp,temp,destx,desty,alpha);\r
+ FreeImage_Unload(temp);\r
+ }\r
+}\r
+\r
+void Bitmap::BlitTrans(const Bitmap &bmp, const int destx, const int desty, const int sourcex, const int sourcey, const int w, const int h)\r
+{\r
+ if(m_bmp && bmp.m_bmp)\r
+ {\r
+ RGBQUAD sourcecol;\r
+ RGBQUAD destcol;\r
+ int sourcew=bmp.Width();\r
+ int sourceh=bmp.Height();\r
+ int destw=Width();\r
+ int desth=Height();\r
+ int dx=destx;\r
+ int dy=desty;\r
+ double alpha=0.0;\r
+ for(int y=sourcey; y<sourcey+h; y++, dy++)\r
+ {\r
+ dx=destx;\r
+ for(int x=sourcex; x<sourcex+w; x++, dx++)\r
+ {\r
+ if(y>=0 && y<sourceh && x>=0 && x<sourcew && dx>=0 && dx<destw && dy>=0 && dy<desth)\r
+ {\r
+ FreeImage_GetPixelColor(bmp.m_bmp,x,(sourceh-1)-y,&sourcecol);\r
+ if(sourcecol.rgbReserved==255) // opaque\r
+ {\r
+ FreeImage_SetPixelColor(m_bmp,dx,(desth-1)-dy,&sourcecol);\r
+ }\r
+ else if(sourcecol.rgbReserved>0) // some translucency\r
+ {\r
+ FreeImage_GetPixelColor(m_bmp,dx,(desth-1)-dy,&destcol);\r
+ alpha=(double)sourcecol.rgbReserved/255.0;\r
+ sourcecol.rgbRed=(sourcecol.rgbRed*alpha)+(destcol.rgbRed*(1.0-alpha));\r
+ sourcecol.rgbGreen=(sourcecol.rgbGreen*alpha)+(destcol.rgbGreen*(1.0-alpha));\r
+ sourcecol.rgbBlue=(sourcecol.rgbBlue*alpha)+(destcol.rgbBlue*(1.0-alpha));\r
+ sourcecol.rgbReserved<destcol.rgbReserved ? sourcecol.rgbReserved=destcol.rgbReserved : false;\r
+ FreeImage_SetPixelColor(m_bmp,dx,(desth-1)-dy,&sourcecol);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+void Bitmap::Clear(RGBQUAD color)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ int h=FreeImage_GetHeight(m_bmp);\r
+ int w=FreeImage_GetWidth(m_bmp);\r
+ for(int y=0; y<h; y++)\r
+ {\r
+ for(int x=0; x<w; x++)\r
+ {\r
+ FreeImage_SetPixelColor(m_bmp,x,y,&color);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+void Bitmap::ClearTransparent()\r
+{\r
+ if(m_bmp)\r
+ {\r
+ RGBQUAD color;\r
+ color.rgbRed=0;\r
+ color.rgbGreen=0;\r
+ color.rgbBlue=0;\r
+ color.rgbReserved=0;\r
+ int h=Height();\r
+ int w=Width();\r
+ for(int y=0; y<h; y++)\r
+ {\r
+ for(int x=0; x<w; x++)\r
+ {\r
+ FreeImage_SetPixelColor(m_bmp,x,y,&color);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+void Bitmap::ConvertBPP(const int bpp)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ FIBITMAP *temp;\r
+ switch(bpp)\r
+ {\r
+ case 2:\r
+ temp=FreeImage_ConvertToGreyscale(m_bmp);\r
+ Destroy();\r
+ m_bmp=temp;\r
+ break;\r
+ case 4:\r
+ temp=FreeImage_ConvertTo4Bits(m_bmp);\r
+ Destroy();\r
+ m_bmp=temp;\r
+ break;\r
+ case 8:\r
+ temp=FreeImage_ConvertTo8Bits(m_bmp);\r
+ Destroy();\r
+ m_bmp=temp;\r
+ break;\r
+ case 16:\r
+ temp=FreeImage_ConvertTo16Bits565(m_bmp);\r
+ Destroy();\r
+ m_bmp=temp;\r
+ break;\r
+ case 24:\r
+ temp=FreeImage_ConvertTo24Bits(m_bmp);\r
+ Destroy();\r
+ m_bmp=temp;\r
+ break;\r
+ case 32:\r
+ default:\r
+ temp=FreeImage_ConvertTo32Bits(m_bmp);\r
+ Destroy();\r
+ m_bmp=temp;\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+const bool Bitmap::Create(const int width, const int height, const int bpp)\r
+{\r
+ Destroy();\r
+ m_bmp=FreeImage_Allocate(width,height,bpp,0,0,0);\r
+ if(m_bmp)\r
+ {\r
+ return true;\r
+ }\r
+ return false;\r
+}\r
+\r
+void Bitmap::Destroy()\r
+{\r
+ if(m_bmp)\r
+ {\r
+ FreeImage_Unload(m_bmp);\r
+ m_bmp=0;\r
+ }\r
+}\r
+\r
+void Bitmap::FastLine(const int x1, const int y1, const int x2, const int y2, RGBQUAD color)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ int width=Width();\r
+ int height=Height();\r
+ int fromx=x1;\r
+ int fromy=y1;\r
+ int tox=x2;\r
+ int toy=y2;\r
+\r
+ fromx<0 ? fromx=0 : false;\r
+ fromx>=width ? fromx=width-1 : false;\r
+ tox<0 ? tox=0 : false;\r
+ tox>=width ? tox=width-1 : false;\r
+ fromy<0 ? fromy=0 : false;\r
+ fromy>=height ? fromy=height-1 : false;\r
+ toy<0 ? toy=0 : false;\r
+ toy>=height ? toy=height-1 : false;\r
+\r
+ int dx=tox-fromx;\r
+ int dy=toy-fromy;\r
+\r
+ if(dx==0 && dy==0)\r
+ {\r
+ return;\r
+ }\r
+\r
+ int xinc1=1;\r
+ if(dx<0)\r
+ {\r
+ xinc1=-1;\r
+ dx=-dx;\r
+ }\r
+ int yinc1=1;\r
+ if(dy<0)\r
+ {\r
+ yinc1=-1;\r
+ dy=-dy;\r
+ }\r
+\r
+ int x=fromx;\r
+ int y=fromy;\r
+ int xinc2=xinc1;\r
+ int yinc2=yinc1;\r
+\r
+ double den;\r
+ double num;\r
+ int numadd;\r
+ int numpixels;\r
+\r
+ if(dx>=dy)\r
+ {\r
+ xinc1=0;\r
+ yinc2=0;\r
+ den=dx+0.0;\r
+ num=0.5*dx;\r
+ numadd=dy;\r
+ numpixels=dx;\r
+ }\r
+ else\r
+ {\r
+ xinc2=0;\r
+ yinc1=0;\r
+ den=dy+0.0;\r
+ num=0.5*dy;\r
+ numadd=dx;\r
+ numpixels=dy;\r
+ }\r
+\r
+ int cpixel;\r
+ for(cpixel=0; cpixel<=numpixels; cpixel++)\r
+ {\r
+ FreeImage_SetPixelColor(m_bmp,x,(height-1)-y,&color);\r
+ num+=numadd;\r
+ if(num>=den)\r
+ {\r
+ num=-den;\r
+ x+=xinc1;\r
+ y+=yinc1;\r
+ }\r
+ x+=xinc2;\r
+ y+=yinc2;\r
+ }\r
+ }\r
+}\r
+\r
+RGBQUAD Bitmap::GetPixel(const int x, const int y) const\r
+{\r
+ RGBQUAD color;\r
+ color.rgbRed=0;\r
+ color.rgbGreen=0;\r
+ color.rgbBlue=0;\r
+ color.rgbReserved=0;\r
+\r
+ if(m_bmp && x>=0 && x<Width() && y>=0 && y<Height())\r
+ {\r
+ FreeImage_GetPixelColor(m_bmp,x,Height()-1-y,&color);\r
+ }\r
+\r
+ return color;\r
+\r
+}\r
+\r
+const int Bitmap::GetPixelIndex(const int x, const int y) const\r
+{\r
+ if(m_bmp)\r
+ {\r
+ BYTE index;\r
+ FreeImage_GetPixelIndex(m_bmp,x,Height()-1-y,&index);\r
+ return index;\r
+ }\r
+ else\r
+ {\r
+ return -1;\r
+ }\r
+}\r
+\r
+void Bitmap::HorizontalOffset(const int y, const double shift)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ int width=Width();\r
+ int height=Height();\r
+ int startx=width-1;\r
+ int endx=ceil(shift);\r
+ int dx=-1;\r
+ int offset1=-(floor(shift));\r
+ int offset2=-(ceil(shift));\r
+ RGBQUAD color1;\r
+ RGBQUAD color2;\r
+ RGBQUAD newcolor;\r
+ double part2=shift-floor(shift);\r
+ double part1=1.0-part2;\r
+\r
+ if(shift<0)\r
+ {\r
+ startx=0;\r
+ endx=width-1-ceil(abs(shift));\r
+ dx=1;\r
+ offset1=-ceil(shift);\r
+ offset2=-floor(shift);\r
+ part2=abs(shift-ceil(shift));\r
+ part1=1.0-part2;\r
+ }\r
+\r
+ FreeImage_GetPixelColor(m_bmp,startx+offset1,(height-1)-y,&color1);\r
+ for(int x=startx+dx; x!=endx; x+=dx)\r
+ {\r
+ FreeImage_GetPixelColor(m_bmp,x+offset2,(height-1)-y,&color2);\r
+ \r
+ newcolor.rgbRed=(color1.rgbRed*part1)+(color2.rgbRed*part2);\r
+ newcolor.rgbGreen=(color1.rgbGreen*part1)+(color2.rgbGreen*part2);\r
+ newcolor.rgbBlue=(color1.rgbBlue*part1)+(color2.rgbBlue*part2);\r
+\r
+ FreeImage_SetPixelColor(m_bmp,x,(height-1)-y,&newcolor);\r
+\r
+ color1=color2;\r
+ }\r
+ }\r
+}\r
+\r
+void Bitmap::Line(const int x1, const int y1, const int x2, const int y2, const RGBQUAD color)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ if(x1!=x2 && y1!=y2)\r
+ {\r
+ AALine(x1,y1,x2,y2,color);\r
+ }\r
+ else\r
+ {\r
+ FastLine(x1,y1,x2,y2,color);\r
+ }\r
+ }\r
+}\r
+\r
+double Bitmap::LineFunction(const double slopex, const double slopey, const int startx, const int starty, const double testx, const double testy)\r
+{\r
+ return fabs(slopex*(testy-starty)-slopey*(testx-startx));\r
+}\r
+\r
+const bool Bitmap::Load(const std::string &typestr, const std::string &filename)\r
+{\r
+ Destroy();\r
+ FREE_IMAGE_FORMAT type=FIF_BMP;\r
+ if(typestr.find("png")!=std::string::npos)\r
+ {\r
+ type=FIF_PNG;\r
+ }\r
+ m_bmp=FreeImage_Load(type,filename.c_str(),0);\r
+ if(m_bmp)\r
+ {\r
+ return true;\r
+ }\r
+ return false;\r
+}\r
+\r
+const bool Bitmap::LoadFromMemory(const std::string &typestr, std::vector<unsigned char> &data)\r
+{\r
+ bool loaded=false;\r
+ Destroy();\r
+ if(data.size()>0)\r
+ {\r
+ FREE_IMAGE_FORMAT type=FIF_BMP;\r
+ if(typestr.find("png")!=std::string::npos)\r
+ {\r
+ type=FIF_PNG;\r
+ }\r
+\r
+ FIMEMORY *mem=FreeImage_OpenMemory((BYTE *)&data[0],data.size());\r
+ m_bmp=FreeImage_LoadFromMemory(type,mem,0);\r
+ if(m_bmp)\r
+ {\r
+ loaded=true;\r
+ }\r
+ FreeImage_CloseMemory(mem);\r
+ }\r
+ return loaded;\r
+}\r
+\r
+Bitmap &Bitmap::operator=(const Bitmap &rhs)\r
+{\r
+ if(this!=&rhs)\r
+ {\r
+ Destroy();\r
+ if(rhs.Width()>0 && rhs.Height()>0)\r
+ {\r
+ m_bmp=FreeImage_Allocate(rhs.Width(),rhs.Height(),rhs.BPP(),0,0,0);\r
+ //FIBITMAP *temp=FreeImage_Copy(rhs.m_bmp,0,0,rhs.Width()-1,rhs.Height()-1);\r
+ //FreeImage_Paste(m_bmp,rhs.m_bmp,0,0,-1);\r
+ //FreeImage_Unload(temp);\r
+ Blit(rhs,0,0,0,0,rhs.Width(),rhs.Height(),-1);\r
+ }\r
+ }\r
+ return *this;\r
+}\r
+\r
+void Bitmap::PutPixel(const int x, const int y, RGBQUAD color)\r
+{\r
+ if(m_bmp && x>=0 && x<FreeImage_GetWidth(m_bmp) && y>=0 && y<FreeImage_GetHeight(m_bmp))\r
+ {\r
+ FreeImage_SetPixelColor(m_bmp,x,(Height()-1)-y,&color);\r
+ }\r
+}\r
+\r
+void Bitmap::Rect(const int x1, const int y1, const int w, const int h, const bool filled, RGBQUAD color)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ int height=Height();\r
+ int width=Width();\r
+ for(int y=y1; y<y1+h; y++)\r
+ {\r
+ if(y>=0 && y<height)\r
+ {\r
+ for(int x=x1; x<x1+w; x++)\r
+ {\r
+ if(x>=0 && x<width)\r
+ {\r
+ if(x==x1 || x==x1+w-1 || y==y1 || y==y1+h-1 || filled)\r
+ {\r
+ FreeImage_SetPixelColor(m_bmp,x,(height-1)-y,&color);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+void Bitmap::Rotate(const double angle, const int shiftx, const int shifty, const int originx, const int originy)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ int height=Height();\r
+ FIBITMAP *old=m_bmp;\r
+ m_bmp=FreeImage_RotateEx(m_bmp,angle,shiftx,-shifty,originx,(height-1)-originy,true);\r
+ FreeImage_Unload(old);\r
+ }\r
+}\r
+\r
+const bool Bitmap::Save(const std::string &filename) const\r
+{\r
+ if(m_bmp)\r
+ {\r
+ FREE_IMAGE_FORMAT type=FIF_BMP;\r
+\r
+ if(filename.find(".png")!=std::string::npos)\r
+ {\r
+ type=FIF_PNG;\r
+ }\r
+\r
+ if(FreeImage_Save(type,m_bmp,filename.c_str(),0))\r
+ {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+}\r
+\r
+const bool Bitmap::SaveToMemory(const std::string &typestr, std::vector<unsigned char> &data) const\r
+{\r
+ bool saved=false;\r
+ if(m_bmp)\r
+ {\r
+ FREE_IMAGE_FORMAT type=FIF_BMP;\r
+ if(typestr.find("png")!=std::string::npos)\r
+ {\r
+ type=FIF_PNG;\r
+ }\r
+ FIMEMORY *mem=FreeImage_OpenMemory(0,0);\r
+ if(FreeImage_SaveToMemory(type,m_bmp,mem,0))\r
+ {\r
+ FreeImage_SeekMemory(mem,0,SEEK_END);\r
+ data.resize(FreeImage_TellMemory(mem));\r
+ FreeImage_SeekMemory(mem,0,SEEK_SET);\r
+ FreeImage_ReadMemory(&data[0],1,data.size(),mem);\r
+ saved=true;\r
+ }\r
+ FreeImage_CloseMemory(mem);\r
+ }\r
+ return saved;\r
+}\r
+\r
+void Bitmap::SetTransparent()\r
+{\r
+ if(m_bmp)\r
+ {\r
+ FreeImage_SetTransparent(m_bmp,true);\r
+ }\r
+}\r
+\r
+void Bitmap::VerticalOffset(const int x, const double shift)\r
+{\r
+ if(m_bmp)\r
+ {\r
+ int width=Width();\r
+ int height=Height();\r
+ int starty=width-1;\r
+ int endy=ceil(shift);\r
+ int dy=-1;\r
+ int offset1=-(floor(shift));\r
+ int offset2=-(ceil(shift));\r
+ RGBQUAD color1;\r
+ RGBQUAD color2;\r
+ RGBQUAD newcolor;\r
+ double part2=shift-floor(shift);\r
+ double part1=1.0-part2;\r
+\r
+ if(shift<0)\r
+ {\r
+ starty=0;\r
+ endy=width-1-ceil(abs(shift));\r
+ dy=1;\r
+ offset1=-ceil(shift);\r
+ offset2=-floor(shift);\r
+ part2=abs(shift-ceil(shift));\r
+ part1=1.0-part2;\r
+ }\r
+\r
+ FreeImage_GetPixelColor(m_bmp,x,(height-1)-(starty+offset1),&color1);\r
+ for(int y=starty+dy; y!=endy; y+=dy)\r
+ {\r
+ FreeImage_GetPixelColor(m_bmp,x,(height-1)-(y+offset2),&color2);\r
+ \r
+ newcolor.rgbRed=(color1.rgbRed*part1)+(color2.rgbRed*part2);\r
+ newcolor.rgbGreen=(color1.rgbGreen*part1)+(color2.rgbGreen*part2);\r
+ newcolor.rgbBlue=(color1.rgbBlue*part1)+(color2.rgbBlue*part2);\r
+\r
+ FreeImage_SetPixelColor(m_bmp,x,(height-1)-y,&newcolor);\r
+\r
+ color1=color2;\r
+ }\r
+ }\r
+}\r
+\r
+} // namespace FreeImage\r
--- /dev/null
+#include "../../../../include/freenet/captcha/freeimage/font.h"\r
+\r
+namespace FreeImage\r
+{\r
+\r
+Font::Font()\r
+{\r
+ m_fontwidth=0;\r
+ m_fontheight=0;\r
+}\r
+\r
+Font::Font(const Bitmap &bmp)\r
+{\r
+ m_fontwidth=0;\r
+ m_fontheight=0;\r
+ Load(bmp);\r
+}\r
+\r
+Font::~Font()\r
+{\r
+\r
+}\r
+\r
+const Bitmap &Font::Char(const int num)\r
+{\r
+ if(num>=0 && num<256 && m_chars.size()>num)\r
+ {\r
+ return m_chars[num];\r
+ }\r
+ else\r
+ {\r
+ return m_blank;\r
+ }\r
+}\r
+\r
+const bool Font::Load(const Bitmap &bmp)\r
+{\r
+ m_fontwidth=bmp.Width()/16;\r
+ m_fontheight=bmp.Height()/14;\r
+\r
+ m_chars.clear();\r
+ m_chars.resize(256);\r
+\r
+ int charnum=32;\r
+ for(int yy=0; yy<bmp.Height(); yy+=m_fontheight)\r
+ {\r
+ for(int xx=0; xx<bmp.Width(); xx+=m_fontwidth)\r
+ {\r
+ bool found=false;\r
+ int width=m_fontwidth;\r
+ int idx=bmp.GetPixelIndex(xx+m_fontwidth-1,yy);\r
+ for(int x=xx+m_fontwidth-1; x>xx && found==false; x--)\r
+ {\r
+ for(int y=yy; y<yy+m_fontheight && found==false; y++)\r
+ {\r
+ if(bmp.GetPixelIndex(x,y)!=idx)\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ if(found==false)\r
+ {\r
+ width--;\r
+ }\r
+ }\r
+ width==0 ? width=1 : width=width;\r
+ width++;\r
+ width>m_fontwidth ? width=m_fontwidth : false;\r
+ m_chars[charnum].Create(width,m_fontheight,32);\r
+ m_chars[charnum].Blit(bmp,0,0,xx,yy,width,m_fontheight,-1);\r
+ m_chars[charnum].SetTransparent();\r
+ RGBQUAD col=m_chars[charnum].GetPixel(m_chars[charnum].Width()-1,0);\r
+ for(int y=0; y<m_chars[charnum].Height(); y++)\r
+ {\r
+ for(int x=0; x<m_chars[charnum].Width(); x++)\r
+ {\r
+ RGBQUAD col2=m_chars[charnum].GetPixel(x,y);\r
+ if(col.rgbRed==col2.rgbRed && col.rgbGreen==col2.rgbGreen && col.rgbBlue==col2.rgbBlue)\r
+ {\r
+ col2.rgbReserved=0;\r
+ m_chars[charnum].PutPixel(x,y,col2);\r
+ }\r
+ }\r
+ }\r
+ charnum++;\r
+ }\r
+ }\r
+\r
+ return true;\r
+}\r
+\r
+} // namespace FreeImage\r
#include "../../include/stringfunctions.h"\r
#include "../../include/option.h"\r
#include "../../include/freenet/captcha/simplecaptcha.h"\r
+#ifdef ALTERNATE_CAPTCHA\r
+#include "../../include/freenet/captcha/alternatecaptcha1.h"\r
+#endif\r
#include "../../include/base64.h"\r
\r
#include <Poco/DateTimeFormatter.h>\r
\r
void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::string &solution)\r
{\r
+#ifdef ALTERNATE_CAPTCHA\r
+ AlternateCaptcha1 captcha;\r
+ m_log->trace("IntroductionPuzzleInserter::GenerateCaptcha using alternate captcha generator");\r
+#else\r
SimpleCaptcha captcha;\r
+#endif\r
std::vector<unsigned char> puzzle;\r
std::vector<unsigned char> puzzlesolution;\r
\r
{\r
// set template\r
std::string templatestr="<html><head></head><body><a href=\"home.htm\">Home</a><br><h1>Could not open template.htm! Place in program directory and restart!</h1><br>[CONTENT]</body></html>";\r
- FILE *infile=fopen("template.htm","r+b");\r
+ FILE *infile=fopen("template.htm","rb");\r
if(infile)\r
{\r
fseek(infile,0,SEEK_END);\r
\r
if(showgenericupdate)\r
{\r
- content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/71/\">FMS Freesite</a><br>";\r
+ content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/72/\">FMS Freesite</a><br>";\r
}\r
\r
content+="Use these pages to administer your FMS installation.";\r
std::string dateadded="";\r
std::string addedmethod="";\r
std::string usk="";\r
- std::string fcphost="";\r
+ std::string fcphost="127.0.0.1";\r
std::string hidden="";\r
int freesiteedition=-1;\r
std::string publishtrustlist="";\r
upd.Reset();\r
\r
st.Bind(0,"FMSVersionEdition");\r
- st.Bind(1,"12");\r
+ st.Bind(1,"15");\r
st.Step();\r
st.Reset();\r
upd.Bind(0,"Program");\r