root/honeybow/trunk/mwwatcher/src/MwWatcherDlg.h

Revision 670, 7.6 kB (checked in by chengyu, 2 years ago)

honeybow sensor mwwatcher component first public release.

Line 
1 // MwWatcherDlg.h
2 //
3 // Header file
4 // Copyright (C) 2006 Artemis: Chinese Honeynet Project
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 //
20 /////////////////////////////////////////////////////////////////////////////
21 //
22
23 #if !defined(AFX_MWWATCHERDLG_H__2639544C_D040_493C_A9AC_80413B2861E6__INCLUDED_)
24 #define AFX_MWWATCHERDLG_H__2639544C_D040_493C_A9AC_80413B2861E6__INCLUDED_
25
26 #if _MSC_VER > 1000
27 #pragma once
28 #endif // _MSC_VER > 1000
29
30 #define WM_SHOWTASK             (WM_USER + 201)
31 #define MAX_DIR_WATCH   10
32
33 #define IDT_RUN_TIMER           1
34 #define IDT_GLOBAL_TIMER        2
35
36 /////////////////////////////////////////////////////////////////////////////
37 //
38 #include "DirectoryChanges.h"
39
40 class CDirectoryChangeHandler_ListBox : public CDirectoryChangeHandler
41 {
42 public:
43         CDirectoryChangeHandler_ListBox(CListBox & list_box);
44         /*      : CDirectoryChangeHandler(),
45                 m_listBox( list_box ){}*/
46         ~CDirectoryChangeHandler_ListBox();
47 protected:
48         //These functions are called when the directory to watch has had a change made to it
49         void On_FileAdded(const CString & strFileName)
50         {
51                 CString strTemp(_T("File Added: ") + strFileName);
52                 AddNotification(strTemp);
53
54                 //m_listBox.AddString((LPCTSTR)strTemp/*_T("File Added: ") + strFileName*/);
55                 //SetHorizontalBar((LPCTSTR)strTemp);
56
57         }
58         void On_FileRemoved(const CString & strFileName)
59         {
60                 CString strTemp(_T("File Removed: ") + strFileName);
61                 AddNotification(strTemp);
62
63                 //m_listBox.AddString(_T("File Removed: ") + strFileName);
64                 //SetHorizontalBar(_T("File Removed: ") + strFileName);
65         }
66         void On_FileModified(const CString & strFileName)
67         {
68                 CString strTemp(_T("File Modified: ") + strFileName);
69                 AddNotification(strTemp);
70
71                 //m_listBox.AddString(_T("File Modified: ") + strFileName);
72                 //SetHorizontalBar(_T("File Modified: ") + strFileName);
73         }
74         void On_FileNameChanged(const CString & strOldFileName, const CString & strNewFileName)
75         {
76                 CString strTemp(_T("File name changed from: ") + strOldFileName + _T(" to: ") + strNewFileName);
77                 AddNotification(strTemp);
78
79                 //m_listBox.AddString(_T("File name changed from: ") + strOldFileName + _T(" to: ") + strNewFileName);
80                 //SetHorizontalBar(_T("File name changed from: ") + strOldFileName + _T(" to: ") + strNewFileName);
81         }
82
83         void On_WatchStarted(DWORD dwError, const CString & strDirectoryName)
84         {
85                 if( dwError == 0 )
86                 {
87                         CString strTemp( _T("Directory Watch Started: ") + strDirectoryName);
88                         AddNotification(strTemp);
89
90                         //m_listBox.AddString( _T("Directory Watch Started: ") + strDirectoryName);
91                         //SetHorizontalBar(_T("Directory Watch Started: ") + strDirectoryName);
92                 }
93                 else
94                 {
95                         CString strTemp( _T("Directory watch failed: ") + strDirectoryName);
96                         AddNotification(strTemp);
97
98                         //m_listBox.AddString( _T("Directory watch failed: ") + strDirectoryName);
99                         //SetHorizontalBar(_T("Directory watch failed: ") + strDirectoryName);
100                 }
101         }
102         void On_WatchStopped(const CString & strDirectoryName)
103         {
104                 //
105                 //      NOTE:  Be careful ! On_WatchStopped can be called AFTER this list box has
106                 //      been destoroyed.  Be carefull whenever interacting w/ windows with this function
107                 //      because the window may not be valid when this function is executed for the last time.
108                 //
109                 //
110                 if( ::IsWindow( m_listBox.GetSafeHwnd() ) )
111                 {
112                         CString strTemp(_T("Stopped watching directory: ") + strDirectoryName);
113                         AddNotification(strTemp);
114
115                         //m_listBox.AddString(_T("Stopped watching directory: ") + strDirectoryName);
116                         //SetHorizontalBar(_T("Stopped watching directory: ") + strDirectoryName);
117                 }
118                 else
119                 {
120                         TRACE(_T("NOTE: m_listBox is not a valid window! This has probably been called as the result of program shutdown sometime after CDirWatcherDlg::OnBtnMonitor2() was used to watch a direcotry.\n"));
121                         TRACE(_T("NOTE: Be sure that you are careful in your implementation of this function to watch out for the same condition if you are dealing w/ windows.\n"));
122 //                      MessageBeep(static_cast<UINT>(-1));
123 //                      MessageBeep(static_cast<UINT>(-1));
124 //                      MessageBeep(static_cast<UINT>(-1));
125                         
126                         //
127                         //      See the comments in DirectoryChanges.h for the CDirectoryChangeHandler::On_WatchStopped() function.
128                         //
129                         //
130                 }
131         }
132         void On_FileUploaded(const CString & strFileName)
133         {
134                 CString strTemp(_T("File Uploaded: ") + strFileName);
135                 AddNotification(strTemp);
136
137                 //m_listBox.AddString(_T("File Uploaded: ") + strFileName);
138                 //SetHorizontalBar(_T("File Uploaded: ") + strFileName);
139         }
140
141         CListBox & m_listBox;
142         HANDLE  hLogFile;
143         HANDLE  hMutex;
144         BOOL    bIsLog;
145        
146
147 private:
148         void SetHorizontalBar();
149         void AddNotification(const CString &strMessage);
150 };
151
152 /////////////////////////////////////////////////////////////////////////////
153 // CMwWatcherDlg dialog
154
155 class CMwWatcherDlg : public CDialog
156 {
157 // Construction
158 public:
159         CMwWatcherDlg(CWnd* pParent = NULL);    // standard constructor
160         
161 // Dialog Data
162         //{{AFX_DATA(CMwWatcherDlg)
163         enum { IDD = IDD_MWWATCHER_DIALOG };
164         CListBox        m_SettingBox;
165         CListBox        m_NotifyBox;
166                 // NOTE: the ClassWizard will add data members here
167         //}}AFX_DATA
168
169         // ClassWizard generated virtual function overrides
170         //{{AFX_VIRTUAL(CMwWatcherDlg)
171         protected:
172         virtual void DoDataExchange(CDataExchange* pDX);        // DDX/DDV support
173         //}}AFX_VIRTUAL
174
175 // Implementation
176 protected:
177         HICON   m_hIcon;
178         LONG    m_old_cx;
179         LONG    m_old_cy;
180
181         // Generated message map functions
182         //{{AFX_MSG(CMwWatcherDlg)
183         virtual BOOL OnInitDialog();
184         afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
185         afx_msg void OnPaint();
186         afx_msg HCURSOR OnQueryDragIcon();
187         virtual void OnCancel();
188         virtual void OnOK();
189         afx_msg void OnHide();
190         afx_msg LRESULT OnBtnShowTask(WPARAM wParam,LPARAM lParam);
191         afx_msg void OnRestart();
192         afx_msg void OnChangeSettings();
193         afx_msg void OnTimer(UINT nIDEvent);
194         afx_msg void OnClear();
195         afx_msg void OnSize(UINT nType, int cx, int cy);
196         //}}AFX_MSG
197         DECLARE_MESSAGE_MAP()
198
199         CDirectoryChangeWatcher                 m_DirWatcher;
200         //CDirectoryChangeHandler_ListBox m_DirChangeHandler;
201         
202         DWORD   GetChangeFlags(int n);
203         BOOL    GetWatchSubDirFlag(int n);
204         void    GetDirectoryToMonitor(int n);
205         BOOL    GetFilterFlag(void);
206         void    GetRebootSetting(void);
207         BOOL    GetUploadMethod(void);
208         void    GetDelayTime(void);
209
210         BOOL    InitService(int n);
211         void    InitFtp();
212
213         void    FtpInit();//initialize the ftp commond file
214         void    FtpPut();//upload file to ftp
215
216         void    CopyPut();//copy sample to a directory
217
218         void    Reboot();
219
220         BOOL    isInWhiteList(const CString &strFileName);
221
222         CString strInitFilePath;
223
224 private:
225         CString m_strDirectoryToMonitor[MAX_DIR_WATCH];
226         CString strInitCommand;
227         CString strGFtpAddress;
228         CString strGFtpUserName;
229         CString strGFtpUserPasswd;
230         CString strGFtpPath;
231         DWORD   dwGDelay;
232         LONG    lRebootTime;
233         BOOL    bSetReboot;
234         BOOL    bFtpPut;
235         HANDLE  hLogFile;
236         CHAR    HomePath[MAX_PATH+1];
237 };
238
239 //{{AFX_INSERT_LOCATION}}
240 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
241
242 #endif // !defined(AFX_MWWATCHERDLG_H__2639544C_D040_493C_A9AC_80413B2861E6__INCLUDED_)
Note: See TracBrowser for help on using the browser.