Пример #1
0
        protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.INFORM, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> Enter The ParseFileNameRemote Function");

                String stdOut = "";
                String stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;
                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Directory | " + Dir);
                    se.Connect();
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Remote Host Already Connected ");
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep secure";
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> SSH command : " + command + " Result : " + stdOut);
                    //stdout : -rwxrw-rw- 1 ibrahim ibrahim 1920 2011-07-04 11:17 secure

                    StringReader sr = new StringReader(stdOut);
                    Boolean fileExistControl = false;

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(' ');
                        if (arr[arr.Length - 1].Equals("secure") == true)
                            fileExistControl = true;
                    }

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        if (fileExistControl)
                        {
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> Secure File is Exist");
                            stdOut = "";
                            stdErr = "";
                            String commandRead;

                            if (readMethod == "nread")
                            {
                                commandRead = tempCustomVar1 + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> commandRead For nread Is : " + commandRead);
                            }
                            else
                            {
                                commandRead = readMethod + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> commandRead For sed Is : " + commandRead);
                            }

                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Position : " + Position);
                            se.RunCommand(commandRead, ref stdOut, ref stdErr);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Result : " + stdOut);
                            //Jun 26 04:34:14 SAMBASERVER sshd[20314]: Accepted password for natek from 172.16.1.14 port 55200 ssh2

                            StringReader srTest = new StringReader(stdOut);
                            se.Close();

                            if (String.IsNullOrEmpty(stdOut))
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Restart The Position");
                                Position = 0;
                            }
                        }
                        else
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> Secure File is NOT Exist");

                    }
                    else
                    {
                        if (fileExistControl)
                        {
                            FileName = Dir + "secure";
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                "  RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->>  Last File Is Null And Setted The File To " + FileName);

                        }
                    }

                    stdOut = "";
                    stdErr = "";
                    se.Close();
                }
                else
                {
                    FileName = Dir;
                }
            }
            catch (Exception exp)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "  RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() In Catch -->>" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "  RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() In Catch -->>" + exp.StackTrace);
                return;
            }

            Log.Log(LogType.FILE, LogLevel.INFORM, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->>  Exit The Function");
        }
 protected override void ParseFileNameRemote()
 {
     String stdOut = "";
     String stdErr = "";
     se = new SshExec(remoteHost, user);
     se.Password = password;
     if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
     {
         se.Connect();
         se.SetTimeout(Int32.MaxValue);
         String command = "ls -lt " + Dir + " | grep ^-";
         Log.Log(LogType.FILE, LogLevel.DEBUG, "SSH command is : " + command);
         se.RunCommand(command, ref stdOut, ref stdErr);
         StringReader sr = new StringReader(stdOut);
         String line = "";
         bool first = true;
         while ((line = sr.ReadLine()) != null)
         {
             if (first)
             {
                 Log.Log(LogType.FILE, LogLevel.DEBUG, "Command returned : " + line);
                 first = false;
             }
             String[] arr = line.Split(' ');
             if (arr[arr.Length - 1].Contains("auth.log"))
             {
                 FileName = Dir + arr[arr.Length - 1];
                 break;
             }
         }
         stdOut = "";
         stdErr = "";
         se.Close();
     }
     else
         FileName = Dir;
 }
