forked from Mirrors/privacore-open-source-search-engine
only do certain things if running
on a machine in matt wells datacenter. like fan switching based on temps, or printing seo links. made seo functions weak overridable placeholder stubs so if seo.o is linked in it will override. include seo.o object if seo.cpp file exists for automatic seo module building and linking.
This commit is contained in:
25
Conf.cpp
25
Conf.cpp
@ -181,6 +181,31 @@ bool Conf::init ( char *dir ) { // , long hostId ) {
|
||||
//g_conf.m_testSpiderEnabled = false;
|
||||
//g_conf.m_testSearchEnabled = false;
|
||||
|
||||
|
||||
//
|
||||
// are we running in Matt Wells's data center?
|
||||
// if so, we want to be able to use the seo tools that are not part
|
||||
// of the open source. we also want to be able to control the
|
||||
// data center fans for optimal cooling.
|
||||
//
|
||||
// get hostname from /etc/host
|
||||
SafeBuf sb;
|
||||
sb.fillFromFile("/etc/hostname");
|
||||
g_errno = 0;
|
||||
bool priv = false;
|
||||
char *hh = sb.getBufStart();
|
||||
// cut off tail
|
||||
sb.removeLastChar('\n');
|
||||
sb.removeLastChar('\n');
|
||||
if ( hh && strcmp(hh,"galileo") == 0) priv = true;
|
||||
if ( hh && strcmp(hh,"sputnik") == 0) priv = true;
|
||||
if ( hh && strcmp(hh,"titan") == 0) priv = true;
|
||||
if ( hh[0]=='g' && hh[1]=='k' && is_digit(hh[2]) ) priv = true;
|
||||
//if(hh[0]=='s' && hh[1]=='p' && is_digit(hh[2])) ) priv = true;
|
||||
if ( priv ) g_conf.m_isMattWells = true;
|
||||
else g_conf.m_isMattWells = false;
|
||||
|
||||
|
||||
// this is not possible
|
||||
/*
|
||||
if ( g_hostdb.getNumGroups() != g_hostdb.m_indexSplits ) {
|
||||
|
4
Conf.h
4
Conf.h
@ -468,6 +468,10 @@ class Conf {
|
||||
// . give suggestions to narrow the search
|
||||
bool m_doNarrowSearch;
|
||||
|
||||
// are we running in Matt Wells's private data center? if so we
|
||||
// use seo tools and control datacenter fans, etc.
|
||||
bool m_isMattWells;
|
||||
|
||||
// maximum number of synonyms/stems to expand a word into
|
||||
//long m_maxSynonyms;
|
||||
|
||||
|
@ -69,7 +69,7 @@ bool HttpRequest::copy ( class HttpRequest *r ) {
|
||||
// . NOTE: http 1.1 uses Keep-Alive by default (use Connection: close to not)
|
||||
bool HttpRequest::set (char *url,long offset,long size,time_t ifModifiedSince,
|
||||
char *userAgent , char *proto , bool doPost ,
|
||||
char *cookie ) {
|
||||
char *cookie , char *additionalHeader ) {
|
||||
|
||||
m_reqBufValid = false;
|
||||
|
||||
@ -257,6 +257,9 @@ bool HttpRequest::set (char *url,long offset,long size,time_t ifModifiedSince,
|
||||
//accept );
|
||||
}
|
||||
|
||||
if ( additionalHeader )
|
||||
m_reqBuf.safePrintf("%s\r\n",additionalHeader );
|
||||
|
||||
// cookie here
|
||||
if ( cookie )
|
||||
m_reqBuf.safePrintf("Cookie: %s\r\n",cookie );
|
||||
|
@ -40,7 +40,8 @@ class HttpRequest {
|
||||
time_t ifModifiedSince = 0 , char *userAgent = NULL ,
|
||||
char *proto = "HTTP/1.0" ,
|
||||
bool doPost = false ,
|
||||
char *cookie = NULL );
|
||||
char *cookie = NULL ,
|
||||
char *additionalHeader = NULL ); // does not incl \r\n
|
||||
|
||||
// use this
|
||||
SafeBuf m_reqBuf;
|
||||
|
@ -127,7 +127,8 @@ bool HttpServer::getDoc ( char *url ,
|
||||
//bool respectDownloadLimit ,
|
||||
char *proto ,
|
||||
bool doPost ,
|
||||
char *cookie ) {
|
||||
char *cookie ,
|
||||
char *additionalHeader ) {
|
||||
//log(LOG_WARN, "http: get doc %s", url->getUrl());
|
||||
// use the HttpRequest class
|
||||
HttpRequest r;
|
||||
@ -148,7 +149,8 @@ bool HttpServer::getDoc ( char *url ,
|
||||
}
|
||||
// this returns false and sets g_errno on error
|
||||
if ( ! r.set ( url , offset , size , ifModifiedSince ,
|
||||
userAgent , proto , doPost , cookie ) ) return true;
|
||||
userAgent , proto , doPost , cookie ,
|
||||
additionalHeader ) ) return true;
|
||||
|
||||
if ( g_conf.m_logDebugSpider )
|
||||
log("spider: httprequest = %s", r.getRequest());
|
||||
|
@ -95,7 +95,8 @@ class HttpServer {
|
||||
// use 1.0
|
||||
char *proto = "HTTP/1.0" ,
|
||||
bool doPost = false ,
|
||||
char *cookie = NULL );
|
||||
char *cookie = NULL ,
|
||||
char *additionalHeader = NULL ); // does not include \r\n
|
||||
|
||||
bool getDoc ( long ip,
|
||||
long port,
|
||||
|
26
Makefile
26
Makefile
@ -71,22 +71,30 @@ HOST=$(shell hostname)
|
||||
#print_vars:
|
||||
# $(HOST)
|
||||
|
||||
# force 32-bit mode using -m32 (apt-get install gcc-multilib to ensure works)
|
||||
# and -m32 should use /usr/lib32/ as the library path.
|
||||
# for old kernel 2.4 we don't use pthreads, just clone. so if compiling
|
||||
# on host "titan" use clone. i still use that. -matt
|
||||
# we can only build a 32-bit binary, so we have to use the 32-bit libraries
|
||||
# provided for now.
|
||||
ifeq ("titan","$(HOST)")
|
||||
CPPFLAGS = -DPRIVATESTUFF -m32 -g -Wall -pipe -Wno-write-strings -Wstrict-aliasing=0 -Wno-uninitialized -static
|
||||
# my machine, titan, runs the old 2.4 kernel, it does not use pthreads because
|
||||
# they were very buggy in 1999. Plus they are still kind of slow even today,
|
||||
# in 2013. So it just uses clone() and does its own "threading". Unfortunately,
|
||||
# the way it works is not even possible on newer kernels because they no longer
|
||||
# allow you to override the _errno_location() function. -- matt
|
||||
CPPFLAGS = -m32 -g -Wall -pipe -Wno-write-strings -Wstrict-aliasing=0 -Wno-uninitialized -static
|
||||
LIBS = ./libz.a ./libssl.a ./libcrypto.a ./libiconv.a ./libm.a
|
||||
OBJS:=$(OBJS) seo.o
|
||||
$(shell rm seo.o)
|
||||
else
|
||||
# use -m32 to force 32-bit mode compilation.
|
||||
# you might have to do apt-get install gcc-multilib to ensure that -m32 works.
|
||||
# -m32 should use /usr/lib32/ as the library path.
|
||||
# i also provide 32-bit libraries for linking that are not so easy to get.
|
||||
CPPFLAGS = -m32 -g -Wall -pipe -Wno-write-strings -Wstrict-aliasing=0 -Wno-uninitialized -static -D_PTHREADS_ -Wno-unused-but-set-variable
|
||||
LIBS= -L. ./libz.a ./libssl.a ./libcrypto.a ./libiconv.a ./libm.a ./libstdc++.a -lpthread
|
||||
endif
|
||||
|
||||
# if you have seo.cpp link that in. This is not part of the open source
|
||||
# distribution but is available for interested parties.
|
||||
ifneq ($(wildcard seo.cpp),)
|
||||
OBJS:=$(OBJS) seo.o
|
||||
endif
|
||||
|
||||
|
||||
|
||||
# let's keep the libraries in the repo for easier bug reporting and debugging
|
||||
# in general if we can. the includes are still in /usr/include/ however...
|
||||
|
@ -347,13 +347,17 @@ bool sendPageResults ( TcpSocket *s , HttpRequest *hr ) {
|
||||
"</a>"
|
||||
|
||||
" "
|
||||
);
|
||||
// SEO functionality not included yet - so redir to gigablast.
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf("<a title=\"Rank higher in "
|
||||
"Google\" href='/seo'>");
|
||||
else
|
||||
sb.safePrintf("<a title=\"Rank higher in "
|
||||
"Google\" href='https://www.gigablast."
|
||||
"com/seo'>");
|
||||
|
||||
/* SEO functionality not included yet - so redir to gigablast. */
|
||||
#ifdef PRIVATESTUFF
|
||||
"<a title=\"Rank higher in Google\" href='/seo'>"
|
||||
#else
|
||||
"<a title=\"Rank higher in Google\" href='https://www.gigablast.com/seo'>"
|
||||
#endif
|
||||
sb.safePrintf(
|
||||
"seo"
|
||||
"</a>"
|
||||
|
||||
@ -2082,11 +2086,11 @@ static int printResult ( SafeBuf &sb,
|
||||
// "c=%s&\">scoring</a>",
|
||||
// coll );
|
||||
//sb.safePrintf(" - <a href=\"/print?c=%s&",coll);
|
||||
#ifdef PRIVATESTUFF
|
||||
sb.safePrintf(" - <a href=\"/seo?");//c=%s&",coll);
|
||||
#else
|
||||
sb.safePrintf(" - <a href=\"https://www.gigablast.com/seo?");//c=%s&",coll);
|
||||
#endif
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf(" - <a href=\"/seo?");//c=%s&",coll);
|
||||
else
|
||||
sb.safePrintf(" - <a href=\"https://www.gigablast."
|
||||
"com/seo?");//c=%s&",coll);
|
||||
//sb.safePrintf("d=%lli",mr->m_docId);
|
||||
sb.safePrintf("u=");
|
||||
sb.urlEncode ( url , gbstrlen(url) , false );
|
||||
@ -3250,15 +3254,16 @@ bool printPairScore ( SafeBuf &sb , SearchInput *si , PairScore *ps ,
|
||||
, getHashGroupString(hg1)
|
||||
, hgw1 );
|
||||
// the word position
|
||||
sb.safePrintf("<td>"
|
||||
sb.safePrintf("<td>");
|
||||
//"<a href=\"/print?d="
|
||||
//"&page=4&recycle=1&"
|
||||
#ifdef PRIVATESTUFF
|
||||
"<a href=\"/seo?d="
|
||||
#else
|
||||
"<a href=\"https://www.gigablast.com/seo?d="
|
||||
#endif
|
||||
"%lli"
|
||||
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf("<a href=\"/seo?d=");
|
||||
else
|
||||
sb.safePrintf("<a href=\"https://www.gigablast.com/seo?d=");
|
||||
|
||||
sb.safePrintf("%lli"
|
||||
"&page=sections&"
|
||||
"hipos=%li&c=%s\">"
|
||||
"%li</a></td>"
|
||||
@ -3331,16 +3336,17 @@ bool printPairScore ( SafeBuf &sb , SearchInput *si , PairScore *ps ,
|
||||
, getHashGroupString(hg2)
|
||||
, hgw2 );
|
||||
// the word position
|
||||
sb.safePrintf("<td>"
|
||||
sb.safePrintf("<td>");
|
||||
//"<a href=\"/print?d="
|
||||
//"%lli"
|
||||
//"&page=4&recycle=1&"
|
||||
#ifdef PRIVATESTUFF
|
||||
"<a href=\"/seo?d="
|
||||
#else
|
||||
"<a href=\"https://www.gigablast.com/seo?d="
|
||||
#endif
|
||||
"%lli"
|
||||
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf("<a href=\"/seo?d=");
|
||||
else
|
||||
sb.safePrintf("<a href=\"https://www.gigablast.com/seo?d=");
|
||||
|
||||
sb.safePrintf("%lli"
|
||||
"&page=sections&"
|
||||
"hipos=%li&c=%s\">"
|
||||
"%li</a></td>"
|
||||
|
42
PageRoot.cpp
42
PageRoot.cpp
@ -104,11 +104,15 @@ bool printWebHomePage ( SafeBuf &sb , HttpRequest *r ) {
|
||||
//g_proxy.insertLoginBarDirective ( &sb );
|
||||
sb.safePrintf("<br><br>\n");
|
||||
// try to avoid using https for images. it is like 10ms slower.
|
||||
#ifdef PRIVATESTUFF
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 height=122 src=http://www.gigablast.com/logo-med.jpg></a>\n");
|
||||
#else
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 height=122 src=/logo-med.jpg></a>\n");
|
||||
#endif
|
||||
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 "
|
||||
"height=122 src=http://www.gigablast.com/logo-"
|
||||
"med.jpg></a>\n");
|
||||
else
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 "
|
||||
"height=122 src=/logo-med.jpg></a>\n");
|
||||
|
||||
sb.safePrintf("<br><br>\n");
|
||||
sb.safePrintf("<br><br><br>\n");
|
||||
sb.safePrintf("<b>web</b> <a href=/seo>seo</a> <a href=\"http://www.gigablast.com/?c=dmoz3\">directory</a> \n");
|
||||
@ -310,11 +314,15 @@ bool printAddUrlHomePage ( SafeBuf &sb , char *url , HttpRequest *r ) {
|
||||
|
||||
sb.safePrintf("\n");
|
||||
sb.safePrintf("<br><br>\n");
|
||||
#ifdef PRIVATESTUFF
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 height=122 src=http://www.gigablast.com/logo-med.jpg></a>\n");
|
||||
#else
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 height=122 src=/logo-med.jpg></a>\n");
|
||||
#endif
|
||||
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 "
|
||||
"height=122 src=http://www.gigablast.com/logo-"
|
||||
"med.jpg></a>\n");
|
||||
else
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 "
|
||||
"height=122 src=/logo-med.jpg></a>\n");
|
||||
|
||||
sb.safePrintf("<br><br>\n");
|
||||
sb.safePrintf("<br><br><br>\n");
|
||||
sb.safePrintf("<a href=/>web</a> <a href=/seo>seo</a> <a href=\"http://www.gigablast.com/?c=dmoz3\">directory</a> \n");
|
||||
@ -444,11 +452,15 @@ bool printDirHomePage ( SafeBuf &sb , HttpRequest *r ) {
|
||||
sb.safePrintf("<body>\n");
|
||||
sb.safePrintf("<br><br>\n");
|
||||
// try to avoid using https for images. it is like 10ms slower.
|
||||
#ifdef PRIVATESTUFF
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 height=122 src=http://www.gigablast.com/logo-med.jpg></a>\n");
|
||||
#else
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 height=122 src=/logo-med.jpg></a>\n");
|
||||
#endif
|
||||
|
||||
if ( g_conf.m_isMattWells )
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 "
|
||||
"height=122 src=http://www.gigablast.com/logo-"
|
||||
"med.jpg></a>\n");
|
||||
else
|
||||
sb.safePrintf("<center><a href=/><img border=0 width=500 "
|
||||
"height=122 src=/logo-med.jpg></a>\n");
|
||||
|
||||
sb.safePrintf("<br><br>\n");
|
||||
sb.safePrintf("<br><br><br>\n");
|
||||
sb.safePrintf("<a href=/>web</a> <a href=/seo>seo</a> <b>directory</b> \n");
|
||||
|
@ -220,11 +220,9 @@ static WebPage s_pages[] = {
|
||||
// "get queries a url matches",
|
||||
// sendPageMatchingQueries , 2 } ,
|
||||
|
||||
#ifdef PRIVATESTUFF
|
||||
{ PAGE_SEO, "seo",0,"seo" , 0 , 0 ,
|
||||
"SEO info",
|
||||
sendPageSEO , 2 } ,
|
||||
#endif
|
||||
|
||||
{ PAGE_ACCESS , "admin/access" , 0 , "access" , 1 , 1 , // usepost
|
||||
//USER_ADMIN | USER_MASTER ,
|
||||
@ -415,9 +413,7 @@ bool Pages::sendDynamicReply ( TcpSocket *s , HttpRequest *r , long page ) {
|
||||
if ( page == PAGE_ROOT ) publicPage = true;
|
||||
// do not deny /NM/Albuquerque urls
|
||||
if ( page == PAGE_RESULTS ) publicPage = true;
|
||||
#ifdef PRIVATESTUFF
|
||||
if ( page == PAGE_SEO ) publicPage = true;
|
||||
#endif
|
||||
if ( page == PAGE_ADDURL ) publicPage = true;
|
||||
if ( page == PAGE_GET ) publicPage = true;
|
||||
|
||||
|
4
Pages.h
4
Pages.h
@ -358,9 +358,9 @@ enum {
|
||||
PAGE_REINDEX ,
|
||||
PAGE_INJECT ,
|
||||
//PAGE_KEYWORDS ,
|
||||
#ifdef PRIVATESTUFF
|
||||
|
||||
PAGE_SEO ,
|
||||
#endif
|
||||
|
||||
PAGE_ACCESS , //40
|
||||
PAGE_SEARCHBOX ,
|
||||
PAGE_ADDURL2 ,
|
||||
|
103
Process.cpp
103
Process.cpp
@ -46,8 +46,10 @@
|
||||
|
||||
// the query log hashtable defined in XmlDoc.cpp
|
||||
//extern HashTableX g_qt;
|
||||
extern SafeBuf g_qbuf;
|
||||
extern long g_qbufNeedSave;
|
||||
|
||||
// normally in seo.cpp, but here so it compiles
|
||||
SafeBuf g_qbuf;
|
||||
long g_qbufNeedSave = 0;
|
||||
|
||||
// for resetAll()
|
||||
//#include "Msg6.h"
|
||||
@ -477,12 +479,12 @@ bool Process::init ( ) {
|
||||
//if ( ! g_loop.registerSleepCallback(10000,NULL,hdtempWrapper,0))
|
||||
// return false;
|
||||
|
||||
// power monitor, every 10 seconds
|
||||
if ( ! g_loop.registerSleepCallback(10000,NULL,powerMonitorWrapper,0))
|
||||
// power monitor, every 30 seconds
|
||||
if ( ! g_loop.registerSleepCallback(30000,NULL,powerMonitorWrapper,0))
|
||||
return false;
|
||||
|
||||
// check temps to possible turn fans on/off every 30 seconds
|
||||
if ( !g_loop.registerSleepCallback(30000,NULL,fanSwitchCheckWrapper,0))
|
||||
// check temps to possible turn fans on/off every 60 seconds
|
||||
if ( !g_loop.registerSleepCallback(60000,NULL,fanSwitchCheckWrapper,0))
|
||||
return false;
|
||||
|
||||
// -99 means unknown
|
||||
@ -495,6 +497,11 @@ bool Process::init ( ) {
|
||||
|
||||
void powerMonitorWrapper ( int fd , void *state ) {
|
||||
if ( g_isYippy ) return;
|
||||
|
||||
// only if in matt wells datacenter
|
||||
if ( ! g_conf.m_isMattWells )
|
||||
return;
|
||||
|
||||
// are we in group #0
|
||||
bool checkPower = false;
|
||||
// get our host
|
||||
@ -509,7 +516,7 @@ void powerMonitorWrapper ( int fd , void *state ) {
|
||||
// if not checking, all done
|
||||
if ( ! checkPower ) return;
|
||||
// only if live
|
||||
if ( ! g_conf.m_isLive ) return;
|
||||
//if ( ! g_conf.m_isLive ) return;
|
||||
// skip if request out already
|
||||
if ( g_process.m_powerReqOut ) return;
|
||||
// the url
|
||||
@ -575,6 +582,8 @@ bool Process::gotPower ( TcpSocket *s ) {
|
||||
char *p;
|
||||
char *dataCtrTempStr;
|
||||
char *roofTempStr;
|
||||
char *tag1,*tag2;
|
||||
float newTemp;
|
||||
|
||||
if ( g_errno ) {
|
||||
log("powermo: had error getting power state: %s. assuming "
|
||||
@ -633,23 +642,33 @@ bool Process::gotPower ( TcpSocket *s ) {
|
||||
// we want to keep the fans on, otherwise we need to send an
|
||||
// http request to the power strip control to turn the fans off
|
||||
//
|
||||
dataCtrTempStr = strstr( content, "\"Exit Temp\",tempf:\"" );
|
||||
tag1 = "\"Exit Temp\",tempf:\"" ;
|
||||
dataCtrTempStr = strstr( content, tag1 );
|
||||
if ( ! dataCtrTempStr ) {
|
||||
log("powermo: could not parse our data ctr temp from "
|
||||
"room alert.");
|
||||
goto skip;
|
||||
}
|
||||
m_dataCtrTemp = atof ( dataCtrTempStr+19+4 );
|
||||
newTemp = atof ( dataCtrTempStr+ gbstrlen(tag1) );
|
||||
if ( newTemp != m_dataCtrTemp )
|
||||
log("powermo: data ctr temp changed from %0.1f to %.01f",
|
||||
m_dataCtrTemp,newTemp);
|
||||
m_dataCtrTemp = newTemp;
|
||||
|
||||
|
||||
roofTempStr = strstr( content, "\"Roof Temp\",tempf:\"" );
|
||||
tag2 = "\"Roof Temp\",tempf:\"";
|
||||
roofTempStr = strstr( content, tag2 );
|
||||
if ( ! dataCtrTempStr ) {
|
||||
log("powermo: could not parse out roof temp from "
|
||||
"room alert.");
|
||||
goto skip;
|
||||
}
|
||||
m_roofTemp = atof ( dataCtrTempStr+19);
|
||||
|
||||
newTemp = atof ( roofTempStr+gbstrlen(tag2));
|
||||
if ( newTemp != m_roofTemp )
|
||||
log("powermo: roof temp changed from %0.1f to %.01f",
|
||||
m_roofTemp,newTemp);
|
||||
m_roofTemp = newTemp;
|
||||
|
||||
|
||||
skip:
|
||||
@ -2127,8 +2146,9 @@ void fanSwitchCheckWrapper ( int fd , void *state ) {
|
||||
|
||||
void Process::checkFanSwitch ( ) {
|
||||
|
||||
// skip for now
|
||||
return;
|
||||
// skip if you are not me, because this controls my custom fan
|
||||
if ( ! g_conf.m_isMattWells )
|
||||
return;
|
||||
|
||||
// are we in group #0
|
||||
bool check = false;
|
||||
@ -2144,7 +2164,7 @@ void Process::checkFanSwitch ( ) {
|
||||
// if not checking, all done
|
||||
if ( ! check ) return;
|
||||
// only if live
|
||||
if ( ! g_conf.m_isLive ) return;
|
||||
//if ( ! g_conf.m_isLive ) return;
|
||||
// skip if request out already
|
||||
if ( m_fanReqOut ) return;
|
||||
// both must be legit
|
||||
@ -2164,13 +2184,16 @@ void Process::checkFanSwitch ( ) {
|
||||
// what is the desired state? assume fans on.
|
||||
m_desiredFanState = 1;
|
||||
// if roof is hotter then fans off! we don't want hotter air.
|
||||
if ( m_roofTemp > m_dataCtrTemp )
|
||||
if ( //m_roofTemp > m_dataCtrTemp &&
|
||||
// even if roof temp is slightly cooler, turn off fans. it
|
||||
// needs to be more than 5 degrees cooler.
|
||||
m_roofTemp + 5.0 > m_dataCtrTemp )
|
||||
// 0 means we want fans to be off
|
||||
m_desiredFanState = 0;
|
||||
// if matches, leave alone
|
||||
if ( m_currentFanState == m_desiredFanState ) return;
|
||||
|
||||
// ok change! the url
|
||||
char *url ;
|
||||
// . the IP9258 power controller
|
||||
// . default ip=192.168.1.100
|
||||
// . default user=admin
|
||||
@ -2182,6 +2205,8 @@ void Process::checkFanSwitch ( ) {
|
||||
// . i changed the ip to 10.5.0.8 since the roomalert is at 10.5.0.9
|
||||
// . turn all 4 ports on or off so we can plug the fans into two
|
||||
// separate ports
|
||||
/*
|
||||
char *url ;
|
||||
if ( m_desiredFanState )
|
||||
url = "http://10.5.0.8/tgi/iocontrol.tgi?"
|
||||
"pw1Name=&"
|
||||
@ -2222,17 +2247,40 @@ void Process::checkFanSwitch ( ) {
|
||||
"P63_TC=Off&"
|
||||
"Apply=Apply"
|
||||
;
|
||||
|
||||
// mark the request as outstanding so we do not overlap it
|
||||
m_fanReqOut = true;
|
||||
// . make a cookie with the login info
|
||||
// . on chrome open the console and click "Network" tab
|
||||
// to view the http network requests and replies
|
||||
char *cookie = "admin=12345678; Taifatech=yes";
|
||||
*/
|
||||
|
||||
//
|
||||
// the new power switch is hopefully less flaky!
|
||||
//
|
||||
SafeBuf urlBuf;
|
||||
|
||||
if ( m_desiredFanState )
|
||||
// this turns it on
|
||||
urlBuf.safePrintf("http://10.5.0.10/outlet.cgi?outlet=1&"
|
||||
"command=1&time=%li",
|
||||
getTimeGlobal());
|
||||
else
|
||||
// this turns it off
|
||||
urlBuf.safePrintf("http://10.5.0.10/outlet.cgi?outlet=1&"
|
||||
"command=0&time=%li",
|
||||
getTimeGlobal());
|
||||
// . make a cookie with the login info
|
||||
// . on chrome open the console and click "Network" tab
|
||||
// to view the http network requests and replies
|
||||
//char *cookie = "admin=12345678; Taifatech=yes";
|
||||
char *cookie = NULL;
|
||||
|
||||
|
||||
// mark the request as outstanding so we do not overlap it
|
||||
m_fanReqOut = true;
|
||||
|
||||
// get it
|
||||
bool status = g_httpServer.
|
||||
getDoc ( url , // url to download
|
||||
getDoc ( urlBuf.getBufStart() , // url to download
|
||||
0 , // ip
|
||||
0 , // offset
|
||||
-1 , // size
|
||||
@ -2250,7 +2298,9 @@ void Process::checkFanSwitch ( ) {
|
||||
//false , // respect download limit?
|
||||
"HTTP/1.1" ,// fake 1.1 otherwise we get error!
|
||||
true , // doPost? converts cgi str to post
|
||||
cookie );
|
||||
cookie ,
|
||||
// additional mime headers
|
||||
"Authorization: Basic YWRtaW46^C");
|
||||
// wait for it
|
||||
if ( ! status ) return;
|
||||
// i guess it is back!
|
||||
@ -2292,8 +2342,13 @@ bool Process::gotFanReply ( TcpSocket *s ) {
|
||||
long contentLen = bufSize - mime.getMimeLen();
|
||||
content[contentLen]='\0';
|
||||
|
||||
// get the state of the power!
|
||||
char *p = strstr ( content ,"\"power\",status:" );
|
||||
// get the state of the power! (from old power switch)
|
||||
//char *p = strstr ( content ,"\"power\",status:" );
|
||||
|
||||
// get the state of the power! (from new power switch)
|
||||
char *tag = "<outlet1_status>";
|
||||
long tagLen = gbstrlen(tag);
|
||||
char *p = strstr ( content, tag );
|
||||
// panic?
|
||||
if ( ! p ) {
|
||||
log("powermo: could not parse out fan power state "
|
||||
@ -2304,7 +2359,7 @@ bool Process::gotFanReply ( TcpSocket *s ) {
|
||||
|
||||
// . get the value
|
||||
// . val is 0 if the fan power off, 1 if on?
|
||||
long val = atoi ( p + 15 );
|
||||
long val = atoi ( p + tagLen );
|
||||
|
||||
m_currentFanState = val;
|
||||
|
||||
|
16
Proxy.cpp
16
Proxy.cpp
@ -2,7 +2,12 @@
|
||||
|
||||
#include "Proxy.h"
|
||||
#include "Statsdb.h"
|
||||
#include "seo.h" // g_secret_tran_key and api_key
|
||||
//#include "seo.h" // g_secret_tran_key and api_key
|
||||
|
||||
|
||||
char *g_secret_tran_key = NULL;
|
||||
char *g_secret_api_key = NULL;
|
||||
|
||||
|
||||
Proxy g_proxy;
|
||||
|
||||
@ -3547,13 +3552,12 @@ bool Proxy::hitCreditCard ( StateUser *su ) {
|
||||
//
|
||||
// INSERT YOUR secret transaction/api key for authorize.net
|
||||
//
|
||||
#ifdef PRIVATESTUFF
|
||||
|
||||
url.safePrintf("&x_tran_key=%s",g_secret_tran_key);
|
||||
url.safePrintf("&x_login=%s",g_secret_api_key);
|
||||
#else
|
||||
url.safePrintf("&x_tran_key=xxxxxxxxxxxxxxx");
|
||||
url.safePrintf("&x_login=yyyyyyyyyy");
|
||||
#endif
|
||||
|
||||
//url.safePrintf("&x_tran_key=xxxxxxxxxxxxxxx");
|
||||
//url.safePrintf("&x_login=yyyyyyyyyy");
|
||||
|
||||
// european requires stuff
|
||||
/*
|
||||
|
@ -69,6 +69,13 @@ struct SafeBuf {
|
||||
void truncLen ( long newLen ) {
|
||||
if ( m_length > newLen ) m_length = newLen; };
|
||||
|
||||
void removeLastChar ( char lastChar ) {
|
||||
if ( m_length <= 0 ) return;
|
||||
if ( m_buf[m_length-1] != lastChar ) return;
|
||||
m_length--;
|
||||
m_buf[m_length] = '\0';
|
||||
};
|
||||
|
||||
//MUTATORS
|
||||
#ifdef _CHECK_FORMAT_STRING_
|
||||
bool safePrintf(char *formatString, ...)
|
||||
|
1
gb.conf
1
gb.conf
@ -594,6 +594,7 @@
|
||||
<logDebugBuildMessages>0</>
|
||||
<logDebugBuildTimeMessages>0</>
|
||||
<logDebugDatabaseMessages>0</>
|
||||
<logDebugDirtyMessages>0</>
|
||||
<logDebugDiskMessages>0</>
|
||||
<logDebugDnsMessages>0</>
|
||||
<logDebugHttpMessages>0</>
|
||||
|
56
main.cpp
56
main.cpp
@ -172,6 +172,27 @@ void dumpClusterdb ( char *coll,long sfn,long numFiles,bool includeTree);
|
||||
void dumpLinkdb ( char *coll,long sfn,long numFiles,bool includeTree,
|
||||
char *url );
|
||||
|
||||
//////
|
||||
//
|
||||
// if seo.o is being linked to it needs to override these weak stubs:
|
||||
//
|
||||
//////
|
||||
bool loadQueryLog() __attribute__((weak));
|
||||
void runSEOQueryLoop ( int fd, void *state ) __attribute__((weak));
|
||||
bool sendPageSEO(TcpSocket *, HttpRequest *) __attribute__((weak));
|
||||
void handleRequest8e(UdpSlot *, long netnice ) __attribute__((weak));
|
||||
void handleRequest4f(UdpSlot *, long netnice ) __attribute__((weak));
|
||||
void handleRequest95(UdpSlot *, long netnice ) __attribute__((weak));
|
||||
|
||||
// make the stubs here. seo.o will override them
|
||||
bool loadQueryLog() { return true; }
|
||||
void runSEOQueryLoop ( int fd, void *state ) { return; }
|
||||
bool sendPageSEO(TcpSocket *s, HttpRequest *hr) {
|
||||
return g_httpServer.sendErrorReply(s,500,"Seo support not present"); }
|
||||
void handleRequest8e(UdpSlot *, long netnice ) {return; }
|
||||
void handleRequest4f(UdpSlot *, long netnice ) {return; }
|
||||
void handleRequest95(UdpSlot *, long netnice ) {return; }
|
||||
|
||||
|
||||
// for cleaning up indexdb
|
||||
void dumpMissing ( char *coll );
|
||||
@ -2780,10 +2801,13 @@ int main ( int argc , char *argv[] ) {
|
||||
//return 1;
|
||||
}
|
||||
|
||||
// the query log split
|
||||
#ifdef PRIVATESTUFF
|
||||
if ( ! loadQueryLog() ) return 1;
|
||||
#endif
|
||||
// the query log split. only for seo tools, so only do if
|
||||
// we are running in Matt Wells's datacenter.
|
||||
if ( g_conf.m_isMattWells && ! loadQueryLog() ) {
|
||||
log("init: failed to load query log. continuing with seo "
|
||||
"support.");
|
||||
//return 1;
|
||||
}
|
||||
|
||||
//if( !g_pageTopDocs.init() ) {
|
||||
// log( "init: PageTopDocs init failed." );
|
||||
@ -3105,10 +3129,11 @@ int main ( int argc , char *argv[] ) {
|
||||
log("db: Failed to init merge sleep callback.");
|
||||
|
||||
// SEO MODULE
|
||||
#ifdef PRIVATESTUFF
|
||||
if ( ! g_loop.registerSleepCallback(2000,(void *)1,runSEOQueryLoop))
|
||||
// . only use if we are in Matt Wells's data center
|
||||
// and have access to the seo tools
|
||||
if ( g_conf.m_isMattWells &&
|
||||
! g_loop.registerSleepCallback(2000,(void *)1,runSEOQueryLoop))
|
||||
log("db: Failed to register seo query loop");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -4798,16 +4823,6 @@ bool registerMsgHandlers1(){
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// to make things compile we need to declare this stuff since the seo
|
||||
// module is not in the open source version
|
||||
//
|
||||
#ifndef PRIVATESTUFF
|
||||
SafeBuf g_qbuf;
|
||||
long g_qbufNeedSave = false;
|
||||
bool sendPageSEO(TcpSocket *, HttpRequest *) { return true;}
|
||||
#endif
|
||||
|
||||
bool registerMsgHandlers2(){
|
||||
Msg0 msg0 ; if ( ! msg0.registerHandler () ) return false;
|
||||
Msg1 msg1 ; if ( ! msg1.registerHandler () ) return false;
|
||||
@ -4834,14 +4849,11 @@ bool registerMsgHandlers2(){
|
||||
|
||||
if ( ! registerHandler4 () ) return false;
|
||||
|
||||
#ifdef PRIVATESTUFF
|
||||
// seo module handlers
|
||||
// seo module handlers. this will just be stubs declared above
|
||||
// if no seo module. the seo module is not part of the open source.
|
||||
if(! g_udpServer.registerHandler(0x8e,handleRequest8e)) return false;
|
||||
if(! g_udpServer.registerHandler(0x4f,handleRequest4f)) return false;
|
||||
if(! g_udpServer.registerHandler(0x95,handleRequest95)) return false;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
Reference in New Issue
Block a user