Changeset 375

Show
Ignore:
Timestamp:
03/09/06 19:10:55 (3 years ago)
Author:
dp
Message:
  • make --help more descriptive, i.e. indicate where options need arguments
  • reactivate --color with new arguments "auto" "never" and "always", auto-detection
    is used for terminals (just like ls)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/nepenthes-core/include/LogManager.hpp

    r321 r375  
    5959                virtual void            logf(uint32_t mask, const char *format, ...); 
    6060                const char                      *getTagName(uint32_t bit); 
    61                 uint32_t                getTagId(const char *tag); 
    62                 uint32_t                parseTagString(const char *tagString); 
     61                uint32_t                        getTagId(const char *tag); 
     62                uint32_t                        parseTagString(const char *tagString); 
     63                void                            setColor(bool setting); 
     64                bool                            getColorSetting(); 
    6365         
    6466        private: 
     67                bool                            m_useColor; 
    6568                list<LogHandlerEntry *> m_Loggers; 
    6669                const char                      *m_Tags[MAX_TAGS]; // use vector instead? 
  • nepenthes/trunk/nepenthes-core/src/ConsoleLogger.cpp

    r321 r375  
    122122 
    123123#else 
    124     printf("[ \033[%d;1m%-5s\033[0m] %s", 
     124        if( m_LogManager->getColorSetting() ) 
     125        { 
     126            printf("[ \033[%d;1m%-5s\033[0m] %s", 
    125127                         g_ColorMap[level], tag.c_str(), message); 
     128        } 
     129        else 
     130        { 
     131                printf("%s", message); 
     132        } 
    126133#endif 
    127134} 
  • nepenthes/trunk/nepenthes-core/src/LogManager.cpp

    r332 r375  
    4444        for( int32_t i = 0; i < MAX_TAGS; i++ ) 
    4545                m_Tags[i] = 0; 
     46 
     47        m_useColor = false; 
    4648} 
    4749 
     
    217219        return mask; 
    218220} 
     221 
     222void LogManager::setColor(bool setting) 
     223{ 
     224        m_useColor = setting; 
     225} 
     226 
     227bool LogManager::getColorSetting() 
     228{ 
     229        return m_useColor; 
     230} 
  • nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp

    r366 r375  
    7878using namespace nepenthes; 
    7979 
     80enum ColorSetting { colorAuto, colorAlways, colorNever }; 
     81 
    8082Nepenthes *g_Nepenthes; 
    8183/** 
     
    185187        string rlpath;  // ringlogger path, gets read from config 
    186188        bool ringlog = false; 
     189        ColorSetting col = colorAuto; 
    187190 
    188191#ifdef WIN32 
     
    205208                        { "log",                        1, 0, 'l' },    // FIXME 
    206209                        { "logging-help",       0, 0, 'L' },    // FIXME 
    207                         { "no-color",          0, 0, 'o' },    // FIXME 
     210                        { "color",                     1, 0, 'o' }, 
    208211                        { "chroot",                     1, 0, 'r' },  
    209212                        { "ringlog",            0, 0, 'R' },  
     
    282285 
    283286                case 'o':       // FIXME set nocolor on console 
    284                         printf("This feature '%c' is todo\nquitting\n",c); 
    285                         run=false; 
     287                        if( !strcmp(optarg, "never") ) 
     288                                col = colorNever; 
     289                        else if( !strcmp(optarg, "always") ) 
     290                                col = colorAlways; 
     291                        else if( !strcmp(optarg, "auto") ) 
     292                                col = colorAuto; 
     293                        else 
     294                        { 
     295                                fprintf(stdout, "Invalid argument for --color; must be one of\n" 
     296                                                "`never', `always' or `auto'.\n"); 
     297                                run = false; 
     298                        } 
     299 
    286300                        break; 
    287301 
     
    416430        if ( run == true || confcheck == true || filecheck == true) 
    417431        { 
     432                switch( col ) 
     433                { 
     434                        case colorAuto: 
     435                                if( isatty(STDOUT_FILENO) ) 
     436                                        m_LogManager->setColor(true); 
     437                                else 
     438                                        m_LogManager->setColor(false); 
     439                                break; 
     440                        case colorNever: 
     441                                m_LogManager->setColor(false); 
     442                                break; 
     443                        case colorAlways: 
     444                                m_LogManager->setColor(true); 
     445                                break; 
     446                } 
     447 
    418448        m_Config = new Config; 
    419449                logInfo("Trying to load Nepenthes Configuration from %s \n",confpath); 
     
    16051635        helpstruct myopts[]= 
    16061636        { 
    1607         {"c",   "config",                       "give path to Config File",                             SYSCONFDIR "/nepenthes.conf"    }, 
    1608                 {"C",   "capabilities",         "force kernel 'security' capabilities", ""                                              }, 
    1609                 {"d",   "disk-log",                     "disk logging tags, see -L",                    "(no filter)"                   }, 
    1610                 {"f",   "file-check",           "check file for known shellcode rmknown,rmnonop",   ""                                          }, 
    1611                 {"h",   "help",                         "show help",                                                    ""                                              }, 
    1612                 {"H",   "large-help",           "show help with default values",                ""                                              }, 
    1613                 {"i",   "info",                         "how to contact us",                                    ""                                              }, 
    1614                 {"k",   "check-config",         "check config for syntax errors",               ""                                              }, 
    1615                 {"l",   "log",                          "console logging tags, see -L",                 "(no filter)"                   }, 
    1616                 {"L",   "logging-help",         "display help for -d and -l",                   ""                                              }, 
    1617                 {"o",   "no-color",                     "log without colors",                                   "FIXME"                                 }, 
    1618         {"r",   "chroot",                       "chroot to",                                                    "default is not to set chroot"}, 
    1619                 {"R",   "ringlog",                      "use ringlogger instead of filelogger", "default is filelogger"}, 
    1620                 {"u",   "user",                         "set user to switch to",                                "default is not to switch"}, 
    1621                 {"g",   "group",                        "set group to switch to (use with -u)", "default is not to switch"}, 
     1637        {"c",   "config=FILE",          "use FILE as configuration file",                               SYSCONFDIR "/nepenthes.conf"    }, 
     1638                {"C",   "capabilities",         "force kernel 'security' capabilities", 0                                               }, 
     1639                {"d",   "disk-log",                     "disk logging tags, see -L",                    0                                               }, 
     1640                {"f",   "file-check=OPTS",      "check file for known shellcode, OPTS can\n" 
     1641                        "                              be any combination of `rmknown' and\n" 
     1642                        "                              `rmnonop'; seperate by comma when needed",   0                   }, 
     1643                {"h",   "help",                         "display help",                                                 0                                               }, 
     1644                {"H",   "large-help",           "display help with default values",             0                                               }, 
     1645                {"i",   "info",                         "how to contact us",                                    0                                               }, 
     1646                {"k",   "check-config",         "check configuration file for syntax errors",           0                       }, 
     1647                {"l",   "log",                          "console logging tags, see -L",                 0                                               }, 
     1648                {"L",   "logging-help",         "display help for -d and -l",                   0                                               }, 
     1649                {"o",   "color=WHEN",           "control color usage. WHEN may be `never',\n" 
     1650                        "                              `always' or `auto'",                                     "`auto'"                }, 
     1651        {"r",   "chroot=DIR",           "chroot to DIR after startup",                          "don't chroot"          }, 
     1652                {"R",   "ringlog",                      "use ringlogger instead of filelogger",                 "filelogger"    }, 
     1653                {"u",   "user=USER",                            "switch to USER after startup", "keep current user"}, 
     1654                {"g",   "group=GROUP",                  "switch to GROUP after startup (use with -u)", "keep current group"}, 
    16221655                {"v",   "version",                      "show version",                                                 ""                                              }, 
    1623                 {"w",   "workingdir",          "where shall the process live",                 PREFIX                                 }, 
     1656                {"w",   "workingdir=DIR",              "set the process' working dir to DIR",                  PREFIX         }, 
    16241657        }; 
    16251658        show_version(); 
    16261659 
    1627         if ( defaults == true ) 
    1628         { 
    1629                 for ( uint32_t i=0;i<sizeof(myopts)/sizeof(helpstruct);i++ ) 
    1630                 { 
    1631                         printf("  -%s,\t--%-12s %-30s %s\n", myopts[i].m_shortOpt, 
    1632                                    myopts[i].m_longOpt, 
    1633                                    myopts[i].m_Description, 
    1634                                    myopts[i].m_Default); 
    1635                 } 
    1636         }else 
    1637         { 
    1638                 for ( uint32_t i=0;i<sizeof(myopts)/sizeof(helpstruct);i++ ) 
    1639                 { 
    1640                         printf("  -%s,\t--%-12s %-30s\n", myopts[i].m_shortOpt, 
    1641                                    myopts[i].m_longOpt, 
    1642                                    myopts[i].m_Description 
    1643                                    ); 
    1644                 } 
    1645  
     1660        for ( uint32_t i=0;i<sizeof(myopts)/sizeof(helpstruct);i++ ) 
     1661        { 
     1662                printf("  -%s, --%-19s %s\n", myopts[i].m_shortOpt, 
     1663                        myopts[i].m_longOpt, 
     1664                        myopts[i].m_Description); 
     1665                 
     1666                if( defaults == true && myopts[i].m_Default ) 
     1667                { 
     1668                        printf("                              Default value/behaviour: %s\n", myopts[i].m_Default); 
     1669                } 
    16461670        } 
    16471671}