summaryrefslogtreecommitdiffabout
path: root/PumpKINDlg.h
Unidiff
Diffstat (limited to 'PumpKINDlg.h') (more/less context) (ignore whitespace changes)
-rw-r--r--PumpKINDlg.h178
1 files changed, 169 insertions, 9 deletions
diff --git a/PumpKINDlg.h b/PumpKINDlg.h
index 42ae62d..b247c56 100644
--- a/PumpKINDlg.h
+++ b/PumpKINDlg.h
@@ -113,11 +113,158 @@ public:
113 #define tftpHdrSize(sizeof(tftp)-sizeof(tftp::tftpPacket)) 113 #define tftpHdrSize(sizeof(tftp)-sizeof(tftp::tftpPacket))
114 #definetftpSlackSize sizeof(tftp::tftpLength) 114 #definetftpSlackSize sizeof(tftp::tftpLength)
115 115
116struct acl_rule {
117 enum {
118 opRRQ=tftp::opRRQ, opWRQ=tftp::opWRQ
119 };
120 int op;
121 DWORD addr, mask;
122 enum {
123 rrqGrant=0, rrqPrompt, rrqDeny,
124 rrqRules,
125 rrqNone=-1
126 };
127 enum {
128 wrqGrant=0, wrqPromptIfExists, wrqPrompt, wrqDeny,
129 wrqRules,
130 wrqNone=-1
131 };
132 int target;
133
134 acl_rule()
135 : op(-1), addr(0), mask(0), target(-1) { }
136 acl_rule(int o,DWORD a,DWORD m,int t)
137 : op(o), addr(a), mask(m), target(t) { }
138 acl_rule(const acl_rule& s)
139 : op(s.op), addr(s.addr), mask(s.mask), target(s.target) { }
140
141 BOOL IsValid() {
142 if(op==opRRQ) {
143 if(target<rrqNone || target>=rrqRules)
144 return FALSE;
145 }else if(op==opWRQ) {
146 if(target<wrqNone || target>=wrqRules)
147 return FALSE;
148 }else
149 return FALSE;
150 return TRUE;
151 }
152
153 BOOL IsMatch(int o,DWORD a) {
154 if(o!=op) return FALSE;
155 if( (a&mask) != (addr&mask)) return FALSE;
156 return TRUE;
157 }
158
159 CString str_addr() {
160 return inet_ntoa(*(struct in_addr*)&addr);
161 }
162 CString str_mask() {
163 return inet_ntoa(*(struct in_addr*)&mask);
164 }
165 CString str_target() {
166 if(op==opRRQ) {
167 switch(target) {
168 case rrqNone: return "fallback";
169 case rrqGrant: return "grant";
170 case rrqPrompt: return "prompt";
171 case rrqDeny: return "deny";
172 default: return "?";
173 }
174 }else if(op==opWRQ) {
175 switch(target) {
176 case wrqNone: return "fallback";
177 case wrqGrant: return "grant";
178 case wrqPromptIfExists: return "prompt if exists";
179 case wrqPrompt: return "prompt";
180 case wrqDeny: return "deny";
181 default: return "?";
182 }
183 }else
184 return "?";
185 }
186
187 void SaveProfile(CWinApp* app,int i) {
188 CString n; n.Format("%d",i);
189 app->WriteProfileInt("ACL","op_"+n,op);
190 app->WriteProfileString("ACL","addr_"+n,str_addr());
191 app->WriteProfileString("ACL","mask_"+n,str_mask());
192 app->WriteProfileInt("ACL","target_"+n,target);
193 }
194
195 void LoadProfile(CWinApp* app,int i) {
196 CString n; n.Format("%d",i);
197 op=app->GetProfileInt("ACL","op_"+n,-1);
198 addr=inet_addr(app->GetProfileString("ACL","addr_"+n));
199 mask=inet_addr(app->GetProfileString("ACL","mask_"+n));
200 target=app->GetProfileInt("ACL","target_"+n,-1);
201 }
202
203};
204
205class acl_rules_t : public CArray<acl_rule,acl_rule&> {
206public:
207
208 acl_rules_t& operator=(const acl_rules_t& s) {
209 // Copy(s); XXX: unsuprisingly, there's a bug in MFC Copy, *pDst++=*pSrc (no ++ for Src)
210 RemoveAll();
211 int ns = s.GetSize();
212 SetSize(ns);
213 for(int i=0;i<ns;++i)
214 m_pData[i]=s.m_pData[i];
215 return *this;
216 }
217
218 int AppendRule(acl_rule& r) {
219 return Add(r);
220 }
221
222 void DeleteRule(int r) {
223 RemoveAt(r);
224 }
225
226 int FindRule(int op,DWORD ip) {
227 for(int i=0;i<GetSize();++i)
228 if(m_pData[i].IsMatch(op,ip))
229 return i;
230 return -1;
231 }
232
233 int FindTarget(int op,DWORD ip) {
234 int r=FindRule(op,ip);
235 if(r<0) return -1;
236 return m_pData[r].target;
237 }
238
239 void SaveProfile(CWinApp* app) {
240 int s=GetSize();
241 for(int i=0;i<s;++i)
242 m_pData[i].SaveProfile(app,i);
243 app->WriteProfileInt("ACL","rules",s);
244 }
245 void LoadProfile(CWinApp* app) {
246 RemoveAll();
247 int s=app->GetProfileInt("ACL","rules",0);
248 for(int i=0;i<s;++i) {
249 acl_rule r;
250 r.LoadProfile(app,i);
251 if(r.IsValid())
252 Add(r);
253 }
254 }
255};
256
116class CPumpKINDlg; 257class CPumpKINDlg;
117 class CListenSocket : public CAsyncSocket{ 258 class CListenSocket : public CAsyncSocket{
118public: 259public:
119 virtual void OnReceive(int nErrorCode);
120 CPumpKINDlg* m_Daddy; 260 CPumpKINDlg* m_Daddy;
261 BOOL m_bListen;
262
263 CListenSocket()
264 : m_bListen(FALSE), m_Daddy(0) { }
265
266 BOOL SetListen(BOOL b);
267 virtual void OnReceive(int nErrorCode);
121}; 268};
122 269
123 typedef CList<tftp*,tftp*>CTFTPList; 270 typedef CList<tftp*,tftp*>CTFTPList;
@@ -220,6 +367,11 @@ class CPumpKINDlg : public CDialog
220{ 367{
221// Construction 368// Construction
222public: 369public:
370 CString m_lastlogerr;
371 void LogLine(LPCTSTR str);
372 CString m_LogFile;
373 BOOL m_bListen;
374 acl_rules_t m_aclRules;
223 CString m_bnwRequest; 375 CString m_bnwRequest;
224 CString m_bnwSuccess; 376 CString m_bnwSuccess;
225 CString m_bnwAbort; 377 CString m_bnwAbort;
@@ -240,7 +392,8 @@ public:
240 UINT m_SpeakPort; 392 UINT m_SpeakPort;
241 void LogLine(UINT msgID); 393 void LogLine(UINT msgID);
242 CTimeMap m_LogTimes; 394 CTimeMap m_LogTimes;
243 void LogLine(LPCTSTR str); 395 void LogLineToFile(LPCTSTR str);
396 void LogLineToScreen(LPCTSTR str);
244 int m_LogLength; 397 int m_LogLength;
245 enum{ 398 enum{
246 subitemFile=0, subitemType, subitemPeer, subitemBytes, subitemTSize 399 subitemFile=0, subitemType, subitemPeer, subitemBytes, subitemTSize
@@ -251,15 +404,19 @@ public:
251 CTIDMap m_Xfers; 404 CTIDMap m_Xfers;
252 CTimeSpan m_TFTPTimeOut; 405 CTimeSpan m_TFTPTimeOut;
253 enum{ 406 enum{
254 rrqGiveAll=0, 407 rrqGiveAll=acl_rule::rrqGrant,
255 rrqAlwaysConfirm, 408 rrqAlwaysConfirm=acl_rule::rrqPrompt,
256 rrqDenyAll 409 rrqDenyAll=acl_rule::rrqDeny,
410 rrqFallback=acl_rule::rrqNone,
411 rrqGrant=rrqGiveAll, rrqDeny=rrqDenyAll, rrqPrompt=rrqAlwaysConfirm
257 }; 412 };
258 enum{ 413 enum{
259 wrqTakeAll=0, 414 wrqTakeAll=acl_rule::wrqGrant,
260 wrqConfirmIfExists, 415 wrqConfirmIfExists=acl_rule::wrqPromptIfExists,
261 wrqAlwaysConfirm, 416 wrqAlwaysConfirm=acl_rule::wrqPrompt,
262 wrqDenyAll 417 wrqDenyAll=acl_rule::wrqDeny,
418 wrqFallback=acl_rule::wrqNone,
419 wrqGrant=wrqTakeAll,wrqDeny=wrqDenyAll, wrqPrompt=wrqAlwaysConfirm
263 }; 420 };
264 UINT m_RRQMode; 421 UINT m_RRQMode;
265 UINT m_WRQMode; 422 UINT m_WRQMode;
@@ -273,6 +430,7 @@ public:
273// Dialog Data 430// Dialog Data
274 //{{AFX_DATA(CPumpKINDlg) 431 //{{AFX_DATA(CPumpKINDlg)
275 enum { IDD = IDD_PUMPKIN_DIALOG }; 432 enum { IDD = IDD_PUMPKIN_DIALOG };
433 CButtonm_ListenCtl;
276 CButtonm_AbortCtl; 434 CButtonm_AbortCtl;
277 CButtonm_OptionsCtl; 435 CButtonm_OptionsCtl;
278 CListBoxm_Log; 436 CListBoxm_Log;
@@ -310,6 +468,7 @@ protected:
310 afx_msg void OnAbort(); 468 afx_msg void OnAbort();
311 afx_msg void OnClose(); 469 afx_msg void OnClose();
312 afx_msg void OnTrayShowpumpkinwindow(); 470 afx_msg void OnTrayShowpumpkinwindow();
471 afx_msg void OnTrayListen();
313 afx_msg void OnTrayExit(); 472 afx_msg void OnTrayExit();
314 afx_msg void OnTrayAboutpumpkin(); 473 afx_msg void OnTrayAboutpumpkin();
315 afx_msg void OnTrayFetchfile(); 474 afx_msg void OnTrayFetchfile();
@@ -322,6 +481,7 @@ protected:
322 afx_msg void OnDropFiles(HDROP hDropInfo); 481 afx_msg void OnDropFiles(HDROP hDropInfo);
323 virtual void OnCancel(); 482 virtual void OnCancel();
324 afx_msg void OnHelp(); 483 afx_msg void OnHelp();
484 afx_msg void OnListening();
325 //}}AFX_MSG 485 //}}AFX_MSG
326 DECLARE_MESSAGE_MAP() 486 DECLARE_MESSAGE_MAP()
327}; 487};