Exemple #1
0
    // ---
    if (!isset($content['ISERROR'])) {
        // Everything was alright, go and check if the entry exists!
        $result = DB_Query("SELECT FieldID FROM " . DB_FIELDS . " WHERE FieldID = '" . $content['FieldID'] . "'");
        $myrow = DB_GetSingleRow($result, true);
        if (!isset($myrow['FieldID'])) {
            // Add custom Field now!
            $sqlquery = "INSERT INTO " . DB_FIELDS . " (FieldID, FieldCaption, FieldDefine, SearchField, FieldAlign, DefaultWidth, FieldType, SearchOnline) \n\t\t\tVALUES (\n\t\t\t\t\t'" . $content['FieldID'] . "', \n\t\t\t\t\t'" . $content['FieldCaption'] . "',\n\t\t\t\t\t'" . $content['FieldDefine'] . "',\n\t\t\t\t\t'" . $content['SearchField'] . "',\n\t\t\t\t\t'" . $content['FieldAlign'] . "', \n\t\t\t\t\t" . $content['DefaultWidth'] . ", \n\t\t\t\t\t" . $content['FieldType'] . ", \n\t\t\t\t\t" . $content['SearchOnline'] . " \n\t\t\t\t\t)";
            $result = DB_Query($sqlquery);
            DB_FreeQuery($result);
            // Do the final redirect
            RedirectResult(GetAndReplaceLangStr($content['LN_FIELDS_HASBEENADDED'], DB_StripSlahes($content['FieldCaption'])), "fields.php");
        } else {
            // Edit the Search Entry now!
            $result = DB_Query("UPDATE " . DB_FIELDS . " SET \n\t\t\t\tFieldCaption = '" . $content['FieldCaption'] . "', \n\t\t\t\tFieldDefine = '" . $content['FieldDefine'] . "', \n\t\t\t\tSearchField = '" . $content['SearchField'] . "', \n\t\t\t\tFieldAlign = '" . $content['FieldAlign'] . "', \n\t\t\t\tDefaultWidth = " . $content['DefaultWidth'] . ", \n\t\t\t\tFieldType = " . $content['FieldType'] . ", \n\t\t\t\tSearchOnline = " . $content['SearchOnline'] . "\n\t\t\t\tWHERE FieldID = '" . $content['FieldID'] . "'");
            DB_FreeQuery($result);
            // Done redirect!
            RedirectResult(GetAndReplaceLangStr($content['LN_FIELDS_HASBEENEDIT'], DB_StripSlahes($content['FieldCaption'])), "fields.php");
        }
    }
}
if (!isset($_POST['op']) && !isset($_GET['op'])) {
    // Default Mode = List Searches
    $content['LISTFIELDS'] = "true";
    // Copy Search array for further modifications
    $content['FIELDS'] = $fields;
    $i = 0;
    // Help counter!
    foreach ($content['FIELDS'] as &$myField) {
        // Allow Delete Operation
        if ($myField['IsInternalField'] && $myField['FieldFromDB']) {
function GetSingleDBEntryOnly($myqry)
{
    // --- Abort in this case!
    if (GetConfigSetting("UserDBEnabled", false) == false) {
        return;
    }
    // ---
    $result = DB_Query($myqry);
    $row = DB_GetRow($result);
    DB_FreeQuery($query_id);
    if (isset($row)) {
        return $row[0];
    } else {
        return -1;
    }
}
Exemple #3
0
function PerformSQLDelete($szDeleteStm, $szErrMsg, $szUserID)
{
    global $content;
    $result = DB_Query($szDeleteStm);
    if ($result == FALSE) {
        $content['ISERROR'] = true;
        $content['ERROR_MSG'] = GetAndReplaceLangStr($content[$szErrMsg], $szUserID);
        return false;
    } else {
        DB_FreeQuery($result);
    }
    // Success
    return true;
}
function ConvertCustomSources()
{
    global $CFG, $content;
    // Insert all searches into the DB!
    foreach ($CFG['Sources'] as $sourceid => &$mySource) {
        // Correct VIEWID!
        if (isset($mySource['ViewID'])) {
            if (isset($CFG['Views'][$mySource['ViewID']]['DBID'])) {
                $mySource['ViewID'] = $CFG['Views'][$mySource['ViewID']]['DBID'];
            }
        } else {
            $mySource['ViewID'] = "";
        }
        // Set empty default
        // Add New Entry
        if ($mySource['SourceType'] == SOURCE_DISK) {
            $result = DB_Query("INSERT INTO `" . DB_SOURCES . "` (Name, Description, SourceType, MsgParserList, MsgNormalize, ViewID, LogLineType, DiskFile) VALUES ( " . "'" . PrepareValueForDB($mySource['Name']) . "', " . "'" . PrepareValueForDB($mySource['Description']) . "', " . " " . PrepareValueForDB($mySource['SourceType']) . " , " . "'" . PrepareValueForDB($mySource['MsgParserList']) . "', " . " " . PrepareValueForDB($mySource['MsgNormalize']) . " , " . "'" . PrepareValueForDB($mySource['ViewID']) . "', " . "'" . PrepareValueForDB($mySource['LogLineType']) . "', " . "'" . PrepareValueForDB($mySource['DiskFile']) . "'" . ")");
        } else {
            if ($mySource['SourceType'] == SOURCE_DB || $mySource['SourceType'] == SOURCE_PDO) {
                // Set Default for number fields
                if (!isset($mySource['DBEnableRowCounting'])) {
                    $mySource['DBEnableRowCounting'] = 0;
                } else {
                    // Force to number
                    $mySource['DBEnableRowCounting'] = intval($mySource['DBEnableRowCounting']);
                }
                if (!isset($mySource['DBType'])) {
                    $mySource['DBType'] = DB_MYSQL;
                }
                // Perform the insert
                $result = DB_Query("INSERT INTO `" . DB_SOURCES . "` (Name, Description, SourceType, MsgParserList, MsgNormalize, ViewID, DBTableType, DBType, DBServer, DBName, DBUser, DBPassword, DBTableName, DBEnableRowCounting) VALUES ( " . "'" . PrepareValueForDB($mySource['Name']) . "', " . "'" . PrepareValueForDB($mySource['Description']) . "', " . " " . PrepareValueForDB($mySource['SourceType']) . " , " . "'" . PrepareValueForDB($mySource['MsgParserList']) . "', " . " " . PrepareValueForDB($mySource['MsgNormalize']) . " , " . "'" . PrepareValueForDB($mySource['ViewID']) . "', " . "'" . PrepareValueForDB($mySource['DBTableType']) . "', " . " " . PrepareValueForDB($mySource['DBType']) . " , " . "'" . PrepareValueForDB($mySource['DBServer']) . "', " . "'" . PrepareValueForDB($mySource['DBName']) . "', " . "'" . PrepareValueForDB($mySource['DBUser']) . "', " . "'" . PrepareValueForDB($mySource['DBPassword']) . "', " . "'" . PrepareValueForDB($mySource['DBTableName']) . "', " . " " . PrepareValueForDB($mySource['DBEnableRowCounting']) . " " . ")");
            } else {
                DieWithFriendlyErrorMsg(GetAndReplaceLangStr($content['LN_CONVERT_ERROR_SOURCEIMPORT'], $mySource['SourceType']));
            }
        }
        // Copy DBID!
        $mySource['DBID'] = DB_ReturnLastInsertID($result);
        DB_FreeQuery($result);
    }
    // --- Check and set DefaultSourceID!
    if (isset($content['DefaultSourceID']) && strlen($content['DefaultSourceID']) > 0 && isset($CFG['Sources'][$content['DefaultSourceID']]['DBID'])) {
        // Copy the new DefaultSourceID back!
        $content['DefaultSourceID'] = $CFG['Sources'][$content['DefaultSourceID']]['DBID'];
        $CFG['DefaultSourceID'] = $content['DefaultSourceID'];
    }
    // ---
}
function CheckLDAPUserLogin($username, $password)
{
    global $content;
    // Create LDAP Searchfilter
    $ldap_filter = '(&' . $content['LDAPSearchFilter'] . '(' . $content['LDAPUidAttribute'] . '=' . $username . '))';
    // Get LDAP Connection
    $ldapConn = DoLDAPConnect();
    if ($ldapConn) {
        if (!DoLDAPBind($ldapConn)) {
            if (GetConfigSetting("DebugUserLogin", 0) == 1) {
                // Die with error
                DebugLDAPErrorAndDie(GetAndReplaceLangStr($content['LN_LOGIN_LDAP_USERBINDFAILED'], $content['LDAPBindDN'], ldap_err2str(ldap_errno($ldapConn))), $ldap_filter);
            }
            return false;
        }
    } else {
        if (GetConfigSetting("DebugUserLogin", 0) == 1) {
            // Die with error
            DebugLDAPErrorAndDie(GetAndReplaceLangStr($content['LN_LOGIN_LDAP_SERVERFAILED'], $content['LDAPServer'] . ":" . $content['LDAPPort'], ldap_err2str(ldap_errno($ldapConn))), $ldap_filter);
        }
        // return false in this case
        return false;
    }
    // Search for the user
    if (!($r = @ldap_search($ldapConn, $content['LDAPBaseDN'], $ldap_filter, array("uid", "cn", "localentryid", "userpassword")))) {
        if (GetConfigSetting("DebugUserLogin", 0) == 1) {
            // Die with error
            DebugLDAPErrorAndDie(GetAndReplaceLangStr($content['LN_LOGIN_LDAP_USERCOULDNOTLOGIN'], $username, ldap_err2str(ldap_errno($ldapConn))), $ldap_filter);
        }
        // return false in this case
        return false;
    }
    $info = ldap_get_entries($ldapConn, $r);
    if (!$info || $info["count"] != 1) {
        if (GetConfigSetting("DebugUserLogin", 0) == 1) {
            // Die with error
            DebugLDAPErrorAndDie(GetAndReplaceLangStr($content['LN_LOGIN_LDAP_USERNOTFOUND'], $username), $ldap_filter);
        }
        // return false in this case
        return false;
    }
    // now we have the user data. Do a bind to check for his password
    if (!($r = @ldap_bind($ldapConn, $info[0]['dn'], $password))) {
        if (GetConfigSetting("DebugUserLogin", 0) == 1) {
            // Die with error
            DebugLDAPErrorAndDie(GetAndReplaceLangStr($content['LN_LOGIN_LDAP_PASSWORDFAIL'], $username), $ldap_filter);
        }
        // return false in this case
        return false;
    }
    // for the moment when a user logs in from LDAP, create it in the DB.
    // then the prefs and group management is done in the DB and we don't rewrite the whole Loganalyzer code…
    //
    // added by czhujer
    //
    $ldapadmingroup = "cn=loganalyzeradminusers,cn=groups,cn=accounts,dc=someorg,dc=en";
    if (LdapCheckGroup($ldapConn, $info[0]['dn'], $ldapadmingroup)) {
        $ldapuser_is_admin = 1;
        $ldapuser_is_readonly = 0;
        //echo "You're (".$info[0]['dn'].") member of \"".$ldapadmingroup."\"";
    } else {
        //echo "You're (".$info[0]['dn'].") not member of \"".$ldapadmingroup."\"";
        $ldapuser_admin = 0;
        $ldapuser_is_readonly = 1;
    }
    /* debug   
       echo "<pre>";  
       print_r($info);  
       echo "</pre>";  
       DebugLDAPErrorAndDie("" , $ldap_filter );   
       */
    //
    // end of czhujer modify
    //
    /* DB_RemoveBadChars() needs to be done here to maintain backwards compatibility even if it is not needed here*/
    $md5pass = md5(DB_RemoveBadChars($password));
    // check if the user already exist
    $sqlquery = "SELECT * FROM `" . DB_USERS . "` WHERE username = '******'";
    $result = DB_Query($sqlquery);
    $myrow = DB_GetSingleRow($result, true);
    if (!isset($myrow['is_admin'])) {
        // Create User | use password to create MD5 Hash, so technically the user could login without LDAP as well
        //$sqlcmd = "INSERT INTO `" . DB_USERS . "` (username, password, is_admin, is_readonly) VALUES ('" . $username . "', '" . $md5pass . "', 0, 1)";
        //modified by czhujer
        $sqlcmd = "INSERT INTO `" . DB_USERS . "` (username, password, is_admin, is_readonly) VALUES " . "('" . $username . "', '" . $md5pass . "', " . intval($ldapuser_is_admin) . ", " . intval($ldapuser_is_readonly) . ")";
        $result = DB_Query($sqlcmd);
        DB_FreeQuery($result);
        $myrow['is_admin'] = 0;
        $myrow['last_login'] = 0;
        $myrow['is_readonly'] = 1;
    }
    // Construct Row and return
    $myrowfinal['username'] = $username;
    $myrowfinal['password'] = $md5pass;
    $myrowfinal['dn'] = $info[0]['dn'];
    if (isset($myrow['ID'])) {
        $myrowfinal['ID'] = $myrow['ID'];
    } else {
        $myrowfinal['ID'] = DB_ReturnLastInsertID();
    }
    // Get from last insert!
    $myrowfinal['is_admin'] = $myrow['is_admin'];
    $myrowfinal['is_readonly'] = $myrow['is_readonly'];
    $myrowfinal['last_login'] = $myrow['last_login'];
    return $myrowfinal;
}