// ========================= Read settings from config xml file void ccwServer::setupHttpServer(){ if( !setupFile.loadFile(PATH_TO_CONFIG)) { cout << "[ERROR] " << ofToDataPath(PATH_TO_CONFIG) << "could not be found OR a parsing error. "<< endl; cout << "Please check location and syntax. Proceeding using default values:" << endl; } else // if config file was opened { cout << "[Setup] Parsing XML\n" << endl; setupFile.pushTag("ccwconfig"); httpSettings.port = setupFile.getValue("port", DEFAULT_HTTP_PORT); httpSettings.directory = setupFile.getValue("dir", DEFAULT_HTTP_DIRECTORY); httpSettings.dirListEnabled = resolveBool(setupFile.getValue("dirlist", DEFAULT_DIRECTORY_LISTING)); httpSettings.validIndices = setupFile.getValue("index", DEFAULT_INDICES); httpSettings.maxThreads = setupFile.getValue("maxthreads", DEFAULT_MAX_THREADS); httpSettings.idleTime = setupFile.getValue("idleTime",NULL); httpSettings.logEnabled = resolveBool(setupFile.getValue("logging","false")); httpSettings.accessLog = setupFile.getValue("accesslog", DEFAULT_ALOG); httpSettings.errorLog = setupFile.getValue("errorlog", DEFAULT_ELOG); // If autoRun was specified true, request HTTP server to start immediately if (httpSettings.autoRun = resolveBool(setupFile.getValue("autorun","false"))) startHttpServer(); } cout << "[Setup] HTTP Server setup complete, using:\n-Port: " << httpSettings.port << "\n-Dir: " << httpSettings.directory << "\n-Directory Listing: " << httpSettings.dirListEnabled << "\n-Indices: " << httpSettings.validIndices << "\n-autoRun: " << httpSettings.autoRun << "\n-Max Threads: " << httpSettings.maxThreads << "\n-Idle Time: " << httpSettings.idleTime << "\n-Access Log: " << httpSettings.accessLog << "\n-Error Log: " << httpSettings.errorLog << "\n" << endl; }
// ========================= Check UI is instantiated before accessing its members void ccwServer::update() { if (startFlag) { startFlag = 0; startHttpServer(); } }
static void setup() { server = createHttpServer("12345"); startHttpServer(server); registerHttpServerRequestHandler(server, "/path", &incrementCounter, NULL); registerHttpServerRequestHandler(server, "^/path2$", &incrementCounter, NULL); counter = 0; request = createHttpRequest(); request->method = HTTP_REQUEST_METHOD_GET; }
//-------------------------------------------------------------- void ccwServer::mouseReleased(int x, int y, int button){ if (httpPortChanged && httpIsRunning) { // indicates the port slider updated httpPortChanged = false; stopHttpServer(); startHttpServer(); } else if (webGuiPortChanged && webGuiIsRunning) { webGuiPortChanged = false; stopWebGuiServer(); startWebGuiServer(); } }
// ======================================= Set the port void ccwServer::setHttpPort(unsigned int newPort) { bool httpWasRunning = httpIsRunning; #ifndef TARGET_OSX // we dont have these buttons on macosx version b_http80->setValue(false); b_http888->setValue(false); #endif b_http8080->setValue(false); if (httpIsRunning) stopHttpServer(); httpSettings.port = newPort; s_httpPort->setValue(newPort); if (httpWasRunning) startHttpServer(); }
int main(int argc, char **argv) { // Extract Wumpus base directory from path name of executable. We need this // to find the config file and all the executables. wumpusDir = duplicateString(argv[0]); int len = strlen(wumpusDir); if (len > 0) { while (wumpusDir[len - 1] != '/') wumpusDir[--len] = 0; if (endsWith(wumpusDir, "bin/")) wumpusDir = concatenateStringsAndFree(wumpusDir, duplicateString("..")); } homeDir = getenv("HOME"); // Now, we need to do 4 things: // 1. start inotifyd // 2. start Wumpus // 3. start HTTP server // 4. make sure the output of inotifyd is fed into Wumpus startWumpusAndInotifyd(); startHttpServer(); // install new signal handler for SIGINT signal(SIGINT, sigintHandler); signal(SIGTERM, sigintHandler); while (inotifydPID != 0) sleep(1); fprintf(stderr, "Wumpus is shutting down. Please wait...\n"); kill(httpdPID, SIGKILL); waitpid(httpdPID, NULL, 0); waitpid(transformPID, NULL, 0); waitpid(wumpusPID, NULL, 0); return 0; } // end of main(int, char**)
// ======================================= Called when an action is performed on the UI void ccwServer::handleGui(int parameterId, int task, void* data, int length) { bool httpWasRunning = httpIsRunning; switch(parameterId) { case uiStartStop: if (httpIsRunning) { stopHttpServer(); ofSetWindowTitle("CCW [Stopped]"); } else { startHttpServer(); } break; case uiMySQLStartStop: if (mySQLIsRunning) { stopMySQLServer(); } else startMySQLServer(); break; case uiWebGuiStartStop: if (webGuiIsRunning) { stopWebGuiServer(); } else startWebGuiServer(); break; case uiPort80: setHttpPort(80); b_http80->setValue(true); break; case uiPort888: setHttpPort(888); b_http888->setValue(true); break; case uiPort8080: setHttpPort(8080); b_http8080->setValue(true); break; case uiAutoRun: if (httpSettings.autoRun) { httpSettings.autoRun = false; b_autoRun->setValue(false); setupFile.setValue("autorun", "false", 0); } else { httpSettings.autoRun = true; b_autoRun->setValue(true); setupFile.setValue("autorun", "true", 0); } setupFile.saveFile(PATH_TO_CONFIG); break; case uiLog: //TODO are they written seperately? if (httpIsRunning) stopHttpServer(); if (httpSettings.logEnabled) { httpSettings.logEnabled = false; b_log->setValue(false); setupFile.setValue("logging", "false", 0); } else { httpSettings.logEnabled = true; b_log->setValue(true); setupFile.setValue("logging", "true", 0); } if (httpWasRunning) startHttpServer(); setupFile.saveFile(PATH_TO_CONFIG); break; case uiDirList: if (httpIsRunning) stopHttpServer(); if (httpSettings.dirListEnabled) { httpSettings.dirListEnabled = false; b_dirList->setValue(false); setupFile.setValue("dirlist", "false", 0); } else { httpSettings.dirListEnabled = true; b_dirList->setValue(true); setupFile.setValue("dirlist", "true", 0); } if (httpWasRunning) startHttpServer(); setupFile.saveFile(PATH_TO_CONFIG); break; case uiPort: httpSettings.port = s_httpPort->mValue; httpPortChanged = true; break; case uiWebGuiPort: webGuiPort = s_webGuiPort->mValue; webGuiPortChanged = true; break; } }