5 #include <unordered_map>
10 std::unordered_map<std::string, Profile> profiles;
11 std::string sqlHost, sqlUser, sqlPass, sqlDB;
12 std::string serialPath;
14 std::shared_ptr<std::unordered_map<std::string, std::string>> parseConf( std::string path ) {
15 std::shared_ptr<std::unordered_map<std::string, std::string>> map( new std::unordered_map<std::string, std::string>() );
19 if( !config.is_open() ) {
20 std::cout << "Where is " << path << "?" << std::endl;
21 throw "Config missing";
26 while( std::getline( config, line1 ) ) {
27 if( line1[0] == '#' || line1.size() == 0 ) {
31 int splitter = line1.find( "=" );
33 if( splitter == -1 ) {
34 std::cerr << "Ignoring malformed config line: " << line1 << std::endl;
38 std::string key = line1.substr( 0, splitter );
39 std::string value = line1.substr( splitter + 1 );
40 map->emplace( key, value );
48 int parseConfig( std::string path ) {
50 auto masterConf = parseConf( path );
52 keyDir = masterConf->at( "key.directory" );
53 sqlHost = masterConf->at( "sql.host" );
54 sqlUser = masterConf->at( "sql.user" );
55 sqlPass = masterConf->at( "sql.password" );
56 sqlDB = masterConf->at( "sql.database" );
57 serialPath = masterConf->at( "serialPath" );
59 std::shared_ptr<std::unordered_map<std::string, std::shared_ptr<CAConfig>>> CAs( new std::unordered_map<std::string, std::shared_ptr<CAConfig>>() );
63 dp = opendir( "profiles" );
66 std::cerr << "Profiles not found " << std::endl;
70 while( ( ep = readdir( dp ) ) ) {
71 if( ep->d_name[0] == '.' ) {
75 std::string profileName( ep->d_name );
77 int splitter = profileName.find( "-" );
79 if( splitter == -1 ) {
80 std::cerr << "Ignoring malformed profile: " << profileName << std::endl;
84 std::string id = profileName.substr( 0, splitter );
86 if( profileName.substr( profileName.size() - 4 ) != ".cfg" ) {
87 std::cerr << "Ignoring malformed profile: " << profileName << std::endl;
91 auto map = parseConf( std::string( "profiles/" ) + profileName );
93 profileName = profileName.substr( 0, profileName.size() - 4 );
96 prof.id = std::stoi( id );
97 prof.eku = map->at( "eku" );
98 prof.ku = map->at( "ku" );
100 if( CAs->find( map->at( "ca" ) ) == CAs->end() ) {
101 std::shared_ptr<CAConfig> ca( new CAConfig( "ca/" + map->at( "ca" ) ) );
102 CAs->emplace( map->at( "ca" ), ca );
105 prof.ca = CAs->at( map->at( "ca" ) );
107 profiles.emplace( profileName, prof );
108 std::cout << "Profile: " << profileName << " up and running." << std::endl;
111 ( void ) closedir( dp );
114 std::cout << profiles.size() << " profiles loaded." << std::endl;
117 std::cerr << "Missing config property key.directory" << std::endl;