Added colorful printing functions

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@139 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-04-17 19:05:06 +00:00
parent 3ec5c66fee
commit a9d08422f5
4 changed files with 99 additions and 45 deletions
+36 -21
View File
@@ -18,13 +18,13 @@ static struct option g_LongOpts[] =
void GenerateHelp( const char *appname )
{
cerr << "USAGE: " << appname << " [options] [znc.conf]" << endl;
cerr << "Options are:" << endl;
cerr << " --help" << endl;
cerr << " --makepass Generates a password for use in config" << endl;
CUtils::PrintMessage("USAGE: " + string(appname) + " [options] [znc.conf]");
CUtils::PrintMessage("Options are:");
CUtils::PrintMessage("\t--help");
CUtils::PrintMessage("\t--makepass Generates a password for use in config");
#ifdef HAVE_LIBSSL
cerr << " --makepem Generates a pemfile for use with SSL" << endl;
cerr << " --encrypt-pem Encrypts the pemfile" << endl;
CUtils::PrintMessage("\t--makepem Generates a pemfile for use with SSL");
CUtils::PrintMessage("\t--encrypt-pem Encrypts the pemfile");
#endif /* HAVE_LIBSSL */
}
@@ -34,7 +34,7 @@ void die(int sig) {
signal( SIGPIPE, SIG_DFL );
#ifdef _DEBUG
cerr << "Exiting on SIG [" << sig << "]" << endl;
CUtils::PrintMessage("Exiting on SIG [" + CUtils::ToString(sig) + "]");
if ( ( sig == SIGABRT ) || ( sig == SIGSEGV ) )
abort();
#endif /* _DEBUG */
@@ -96,33 +96,42 @@ int main(int argc, char** argv) {
sConfig = argv[optind];
#ifdef HAVE_LIBSSL
if ( bMakePem ) {
if (bMakePem) {
CZNC* pZNC = CZNC::New();
pZNC->InitDirs("");
string 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 ) {
cerr << "Unable to open pem file [" << sPemFile << "]" << endl;
if (!f) {
CUtils::PrintStatus(false, "Unable to open");
delete pZNC;
return( 1 );
return 1 ;
}
CUtils::GenerateCert( f, bEncPem );
fclose( f );
fclose(f);
cout << "Wrote pem file to [" << sPemFile << "]" << endl;
CUtils::PrintStatus(true);
delete pZNC;
return( 0 );
return 0;
}
#endif /* HAVE_LIBSSL */
if ( bMakePass ) {
char* pass = getpass( "Enter Password: " );
int iLen = strlen(pass);
cout << "Use this in the <User> section of your config:" << endl << endl << "Pass = " << CMD5(pass, iLen) << " -" << endl << endl;
memset((char*) pass, 0, iLen); // Null out our pass so it doesn't sit in memory
CUtils::PrintMessage("Use this in the <User> section of your config:");
CUtils::PrintMessage("Pass = " + string((const char*) CMD5(pass, iLen)) + " -");
memset((char*) pass, 0, iLen); // null out our pass so it doesn't sit in memory
return 0;
}
@@ -130,33 +139,39 @@ int main(int argc, char** argv) {
pZNC->InitDirs(((argc) ? argv[0] : ""));
if (!pZNC->ParseConfig(sConfig)) {
cerr << endl << "*** Unrecoverable error while parsing config." << endl;
CUtils::PrintError("Unrecoverable error while parsing config.");
delete pZNC;
return 1;
}
if (!pZNC->GetListenPort()) {
cerr << "You must supply a ListenPort in your config." << endl;
CUtils::PrintError("You must supply a ListenPort in your config.");
delete pZNC;
return 1;
}
if (!pZNC->OnBoot()) {
cerr << "Exiting due to module boot errors." << endl;
CUtils::PrintError("Exiting due to module boot errors.");
delete pZNC;
return 1;
}
#ifndef _DEBUG
CUtils::PrintAction("Forking into the background");
int iPid = fork();
if (iPid == -1) {
cerr << "Failed to fork into background: [" << strerror(errno) << "]" << endl;
CUtils::PrintStatus(false, strerror(errno));
delete pZNC;
exit(1);
}
if (iPid > 0) {
cout << "ZNC - by prozac [port: " << ((pZNC->IsSSL()) ? "+" : "") << pZNC->GetListenPort() << "] [pid: " << iPid << "]" << endl;
CUtils::PrintStatus(true, "[pid: " + CUtils::ToString(iPid) + "]");
CUtils::PrintMessage("ZNC - by prozac@gmail.com");
// [port: " << ((pZNC->IsSSL()) ? "+" : "") << pZNC->GetListenPort() << "] [pid: " << iPid << "]" << endl;
pZNC->WritePidFile(iPid);
exit(0);
}