FB::variant BracExtenssionProviderAPI::setExtensionPath(const FB::variant& msg) { m_extension_path = msg.cast<std::string>(); size_t index = 0; #if defined _WIN32 std::string env_var = "LOCALAPPDATA"; #elif defined __APPLE__ std::string env_var = "USER"; #endif std::string signedvar = '%' + std::string(env_var) + '%'; index = m_extension_path.find(signedvar, index); if (std::string::npos != index) { m_extension_path.replace(index, signedvar.length(), get_env(env_var.c_str())); log("Extension path is set to ('" + std::string(get_env(env_var.c_str())) + "'): " + m_extension_path); } else { log("No environment variable was found: " + m_extension_path); } #if defined __APPLE__ std::string esc_ext_path = escape_path(m_extension_path); systemCall("chmod 700 " + esc_ext_path + "/bin/7za"); systemCall("chmod 700 " + esc_ext_path + "/bin/clg-crop.app"); systemCall("chmod 700 " + esc_ext_path + "/bin/clg-snapshot.app"); #endif return m_extension_path; }
/** * Adds a Routing table with the default route to the default Gateway of the default interface * And routes all marked Packets through this Routing Table * Return on success: 0 * Return on failure: >0 */ int routingHandler::createRouteTable() { std::string addDefaultRouting("ip route add default via "); addDefaultRouting.append(gateway); addDefaultRouting.append(" dev "); //std::string addDefaultRouting("ip route add default dev "); addDefaultRouting.append(interface); addDefaultRouting.append(" table "); addDefaultRouting.append(tableName); int addDefaultRoutingReturnValue = systemCall(addDefaultRouting.c_str()); if(addDefaultRoutingReturnValue != 0){ debugMessage("Firing: "+addDefaultRouting); debugMessage("ReturnValue: "+intToString(addDefaultRoutingReturnValue)); return addDefaultRoutingReturnValue; } std::string addMarkedRoute("ip rule add fwmark 0x"); addMarkedRoute.append(intToString(markerId)); addMarkedRoute.append(" table "); addMarkedRoute.append(tableName); int addMarkedRouteReturnValue = systemCall(addMarkedRoute.c_str()); if(addMarkedRouteReturnValue != 0){ debugMessage("Firing: "+addMarkedRoute); debugMessage("ReturnValue: "+intToString(addMarkedRouteReturnValue)); } return addMarkedRouteReturnValue; }
/** * Sets the Rp-Filter-Value for an interface to a specific value * Return on success: 0 * Return on failure: >0 */ int routingHandler::setRpFilterTo( int value, std::string deviceInterface) { std::string deactivateRpFilter("sysctl net.ipv4.conf."); deactivateRpFilter.append(deviceInterface); deactivateRpFilter.append(".rp_filter="); deactivateRpFilter.append(intToString(value)); return systemCall(deactivateRpFilter.c_str()); }
/** * Create a backup file with the rp filter value of the default interface * Return on success: 0 * Return on failure: >0 */ int routingHandler::backupRpFilter() { int value = getRpFilterValue(interface); std::string command("sudo echo "); command.append(intToString(value)); command.append(" > "); command.append(createBackupFilename(saveFilePrefixRPFilter, interface)); return systemCall(command.c_str()); }
FB::variant BracExtenssionProviderAPI::cleanup(const FB::variant& msg) { std::string command; #if defined _WIN32 command = "rmdir /S /Q \"" + escape_path(m_screenshot_dir) + "\""; #elif defined __APPLE__ command = "rm -Rf " + escape_path(m_screenshot_dir); #endif systemCall(command); return "done!"; }
int routingHandler::createRTTablesEntry() { std::string addTablecommand("echo "); addTablecommand.append(getRTTTableString()); addTablecommand.append(" >> \""); addTablecommand.append(fileRTTables); addTablecommand.append("\""); int returnValue = systemCall(addTablecommand.c_str()); if(returnValue != 0){ debugMessage("Firing "+addTablecommand); } return returnValue; }
//#pragma argsused short PD_style _Ask_AsqlSys( OpndType *lpOpnd, short ParaNum, short *OpndTop, \ short *CurState ) // OpndType *lpOpnd; pointer of opnd stack // short ParaNum; parameter number for this action // short *OpndTop; system opnd top // short *CurState; the action sequence working state { char parameter[256]; char *sz; short sysFunNo; int i; extern WSToMT FromToStru fFrTo; switch( lpOpnd[0].type ) { case LONG_TYPE: sysFunNo = (short)*(long *)lpOpnd[0].values; break; case INT_TYPE: sysFunNo = *(short *)lpOpnd[0].values; break; case CHR_TYPE: sysFunNo = (short)*(char *)lpOpnd[0].values; break; default: sysFunNo = 0; } switch( sysFunNo ) { case 3001: { // //build hzth // char *s; char buf[MAXPATH]; s = GetCfgKey(csuDataDictionary, "SYSTEM", NULL, "CODE"); if( s != NULL ) { strZcpy(buf, s, MAXPATH); if( hBuildCodeLib(buf) != 1 ) { strZcpy(ErrorSet.string, buf, XES_LENGTH); return 1; } if( hOpen(buf) != 1 ) { strZcpy(ErrorSet.string, buf, XES_LENGTH); return 1; } } *OpndTop -= ParaNum; /* maintain the opnd stack */ return( 0 ); } // //secret // case 32123: { //if( stricmp(asqlEnv.szUser, "ADMIN") == 0 ) { dictDupFile(); } *OpndTop -= ParaNum; /* maintain the opnd stack */ return( 0 ); } // //secret // case 32124: { //if( stricmp(asqlEnv.szUser, "ADMIN") == 0 ) { dictReopenCfgFile(); } *OpndTop -= ParaNum; /* maintain the opnd stack */ return( 0 ); } }; sz = xGetOpndString(&lpOpnd[1]); if( sz == NULL ) parameter[0] = '\0'; else strZcpy(parameter, sz, 255); switch( sysFunNo ) { case 1: #ifndef _WINDOWS_ #ifdef FOR_TGMIS systemCall(parameter); #else system(parameter); #endif #else { STARTUPINFO si; PROCESS_INFORMATION pi; HANDLE hProcess; DWORD dwExitCode; _try { ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(si); si.wShowWindow = SW_HIDE; if( CreateProcess(NULL, parameter, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi) ) { hProcess = pi.hProcess; CloseHandle(pi.hThread); if( WaitForSingleObject(hProcess, INFINITE) != WAIT_FAILED ) { GetExitCodeProcess(hProcess, &dwExitCode); CloseHandle(hProcess); } } else { //ErrorSet.xERROR = GetLastError(); dwExitCode = FormatMessage( FORMAT_MESSAGE_IGNORE_INSERTS |FORMAT_MESSAGE_FROM_SYSTEM, \ NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language parameter, 256, NULL ); strZcpy(ErrorSet.string, parameter, XES_LENGTH); return 1; } } _except( EXCEPTION_EXECUTE_HANDLER ) { return 1; } } #endif break; case 2: mkdirs(parameter); break; case 3: unlink(parameter); break; case 10: buildDatabase(parameter); break; case 11: dropDatabase(parameter); break; case 100: uncatchTable(parameter); break; case 2001: { // //create index parameter on fFrTo.cSouDbfNum[i] (lpOpnd[3]) // if( ParaNum < 4 ) { ErrorSet.xERROR = iSysParaErr; return 1; } i = xGetOpndLong(&lpOpnd[2]) - 1; if( i < 0 || i >= fFrTo.cSouDbfNum ) { ErrorSet.xERROR = iSysParaErr; return 1; } sz = xGetOpndString(&lpOpnd[3]); if( fFrTo.AsqlDatabase[0] == '\0' ) { buildIndexAndRegThem("DBROOT", fFrTo.cSouFName[i], parameter, sz); } else { buildIndexAndRegThem(fFrTo.AsqlDatabase, fFrTo.cSouFName[i], parameter, sz); } break; } case 2002: { // //drop index parameter on fFrTo.cSouDbfNum[i] // if( ParaNum < 3 ) { ErrorSet.xERROR = iSysParaErr; return 1; } i = xGetOpndLong(&lpOpnd[2]) - 1; if( i < 0 || i >= fFrTo.cSouDbfNum ) { ErrorSet.xERROR = iSysParaErr; return 1; } if( fFrTo.AsqlDatabase[0] == '\0' ) { dropIndexAndRegThem("DBROOT", fFrTo.cSouFName[i], parameter); } else { dropIndexAndRegThem(fFrTo.AsqlDatabase, fFrTo.cSouFName[i], parameter); } break; } } *OpndTop -= ParaNum; /* maintain the opnd stack */ return( 0 ); } /* end of function _Ask_AsqlSys() */
FB::variant BracExtenssionProviderAPI::saveToBracFile(const FB::variant& msg) { std::string command = ""; if (msg.empty()) log("Received message is empty."); std::string msg_str = msg.cast<std::string>(); std::istringstream input(msg_str); jsonxx::Object o; if(!jsonxx::Object::parse(input, o)) { log("Couldn't parse the JSON message."); return "error"; } if(!o.has<jsonxx::Object>("brac")) { log("Couldn't find the brac JSON object."); return "error"; } jsonxx::Object & brac_info = o.get<jsonxx::Object>("brac"); jsonxx::Object & bric_info = o.get<jsonxx::Object>("bric"); std::string path = brac_info.get<std::string>("filepath"); std::string path_orig = path; path += ".zip"; #if defined _WIN32 char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath(path.c_str(), drive, dir, fname, ext); command = "rename \"" + path_orig + "\" \"" + fname + ext + "\""; #elif defined __APPLE__ std::string escaped_path = escape_path(path); std::string escaped_path_orig = escape_path(path_orig); command = "mv " + escaped_path_orig + " " + escaped_path; #endif systemCall(command); #if defined _WIN32 command = "cd /d \"" + m_extension_path + "\" & bin\\7za.exe e -y \"" + path + "\" brac.xml"; #elif defined __APPLE__ std::string escaped_extension_path = escape_path(m_extension_path); command = "cd " + escaped_extension_path + "; bin/7za e -y " + escaped_path + " brac.xml"; #endif systemCall(command); std::string in_file = m_extension_path + "/brac.xml"; pugi::xml_document brac_xml; pugi::xml_parse_result result = brac_xml.load_file(in_file.c_str()); if (!result) log(result.description()); pugi::xml_node brac_node = brac_xml.child("brac"); if (brac_node.empty()) { log("brac node could not be found"); return "error"; } pugi::xml_node layers_node = brac_node.child("layers"); if (layers_node.empty()) { log("layers node could not be found"); return "error"; } pugi::xml_object_range<pugi::xml_node_iterator> layers = layers_node.children(); int max_id = -1; if (layers.begin() != layers.end()) for (pugi::xml_node_iterator itr = layers.begin(); itr != layers.end(); ++itr) if (max_id < itr->attribute("id").as_int()) max_id = itr->attribute("id").as_int(); int new_brac_num = max_id + 1; pugi::xml_node bric_node = layers_node.append_child("bric"); time_t t = time(0); // get current time struct tm * now = localtime( &t ); char time_now[50]; sprintf(time_now, "%d-%02d-%02d %02d:%02d:%02d", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec ); bric_node.append_attribute("revision" ).set_value(1); bric_node.append_attribute("lastupdate" ).set_value(time_now); bric_node.append_attribute("id" ).set_value(new_brac_num); bric_node.append_attribute("alpha" ).set_value(bric_info.get<std::string>("alpha" ).c_str()); bric_node.append_attribute("order" ).set_value(bric_info.get<std::string>("order" ).c_str()); bric_node.append_attribute("resolution" ).set_value(bric_info.get<std::string>("resolution" ).c_str()); bric_node.append_attribute("position" ).set_value(bric_info.get<std::string>("position" ).c_str()); bric_node.append_attribute("maskposition").set_value(bric_info.get<std::string>("maskposition").c_str()); bric_node.append_attribute("rotate" ).set_value(bric_info.get<std::string>("rotation" ).c_str()); bric_node.append_attribute("scale" ).set_value(bric_info.get<std::string>("scale" ).c_str()); bric_node.append_attribute("timeinterval").set_value(bric_info.get<std::string>("timeInterval").c_str()); bric_node.append_child(pugi::node_pcdata).set_value(bric_info.get<std::string>("comment").c_str()); brac_node.attribute("name") .set_value(brac_info.get<std::string>("name").c_str()); brac_node.attribute("artist").set_value(brac_info.get<std::string>("artist").c_str()); brac_node.attribute("tags") .set_value(brac_info.get<std::string>("tags").c_str()); pugi::xml_object_range<pugi::xml_node_iterator> children = brac_node.children(); for (pugi::xml_node_iterator itr = children.begin(); itr != children.end(); ++itr) if (itr->type() == pugi::node_pcdata) { brac_node.remove_child(*itr); itr = children.begin(); } brac_node.append_child(pugi::node_pcdata).set_value(brac_info.get<std::string>("comment").c_str()); std::string out_file = m_extension_path + "/brac.xml"; if (!brac_xml.save_file(out_file.c_str())) log("Error occurred while creating the new brac file: " + out_file); #if defined _WIN32 command = "cd /d \"" + m_extension_path + "\" & bin\\7za.exe u \"" + path + "\" brac.xml & del /F /Q brac.xml"; #elif defined __APPLE__ command = "cd " + escaped_extension_path + "; bin/7za u " + escaped_path + " brac.xml; rm -f brac.xml"; #endif systemCall(command); std::stringstream stm; stm << new_brac_num; std::string new_bric_path = m_extension_path + "/temp/bric." + stm.str(); #if defined _WIN32 command = "mkdir \"" + new_bric_path + "\""; #elif defined __APPLE__ std::string escaped_new_bric_path = escape_path(new_bric_path); command = "mkdir -p " + escaped_new_bric_path; #endif systemCall(command); pugi::xml_document bric_xml; pugi::xml_node root_node = bric_xml.append_child("bric"); root_node.append_attribute("version" ).set_value("1.0"); root_node.append_attribute("title" ).set_value(bric_info.get<std::string>("title" ).c_str()); root_node.append_attribute("timeinterval").set_value(bric_info.get<std::string>("timeInterval").c_str()); root_node.append_attribute("startdate" ).set_value(bric_info.get<std::string>("startDate" ).c_str()); root_node.append_attribute("url" ).set_value(bric_info.get<std::string>("url" ).c_str()); root_node.append_attribute("region" ).set_value(bric_info.get<std::string>("region" ).c_str()); root_node.append_attribute("tags" ).set_value(bric_info.get<std::string>("tags" ).c_str()); pugi::xml_node snapshot_node = root_node.append_child("snapshot"); snapshot_node.append_attribute("revision").set_value("1"); snapshot_node.append_attribute("date").set_value(time_now); std::string new_bric_filepath = new_bric_path + "/bric.xml"; std::string bric_screenshot_filename = "1.png"; std::string bric_screenshot = new_bric_path + "/" + bric_screenshot_filename; std::string bric_thumbnail = "thumb.png"; std::string bric_thumbnail_path = new_bric_path + "/" + bric_thumbnail; if (!bric_xml.save_file(new_bric_filepath.c_str())) log("Error occurred while creating the new bric file: " + new_bric_filepath); std::vector<std::string> brac_resolution = split(brac_info.get<std::string>("resolution"), ' '); if (brac_resolution.size() != 2) log("Brac resolution should be a pair of integer numbers, separated by space character."); std::vector<std::string> bric_region = split(bric_info.get<std::string>("local_region"), ' '); if (bric_region.size() != 4) log("Bric region should be four integer numbers, separated by space character."); std::string mask_layer_b64 = bric_info.get<std::string>("mask_b64").c_str(); bool mask_created = false; std::string mask_filename = new_bric_path + "/mask.png"; if (!mask_layer_b64.empty()) { std::string decoded = base64_decode(mask_layer_b64); mask_created = saveBinaryFile(mask_filename.c_str(), decoded.c_str(), decoded.size()); } #if defined _WIN32 command = "cd /d \"" + m_extension_path + "\" & move \"" + m_screenshot_dir + "\\" + m_screenshot_filename + "\" \"" + bric_screenshot + "\""; systemCall(command); //*/ command = "cd /d \"" + m_extension_path + "\" & bin\\clg-crop.exe" + " \"" + bric_screenshot + "\" " + bric_region[0] + " " + bric_region[1] + " " + bric_region[2] + " " + bric_region[3]; /*/ command = "cd /d \"" + m_extension_path + "\" & python bin\\crop.py" + " \"" + bric_screenshot + "\" " + bric_region[0] + " " + bric_region[1] + " " + bric_region[2] + " " + bric_region[3]; //*/ systemCall(command); command = "cd /d \"" + new_bric_path + "\" & copy " + bric_screenshot_filename + " " + bric_thumbnail; systemCall(command); command = "cd /d \"" + m_extension_path + "\" & bin\\7za.exe a \"" + path + "\" \"" + new_bric_path + "\""; systemCall(command); command = "rmdir /S /Q \"" + m_extension_path + "\\temp\""; systemCall(command); _splitpath(path_orig.c_str(), drive, dir, fname, ext); command = "rename \"" + path + "\" \"" + fname + ext + "\""; systemCall(command); #elif defined __APPLE__ std::string escaped_bric_screenshot = escape_path(bric_screenshot); std::string escaped_screenshot_dir = escape_path(m_screenshot_dir); command = "mv " + escaped_screenshot_dir + "/" + m_screenshot_filename + " " + escaped_bric_screenshot; systemCall(command); //*/ command = "cd " + escaped_extension_path + "; open -gW bin/clg-crop.app --args " + " " + escaped_bric_screenshot + " " + bric_region[0] + " " + bric_region[1] + " " + bric_region[2] + " " + bric_region[3]; /*/ command = "cd " + escaped_extension_path + "; bin/crop.py" + " " + escaped_bric_screenshot + " " + bric_region[0] + " " + bric_region[1] + " " + bric_region[2] + " " + bric_region[3]; //*/ systemCall(command); std::string escaped_bric_thumbnail = escape_path(bric_thumbnail_path); command = "cp \"" + escaped_bric_screenshot + "\" \"" + escaped_bric_thumbnail + "\""; systemCall(command); command = "cd " + escaped_extension_path + "; bin/7za a " + escaped_path + " " + escaped_new_bric_path; systemCall(command); command = "rm -Rf " + escaped_extension_path + "/temp"; systemCall(command); command = "mv " + escaped_path + " " + escaped_path_orig; systemCall(command); #endif fire_cleanup(); return "done!"; }
FB::variant BracExtenssionProviderAPI::takeSnapShot(const FB::variant& msg) { if (msg.empty()) { log("Received message is empty."); return false; } std::string msg_str = msg.cast<std::string>(); std::istringstream input(msg_str); jsonxx::Object o; if(!jsonxx::Object::parse(input, o)) log("Couldn't parse the JSON message."); std::string url = o.get<std::string>("url"); std::string width = o.get<std::string>("width"); std::string height = o.get<std::string>("height"); std::string scrollLeft = o.get<std::string>("scrollLeft"); std::string scrollTop = o.get<std::string>("scrollTop"); m_screenshot_dir = m_extension_path + "/img/screenshot"; m_screenshot_filename = o.get<std::string>("filename"); std::string command = ""; #if defined _WIN32 command = "mkdir \"" + escape_path(m_screenshot_dir) + "\""; systemCall(command); std::string filepath = m_screenshot_dir + "/" + m_screenshot_filename; //*/ command = "cd /d \"" + m_extension_path + "\" & bin\\clg-snapshot.exe " + "\"" + url + "\" " // target url + "\"" + filepath + "\" " // target filepath + width + " " // window width + height + " " // window height + scrollLeft + " " // scrollLeft + scrollTop // scrollTop ;// using default timeout /*/ command = "cd /d \"" + m_extension_path + "\" & python bin\\snapshot.py " + "\"" + url + "\" " // target url + "\"" + filepath + "\" " // target filepath + width + " " // window width + height + " " // window height + scrollLeft + " " // scrollLeft + scrollTop // scrollTop ;// using default timeout //*/ systemCall(command); #elif defined __APPLE__ std::string escaped_extension_path = escape_path(m_extension_path); std::string escaped_dir = escape_path(m_screenshot_dir); command = "mkdir -p " + escaped_dir; systemCall(command); std::string filepath = escaped_dir + "/" + m_screenshot_filename; //*/ command = "cd " + escaped_extension_path + "; " + "open -gW bin/clg-snapshot.app --args " + "'" + url + "' " // target url + "'" + filepath + "' " // target filepath + width + " " // window width + height + " " // window height + scrollLeft + " " // scrollLeft + scrollTop // scrollTop ;// using default timeout /*/ command = "cd " + escaped_extension_path + "; " + "bin/snapshot.py " + "'" + url + "' " // target url + "'" + filepath + "' " // target filepath + width + " " // window width + height + " " // window height + scrollLeft + " " // scrollLeft + scrollTop // scrollTop ;// using default timeout //*/ systemCall(command); #endif return "done!"; }
void Histogram::plot(string outprefix, string ext, string xlabel, string ylabel) { if (bins_.size() == 0) { return; } string outfile_plot = outprefix + '.' + ext; string outfile_R = outprefix + ".R"; ofstream ofs(outfile_R.c_str()); if (!ofs.good()) { cerr << "Error opening file '" << outfile_R << "'" << endl; exit(1); } unsigned long currentBin; double mean, stddev; meanAndStddev(mean, stddev); mean = mean ? mean : 1; stringstream xCoords; stringstream yCoords; currentBin = bins_.begin()->first; for (map<unsigned long, unsigned long>::iterator p = bins_.begin(); p != bins_.end(); p++) { double xval = p->first; if (!plotLabelXcoordsLeftBin_) xval += 0.5 * binWidth_; if (plotTrim_ && xval < mean - plotTrim_ * stddev) { continue; } else if (plotTrim_ && xval > mean + plotTrim_ * stddev) { break; } if (plotXdivide_) xval /= plotXdivide_; while (currentBin < p->first) { double x = currentBin; if (!plotLabelXcoordsLeftBin_) currentBin += 0.5 * binWidth_; if (plotXdivide_) x /= plotXdivide_; xCoords << ',' << x; yCoords << ",0"; currentBin += binWidth_; } xCoords << ',' << xval; yCoords << ',' << p->second; currentBin += binWidth_; } string x = xCoords.str(); string y = yCoords.str(); if (x[x.size() - 1] == ',') x.resize(x.size() - 1); if (y[y.size() - 1] == ',') y.resize(y.size() - 1); ofs << "x = c(" << x.substr(1, x.size() - 1) << ')' << endl << "y = c(" << y.substr(1, y.size() - 1) << ')' << endl << ext << "(\"" << outfile_plot << "\")" << endl << "plot(x, y, xlab=\"" << xlabel << "\", ylab=\"" << ylabel << "\", type=\"l\")" << endl; for (vector<double>::iterator i = plotVlines_.begin(); i != plotVlines_.end(); i++) { ofs << "abline(v=" << *i << ", col=\"red\", lty=2)" << endl; } ofs << "dev.off()" << endl; ofs.close(); systemCall("R CMD BATCH " + outfile_R + " " + outfile_R + "out"); }
/** * Creates two IP Table Entries. * First to mark all Packets, which are going out to the destination address (We'll need this to specify the right routing table with ip route) * Second to change the Source Address to the right outgoing interface, so that the return messages will arrive on this interface. * Return on success: 0 * Return on failure: >0 */ int routingHandler::createIpTablesEntries() { std::string markIpTables(""); if(ipv6){ markIpTables.append("ip6tables"); }else{ markIpTables.append("iptables"); } markIpTables.append(" -A OUTPUT -t mangle -p "); markIpTables.append(protocol); markIpTables.append(" --dport "); markIpTables.append(intToString(destinationPort)); markIpTables.append(" --destination "); markIpTables.append(destinationAddress); markIpTables.append(" -j MARK --set-mark "); markIpTables.append(intToString(markerId)); int markIpTablesReturnValue = systemCall(markIpTables.c_str()); if(markIpTablesReturnValue != 0){ debugMessage("Firing: "+markIpTables); debugMessage("ReturnValue: "+intToString(markIpTablesReturnValue)); return markIpTablesReturnValue; } std::string changeSourceIpTables(""); if(ipv6){ changeSourceIpTables.append("ip6tables"); changeSourceIpTables.append(" -A POSTROUTING -t mangle -p "); changeSourceIpTables.append(protocol); changeSourceIpTables.append(" --dport "); changeSourceIpTables.append(intToString(destinationPort)); changeSourceIpTables.append(" --destination "); changeSourceIpTables.append(destinationAddress); changeSourceIpTables.append(" --source "); changeSourceIpTables.append(sourceAddress); }else{ changeSourceIpTables.append("iptables"); changeSourceIpTables.append(" -A POSTROUTING -t nat -p "); changeSourceIpTables.append(protocol); changeSourceIpTables.append(" --dport "); changeSourceIpTables.append(intToString(destinationPort)); changeSourceIpTables.append(" --destination "); changeSourceIpTables.append(destinationAddress); changeSourceIpTables.append(" -j SNAT --to "); changeSourceIpTables.append(sourceAddress); } int changeSourceIpTablesReturnValue = systemCall(changeSourceIpTables.c_str()); if(changeSourceIpTablesReturnValue != 0){ debugMessage("Firing: "+changeSourceIpTables); debugMessage("ReturnValue: "+intToString(changeSourceIpTablesReturnValue)); } return changeSourceIpTablesReturnValue; }
/** * Restores the IP Tables from the backup file * Return on success: 0 * Return on failure: >0 */ int routingHandler::restoreIPTables() { std::string command = "iptables-restore < \""; command.append(createBackupFilename(saveFilePrefixIPTables, interface)); command.append("\""); return systemCall(command.c_str()); }
/** * Flushes the created Routing table, so that there are no traces left * Return on success: 0 * Return on failure: >0 */ int routingHandler::removeRouteTable() { std::string removeDefaultRouting("ip route flush table "); removeDefaultRouting.append(tableName); return systemCall(removeDefaultRouting.c_str()); }