Пример #3
0
        protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.INFORM, " TinyProxyRecorder In ParseFileNameRemote() -->> Enter The Function");

                String stdOut = "";
                String stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Home Directory | " + Dir);

                    se.Connect();
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep messages";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> SSH command : " + command);
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    StringReader sr = new StringReader(stdOut);

                    ArrayList arrFileNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(' ');
                        if (arr[arr.Length - 1].Contains("messages") == true && arr[arr.Length - 1].Contains("gz") == false && arr[arr.Length - 1].Contains("bz2") == false)
                            arrFileNameList.Add(arr[arr.Length - 1]);
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> LastFile Is = " + lastFile);

                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i]) == base.lastFile)
                            {
                                bLastFileExist = true;
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            stdOut = "";
                            stdErr = "";
                            String commandRead;

                            if (readMethod == "nread")
                            {
                                commandRead = tempCustomVar1 + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> commandRead For nread Is : " + commandRead);
                            }
                            else
                            {
                                commandRead = readMethod + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> commandRead For sed Is : " + commandRead);
                            }

                            se.RunCommand(commandRead, ref stdOut, ref stdErr);
                            se.Close();

                            StringReader srTest = new StringReader(stdOut);
                            Int64 posTest = Position;
                            String lineTest = "";
                            while ((lineTest = srTest.ReadLine()) != null)
                            {
                                if (lineTest.StartsWith("~?`Position"))
                                {
                                    try
                                    {
                                        String[] arrIn = lineTest.Split('\t');
                                        String[] arrPos = arrIn[0].Split(':');
                                        String[] arrLast = arrIn[1].Split('`');
                                        posTest = Convert.ToInt64(arrPos[1]); // değişti Convert.ToUInt32s
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Log(LogType.FILE, LogLevel.ERROR, " TinyProxyRecorder In ParseFileNameRemote() In Try Catch -->> " + ex.Message);
                                    }
                                }
                            }

                            if (posTest > Position)
                            {
                                Log.Log(LogType.FILE, LogLevel.INFORM,
                                    " TinyProxyRecorder In ParseFileNameRemote() -->> posTest > Position So Continiou With Same File ");

                                FileName = lastFile;

                                Log.Log(LogType.FILE, LogLevel.INFORM,
                                    " TinyProxyRecorder In ParseFileNameRemote() -->> LastFile Is " + lastFile);
                            }
                            else
                            {

                                Log.Log(LogType.FILE, LogLevel.INFORM,
                                   " TinyProxyRecorder In ParseFileNameRemote() -->> Finished Reading The File");

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString() == lastFile)
                                    {
                                        if (i + 1 == dFileNameList.Length)
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                                " TinyProxyRecorder In ParseFileNameRemote() -->> There Is No New File And Continiou With Same File And Waiting For a New Record " + FileName);
                                            break;
                                        }
                                        else
                                        {
                                            FileName = Dir + dFileNameList[(i + 1)].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                                " TinyProxyRecorder In ParseFileNameRemote() -->> Finished Reading The File And Continiou With New File " + FileName);
                                            break;

                                        }
                                    }
                                }
                            }
                        }
                        else
                            SetNextFile(dFileNameList, "ParseFileNameRemote()");

                    }
                    else
                    {

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString();
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                "  TinyProxyRecorder In ParseFileNameRemote() -->>  Last File Is Null And Setted The File To " + FileName);

                        }
                    }
                    stdOut = "";
                    stdErr = "";
                    se.Close();
                }
                else
                {
                    FileName = Dir;
                }
            }
            catch (Exception exp)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "  TinyProxyRecorder In ParseFileNameRemote() In Catch -->>" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "  TinyProxyRecorder In ParseFileNameRemote() In Catch -->>" + exp.StackTrace);
                return;
            }

            Log.Log(LogType.FILE, LogLevel.INFORM, " TinyProxyRecorder In ParseFileNameRemote() -->>  Exit The Function");
        }
        private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                timer1.Enabled = false;
                L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick -->> Timer is Started");
                String stdOut = "";
                String stdErr = "";

                string _fileId = "";
                string _filePattern = "";
                string _fileName = "";
                string _fileCreateTime = "";
                int port;
                String remoteHost = null;
                String line = "";

                if (remote_host.Contains(":"))
                {
                    port = Convert.ToInt32(remote_host.Split(':')[1]);
                    remoteHost = remote_host.Split(':')[0];
                }
                else
                {
                    remoteHost = remote_host;
                    port = 22;
                }

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (location.EndsWith("/"))
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG,
                            " NginxAccessV_1_0_0Recorder In timer1_Tick() --> Directory | " + location);
                    if (!se.Connected)
                    {
                        se.Connect(port);
                    }
                    se.SetTimeout(Int32.MaxValue);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() --> lastFile: " + lastFile);

                    string[] linuxFileParameters = lastFile.Trim().Split(';');

                    if (linuxFileParameters.Length > 0)
                    {
                        _fileId = linuxFileParameters[0];
                        _fileName = linuxFileParameters[1];
                        _filePattern = linuxFileParameters[2];
                        _fileCreateTime = linuxFileParameters[3];
                    }
                    else
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, "LastFile is unrecognized:" + lastFile);
                        return;
                    }

                    if (_fileCreateTime == "-1")
                    {
                        long dt = (long)DateTimeToUnixTimestamp(DateTime.Now);
                        _fileCreateTime = dt.ToString();
                    }

                    L.Log(LogType.FILE, LogLevel.DEBUG, "_fileId: " + _fileId);
                    L.Log(LogType.FILE, LogLevel.DEBUG, "_fileName: " + _fileName);
                    L.Log(LogType.FILE, LogLevel.DEBUG, "_filePattern: " + _filePattern);
                    L.Log(LogType.FILE, LogLevel.DEBUG, "_fileCreateTime: " + _fileCreateTime);

                    if (last_recordnum == 0)
                    {
                        last_recordnum = 1;
                    }

                    String command = location + "printLog.sh" + " key " + location + " " + _fileId.Trim() + " " +
                                     _fileName.Trim() + " '"
                                     + _filePattern.Trim() + "' "
                                     + _fileCreateTime + " "
                                     + last_recordnum + " " +
                                     (last_recordnum + max_record_send);

                    se.RunCommand(command, ref stdOut, ref stdErr);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> SSH command : " + command);

                    StringReader sr = new StringReader(stdOut);
                    L.Log(LogType.FILE, LogLevel.DEBUG,
                          "NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Result: " + stdOut);

                    int state = 1;
                    int lineCounter = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        switch (state)
                        {
                            case 1:
                                L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Start While.");
                                if (line.Equals("key;BEGIN;NEW"))
                                {
                                    state = 2;
                                }
                                else if (line.Equals("key;BEGIN;OK"))
                                {
                                    state = 5;
                                }
                                else if (line.Equals("key;NOFILE"))
                                {
                                    L.Log(LogType.FILE, LogLevel.WARN, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 1 Error There is no file.");
                                    return;
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 1 Error Unknown Line. " + line);
                                    return;
                                }
                                break;
                            case 2:
                                if (line.StartsWith("FILE;"))
                                {
                                    string[] lineArr = line.Split(new char[] { ';' }, 4);
                                    if (lineArr.Length == 4)
                                    {
                                        _fileId = lineArr[1];
                                        _fileCreateTime = lineArr[2];
                                        _fileName = lineArr[3];
                                        state = 3;
                                        break;
                                    }
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 2 Error Missing Fields. " + line);
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 2 Error Unknown Line. " + line);
                                }
                                return;
                            case 3:
                                if (line.Equals("key;ENDS"))
                                {
                                    try
                                    {
                                        CustomServiceBase customServiceBase = base.GetInstanceService("Security Manager Remote Recorder");

                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sending. " + lastFile + " / " + _fileId + ";" + _fileName + ";" + _filePattern + ";" + _fileCreateTime);
                                        customServiceBase.SetReg(Id, "0", "", _fileId + ";" + _fileName + ";" + _filePattern + ";" + _fileCreateTime, "", LastRecordDate);
                                        last_recordnum = 0;
                                        lastFile = _fileId + ";" + _fileName + ";" + _filePattern + ";" +
                                                   _fileCreateTime;
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sended." + lastFile);
                                    }
                                    catch (Exception exception)
                                    {
                                        L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sending Error." + exception.Message);
                                    }
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 3 Error Unknown Line. " + line);
                                }
                                return;
                            case 5:
                                if (line.StartsWith("FILE;"))
                                {
                                    string[] lineArr = line.Split(new char[] { ';' }, 4);
                                    if (lineArr.Length == 4)
                                    {
                                        _fileId = lineArr[1];
                                        _fileCreateTime = lineArr[2];
                                        _fileName = lineArr[3];
                                        state = 6;
                                        break;
                                    }
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 5 Error Missing Fields. " + line);
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 5 Error Unknown Line. " + line);
                                }
                                return;
                            case 6:
                                if (line.Equals("OUTPUT;BEGIN"))
                                {
                                    try
                                    {
                                        CustomServiceBase customServiceBase = base.GetInstanceService("Security Manager Remote Recorder");
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sending.");
                                        customServiceBase.SetReg(Id, last_recordnum.ToString(), line, _fileId + ";" + _fileName + ";" + _filePattern + ";" + _fileCreateTime, "", LastRecordDate);
                                        lastFile = _fileId + ";" + _fileName + ";" + _filePattern + ";" +
                                                   _fileCreateTime;
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sended.");
                                        state = 7;
                                        break;
                                    }
                                    catch (Exception exception)
                                    {
                                        L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In CoderParse() -->> Record sending Error." + exception.Message);
                                    }
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 3 Error Unknown Line. " + line);
                                }
                                return;
                            case 7:
                                if (line.StartsWith("+"))
                                {
                                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> lines: " + line);
                                    if (CoderParse(line.Substring(1).Trim()))
                                    {
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Date inserted. ");
                                        lineCounter++;
                                        break;
                                    }
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 7 Error Unknown Line. " + line);
                                }
                                return;
                        }
                    }
                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> DEBUG." + state + " / " + lineCounter + " / " + max_record_send);

                    if (state > 1)
                    {
                        if (lineCounter < max_record_send)
                        {
                            CheckEOF(_fileId, _fileName, _filePattern, _fileCreateTime);
                        }
                    }
                    else
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 0 Error Unexpected end of stream.");
                    }
                }
            }
            catch (Exception exception)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick -->> Error : " + exception.ToString());
            }
            finally
            {
                timer1.Enabled = true;
                L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick -->> Timer is finished.");
            }
        }
        protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.INFORM, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Enter The Function ");

                string stdOut = "";
                string stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Home Directory | " + Dir);

                    se.Connect();
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep administrative";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->> SSH command : " + command);
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Dosya ismi okundu: " + line);
                        String[] arr = line.Split('.');
                        if (arr[0].StartsWith("administrative") == true)
                        {
                            arrFileNameList.Add(arr);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Okunan Dosya ismi arrayFileNameList'e atıldı. ");
                        }
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı. ");

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> LastFile is not null: " + lastFile);

                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            if (IsLineHereRemote(dFileNameList) == false)
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->>Last line could not find any file : " + lastFile);
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->>Directorydeki tüm dosyalar alınmak isteniyor ise LastFile ve Position'ı sıfırlayınız. ");
                            }
                            else
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->> FileName ayarlandı. FileName: " + FileName);
                            }
                        }
                        else
                        {
                            FileName = Dir + dFileNameList[0].ToString();
                            Position = 0;
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " | LastFile Silinmis , Dosya Bulunamadı  Yeni File : " + FileName);
                        }
                    }
                    else
                    {
                            if (dFileNameList.Length > 0)
                            {
                                FileName = Dir + dFileNameList[0].ToString();
                                lastFile = FileName;
                                Position = 0;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> LastName Is Null and FileName Is Setted To : " + FileName);
                            }
                            else
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "  LabrisAdministrativeRecorder In ParseFileNameRemote() -->> In The Log Location There Is No Log File");
                            }
                    }
                }
                else
                {
                    FileName = Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                }
            }
            catch (Exception exp)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "LabrisAdministrativeRecorder In ParseFileNameRemote() In Catch -->>" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "LabrisAdministrativeRecorder In ParseFileNameRemote() In Catch -->>" + exp.StackTrace);
                return;
            }

            Log.Log(LogType.FILE, LogLevel.INFORM, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->>  Exit The Function");
        }
        protected override void ParseFileNameRemote()
        {
            try
            {

                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | Started ");

                String stdOut = "";
                String stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {

                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Home Directory | " + Dir);

                    se.Connect();
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep ^-";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | SSH command -1 : " + command);
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    StringReader sr = new StringReader(stdOut);

                    ArrayList arrFileNameList = new ArrayList();
                    while ((line = sr.ReadLine()) != null)
                    {

                        String[] arr = line.Split(' ');
                        if (arr[arr.Length - 1].StartsWith("MSGTRKM") == true)
                            arrFileNameList.Add(arr[arr.Length - 1]);

                    }

                    String[] dFileNameList = SortFileNameByFileNumber(arrFileNameList);

                    if (string.IsNullOrEmpty(lastFile) == false)
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | LastFile  = " + lastFile);

                        bool bLastFileExist = false;
                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {

                            String wcArg = "";
                            String wcCmd = "";
                            if (readMethod == "sed")
                            {
                                wcCmd = "wc";
                                wcArg = "-l";
                            }
                            else if (readMethod == "nread")
                            {
                                wcCmd = "wc";
                                wcArg = "-c";
                            }

                            command = wcCmd + " " + wcArg + " " + lastFile;

                            stdOut = "";
                            stdErr = "";

                            se.RunCommand(command, ref stdOut, ref stdErr);

                            String[] arr = SpaceSplit(stdOut, false);
                            Int64 lFileIndex = Convert.ToInt64(arr[0]);//Dosyadaki satýr sayýsý
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | FileIndex  = " + lFileIndex.ToString());

                            if (lFileIndex > Position)
                            {

                                //Dosya Sonuna Kadar okunmamýs Ayný Dosyaya Devam Edecek;
                                Log.Log(LogType.FILE, LogLevel.DEBUG,
                                    "ParseFileNameRemote() | FileIndex ( " + lFileIndex.ToString() + " ) > Position (" + Position.ToString() + " )");

                                FileName = lastFile;

                                Log.Log(LogType.FILE, LogLevel.DEBUG,
                                    "ParseFileNameRemote() | FileName = LastFile " + lastFile);

                            }
                            else
                            {

                                Log.Log(LogType.FILE, LogLevel.DEBUG,
                                   "ParseFileNameRemote() | ParseFileNameRemote() | Dosya Sonuna Kadar Okundu Position (" + this.Position.ToString() + " )  > FileIndex ( " + lFileIndex.ToString() + " )");

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString() == lastFile)
                                    {
                                        if (i + 1 == dFileNameList.Length)
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                                "ParseFileNameRemote() | Yeni Dosya Yok Ayný Dosyaya Devam : " + FileName);
                                            break;

                                        }
                                        else
                                        {
                                            FileName = Dir + dFileNameList[(i + 1)].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                                "ParseFileNameRemote() | Yeni Dosya  : " + FileName);
                                            break;

                                        }
                                    }
                                }
                            }
                        }
                        else
                            SetNextFile(dFileNameList, "ParseFileNameRemote()");

                    }
                    else
                    {

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString();
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                "ParseFileNameRemote() |LastName is null Ýlk FileName Set  : " + FileName);

                        }

                    }
                    stdOut = "";
                    stdErr = "";
                    se.Close();

                }
                else
                    FileName = Dir;

            }
            catch (Exception exp)
            {

                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() |" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() |" + exp.StackTrace);
                return;
            }
        }
        private void timer1_Tick_old(object sender, System.Timers.ElapsedEventArgs e)
        {
            L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Timer tetiklenme anı: " + e.SignalTime.ToLongTimeString());

            timer1.Enabled = false;
            String stdOut = "";
            String stdErr = "";
            String line = "";
            Rec rec = new Rec();
            recList = new ArrayList();
            SshExec se = null;

            try
            {
                L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> SshExec nesnesi için. Host: " + remoteHost + ", User: "******", Pass: *******");

                se = new SshExec(remoteHost, user);
                if (!String.IsNullOrEmpty(password))
                    se.Password = password;

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> SshExec nesnesi üretildi.");

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Started to connect and parse lines.");

                if (!se.Connected)
                {
                    try
                    {
                        se.Connect(22, 2000);
                        L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı açıldı.");
                        se.SetTimeout(15000);
                        L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Timeout atandı. 15000");
                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Connection problem. Hata : " + ex.ToString());
                    }
                }
                else
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Zaten kurulu olan bağlantı ile devam ediliyor.");
                }

                if (se.Connected)
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı şuan açık. Komut çalıştırılabilir.");
                }
                else
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı şuan kapalı. Komut çalışmayacak!!");
                }

                try
                {
                    se.RunCommand("show ip dhcp binding ", ref stdOut, ref stdErr);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Komut çalıştırıldı. show ip dhcp binding");
                }
                catch (Exception ex)
                {
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Komut çalıştırılamadı!!!   show ip dhcp binding");
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Hata: " + ex.ToString());
                }

                String stdOut1 = "";
                String stdErr1 = "";

                if (se.Connected)
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Bağlantı şuan açık. Komut çalıştırılabilir.");
                }
                else
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Bağlantı kopuk. Komut çalışmayacak!!");
                }

                try
                {
                    se.RunCommand("exit", ref stdOut1, ref stdErr1);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Komut çalıştırıldı. exit");
                }
                catch (Exception ex)
                {
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Komut çalıştırılamadı!!!  exit");
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Hata: " + ex.ToString());
                }

                if (se.Connected)
                {
                    se.Close();
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı kesildi.");
                }

                StringReader sr = new StringReader(stdOut);

                while ((line = sr.ReadLine()) != null)
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Line: " + line);
                    rec.Description = line;
                    String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    if (arr.Length >= 8)
                    {
                        rec.Description = line;

                        if (arr[0].Contains("."))
                        {
                            rec.ComputerName = remoteHost;
                            rec.CustomStr1 = arr[0];
                            tempMac = arr[1];

                            tempMac = tempMac.Remove(0, 2);
                            string[] arrMac = tempMac.Split('.');
                            tempMac = "";
                            for (int i = 0; i < arrMac.Length; i++)
                            {
                                tempMac += arrMac[i];
                            }
                            rec.CustomStr2 = tempMac.Trim();
                            rec.EventType = arr[7];

                            for (int i = 2; i < 6; i++)
                            {
                                tempDate += arr[i] + " ";
                            }
                            tempDate = tempDate.Trim();

                            if (arr[6] == "PM" && Convert.ToDateTime(tempDate).Hour != 12)
                            {
                                rec.Datetime = Convert.ToDateTime(tempDate, CultureInfo.InvariantCulture).AddDays(-8).AddHours(12).ToString("dd/MM/yyyy HH:mm:ss");
                            }
                            else
                            {
                                rec.Datetime = Convert.ToDateTime(tempDate, CultureInfo.InvariantCulture).AddDays(-8).ToString("dd/MM/yyyy HH:mm:ss");
                            }

                            if (Convert.ToDateTime(tempDate).Date.Day == DateTime.Now.Date.Day)
                            {
                                rec.CustomStr3 = "Removed";
                            }

                            tempDate = "";
                            recList.Add(rec);
                        }
                    }
                }

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Çekilen veriler tarihlerine bakılarak kaydedilecek.");
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Kalınan LastPosition: " + Local_LastPosition);

                lastDate = new DateTime();
                bool lastPositionSetted = DateTime.TryParse(Local_LastPosition, out lastDate);

                foreach (Rec r in recList)
                {
                    if (!lastPositionSetted)
                    {
                        //İlk kayıtlar.
                        CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                        s.SetData(Dal, virtualhost, r);
                        L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> LastPosition is null. Veri ataması gerçekleştirildi.");
                    }
                    else
                    {
                        //Daha önce kayıt alınmış.
                        if (Convert.ToDateTime(r.Datetime) > lastDate)
                        {
                            //Değişen kayıt olmuş. Veritabanına eklenmeli.
                            CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                            s.SetData(Dal, virtualhost, r);
                            L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Record Date daha büyük. Veri ataması gerçekleştirildi. : " + r.Datetime);
                        }
                        else
                        {
                            //Tarih aynı. Kayıt işlemi yapılmayacak.
                            L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Record Date daha küçük. Kaydedilmedi!. Tarih: " + r.Datetime);
                        }
                    }
                }

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> En büyük tarih belirleniyor.");
                maxDate = lastDate.ToString();

                foreach (Rec r in recList)
                {
                    if (Convert.ToDateTime(r.Datetime) > Convert.ToDateTime(maxDate))
                    {
                        maxDate = r.Datetime;
                    }
                }

                CustomServiceBase ser = base.GetInstanceService("Security Manager Remote Recorder");
                ser.SetReg(ID, maxDate, "", "", "");
                Local_LastPosition = maxDate;
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Yeni LastPosition atandı. LastPostion: " + Local_LastPosition);
            }
            catch (Exception ex)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Recorder Main Exception: " + ex.ToString());
            }
            finally
            {
                if (se != null)
                {
                    if (se.Connected)
                    {
                        se.Close();
                        L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı kesildi.");
                    }
                }

                tempDate = "";
                tempMac = "";
                timer1.Enabled = true;
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Timer'ın işi bitti. Time: " + DateTime.Now.ToLongTimeString());
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Bir Sonraki Tetikleme " + timer_interval / 60000 + " dakika sonra gerçekleşecektir.");
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> ===============================================");
                recList.Clear();
            }
        }