function LoadSourcesFromDatabase()
{
    // Needed to make global
    global $CFG, $content;
    // --- Create SQL Query
    // Create Where for USERID
    if (isset($content['SESSION_LOGGEDIN']) && $content['SESSION_LOGGEDIN']) {
        $szWhereUser = "******" . DB_SOURCES . "`.userid = " . $content['SESSION_USERID'] . " ";
    } else {
        $szWhereUser = "";
    }
    if (isset($content['SESSION_GROUPIDS'])) {
        $szGroupWhere = " OR `" . DB_SOURCES . "`.groupid IN (" . $content['SESSION_GROUPIDS'] . ")";
    } else {
        $szGroupWhere = "";
    }
    $sqlquery = " SELECT " . DB_SOURCES . ".*, " . DB_USERS . ".username, " . DB_GROUPS . ".groupname " . " FROM `" . DB_SOURCES . "`" . " LEFT OUTER JOIN (`" . DB_USERS . "`) ON (`" . DB_SOURCES . "`.userid=`" . DB_USERS . "`.ID ) " . " LEFT OUTER JOIN (`" . DB_GROUPS . "`) ON (`" . DB_SOURCES . "`.groupid=`" . DB_GROUPS . "`.ID ) " . " WHERE (`" . DB_SOURCES . "`.userid IS NULL AND `" . DB_SOURCES . "`.groupid IS NULL) " . $szWhereUser . $szGroupWhere . " ORDER BY `" . DB_SOURCES . "`.userid, `" . DB_SOURCES . "`.groupid, `" . DB_SOURCES . "`.Name";
    // ---
    // Get Sources from DB now!
    $result = DB_Query($sqlquery);
    $myrows = DB_GetAllRows($result, true);
    if (isset($myrows) && count($myrows) > 0) {
        // Overwrite existing Sources array
        unset($CFG['Sources']);
        // Append to Source Array
        foreach ($myrows as &$mySource) {
            // Append to Source Array
            $CFG['Sources'][$mySource['ID']] = $mySource;
            //['ID'];
        }
        // Copy to content array!
        $content['Sources'] = $CFG['Sources'];
    }
}
function WriteConfigValue($szPropName, $is_global = true, $userid = false, $groupid = false, $bForceStripSlahes = false)
{
    global $content;
    // --- Abort in this case!
    if (GetConfigSetting("UserDBEnabled", false) == false) {
        return;
    }
    // ---
    if ($is_global) {
        if (isset($content[$szPropName])) {
            // Copy value for DB and check for BadDB Chars!
            $szDbValue = PrepareValueForDB($content[$szPropName], $bForceStripSlahes);
        } else {
            // Set empty in this case
            $szDbValue = "";
            $content[$szPropName] = "";
        }
        // Copy to $CFG array as well
        $CFG[$szPropName] = $content[$szPropName];
        // Check if we need to INSERT or UPDATE
        $result = DB_Query("SELECT propname FROM `" . DB_CONFIG . "` WHERE propname = '" . $szPropName . "' AND is_global = " . $is_global);
        $rows = DB_GetAllRows($result, true);
        if (!isset($rows)) {
            // New Entry
            if (strlen($szDbValue) < 255) {
                $result = DB_Query("INSERT INTO  `" . DB_CONFIG . "` (propname, propvalue, is_global) VALUES ( '" . $szPropName . "', '" . $szDbValue . "', " . $is_global . ")");
            } else {
                $result = DB_Query("INSERT INTO  `" . DB_CONFIG . "` (propname, propvalue_text, is_global) VALUES ( '" . $szPropName . "', '" . $szDbValue . "', " . $is_global . ")");
            }
            DB_FreeQuery($result);
        } else {
            // Update Entry
            if (strlen($szDbValue) < 255) {
                $result = DB_Query("UPDATE `" . DB_CONFIG . "` SET propvalue = '" . $szDbValue . "', propvalue_text = '' WHERE propname = '" . $szPropName . "' AND is_global = " . $is_global);
            } else {
                $result = DB_Query("UPDATE `" . DB_CONFIG . "` SET propvalue_text = '" . $szDbValue . "', propvalue = '' WHERE propname = '" . $szPropName . "' AND is_global = " . $is_global);
            }
            DB_FreeQuery($result);
        }
    } else {
        if ($userid != false) {
            global $USERCFG;
            if (isset($USERCFG[$szPropName])) {
                // Copy value for DB and check for BadDB Chars!
                $szDbValue = PrepareValueForDB($USERCFG[$szPropName], $bForceStripSlahes);
            } else {
                // Set empty in this case
                $szDbValue = "";
                $USERCFG[$szPropName] = "";
            }
            // Check if we need to INSERT or UPDATE
            $result = DB_Query("SELECT propname FROM `" . DB_CONFIG . "` WHERE propname = '" . $szPropName . "' AND userid = " . $userid);
            $rows = DB_GetAllRows($result, true);
            if (!isset($rows)) {
                // New Entry
                $result = DB_Query("INSERT INTO  `" . DB_CONFIG . "` (propname, propvalue, userid) VALUES ( '" . $szPropName . "', '" . $szDbValue . "', " . $userid . ")");
                DB_FreeQuery($result);
            } else {
                // Update Entry
                $result = DB_Query("UPDATE `" . DB_CONFIG . "` SET propvalue = '" . $szDbValue . "' WHERE propname = '" . $szPropName . "' AND userid = " . $userid);
                DB_FreeQuery($result);
            }
        } else {
            if ($groupid != false) {
                DieWithFriendlyErrorMsg("Critical Error occured in WriteConfigValue, writing GROUP specific properties is not supported yet!");
            }
        }
    }
}
Exemple #3
0
 $result = DB_Query($sqlquery);
 $content['GROUPS'] = DB_GetAllRows($result, true);
 if (count($content['GROUPS']) > 0) {
     // --- Process Groups
     for ($i = 0; $i < count($content['GROUPS']); $i++) {
         // --- Set CSS Class
         if ($i % 2 == 0) {
             $content['GROUPS'][$i]['cssclass'] = "line1";
         } else {
             $content['GROUPS'][$i]['cssclass'] = "line2";
         }
         // ---
         // --- Read all Memberentries for this group
         $sqlquery = "SELECT " . DB_USERS . ".username, " . DB_GROUPMEMBERS . ".userid, " . DB_GROUPMEMBERS . ".groupid, " . DB_GROUPMEMBERS . ".is_member " . " FROM " . DB_GROUPMEMBERS . " INNER JOIN (" . DB_USERS . ") ON (" . DB_GROUPMEMBERS . ".userid=" . DB_USERS . ".ID) " . " WHERE " . DB_GROUPMEMBERS . ".groupid = " . $content['GROUPS'][$i]['ID'] . " ORDER BY " . DB_USERS . ".username";
         $result = DB_Query($sqlquery);
         $content['GROUPS'][$i]['USERS'] = DB_GetAllRows($result, true);
         if (count($content['GROUPS'][$i]['USERS']) > 0) {
             // Enable Groupmembers
             $content['GROUPS'][$i]['GROUPMEMBERS'] = true;
             // Process Groups
             $subUserCount = count($content['GROUPS'][$i]['USERS']);
             for ($j = 0; $j < $subUserCount; $j++) {
                 $content['GROUPS'][$i]['USERS'][$j]['seperator'] = ", ";
             }
             $content['GROUPS'][$i]['USERS'][$subUserCount - 1]['seperator'] = "";
             // last one is empty
         }
         // ---
     }
     // ---
 } else {
function InitConfigurationValues()
{
    global $content, $CFG, $LANG, $gl_root_path;
    // To avoid this code in case of conversion
    if (!defined('IN_PHPLOGCON_CONVERT')) {
        // If Database is enabled, try to read from database!
        if (GetConfigSetting("UserDBEnabled", false)) {
            // Get configuration variables
            $result = DB_Query("SELECT * FROM `" . DB_CONFIG . "` WHERE is_global = true");
            if ($result) {
                $rows = DB_GetAllRows($result, true);
                // Read results from DB and overwrite in $CFG Array!
                if (isset($rows)) {
                    for ($i = 0; $i < count($rows); $i++) {
                        // Obtain the right value
                        if (isset($rows[$i]['propvalue_text']) && strlen($rows[$i]['propvalue_text']) > 0) {
                            $myValue = $rows[$i]['propvalue_text'];
                        } else {
                            $myValue = $rows[$i]['propvalue'];
                        }
                        $CFG[$rows[$i]['propname']] = $myValue;
                        $content[$rows[$i]['propname']] = $myValue;
                    }
                }
            } else {
                // Critical ERROR HERE!
                DieWithFriendlyErrorMsg("Critical Error occured while trying to access the database in table '" . DB_CONFIG . "'");
            }
            // Database Version Checker!
            if ($content['database_internalversion'] > $content['database_installedversion']) {
                // Database is out of date, we need to upgrade
                $content['database_forcedatabaseupdate'] = "yes";
            }
            // Now we init the user session stuff
            InitUserSession();
            if (!$content['SESSION_LOGGEDIN']) {
                // Check if user needs to be logged in
                if (GetConfigSetting("UserDBLoginRequired", false)) {
                    // Redirect USER if not on loginpage or installpage!
                    if (!defined("IS_NOLOGINPAGE") && !defined("IN_PHPLOGCON_INSTALL") && !defined("IN_PHPLOGCON_COMMANDLINE")) {
                        RedirectToUserLogin();
                    }
                } else {
                    if (defined('IS_ADMINPAGE')) {
                        // Language System not initialized yet
                        DieWithFriendlyErrorMsg("You need to be logged in in order to access the admin pages.", "login.php", "Click here to login");
                    }
                }
            }
            // Load field definitions from DB, very first thing todo!
            LoadFieldsFromDatabase();
            // Load Configured Searches
            LoadSearchesFromDatabase();
            // Load Configured Charts
            LoadChartsFromDatabase();
            // Load Configured Views
            LoadViewsFromDatabase();
            // Load Configured Mappings
            LoadDBMappingsFromDatabase();
            // Load Configured Sources
            LoadSourcesFromDatabase();
        } else {
            if (defined('IS_ADMINPAGE') || defined("IS_NOLOGINPAGE")) {
                // Language System not initialized yet
                DieWithFriendlyErrorMsg("The LogAnalyzer user system is currently disabled or not installed.");
            }
        }
    }
    // --- Language Handling
    // Set gen language default
    $content['gen_lang'] = GetConfigSetting("ViewDefaultLanguage", "en", CFGLEVEL_GLOBAL);
    // Now check for current used language
    if (isset($_SESSION['CUSTOM_LANG']) && VerifyLanguage($_SESSION['CUSTOM_LANG'])) {
        $content['user_lang'] = $_SESSION['CUSTOM_LANG'];
        $LANG = $content['user_lang'];
    } else {
        if (isset($content['gen_lang']) && VerifyLanguage($content['gen_lang'])) {
            $content['user_lang'] = $content['gen_lang'];
            $LANG = $content['user_lang'];
        } else {
            $content['user_lang'] = GetConfigSetting("ViewDefaultLanguage", "en", CFGLEVEL_USER);
            $LANG = $content['user_lang'];
            $content['gen_lang'] = $content['user_lang'];
        }
    }
    // ---
    // Paging Size handling!
    if (!isset($_SESSION['PAGESIZE_ID'])) {
        // Default is 0!
        $_SESSION['PAGESIZE_ID'] = 0;
    }
    // Auto reload handling!
    if (!isset($_SESSION['AUTORELOAD_ID'])) {
        if (GetConfigSetting("ViewEnableAutoReloadSeconds", 0, CFGLEVEL_USER) > 0) {
            $_SESSION['AUTORELOAD_ID'] = 1;
        } else {
            // Default is 0, which means auto reload disabled
            $_SESSION['AUTORELOAD_ID'] = 0;
        }
    }
    // --- Theme Handling
    if (!isset($content['web_theme'])) {
        $content['web_theme'] = GetConfigSetting("ViewDefaultTheme", "default", CFGLEVEL_USER);
    }
    if (isset($_SESSION['CUSTOM_THEME']) && VerifyTheme($_SESSION['CUSTOM_THEME'])) {
        $content['user_theme'] = $_SESSION['CUSTOM_THEME'];
    } else {
        $content['user_theme'] = $content['web_theme'];
    }
    // Init Theme About Info ^^
    InitThemeAbout($content['user_theme']);
    // ---
    // --- Handle HTML Injection stuff
    if (strlen(GetConfigSetting("InjectHtmlHeader", false)) > 0) {
        $content['EXTRA_HTMLHEAD'] .= $CFG['InjectHtmlHeader'];
    } else {
        $content['InjectHtmlHeader'] = "";
    }
    // Init Option
    if (strlen(GetConfigSetting("InjectBodyHeader", false)) > 0) {
        $content['EXTRA_HEADER'] .= $CFG['InjectBodyHeader'];
    } else {
        $content['InjectBodyHeader'] = "";
    }
    // Init Option
    if (strlen(GetConfigSetting("InjectBodyFooter", false)) > 0) {
        $content['EXTRA_FOOTER'] .= $CFG['InjectBodyFooter'];
    } else {
        $content['InjectBodyFooter'] = "";
    }
    // Init Option
    // ---
    // --- Handle Optional Logo URL!
    if (strlen(GetConfigSetting("PhplogconLogoUrl", false)) > 0) {
        $content['EXTRA_PHPLOGCON_LOGO'] = $CFG['PhplogconLogoUrl'];
    } else {
        $content['PhplogconLogoUrl'] = "";
    }
    // Init Option
    // ---
    // --- Set Proxy Option
    if (strlen(GetConfigSetting("UseProxyServerForRemoteQueries", false)) <= 0) {
        $content['UseProxyServerForRemoteQueries'] = "";
    }
    // Init Option
    // ---
    // --- Read Encoding Option, and set default!
    $content['HeaderDefaultEncoding'] = GetConfigSetting("HeaderDefaultEncoding", ENC_ISO_8859_1);
    // ---
    // --- Read ContextLinks Option, and set default!
    $content['EnableContextLinks'] = GetConfigSetting("EnableContextLinks", 1);
    // ---
    // Init main langauge file now!
    IncludeLanguageFile($gl_root_path . '/lang/' . $LANG . '/main.php');
    // Init other things which are needed
    InitFrontEndVariables();
}
        }
    }
}
if (!isset($_POST['op']) && !isset($_GET['op'])) {
    // Default Mode = List Users
    $content['LISTUSERS'] = "true";
    // Set AddUsers TAB!
    if ($content['UserDBAuthMode'] == USERDB_AUTH_LDAP) {
        $content["ALLOWADDUSERS"] = "false";
    } else {
        $content["ALLOWADDUSERS"] = "true";
    }
    // Read all Serverentries
    $sqlquery = "SELECT ID, " . " username, " . " is_admin, " . " is_readonly " . " FROM " . DB_USERS . " ORDER BY ID ";
    $result = DB_Query($sqlquery);
    $content['USERS'] = DB_GetAllRows($result, true);
    // --- Process Users
    for ($i = 0; $i < count($content['USERS']); $i++) {
        // --- Set Image for IsAdmin
        if ($content['USERS'][$i]['is_admin'] == 1) {
            $content['USERS'][$i]['is_isadmin_string'] = $content['MENU_SELECTION_ENABLED'];
            $content['USERS'][$i]['set_isadmin'] = 0;
        } else {
            $content['USERS'][$i]['is_isadmin_string'] = $content['MENU_SELECTION_DISABLED'];
            $content['USERS'][$i]['set_isadmin'] = 1;
        }
        // ---
        // --- Set Image for IsReadonly
        if ($content['USERS'][$i]['is_readonly'] == 1) {
            $content['USERS'][$i]['is_readonly_string'] = $content['MENU_SELECTION_ENABLED'];
            $content['USERS'][$i]['set_isreadonly'] = 0;
function GetGroupsForSelectfield()
{
    global $content;
    $sqlquery = "SELECT " . DB_GROUPS . ".ID as mygroupid, " . DB_GROUPS . ".groupname " . "FROM `" . DB_GROUPS . "`" . " ORDER BY `" . DB_GROUPS . "`.groupname";
    $result = DB_Query($sqlquery);
    $mygroups = DB_GetAllRows($result, true);
    if (isset($mygroups) && count($mygroups) > 0) {
        // Process All Groups
        for ($i = 0; $i < count($mygroups); $i++) {
            $mygroups[$i]['group_selected'] = "";
        }
        // Enable Group Selection
        array_unshift($mygroups, array("mygroupid" => -1, "groupname" => $content['LN_SEARCH_SELGROUPENABLE'], "group_selected" => ""));
        // return result
        return $mygroups;
    } else {
        return false;
    }
    // ---
}