}
{
- std::string fileName(_ip + ".sh");
+ std::ostream * stream = NULL;
+ std::string fileName(_settings.scriptBase() + "/" + _ip + ".sh");
std::string newFileName(fileName + ".new");
- std::ofstream script(newFileName.c_str());
- script << "#!/bin/sh\n";
- if (!dropACLs(target, script)) {
+
+ if (_settings.dumpScripts()) {
+ stream = new std::ofstream(newFileName.c_str());
+ *stream << "#!/bin/sh\n";
+ } else {
+ stream = new std::stringstream;
+ }
+
+ if (!dropACLs(target, *stream)) {
logger << "Switch::sync() - failed to drop ACLs for the switch '" << _ip << "'" << std::endl;
+ delete stream;
return;
}
- if (!createACLs(target, script)) {
+ if (!createACLs(target, *stream)) {
logger << "Switch::sync() - failed to create ACLs for the switch '" << _ip << "'" << std::endl;
+ delete stream;
return;
}
- script.close();
- rename(newFileName.c_str(), fileName.c_str());
+
+ delete stream;
+ if (_settings.dumpScripts())
+ rename(newFileName.c_str(), fileName.c_str());
}
if (_settings.isDebug()) {
size_t chunks = aclsList.size() / _settings.maxACLPerPDU() + 1;
for (size_t i = 0; i < chunks && it != aclsList.end(); ++i) {
Pdu pdu;
- stream << "snmpset -v2c -cgts_community_w " << _ip;
+ if (_settings.dumpScripts())
+ stream << "snmpset -v2c -c" << _writeCommunity << " " << _ip;
for (size_t j = 0; j < _settings.maxACLPerPDU() && it != aclsList.end(); ++j, ++it) {
int id;
if (int c = it->get_value(id) != SNMP_CLASS_SUCCESS) {
Vb vb(Oid(dropACLOid.c_str()));
vb.set_value(int(6));
pdu += vb;
- stream << " " << dropACLOid << " i 6";
+ if (_settings.dumpScripts())
+ stream << " " << dropACLOid << " i 6";
}
- stream << "\n";
+ if (_settings.dumpScripts())
+ stream << "\n";
if (int c = _snmp.set(pdu, target) != SNMP_CLASS_SUCCESS) {
if (c != SNMP_ERROR_TOO_BIG) {
logger << "Switch::dropACLsByTable() - failed to invoke Snmp::set for the switch '" << _ip << "'. Error message: '" << Snmp::error_msg(c) << "'" << std::endl;
pdu.clear();
_aclsCreated = true;
++pos;
- stream << "snmpset -v2c -cgts_community_w " << _ip << " " << *it << "\n";
+ if (_settings.dumpScripts())
+ stream << "snmpset -v2c -c" << _writeCommunity << " " << _ip << " " << *it << "\n";
}
return true;
}