summaryrefslogtreecommitdiffabout
path: root/PumpKINDlg.h
authorMichael Krelin <hacker@klever.net>2006-02-02 23:07:50 (UTC)
committer Michael Krelin <hacker@klever.net>2006-02-02 23:07:50 (UTC)
commit39bb4331674cc77560a546f4f9b14b143603d4be (patch) (side-by-side diff)
treefbbc1006c655888a5483ddd359c52b863e7a27ab /PumpKINDlg.h
parentfedc32eb7d20e5278a2125ead3ed125dc63b5746 (diff)
downloadpumpkin-39bb4331674cc77560a546f4f9b14b143603d4be.zip
pumpkin-39bb4331674cc77560a546f4f9b14b143603d4be.tar.gz
pumpkin-39bb4331674cc77560a546f4f9b14b143603d4be.tar.bz2
- version bump to 2.7
- year bump to 2006 - ip-based access control - server switchable off - logging to file git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@144 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'PumpKINDlg.h') (more/less context) (show 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
@@ -115,2 +115,143 @@ public:
+struct acl_rule {
+ enum {
+ opRRQ=tftp::opRRQ, opWRQ=tftp::opWRQ
+ };
+ int op;
+ DWORD addr, mask;
+ enum {
+ rrqGrant=0, rrqPrompt, rrqDeny,
+ rrqRules,
+ rrqNone=-1
+ };
+ enum {
+ wrqGrant=0, wrqPromptIfExists, wrqPrompt, wrqDeny,
+ wrqRules,
+ wrqNone=-1
+ };
+ int target;
+
+ acl_rule()
+ : op(-1), addr(0), mask(0), target(-1) { }
+ acl_rule(int o,DWORD a,DWORD m,int t)
+ : op(o), addr(a), mask(m), target(t) { }
+ acl_rule(const acl_rule& s)
+ : op(s.op), addr(s.addr), mask(s.mask), target(s.target) { }
+
+ BOOL IsValid() {
+ if(op==opRRQ) {
+ if(target<rrqNone || target>=rrqRules)
+ return FALSE;
+ }else if(op==opWRQ) {
+ if(target<wrqNone || target>=wrqRules)
+ return FALSE;
+ }else
+ return FALSE;
+ return TRUE;
+ }
+
+ BOOL IsMatch(int o,DWORD a) {
+ if(o!=op) return FALSE;
+ if( (a&mask) != (addr&mask)) return FALSE;
+ return TRUE;
+ }
+
+ CString str_addr() {
+ return inet_ntoa(*(struct in_addr*)&addr);
+ }
+ CString str_mask() {
+ return inet_ntoa(*(struct in_addr*)&mask);
+ }
+ CString str_target() {
+ if(op==opRRQ) {
+ switch(target) {
+ case rrqNone: return "fallback";
+ case rrqGrant: return "grant";
+ case rrqPrompt: return "prompt";
+ case rrqDeny: return "deny";
+ default: return "?";
+ }
+ }else if(op==opWRQ) {
+ switch(target) {
+ case wrqNone: return "fallback";
+ case wrqGrant: return "grant";
+ case wrqPromptIfExists: return "prompt if exists";
+ case wrqPrompt: return "prompt";
+ case wrqDeny: return "deny";
+ default: return "?";
+ }
+ }else
+ return "?";
+ }
+
+ void SaveProfile(CWinApp* app,int i) {
+ CString n; n.Format("%d",i);
+ app->WriteProfileInt("ACL","op_"+n,op);
+ app->WriteProfileString("ACL","addr_"+n,str_addr());
+ app->WriteProfileString("ACL","mask_"+n,str_mask());
+ app->WriteProfileInt("ACL","target_"+n,target);
+ }
+
+ void LoadProfile(CWinApp* app,int i) {
+ CString n; n.Format("%d",i);
+ op=app->GetProfileInt("ACL","op_"+n,-1);
+ addr=inet_addr(app->GetProfileString("ACL","addr_"+n));
+ mask=inet_addr(app->GetProfileString("ACL","mask_"+n));
+ target=app->GetProfileInt("ACL","target_"+n,-1);
+ }
+
+};
+
+class acl_rules_t : public CArray<acl_rule,acl_rule&> {
+public:
+
+ acl_rules_t& operator=(const acl_rules_t& s) {
+ // Copy(s); XXX: unsuprisingly, there's a bug in MFC Copy, *pDst++=*pSrc (no ++ for Src)
+ RemoveAll();
+ int ns = s.GetSize();
+ SetSize(ns);
+ for(int i=0;i<ns;++i)
+ m_pData[i]=s.m_pData[i];
+ return *this;
+ }
+
+ int AppendRule(acl_rule& r) {
+ return Add(r);
+ }
+
+ void DeleteRule(int r) {
+ RemoveAt(r);
+ }
+
+ int FindRule(int op,DWORD ip) {
+ for(int i=0;i<GetSize();++i)
+ if(m_pData[i].IsMatch(op,ip))
+ return i;
+ return -1;
+ }
+
+ int FindTarget(int op,DWORD ip) {
+ int r=FindRule(op,ip);
+ if(r<0) return -1;
+ return m_pData[r].target;
+ }
+
+ void SaveProfile(CWinApp* app) {
+ int s=GetSize();
+ for(int i=0;i<s;++i)
+ m_pData[i].SaveProfile(app,i);
+ app->WriteProfileInt("ACL","rules",s);
+ }
+ void LoadProfile(CWinApp* app) {
+ RemoveAll();
+ int s=app->GetProfileInt("ACL","rules",0);
+ for(int i=0;i<s;++i) {
+ acl_rule r;
+ r.LoadProfile(app,i);
+ if(r.IsValid())
+ Add(r);
+ }
+ }
+};
+
class CPumpKINDlg;
@@ -118,4 +259,10 @@ class CListenSocket : public CAsyncSocket {
public:
- virtual void OnReceive(int nErrorCode);
CPumpKINDlg* m_Daddy;
+ BOOL m_bListen;
+
+ CListenSocket()
+ : m_bListen(FALSE), m_Daddy(0) { }
+
+ BOOL SetListen(BOOL b);
+ virtual void OnReceive(int nErrorCode);
};
@@ -222,2 +369,7 @@ class CPumpKINDlg : public CDialog
public:
+ CString m_lastlogerr;
+ void LogLine(LPCTSTR str);
+ CString m_LogFile;
+ BOOL m_bListen;
+ acl_rules_t m_aclRules;
CString m_bnwRequest;
@@ -242,3 +394,4 @@ public:
CTimeMap m_LogTimes;
- void LogLine(LPCTSTR str);
+ void LogLineToFile(LPCTSTR str);
+ void LogLineToScreen(LPCTSTR str);
int m_LogLength;
@@ -253,11 +406,15 @@ public:
enum {
- rrqGiveAll=0,
- rrqAlwaysConfirm,
- rrqDenyAll
+ rrqGiveAll=acl_rule::rrqGrant,
+ rrqAlwaysConfirm=acl_rule::rrqPrompt,
+ rrqDenyAll=acl_rule::rrqDeny,
+ rrqFallback=acl_rule::rrqNone,
+ rrqGrant=rrqGiveAll, rrqDeny=rrqDenyAll, rrqPrompt=rrqAlwaysConfirm
};
enum {
- wrqTakeAll=0,
- wrqConfirmIfExists,
- wrqAlwaysConfirm,
- wrqDenyAll
+ wrqTakeAll=acl_rule::wrqGrant,
+ wrqConfirmIfExists=acl_rule::wrqPromptIfExists,
+ wrqAlwaysConfirm=acl_rule::wrqPrompt,
+ wrqDenyAll=acl_rule::wrqDeny,
+ wrqFallback=acl_rule::wrqNone,
+ wrqGrant=wrqTakeAll,wrqDeny=wrqDenyAll, wrqPrompt=wrqAlwaysConfirm
};
@@ -275,2 +432,3 @@ public:
enum { IDD = IDD_PUMPKIN_DIALOG };
+ CButton m_ListenCtl;
CButton m_AbortCtl;
@@ -312,2 +470,3 @@ protected:
afx_msg void OnTrayShowpumpkinwindow();
+ afx_msg void OnTrayListen();
afx_msg void OnTrayExit();
@@ -324,2 +483,3 @@ protected:
afx_msg void OnHelp();
+ afx_msg void OnListening();
//}}AFX_MSG