Merge pull request #658 from jpnurmi/makeconf

makeconf cont'd
This commit is contained in:
Alexey Sokolov
2014-09-12 22:43:37 +01:00
+101 -111
View File
@@ -572,7 +572,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
}
CUtils::PrintMessage("");
CUtils::PrintMessage("First let's start with some global settings...");
CUtils::PrintMessage("-- Global settings --");
CUtils::PrintMessage("");
// Listen
@@ -590,22 +590,26 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
do {
bSuccess = true;
while (true) {
if (!CUtils::GetNumInput("What port would you like ZNC to listen on?", uListenPort, 1025, 65535)) {
if (!CUtils::GetNumInput("Listen on port", uListenPort, 1025, 65534)) {
continue;
}
if (uListenPort == 6667 && !CUtils::GetBoolInput("Warning: Some web browsers reject port 6667. If you intend to use ZNC's web interface, you might want to use another port. Proceed with port 6667 anyway?", true)) {
continue;
if (uListenPort == 6667) {
CUtils::PrintStatus(false, "WARNING: Some web browsers reject port 6667. If you intend to");
CUtils::PrintStatus(false, "use ZNC's web interface, you might want to use another port.");
if (!CUtils::GetBoolInput("Proceed with port 6667 anyway?", true)) {
continue;
}
}
break;
}
#ifdef HAVE_LIBSSL
bListenSSL = CUtils::GetBoolInput("Would you like ZNC to listen using SSL?", bListenSSL);
bListenSSL = CUtils::GetBoolInput("Listen using SSL", bListenSSL);
#endif
#ifdef HAVE_IPV6
b6 = CUtils::GetBoolInput("Would you like ZNC to listen using both IPv4 and IPv6?", b6);
b6 = CUtils::GetBoolInput("Listen using both IPv4 and IPv6", b6);
#endif
// Don't ask for listen host, it may be configured later if needed.
@@ -647,129 +651,115 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
vsGlobalModNames.push_back(it->GetName());
vsLines.push_back("LoadModule = " + it->GetName());
}
CUtils::PrintMessage("Enabled the default global modules [" + CString(", ").Join(vsGlobalModNames.begin(), vsGlobalModNames.end()) + "]");
CUtils::PrintMessage("Enabled global modules [" + CString(", ").Join(vsGlobalModNames.begin(), vsGlobalModNames.end()) + "]");
// User
CUtils::PrintMessage("");
CUtils::PrintMessage("Now we need to set up a user...");
CUtils::PrintMessage("-- Admin user settings --");
CUtils::PrintMessage("");
bool bFirstUser = true;
vsLines.push_back("");
CString sNick;
do {
CUtils::GetInput("Username", sUser, "", "alphanumeric");
} while (!CUser::IsValidUserName(sUser));
vsLines.push_back("<User " + sUser + ">");
CString sSalt;
sAnswer = CUtils::GetSaltedHashPass(sSalt);
vsLines.push_back("\tPass = " + CUtils::sDefaultHash + "#" + sAnswer + "#" + sSalt + "#");
vsLines.push_back("\tAdmin = true");
CUtils::GetInput("Nick", sNick, CUser::MakeCleanUserName(sUser));
vsLines.push_back("\tNick = " + sNick);
CUtils::GetInput("Alternate nick", sAnswer, sNick + "_");
if (!sAnswer.empty()) {
vsLines.push_back("\tAltNick = " + sAnswer);
}
CUtils::GetInput("Ident", sAnswer, sUser);
vsLines.push_back("\tIdent = " + sAnswer);
CUtils::GetInput("Real name", sAnswer, "Got ZNC?");
vsLines.push_back("\tRealName = " + sAnswer);
CUtils::GetInput("Bind host", sAnswer, "", "optional");
if (!sAnswer.empty()) {
vsLines.push_back("\tBindHost = " + sAnswer);
}
set<CModInfo> ssUserMods;
GetModules().GetDefaultMods(ssUserMods, CModInfo::UserModule);
vector<CString> vsUserModNames;
for (set<CModInfo>::const_iterator it = ssUserMods.begin(); it != ssUserMods.end(); ++it) {
vsUserModNames.push_back(it->GetName());
vsLines.push_back("\tLoadModule = " + it->GetName());
}
CUtils::PrintMessage("Enabled user modules [" + CString(", ").Join(vsUserModNames.begin(), vsUserModNames.end()) + "]");
CUtils::PrintMessage("");
if (CUtils::GetBoolInput("Set up a network?", true)) {
vsLines.push_back("");
CString sNick;
CUtils::PrintMessage("");
CUtils::PrintMessage("-- Network settings --");
CUtils::PrintMessage("");
do {
CUtils::GetInput("Username", sUser, "", "AlphaNumeric");
} while (!CUser::IsValidUserName(sUser));
CUtils::GetInput("Name", sNetwork, "freenode");
} while (!CIRCNetwork::IsValidNetwork(sNetwork));
vsLines.push_back("<User " + sUser + ">");
CString sSalt;
sAnswer = CUtils::GetSaltedHashPass(sSalt);
vsLines.push_back("\tPass = " + CUtils::sDefaultHash + "#" + sAnswer + "#" + sSalt + "#");
vsLines.push_back("\t<Network " + sNetwork + ">");
if (CUtils::GetBoolInput("Would you like this user to be an admin?", bFirstUser)) {
vsLines.push_back("\tAdmin = true");
} else {
vsLines.push_back("\tAdmin = false");
set<CModInfo> ssNetworkMods;
GetModules().GetDefaultMods(ssNetworkMods, CModInfo::NetworkModule);
vector<CString> vsNetworkModNames;
for (set<CModInfo>::const_iterator it = ssNetworkMods.begin(); it != ssNetworkMods.end(); ++it) {
vsNetworkModNames.push_back(it->GetName());
vsLines.push_back("\t\tLoadModule = " + it->GetName());
}
CUtils::GetInput("Nick", sNick, CUser::MakeCleanUserName(sUser));
vsLines.push_back("\tNick = " + sNick);
CUtils::GetInput("Alt Nick", sAnswer, sNick + "_");
if (!sAnswer.empty()) {
vsLines.push_back("\tAltNick = " + sAnswer);
}
CUtils::GetInput("Ident", sAnswer, sUser);
vsLines.push_back("\tIdent = " + sAnswer);
CUtils::GetInput("Real Name", sAnswer, "Got ZNC?");
vsLines.push_back("\tRealName = " + sAnswer);
CUtils::GetInput("Bind Host", sAnswer, "", "optional");
if (!sAnswer.empty()) {
vsLines.push_back("\tBindHost = " + sAnswer);
}
set<CModInfo> ssUserMods;
GetModules().GetDefaultMods(ssUserMods, CModInfo::UserModule);
vector<CString> vsUserModNames;
for (set<CModInfo>::const_iterator it = ssUserMods.begin(); it != ssUserMods.end(); ++it) {
vsUserModNames.push_back(it->GetName());
vsLines.push_back("\tLoadModule = " + it->GetName());
}
CUtils::PrintMessage("Enabled the default user modules [" + CString(", ").Join(vsUserModNames.begin(), vsUserModNames.end()) + "]");
CUtils::PrintMessage("");
CString sAAnother = "a";
while (CUtils::GetBoolInput("Would you like to set up " + sAAnother + " network?", false)) {
sAAnother = "another";
vsLines.push_back("");
do {
CUtils::GetInput("Network", sNetwork, "", "e.g. `freenode' or `efnet'");
} while (!CIRCNetwork::IsValidNetwork(sNetwork));
vsLines.push_back("\t<Network " + sNetwork + ">");
set<CModInfo> ssNetworkMods;
GetModules().GetDefaultMods(ssNetworkMods, CModInfo::NetworkModule);
vector<CString> vsNetworkModNames;
for (set<CModInfo>::const_iterator it = ssNetworkMods.begin(); it != ssNetworkMods.end(); ++it) {
vsNetworkModNames.push_back(it->GetName());
vsLines.push_back("\t\tLoadModule = " + it->GetName());
}
CUtils::PrintMessage("Enabled the default network modules [" + CString(", ").Join(vsNetworkModNames.begin(), vsNetworkModNames.end()) + "]");
vsLines.push_back("");
CUtils::PrintMessage("");
CUtils::PrintMessage("-- IRC Servers --");
CUtils::PrintMessage("Only add servers from the same IRC network.");
CUtils::PrintMessage("If a server from the list can't be reached, another server will be used.");
CUtils::PrintMessage("");
do {
CString sHost, sPass;
bool bSSL = false;
unsigned int uServerPort = 0;
while (!CUtils::GetInput("IRC server", sHost, "", "host only") || !CServer::IsValidHostName(sHost)) ;
while (!CUtils::GetNumInput("[" + sHost + "] Port", uServerPort, 1, 65535, 6667)) ;
CUtils::GetInput("[" + sHost + "] Password (probably empty)", sPass);
CString sHost, sPass, sHint;
bool bSSL = false;
unsigned int uServerPort = 0;
if (sNetwork.Equals("freenode")) {
sHost = "chat.freenode.net";
#ifdef HAVE_LIBSSL
bSSL = CUtils::GetBoolInput("Does this server use SSL?", uServerPort == 6697);
bSSL = true;
#endif
vsLines.push_back("\t\tServer = " + sHost + ((bSSL) ? " +" : " ") + CString(uServerPort) + " " + sPass);
CUtils::PrintMessage("");
} while (CUtils::GetBoolInput("Would you like to add another server for this IRC network?", false));
vsLines.push_back("");
CUtils::PrintMessage("");
CUtils::PrintMessage("-- Channels --");
CUtils::PrintMessage("");
CString sArg = "a";
CString sPost = " for ZNC to automatically join?";
bool bDefault = true;
while (CUtils::GetBoolInput("Would you like to add " + sArg + " channel" + sPost, bDefault)) {
while (!CUtils::GetInput("Channel name", sAnswer)) ;
vsLines.push_back("\t\t<Chan " + sAnswer + ">");
vsLines.push_back("\t\t</Chan>");
sArg = "another";
sPost = "?";
bDefault = false;
}
vsLines.push_back("\t</Network>");
} else {
sHint = "host only";
}
vsLines.push_back("</User>");
while (!CUtils::GetInput("Server host", sHost, sHost, sHint) || !CServer::IsValidHostName(sHost));
#ifdef HAVE_LIBSSL
bSSL = CUtils::GetBoolInput("Server uses SSL?", bSSL);
#endif
while (!CUtils::GetNumInput("Server port", uServerPort, 1, 65535, bSSL ? 6697 : 6667));
CUtils::GetInput("Server password (probably empty)", sPass);
CUtils::PrintMessage("");
bFirstUser = false;
} while (CUtils::GetBoolInput("Would you like to set up another user?", false));
vsLines.push_back("\t\tServer = " + sHost + ((bSSL) ? " +" : " ") + CString(uServerPort) + " " + sPass);
CString sChans;
if (CUtils::GetInput("Initial channels", sChans)) {
vsLines.push_back("");
VCString vsChans;
sChans.Replace(",", " ");
sChans.Replace(";", " ");
sChans.Split(" ", vsChans, false, "", "", true, true);
for (const CString& sChan : vsChans) {
vsLines.push_back("\t\t<Chan " + sChan + ">");
vsLines.push_back("\t\t</Chan>");
}
}
CUtils::PrintMessage("Enabled network modules [" + CString(", ").Join(vsNetworkModNames.begin(), vsNetworkModNames.end()) + "]");
vsLines.push_back("\t</Network>");
}
vsLines.push_back("</User>");
CUtils::PrintMessage("");
// !User
CFile File;