mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
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:
14
Utils.cpp
14
Utils.cpp
@@ -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";
|
||||
|
||||
2
Utils.h
2
Utils.h
@@ -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:
|
||||
|
||||
23
main.cpp
23
main.cpp
@@ -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
50
znc.cpp
@@ -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
1
znc.h
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user