Beispiel #1
0
void Options::Check_Configuration_Directory()
{
    // Create Configuration Directory If Needed
    FilePath config_dir(m_gui_config_settings["MSC_HOME"]);
    if( !config_dir.Exists() || !config_dir.Is_Directory() )
    {
        if( config_dir.Create_Directory( true ) ){
            LOG_MSG(LogLevel::INFO) << "Created MSC Home Directory at " << config_dir.ToString();
        }
        else{
            LOG_MSG(LogLevel::ERROR) << "Unable to Create Directory (" << config_dir.ToString() << ")";
        }
    }
    

    // Check the Configuration File
    FilePath config_file_path = config_dir / FilePath("options.cfg");
    if( !config_file_path.Exists() )
    {
        // Generate the Config File
        Generate_Configuration_File( config_file_path );
    }

    // check the services directory
    FilePath services_path = config_dir / FilePath("services");
    if( !services_path.Exists() || !services_path.Is_Directory() ){
        LOG_MSG(LogLevel::INFO) << "Creating Services Directory: " << services_path.ToString();
        if( !services_path.Create_Directory() ){
            LOG_MSG(LogLevel::ERROR) << "Unable to create service directory: " << services_path.ToString();
        }
    }

}
QDir Settings::OpenConfigDirectory()
{
    QDir config_dir(QStandardPaths::writableLocation(
                        QStandardPaths::ConfigLocation));
    if (!config_dir.exists())
    {
        QDir dir;
        if (!dir.mkdir(config_dir.path()))
        {
            SendErrorMessage("Could not create configuration directory");
            abort();
        }
    }
    return config_dir;
}
Beispiel #3
0
void Options::Load_Map_Services()
{
    // MSC Variables
    MSC::Status msc_status;
    
    // Define the services directory
    FilePath config_dir(m_gui_config_settings["MSC_HOME"]);
    FilePath services_dir = config_dir / FilePath("services");
    
    std::string services_regex_pattern = m_gui_config_settings["SERVICES_REGEX_PATTERN"];

    // Get a list of service config files in the services directory
    std::vector<FilePath> service_files = services_dir.Get_Contents(services_regex_pattern);
    
    // Print the services list
    LOG_MSG(LogLevel::INFO) << "Detected " << service_files.size() << " service files.";
    for( size_t i=0; i<service_files.size(); i++ )
    {
        LOG_MSG(LogLevel::INFO) << " - " << service_files[i];

        // Check if already added
        if( m_map_services.find(service_files[i]) != m_map_services.end() ){
            LOG_MSG(LogLevel::INFO) << " Already added.";
        }

        // Add otherwise
        else{
            // Create MSC
            auto connector = MSC::MapServiceConnectorFactory::Create( service_files[i].ToString(), msc_status );

            // check connector status for errors
            if( connector == nullptr || msc_status.Get_Code() != MSC::StatusCode::SUCCESS ){
                LOG_MSG(LogLevel::ERROR) << "Unable to Create Map-Service-Connector. Details: " << msc_status.ToString();
            }

            // Add to service list
            else{
                m_map_services[service_files[i]] = connector;
            }
        }
    }

}
Beispiel #4
0
void Application::createUserConfiguration(void)
{
    QDir config_dir(GlobalAttributes::CONFIGURATIONS_DIR);

    try
    {
        //If the directory not exists or is empty
        if(!config_dir.exists() ||
                config_dir.entryList({QString("*%1").arg(GlobalAttributes::CONFIGURATION_EXT)},
                                     QDir::Files | QDir::NoDotAndDotDot).isEmpty())
            copyFilesRecursively(GlobalAttributes::TMPL_CONFIGURATIONS_DIR, GlobalAttributes::CONFIGURATIONS_DIR);
    }
    catch(Exception &e)
    {
        Messagebox msg_box;
        msg_box.show(e, trUtf8("Failed to create initial configuration in `%1'! Check if the current user has write permission over that path and at least read permission over `%2'.").arg(GlobalAttributes::CONFIGURATIONS_DIR, CONFDIR));
        throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e);
    }
}
bool Parser::ParseConfigDir(const std::string& path) {
    INFO("Parsing directory %s...\n", path.c_str());
    std::unique_ptr<DIR, int(*)(DIR*)> config_dir(opendir(path.c_str()), closedir);
    if (!config_dir) {
        ERROR("Could not import directory '%s'\n", path.c_str());
        return false;
    }
    dirent* current_file;
    while ((current_file = readdir(config_dir.get()))) {
        std::string current_path =
            android::base::StringPrintf("%s/%s", path.c_str(), current_file->d_name);
        // Ignore directories and only process regular files.
        if (current_file->d_type == DT_REG) {
            if (!ParseConfigFile(current_path)) {
                ERROR("could not import file '%s'\n", current_path.c_str());
            }
        }
    }
    return true;
}
Beispiel #6
0
/* Setup Windows after install */
int main(int argc, char **argv)
{
    int i = 0;
    time_t tm;
    struct tm *p;
    char win_dir[2048];

    if (argc >= 2) {
        if (chdir(argv[1]) != 0) {
            printf("%s: Invalid directory: '%s'.\n", argv[0], argv[1]);
            return (0);
        }
    }

    /* Check if ossec was installed already */
    if (!fileexist(OSSECCONF)) {
        printf("%s: Unable to find ossec config: '%s'", argv[0], OSSECCONF);
        exit(0);
    }

    /* Get today's day */
    tm = time(NULL);
    p = localtime(&tm);

    total = 0;

    printf("%s: Looking for IIS log files to monitor.\r\n",
           argv[0]);
    printf("%s: For more information: http://www.ossec.net/en/win.html\r\n",
           argv[0]);
    printf("\r\n");

    /* Get Window directory */
    get_win_dir(win_dir, sizeof(win_dir) - 1);

    /* Look for IIS log files */
    while (i <= 254) {
        char lfile[OS_MAXSTR + 1];
        char vfile[OS_MAXSTR + 1];

        i++;

        /* Search for NCSA */
        snprintf(lfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\W3SVC%d\\nc%02d%02d%02d.log",
                 win_dir, i, (p->tm_year + 1900) - 2000, p->tm_mon + 1, p->tm_mday);
        snprintf(vfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\W3SVC%d\\nc%%y%%m%%d.log",
                 win_dir, i);

        /* Try dir-based */
        config_iis(argv[0], lfile, vfile);

        /* Search for W3C extended */
        snprintf(lfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\W3SVC%d\\ex%02d%02d%02d.log",
                 win_dir, i, (p->tm_year + 1900) - 2000, p->tm_mon + 1, p->tm_mday);

        snprintf(vfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\W3SVC%d\\ex%%y%%m%%d.log",
                 win_dir, i);

        /* Try dir-based */
        if (config_iis(argv[0], lfile, vfile) == 0) {
            snprintf(lfile,
                     OS_MAXSTR,
                     "%s\\System32\\LogFiles\\W3SVC%d", win_dir, i);
            config_dir(argv[0], lfile, vfile);
        }

        /* Search for FTP Extended format */
        snprintf(lfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\MSFTPSVC%d\\ex%02d%02d%02d.log",
                 win_dir, i, (p->tm_year + 1900) - 2000, p->tm_mon + 1, p->tm_mday);

        snprintf(vfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\MSFTPSVC%d\\ex%%y%%m%%d.log",
                 win_dir, i);
        if (config_iis(argv[0], lfile, vfile) == 0) {
            snprintf(lfile,
                     OS_MAXSTR,
                     "%s\\System32\\LogFiles\\MSFTPSVC%d", win_dir, i);
            config_dir(argv[0], lfile, vfile);
        }

        /* Search for IIS SMTP logs */
        snprintf(lfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\SMTPSVC%d\\ex%02d%02d%02d.log",
                 win_dir, i, (p->tm_year + 1900) - 2000, p->tm_mon + 1, p->tm_mday);

        snprintf(vfile,
                 OS_MAXSTR,
                 "%s\\System32\\LogFiles\\SMTPSVC%d\\ex%%y%%m%%d.log",
                 win_dir, i);
        if (config_iis(argv[0], lfile, vfile) == 0) {
            snprintf(lfile,
                     OS_MAXSTR,
                     "%s\\System32\\LogFiles\\SMTPSVC%d", win_dir, i);
            config_dir(argv[0], lfile, vfile);
        }
    }

    if (total == 0) {
        printf("%s: No IIS log added. Look at the link above for more "
               "information.\r\n", argv[0]);
    }

    return (0);
}
std::string Runtime::config_file_path(const std::string& file_name)
{
	return config_dir() + "/" + file_name;
}
Beispiel #8
0
MainWidget::MainWidget(QWidget *parent,const char *name)
  :QWidget(parent,name)
{
  //
  // Read Command Options
  //
  RDCmdSwitch *cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdselect","\n");
  delete cmd;

  //
  // Read Configuration
  //
  monitor_config=new RDMonitorConfig();
  monitor_config->load();
  QDesktopWidget *dw=qApp->desktop();
  int width=sizeHint().width();
  int height=sizeHint().height();
  switch(monitor_config->position()) {
  case RDMonitorConfig::UpperLeft:
    setGeometry(0,RDMONITOR_HEIGHT,width,sizeHint().height());
    break;

  case RDMonitorConfig::UpperCenter:
    setGeometry((dw->size().width()-width)/2,RDMONITOR_HEIGHT,width,height);
    break;

  case RDMonitorConfig::UpperRight:
    setGeometry(dw->size().width()-width,RDMONITOR_HEIGHT,width,height);
    break;

  case RDMonitorConfig::LowerLeft:
    setGeometry(0,dw->size().height()-height+RDMONITOR_HEIGHT,width,height);
    break;

  case RDMonitorConfig::LowerCenter:
    setGeometry((dw->size().width()-width)/2,
		dw->size().height()-height+RDMONITOR_HEIGHT,width,height);
    break;

  case RDMonitorConfig::LowerRight:
    setGeometry(dw->size().width()-width,
		dw->size().height()-height+RDMONITOR_HEIGHT,width,height);
    break;

  case RDMonitorConfig::LastPosition:
    break;
  }

  //
  // Fix the Window Size
  //
  setMinimumWidth(sizeHint().width());
  setMinimumHeight(sizeHint().height());

  //
  // Generate Fonts
  //
  QFont default_font("Helvetica",12,QFont::Normal);
  default_font.setPixelSize(12);
  qApp->setFont(default_font);
  QFont button_font=QFont("Helvetica",12,QFont::Bold);
  button_font.setPixelSize(12);
  QFont label_font=QFont("Helvetica",16,QFont::Bold);
  label_font.setPixelSize(16);

  //
  // Create And Set Icons
  //
  login_rivendell_map=new QPixmap(rivendell_xpm);
  setIcon(*login_rivendell_map);
  setCaption(tr("RDSelect")+" v"+VERSION);
  greencheckmark_map=new QPixmap(greencheckmark_xpm);
  redx_map=new QPixmap(redx_xpm);

  //
  // Load Configs
  //
  select_current_id=-1;
  char target[1500];
  ssize_t n;
  if((n=readlink(RD_CONF_FILE,target,1500))>0) {
    target[n]=0;
  }
  else {
    target[0]=0;
  }
  QDir config_dir(RD_DEFAULT_RDSELECT_DIR);
  config_dir.setFilter(QDir::Files|QDir::Readable);
  config_dir.setNameFilter("*.conf");
  select_filenames=config_dir.entryList();
  for(unsigned i=0;i<select_filenames.size();i++) {
    select_filenames[i]=
      QString(RD_DEFAULT_RDSELECT_DIR)+"/"+select_filenames[i];
    if(select_filenames[i]==target) {
      select_current_id=i;
    }
    select_configs.push_back(new RDConfig());
    select_configs.back()->setFilename(select_filenames[i]);
    select_configs.back()->load();
  }

  //
  // Current System Label
  //
  select_current_label=new QLabel(this);
  select_current_label->setFont(label_font);
  select_current_label->setAlignment(AlignCenter);

  //
  // Selector Box
  //
  select_box=new QListBox(this);
  select_box->setFont(default_font);
  connect(select_box,SIGNAL(doubleClicked(QListBoxItem *)),
	  this,SLOT(doubleClickedData(QListBoxItem *)));
  for(unsigned i=0;i<select_configs.size();i++) {
    select_box->insertItem(select_configs[i]->label());
  }
  select_label=new QLabel(select_box,tr("Available Systems"),this);
  select_label->setFont(button_font);

  //
  // Ok Button
  //
  ok_button=new QPushButton(this);
  ok_button->setFont(button_font);
  ok_button->setText(tr("Select"));
  connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));

  //
  // Cancel Button
  //
  cancel_button=new QPushButton(this,"cancel_button");
  cancel_button->setFont(button_font);
  cancel_button->setText(tr("&Cancel"));
  connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));

  SetSystem(select_current_id);
  SetCurrentItem(select_current_id);
  select_box->clearSelection();

  //
  // Check for Root User 
  //

  setuid(geteuid());  // So the SETUID bit works as expected
  if(getuid()!=0) {
    QMessageBox::information(this,tr("RDSelect"),
			     tr("Only root can run this utility!"));
    exit(256);
  }
}