Added prompt for pem file generation

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@557 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-10-10 04:33:30 +00:00
parent e3b723de5b
commit bf1715973b
5 changed files with 46 additions and 44 deletions

View File

@@ -41,7 +41,7 @@ char *strcasestr(const char *big, const char *little) {
#endif /* __sun */
#ifdef HAVE_LIBSSL
void CUtils::GenerateCert(FILE *pOut, bool bEncPrivKey) {
void CUtils::GenerateCert(FILE *pOut, bool bEncPrivKey, const CString& sHost) {
EVP_PKEY *pKey = NULL;
X509 *pCert = NULL;
X509_NAME *pName = NULL;
@@ -72,8 +72,16 @@ void CUtils::GenerateCert(FILE *pOut, bool bEncPrivKey) {
pName = X509_get_subject_name( pCert );
char *pLogName = getenv("LOGNAME");
char *pHostName = getenv("HOSTNAME");
const char *pLogName = getenv("LOGNAME");
const char *pHostName = NULL;
if (!sHost.empty()) {
pHostName = sHost.c_str();
}
if (!pHostName) {
pHostName = getenv("HOSTNAME");
}
if (!pLogName) {
pLogName = "Unknown";

View File

@@ -51,7 +51,7 @@ public:
return iTime;
}
#ifdef HAVE_LIBSSL
static void GenerateCert(FILE *pOut, bool bEncPrivKey = false);
static void GenerateCert(FILE *pOut, bool bEncPrivKey = false, const CString& sHost = "");
#endif /* HAVE_LIBSSL */
private:

View File

@@ -138,28 +138,7 @@ int main(int argc, char** argv, char** envp) {
if (bMakePem) {
CZNC* pZNC = &CZNC::Get();
pZNC->InitDirs("");
CString sPemFile = pZNC->GetPemLocation();
CUtils::PrintAction("Writing Pem file [" + sPemFile + "]");
if (CFile::Exists(sPemFile)) {
CUtils::PrintStatus(false, "File already exists");
delete pZNC;
return 1;
}
FILE *f = fopen(sPemFile.c_str(), "w");
if (!f) {
CUtils::PrintStatus(false, "Unable to open");
delete pZNC;
return 1 ;
}
CUtils::GenerateCert(f, bEncPem);
fclose(f);
CUtils::PrintStatus(true);
pZNC->WritePemFile();
delete pZNC;
return 0;

50
znc.cpp
View File

@@ -198,6 +198,37 @@ bool CZNC::WritePidFile(int iPid) {
return false;
}
bool CZNC::WritePemFile() {
CString sPemFile = GetPemLocation();
const char* pHostName = getenv("HOSTNAME");
CString sHost;
if (pHostName) {
sHost = pHostName;
}
if (CFile::Exists(sPemFile)) {
CUtils::PrintError("Pem file [" + sPemFile + "] already exists");
return false;
}
while (!CUtils::GetInput("hostname of your shell", sHost, sHost, "including the '.com' portion"));
CUtils::PrintAction("Writing Pem file [" + sPemFile + "]");
FILE *f = fopen(sPemFile.c_str(), "w");
if (!f) {
CUtils::PrintStatus(false, "Unable to open");
return false;
}
CUtils::GenerateCert(f, false, sHost);
fclose(f);
CUtils::PrintStatus(true);
return true;
}
void CZNC::DeleteUsers() {
for (map<CString,CUser*>::iterator a = m_msUsers.begin(); a != m_msUsers.end(); a++) {
delete a->second;
@@ -924,24 +955,7 @@ bool CZNC::ParseConfig(const CString& sConfig) {
CUtils::PrintStatus(false, "Unable to locate pem file: [" + sPemFile + "]");
if (CUtils::GetBoolInput("Would you like to create a new pem file?", true)) {
CUtils::PrintAction("Writing Pem file [" + sPemFile + "]");
if (CFile::Exists(sPemFile)) {
CUtils::PrintStatus(false, "File already exists");
return false;
}
FILE *f = fopen(sPemFile.c_str(), "w");
if (!f) {
CUtils::PrintStatus(false, "Unable to open");
return false;
}
CUtils::GenerateCert(f, false);
fclose(f);
CUtils::PrintStatus(true);
WritePemFile();
} else {
return false;
}

1
znc.h
View File

@@ -61,6 +61,7 @@ public:
const CString& GetConfBackupPath() const { if (!CFile::Exists(m_sConfBackupPath)) { CUtils::MakeDir(m_sConfBackupPath); } return m_sConfBackupPath; }
const CString& GetUserPath() const { if (!CFile::Exists(m_sUserPath)) { CUtils::MakeDir(m_sUserPath); } return m_sUserPath; }
CString GetPemLocation() const { return GetZNCPath() + "/znc.pem"; }
bool WritePemFile();
const CString& GetISpoofFile() const { return m_sISpoofFile; }
const CString& GetISpoofFormat() const { return m_sISpoofFormat; }
const VCString& GetVHosts() const { return m_vsVHosts; }