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; }