void login_dialog::db_connect() { QString errstr; QString qcs=connect_string(); if (!ConnectDb(qcs.toLocal8Bit(), &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); } else { QSettings settings("Manitou-Mail", "manitou-ui"); settings.setValue("login", login()); settings.setValue("dbname", dbnames()); // stringlist settings.setValue("host", host()); settings.setValue("params", params()); accept(); } }
int main(int argc, char *argv[]) { pentry entries[MAXPOSTVARS]; entry gentries[MAXGETVARS]; char *gcl; register int i; int cl=0; ConnectDb(); if(getenv("REMOTE_ADDR")!=NULL) sprintf(gcHost,"%.99s",getenv("REMOTE_ADDR")); if(getenv("HTTP_USER_AGENT")!=NULL) { if(strstr(getenv("HTTP_USER_AGENT"),"Firefox")) guBrowserFirefox=1; } #if defined(Linux) gethostname(gcHostname, 98); #else //Solaris sysinfo(SI_HOSTNAME, gcHostname, 98); #endif if(strcmp(getenv("REQUEST_METHOD"),"POST")) { //Get //SSLCookieLogin(); gcl = getenv("QUERY_STRING"); for(i=0;gcl[0] != '\0' && i<MAXGETVARS;i++) { getword(gentries[i].val,gcl,'&'); plustospace(gentries[i].val); unescape_url(gentries[i].val); getword(gentries[i].name,gentries[i].val,'='); if(!strcmp(gentries[i].name,"gcFunction")) sprintf(gcFunction,"%.99s",gentries[i].val); else if(!strcmp(gentries[i].name,"gcPage")) sprintf(gcPage,"%.99s",gentries[i].val); } if(gcPage[0]) { if(!strcmp(gcPage,"MyAccount")) MyAccountGetHook(gentries,i); } } else { //Post cl = atoi(getenv("CONTENT_LENGTH")); for(i=0;cl && (!feof(stdin)) && i<MAXPOSTVARS ;i++) { entries[i].val = fmakeword(stdin,'&',&cl); plustospace(entries[i].val); unescape_url(entries[i].val); entries[i].name = makeword(entries[i].val,'='); if(!strcmp(entries[i].name,"gcFunction")) sprintf(gcFunction,"%.99s",entries[i].val); else if(!strcmp(entries[i].name,"gcPage")) sprintf(gcPage,"%.99s",entries[i].val); else if(!strcmp(entries[i].name,"gcLogin")) sprintf(gcLogin,"%.99s",entries[i].val); else if(!strcmp(entries[i].name,"gcPasswd")) sprintf(gcPasswd,"%.99s",entries[i].val); } } //Not required to be logged in gcFunction section if(gcFunction[0]) { if(!strncmp(gcFunction,"Logout",5)) { printf("Set-Cookie: iRadiusLogin=; expires=\"Mon, 01-Jan-1971 00:10:10 GMT\"\n"); printf("Set-Cookie: iRadiusPasswd=; expires=\"Mon, 01-Jan-1971 00:10:10 GMT\"\n"); guPermLevel=0; gcUser[0]=0; guLoginClient=0; htmlLogin(); } } /*if(!strcmp(gcFunction,"Login")) SetLogin(); if(!guPermLevel || !gcUser[0] || !guLoginClient) SSLCookieLogin()¨; //First page after valid login if(!strcmp(gcFunction,"Login")) htmlMyAccountd();*/ //Per page command tree MyAccountCommands(entries,i); //default logged in page htmlMyAccount(); return(0); }//end of main()
int main(int argc, char **argv) { manitou_application app(argc,argv); gl_pApplication=&app; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // The location of the data files depends on the prefix choosen at configure // time except under windows. QString s = QString(MANITOU_DATADIR); QString manitou_tr_path = s + "/translations"; QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_WIN) // under windows, the data directories are expected to be at the same level // than the executable file QString s = QApplication::applicationDirPath(); QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QString manitou_tr_path = s + "/translations"; gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_MAC) // we use embedded resources on Mac QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = ":/images"; QString s = QApplication::applicationDirPath(); gl_help_path = s + "/help"; QString manitou_tr_path = s + "/translations"; #endif const char* cnx_string=NULL; QString conf_name; bool explicit_config=false; while(1) { int option_index = 0; static optstruct long_options[] = { {"debug-output", 1, 0, 'l'}, {"debug-window", 1, 0, 'w'}, {"config", 1, 0, 'c'}, {"dbcnx", 1, 0, 'd'}, {"help", 1, 0, 'h'}, {0, 0, 0, 0} }; int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (OPTARG) printf (" with arg %s", OPTARG); printf ("\n"); break; case '?': usage(argv[0]); break; case 'h': usage(argv[0]); break; case 'c': conf_name = OPTARG; explicit_config=true; break; case 'l': global_debug_level = OPTARG?atoi(OPTARG):10; break; case 'w': global_debug_level = OPTARG?atoi(OPTARG):10; global_debug_window = 1; break; case 'd': cnx_string = OPTARG; break; } } if (OPTIND < argc && !cnx_string) { /* compatibility with earlier versions: if there are non-named arguments on the command line, they will be interpreted as a connection string */ cnx_string = argv[OPTIND]; } QTranslator translator; QTranslator translator_qt; QLocale locale = QLocale::system(); // search for a translation file, except for the C locale if (locale.name() != QLocale::c().name()) { if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path)) app.installTranslator(&translator_qt); if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) { app.installTranslator(&translator); } else { QString tq = QString("manitou_")+locale.name(); DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData()); } } if (conf_name.isEmpty()) { // then configuration is hostname-OSname QString hostname=QHostInfo::localHostName().toLower(); if (hostname.isEmpty()) hostname="unknown"; QString uname; #ifndef Q_OS_WIN struct utsname u; if (::uname(&u)==0 && u.sysname[0]) { uname = QString(u.sysname).toLower(); } #else uname="windows"; #endif conf_name = hostname + "-" + uname; } /* Call createUuid() before creating any window as a workaround against QTBUG-11080 or QTBUG-11213 in Qt-4.6.2 on Linux. Otherwise, createUuid() may return a UUID that is always the same when creating a new Message-Id later on. The fix for this Qt bug has not been backported in Ubuntu-10.04 LTS at this time (2012-10-08). */ (void)QUuid::createUuid(); if (cnx_string==NULL) { login_dialog dlg; if (dlg.exec() == QDialog::Rejected) return 0; } else { QString errstr; if (!ConnectDb(cnx_string, &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); return 1; } } if (!explicit_config) { printf("Configuration used: %s\n", conf_name.toLocal8Bit().constData()); } global_conf.set_name(conf_name); global_conf.init(); global_conf.apply(); if (!QFile::exists(gl_xpm_path+"/"+FT_ICON16_QUIT)) { gl_pApplication->display_warning(QObject::tr("Icon files not found at: %1").arg(gl_xpm_path)); } msgs_filter filter; QString sq = get_config().get_string("display/start_query"); filter.m_sql_stmt= sq.isEmpty() ? "0" : sq; #ifdef Q_OS_UNIX gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false); #endif users_repository::fetch(); message_port::init(); msg_status_cache::init_db(); tags_repository::fetch(); app.setup_desktop_tray_icon(); msg_list_window* w = new msg_list_window(&filter,0); w->show(); app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup())); app.exec(); DisconnectDb(); return 0; }
int main(int argc, char **argv) { manitou_application app(argc,argv); gl_pApplication=&app; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // The location of the data files depends on the prefix choosen at configure // time except under windows. QString s = QString(MANITOU_DATADIR); QString manitou_tr_path = s + "/translations"; QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_WIN) // under windows, the data directories are expected to be at the same level // than the executable file QString s = QApplication::applicationDirPath(); QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QString manitou_tr_path = s + "/translations"; gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_MAC) // we use embedded resources on Mac QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = ":/images"; QString manitou_tr_path = ":/translations"; #endif const char* cnx_string=NULL; QString conf_name; bool explicit_config=false; while(1) { int option_index = 0; static optstruct long_options[] = { {"debug-output", 1, 0, 'l'}, {"debug-window", 1, 0, 'w'}, {"config", 1, 0, 'c'}, {"dbcnx", 1, 0, 'd'}, {"help", 1, 0, 'h'}, {0, 0, 0, 0} }; int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (OPTARG) printf (" with arg %s", OPTARG); printf ("\n"); break; case '?': usage(argv[0]); break; case 'h': usage(argv[0]); break; case 'c': conf_name = OPTARG; explicit_config=true; break; case 'l': global_debug_level = OPTARG?atoi(OPTARG):10; break; case 'w': global_debug_level = OPTARG?atoi(OPTARG):10; global_debug_window = 1; break; case 'd': cnx_string = OPTARG; break; } } if (OPTIND < argc && !cnx_string) { /* compatibility with earlier versions: if there are non-named arguments on the command line, they will be interpreted as a connection string */ cnx_string = argv[OPTIND]; } QTranslator translator; QTranslator translator_qt; QLocale locale = QLocale::system(); // search for a translation file, except for the C locale if (locale.name() != QLocale::c().name()) { if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path)) app.installTranslator(&translator_qt); if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) { app.installTranslator(&translator); } else { QString tq = QString("manitou_")+locale.name(); DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData()); } } if (conf_name.isEmpty()) { // then configuration is hostname-OSname QString hostname=QHostInfo::localHostName().toLower(); if (hostname.isEmpty()) hostname="unknown"; QString uname; #ifndef Q_OS_WIN struct utsname u; if (::uname(&u)==0 && u.sysname[0]) { uname = QString(u.sysname).toLower(); } #else uname="windows"; #endif conf_name = hostname + "-" + uname; } int connected=0; if (cnx_string==NULL) { // get the connection parameters from a dialog box QString qcs; login_dialog dlg; QSettings settings("Manitou-Mail", "manitou-ui"); dlg.set_login(settings.value("login").toString()); dlg.set_dbname(settings.value("dbname").toString()); dlg.set_host(settings.value("host").toString()); dlg.set_params(settings.value("params").toString()); dlg.set_focus(); do { if (dlg.exec()==1) { qcs = dlg.connect_string(); } else { helper::close(); exit(0); // exit if connection dialog closed with 'Cancel' } QString errstr; if (!(connected=ConnectDb(qcs.toLocal8Bit(), &errstr))) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); } else { settings.setValue("login", dlg.login()); settings.setValue("dbname", dlg.dbnames()); // stringlist settings.setValue("host", dlg.host()); settings.setValue("params", dlg.params()); } } while (!connected); } else { QString errstr; if (!ConnectDb(cnx_string, &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); exit(1); } } if (!explicit_config) { QByteArray qb = conf_name.toLatin1(); printf("Configuration used: %s\n", qb.constData()); fflush(stdout); } global_conf.set_name(conf_name); global_conf.init(); global_conf.apply(); msgs_filter filter; filter.m_sql_stmt="0"; #ifdef Q_OS_UNIX gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false); #endif /* Instantiate the user in the database if necessary. Ideally we should ask for a fullname if not already known, but there's no GUI support for that yet */ user::create_if_missing(QString::null); users_repository::fetch(); message_port::init(); msg_status_cache::init_db(); msg_list_window* w = new msg_list_window(&filter,0); w->show(); app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup())); app.exec(); DisconnectDb(); DBG_PRINTF(1, "end"); return 0; }
void CDbWriteThread::run( ) { ConnectDb( ); exec( ); }