Пример #1
0
void ofxWebServer::start(string str, int port) {
		ctx = mg_start();
		mg_set_option(ctx,"ports",ofToString(port).c_str());
		mg_set_error_callback(ctx, 404, ccwServer::show404, NULL);
		mg_set_error_callback(ctx, 403, ccwServer::show403, NULL);
		
	#ifdef TARGET_OSX
		mg_set_option(ctx, "root", "/Applications/CCW/data/plugins/WebGUI/client/");
	#endif
	#ifdef _WIN32
		mg_set_option(ctx, "root", ".\\data\\plugins\\WebGUI\\client\\");
	#endif
}
Пример #2
0
void ofxWebServer::start(string root, int port, bool dirList, string indexes, int maxThreads, int idleTime, string aLog, string eLog) {
	ctx = mg_start();     // Start Mongoose serving thread
	mg_set_option(ctx, "root", ofToDataPath(root, true).c_str());  // Set document root
	mg_set_option(ctx, "ports", ofToString(port).c_str());    // Listen on port XXXX
	mg_set_option(ctx, "dir_list", ofToString(dirList).c_str());
	mg_set_option(ctx, "index_files", indexes.c_str());
	mg_set_option(ctx, "max_threads", ofToString(maxThreads).c_str());
	mg_set_option(ctx, "idle_time", ofToString(idleTime).c_str());
	mg_set_option(ctx, "access_log", ofToDataPath(aLog).c_str());
	mg_set_option(ctx, "error_log", ofToDataPath(eLog).c_str());
	mg_set_option(ctx, "cgi_ext", "php");
	
	#ifdef _WIN32
		mg_set_option(ctx, "cgi_interp", ofToDataPath("php/php-cgi.exe").c_str());
	#endif // WIN32

	
	#ifdef MACOSX
	// Ugly workaround - osx doesn't like the relative paths
	// Get the absolute location of the executable file in the bundle.
	CFBundleRef appBundle     = CFBundleGetMainBundle();
	CFURLRef   executableURL = CFBundleCopyExecutableURL(appBundle);
	char execFile[4096];
	if (CFURLGetFileSystemRepresentation(executableURL, TRUE, (UInt8 *)execFile, 4096))
	{
		// Strip out the filename to just get the path
		string strExecFile = execFile;
		int found = strExecFile.find_last_of("/");
		string strPath = strExecFile.substr(0, found);
		strPath.append("/../../../data/php/php-cgi");
		mg_set_option(ctx, "cgi_interp", strPath.c_str());
	}
	else cout << "Couldn't get absolute path. No PHP. \n";
	#endif //osx

	

	aLogFile = ofToDataPath(aLog).c_str();
	eLogFile = ofToDataPath(eLog).c_str();
	
	mg_set_error_callback(ctx, 404, &show404, NULL);
	mg_set_error_callback(ctx, 403, &show403, NULL);
}
Пример #3
0
void ofxWebServer::start(ofxWebServerSettings *settings) {
	ctx = mg_start();     // Start Mongoose serving thread
	
	// Set document root
	if (!mg_set_option(ctx, "root", ofToDataPath(settings->directory, true).c_str())) 
		cout << "[ERROR] Could not set HTTP serving directory, check ccw-config syntax" << endl; 
	
	// Listen on port XXXX
	if (!mg_set_option(ctx, "ports", ofToString(int(settings->port)).c_str()))
		cout << "[ERROR] Could not set HTTP port, check ccw-config syntax" << endl;
	
	// Should directory listing be enabled?	
	if (!mg_set_option(ctx, "dir_list", ofToString(settings->dirListEnabled).c_str()))
		cout << "[ERROR] Could not set directory listing, check ccw-config syntax" << endl;
	
	// Which index files to search for?
	if (!mg_set_option(ctx, "index_files", settings->validIndices.c_str()))
		cout << "[ERROR] Could not set index files, check ccw-config syntax" << endl;
	
	// Maximum threads to spawn
	if (!mg_set_option(ctx, "max_threads", ofToString(settings->maxThreads).c_str()))
		cout << "[ERROR] Could not set max threads, check ccw-config syntax" << endl;
	
	// Idle time
	if (!mg_set_option(ctx, "idle_time", ofToString(settings->idleTime).c_str()))
		cout << "[ERROR] Could not set idle time, check ccw-config syntax" << endl;
	
	if (settings->logEnabled) {
		// Access log location
		if (!mg_set_option(ctx, "access_log", ofToDataPath(settings->accessLog).c_str()))
			cout << "[ERROR] Could not set access log location, check ccw-config syntax" << endl;
	
		// Error log location
		if (!mg_set_option(ctx, "error_log", ofToDataPath(settings->errorLog).c_str()))
			cout << "[ERROR] Could not set error log location, check ccw-config syntax" << endl;
	}
	
	// Currently, force php as only cgi extension
	mg_set_option(ctx, "cgi_ext", "php"); // TODO: revise
	
	/*
	 * TODO: Unimplemented mongoose options
	 */
	
	#ifdef _WIN32
		mg_set_option(ctx, "cgi_interp", ofToDataPath("plugins/PHP/php-cgi.exe").c_str());
	#endif // WIN32
	
	#ifdef TARGET_OSX
	// Ugly workaround - osx doesn't like the relative paths
	// Get the absolute location of the executable file in the bundle.
	CFBundleRef appBundle     = CFBundleGetMainBundle();
	CFURLRef   executableURL = CFBundleCopyExecutableURL(appBundle);
	char execFile[4096];
	if (CFURLGetFileSystemRepresentation(executableURL, TRUE, (UInt8 *)execFile, 4096))
	{
		// Strip out the filename to just get the path
		string strExecFile = execFile;
		int found = strExecFile.find_last_of("/");
		string strPath = strExecFile.substr(0, found);
		strPath.append("/../../../data/plugins/PHP/php-cgi");
		if (mg_set_option(ctx, "cgi_interp", strPath.c_str()))
			cout << "Looking for " << strPath << endl;
		else cout << "[ERROR] Could not set php-cgi path" << endl;
	}
	else cout << "Couldn't get absolute path. No PHP. \n";
	#endif //osx
	
	/*#ifdef MACOSX
		mg_set_option(ctx, "cgi_interp", ofToDataPath("php/php-cgi").c_str());
	#endif*/
	
//	aLogFile = ofToDataPath(settings->accessLog).c_str();
//	eLogFile = ofToDataPath(settings->errorLog).c_str();
	
	mg_set_error_callback(ctx, 404, ccwServer::show404, NULL);
	mg_set_error_callback(ctx, 403, ccwServer::show403, NULL);
}