-rw-r--r-- | PropsACL.cpp | 290 |
1 files changed, 0 insertions, 290 deletions
diff --git a/PropsACL.cpp b/PropsACL.cpp deleted file mode 100644 index 6d918ad..0000000 --- a/PropsACL.cpp +++ b/dev/null | |||
@@ -1,290 +0,0 @@ | |||
1 | // PropsACL.cpp : implementation file | ||
2 | // | ||
3 | |||
4 | #include "stdafx.h" | ||
5 | #include "PumpKIN.h" | ||
6 | #include "PumpKINDlg.h" | ||
7 | #include "ACLTargetCombo.h" | ||
8 | #include "PropsACL.h" | ||
9 | |||
10 | #ifdef _DEBUG | ||
11 | #define new DEBUG_NEW | ||
12 | #undef THIS_FILE | ||
13 | static char THIS_FILE[] = __FILE__; | ||
14 | #endif | ||
15 | |||
16 | ///////////////////////////////////////////////////////////////////////////// | ||
17 | // CPropsACL property page | ||
18 | |||
19 | IMPLEMENT_DYNCREATE(CPropsACL, CPropertyPage) | ||
20 | |||
21 | CPropsACL::CPropsACL() : CPropertyPage(CPropsACL::IDD) | ||
22 | { | ||
23 | //{{AFX_DATA_INIT(CPropsACL) | ||
24 | //}}AFX_DATA_INIT | ||
25 | } | ||
26 | |||
27 | CPropsACL::~CPropsACL() | ||
28 | { | ||
29 | } | ||
30 | |||
31 | void CPropsACL::DoDataExchange(CDataExchange* pDX) | ||
32 | { | ||
33 | CPropertyPage::DoDataExchange(pDX); | ||
34 | //{{AFX_DATA_MAP(CPropsACL) | ||
35 | DDX_Control(pDX, IDC_ACL_REPLACE, m_ReplaceCtl); | ||
36 | DDX_Control(pDX, IDC_ACL_NETMASK, m_NetmaskCtl); | ||
37 | DDX_Control(pDX, IDC_ACL_XFER, m_XferCtl); | ||
38 | DDX_Control(pDX, IDC_ACL_UP, m_UpCtl); | ||
39 | DDX_Control(pDX, IDC_ACL_RULE, m_RuleCtl); | ||
40 | DDX_Control(pDX, IDC_ACL_REMOVE, m_RemoveCtl); | ||
41 | DDX_Control(pDX, IDC_ACL_LIST, m_ListCtl); | ||
42 | DDX_Control(pDX, IDC_ACL_DOWN, m_DownCtl); | ||
43 | DDX_Control(pDX, IDC_ACL_ADDR, m_AddrCtl); | ||
44 | DDX_Control(pDX, IDC_ACL_ADD, m_AddCtl); | ||
45 | //}}AFX_DATA_MAP | ||
46 | } | ||
47 | |||
48 | |||
49 | BEGIN_MESSAGE_MAP(CPropsACL, CPropertyPage) | ||
50 | //{{AFX_MSG_MAP(CPropsACL) | ||
51 | ON_CBN_SELCHANGE(IDC_ACL_XFER, OnSelchangeAclXfer) | ||
52 | ON_NOTIFY(LVN_ITEMCHANGED, IDC_ACL_LIST, OnItemchangedAclList) | ||
53 | ON_BN_CLICKED(IDC_ACL_ADD, OnAclAdd) | ||
54 | ON_BN_CLICKED(IDC_ACL_REPLACE, OnAclReplace) | ||
55 | ON_BN_CLICKED(IDC_ACL_REMOVE, OnAclRemove) | ||
56 | ON_BN_CLICKED(IDC_ACL_UP, OnAclUp) | ||
57 | ON_BN_CLICKED(IDC_ACL_DOWN, OnAclDown) | ||
58 | //}}AFX_MSG_MAP | ||
59 | END_MESSAGE_MAP() | ||
60 | |||
61 | ///////////////////////////////////////////////////////////////////////////// | ||
62 | // CPropsACL message handlers | ||
63 | |||
64 | BOOL CPropsACL::OnInitDialog() | ||
65 | { | ||
66 | CPropertyPage::OnInitDialog(); | ||
67 | |||
68 | m_FocusedRule=-1; | ||
69 | |||
70 | m_Images.Create(16,16,TRUE,2,1); | ||
71 | m_iRRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_RRQ)); | ||
72 | m_iWRQ = m_Images.Add(AfxGetApp()->LoadIcon(IDI_WRQ)); | ||
73 | ASSERT(m_iRRQ>=0); ASSERT(m_iWRQ>=0); | ||
74 | m_ListCtl.SetImageList(&m_Images,LVSIL_NORMAL); | ||
75 | m_ListCtl.SetImageList(&m_Images,LVSIL_SMALL); | ||
76 | m_ListCtl.SetImageList(&m_Images,LVSIL_STATE); | ||
77 | |||
78 | CRect lrc; m_ListCtl.GetClientRect(&lrc); | ||
79 | long lrcw3 = lrc.Width()/3; | ||
80 | m_ListCtl.InsertColumn(0,"IP",LVCFMT_LEFT,lrcw3,subitemIP); | ||
81 | m_ListCtl.InsertColumn(1,"netmask",LVCFMT_LEFT,lrcw3,subitemNM); | ||
82 | m_ListCtl.InsertColumn(2,"action",LVCFMT_LEFT,lrc.Width()-lrcw3*2,subitemAction); | ||
83 | |||
84 | m_UpCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_UP)); | ||
85 | m_DownCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_DOWN)); | ||
86 | m_RemoveCtl.SetIcon(AfxGetApp()->LoadIcon(IDI_REMOVE)); | ||
87 | |||
88 | m_XferCtl.SetItemData(0,tftp::opRRQ); | ||
89 | m_XferCtl.SetItemData(1,tftp::opWRQ); | ||
90 | |||
91 | m_AddrCtl.SetWindowText("192.168.0.0"); | ||
92 | m_NetmaskCtl.SetWindowText("255.255.255.0"); | ||
93 | |||
94 | for(int i=0;i<m_rulist.GetSize();++i) { | ||
95 | m_ListCtl.InsertItem(i,0); | ||
96 | SetListRule(i,m_rulist[i]); | ||
97 | } | ||
98 | |||
99 | UpdateControls(); | ||
100 | |||
101 | return TRUE; // return TRUE unless you set the focus to a control | ||
102 | // EXCEPTION: OCX Property Pages should return FALSE | ||
103 | } | ||
104 | |||
105 | void CPropsACL::OnSelchangeAclXfer() { | ||
106 | int cs = m_XferCtl.GetCurSel(); | ||
107 | if(cs==CB_ERR) { | ||
108 | m_RuleCtl.EnableWindow(FALSE); | ||
109 | }else{ | ||
110 | int rq = m_XferCtl.GetItemData(cs); | ||
111 | m_RuleCtl.SetOp(rq); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | void CPropsACL::OnItemchangedAclList(NMHDR* pNMHDR, LRESULT* pResult) { | ||
116 | NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; | ||
117 | if( | ||
118 | (pNMListView->uChanged&LVIF_STATE) | ||
119 | && | ||
120 | (pNMListView->uNewState&LVIS_FOCUSED)!=(pNMListView->uOldState&LVIS_FOCUSED) | ||
121 | && | ||
122 | pNMListView->iItem>=0 && pNMListView->iItem<m_ListCtl.GetItemCount() | ||
123 | ){ | ||
124 | if(pNMListView->uNewState&LVIS_FOCUSED) | ||
125 | m_FocusedRule=pNMListView->iItem; | ||
126 | else if(pNMListView->iItem==m_FocusedRule) | ||
127 | m_FocusedRule=-1; | ||
128 | UpdateControls(); | ||
129 | } | ||
130 | |||
131 | *pResult = 0; | ||
132 | } | ||
133 | |||
134 | void CPropsACL::UpdateControls() { | ||
135 | if(m_FocusedRule>=m_rulist.GetSize()) | ||
136 | m_FocusedRule=-1; | ||
137 | if(m_FocusedRule>=0) { | ||
138 | m_UpCtl.EnableWindow(m_FocusedRule>0); | ||
139 | m_DownCtl.EnableWindow(m_FocusedRule<(m_ListCtl.GetItemCount()-1)); | ||
140 | acl_rule r; | ||
141 | GetListRule(m_FocusedRule,r); | ||
142 | SetRule(r); | ||
143 | m_AddCtl.EnableWindow(TRUE); | ||
144 | m_ReplaceCtl.EnableWindow(TRUE); | ||
145 | }else{ | ||
146 | OnSelchangeAclXfer(); | ||
147 | m_AddCtl.EnableWindow(TRUE); | ||
148 | m_ReplaceCtl.EnableWindow(FALSE); | ||
149 | } | ||
150 | m_RemoveCtl.EnableWindow(m_ListCtl.GetSelectedCount()!=0 || m_FocusedRule>=0); | ||
151 | } | ||
152 | |||
153 | void CPropsACL::OnAclAdd() { | ||
154 | acl_rule r; | ||
155 | UINT err=GetRule(r); | ||
156 | if(err) { | ||
157 | AfxMessageBox(err,MB_OK); | ||
158 | }else{ | ||
159 | int i=m_rulist.AppendRule(r); | ||
160 | ASSERT(r.op==acl_rule::opRRQ || r.op==acl_rule::opWRQ); | ||
161 | m_ListCtl.InsertItem(i,0); | ||
162 | SetListRule(i,r); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | void CPropsACL::OnAclReplace() { | ||
167 | acl_rule r; | ||
168 | UINT err=GetRule(r); | ||
169 | if(err) { | ||
170 | AfxMessageBox(err,MB_OK); | ||
171 | }else{ | ||
172 | ASSERT(m_FocusedRule>=0); | ||
173 | m_rulist[m_FocusedRule]=r; | ||
174 | SetListRule(m_FocusedRule,r); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | int CPropsACL::GetOp() { | ||
179 | int cs=m_XferCtl.GetCurSel(); | ||
180 | if(cs==CB_ERR) | ||
181 | return -1; | ||
182 | else | ||
183 | return m_XferCtl.GetItemData(cs); | ||
184 | } | ||
185 | |||
186 | void CPropsACL::SetOp(int op) { | ||
187 | int os=m_XferCtl.GetCount(); | ||
188 | for(int i=0;i<os;++i) { | ||
189 | if(m_XferCtl.GetItemData(i)==op) { | ||
190 | m_XferCtl.SetCurSel(i); | ||
191 | return; | ||
192 | } | ||
193 | } | ||
194 | m_XferCtl.SetCurSel(-1); | ||
195 | } | ||
196 | |||
197 | void CPropsACL::SetListRule(int i,acl_rule& r) { | ||
198 | m_ListCtl.SetItem(i,subitemIP,LVIF_TEXT|LVIF_IMAGE,r.str_addr(),(r.op==acl_rule::opRRQ)?m_iRRQ:m_iWRQ,0,0,0); | ||
199 | m_ListCtl.SetItemText(i,subitemNM,r.str_mask()); | ||
200 | m_ListCtl.SetItemText(i,subitemAction,r.str_target()); | ||
201 | } | ||
202 | |||
203 | void CPropsACL::SetRule(acl_rule& r) { | ||
204 | SetOp(r.op); | ||
205 | m_AddrCtl.SetWindowText(r.str_addr()); | ||
206 | m_NetmaskCtl.SetWindowText(r.str_mask()); | ||
207 | m_RuleCtl.SetTarget(r.target,r.op); | ||
208 | } | ||
209 | |||
210 | void CPropsACL::GetListRule(int i,acl_rule& r) { | ||
211 | r = m_rulist[i]; | ||
212 | } | ||
213 | |||
214 | UINT CPropsACL::GetRule(acl_rule& r) | ||
215 | { | ||
216 | UINT rv=0; | ||
217 | r.op=GetOp(); | ||
218 | if(r.op!=acl_rule::opRRQ && r.op!=acl_rule::opWRQ) | ||
219 | rv=IDS_NO_XFER_OP; | ||
220 | else{ | ||
221 | CString t; | ||
222 | m_AddrCtl.GetWindowText(t); | ||
223 | if(t.IsEmpty() || ( (r.addr=inet_addr((LPCSTR)t))==INADDR_NONE && t!="255.255.255.255") ) | ||
224 | rv=IDS_INVALID_IP; | ||
225 | else{ | ||
226 | m_NetmaskCtl.GetWindowText(t); | ||
227 | if(t.IsEmpty() || ( (r.mask=inet_addr((LPCSTR)t))==INADDR_NONE && t!="255.255.255.255") ) | ||
228 | rv=IDS_INVALID_NETMASK; | ||
229 | else{ | ||
230 | r.target=m_RuleCtl.GetTarget(); | ||
231 | if(!r.IsValid()) | ||
232 | rv=IDS_INVALID_RULE; | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | return rv; | ||
237 | } | ||
238 | |||
239 | void CPropsACL::OnAclRemove() { | ||
240 | ASSERT(m_FocusedRule>=0); | ||
241 | int fr=m_FocusedRule; | ||
242 | if(fr<0 || fr>=m_rulist.GetSize()) return; | ||
243 | m_rulist.DeleteRule(fr); | ||
244 | m_ListCtl.DeleteItem(fr); | ||
245 | ASSERT(m_rulist.GetSize()==m_ListCtl.GetItemCount()); | ||
246 | if(fr>=m_rulist.GetSize()) { | ||
247 | if(fr>0) { | ||
248 | fr=m_rulist.GetSize()-1; | ||
249 | } | ||
250 | }else | ||
251 | fr=-1; | ||
252 | if(fr>0) | ||
253 | SetListFocusSelection(fr); | ||
254 | m_ListCtl.SetFocus(); | ||
255 | } | ||
256 | |||
257 | void CPropsACL::OnAclUp() { | ||
258 | int s=m_FocusedRule; | ||
259 | if(s<=0) return; | ||
260 | int d=s-1; | ||
261 | acl_rule r=m_rulist[s]; | ||
262 | m_rulist[s]=m_rulist[d]; | ||
263 | m_rulist[d]=r; | ||
264 | SetListRule(d,m_rulist[d]); | ||
265 | SetListRule(s,m_rulist[s]); | ||
266 | SetListFocusSelection(d); | ||
267 | m_ListCtl.SetFocus(); | ||
268 | } | ||
269 | |||
270 | void CPropsACL::OnAclDown() { | ||
271 | int s=m_FocusedRule; | ||
272 | int d=s+1; | ||
273 | if(s<0 || d>=m_rulist.GetSize()) return; | ||
274 | acl_rule r=m_rulist[s]; | ||
275 | m_rulist[s]=m_rulist[d]; | ||
276 | m_rulist[d]=r; | ||
277 | SetListRule(d,m_rulist[d]); | ||
278 | SetListRule(s,m_rulist[s]); | ||
279 | SetListFocusSelection(d); | ||
280 | m_ListCtl.SetFocus(); | ||
281 | } | ||
282 | |||
283 | void CPropsACL::SetListFocusSelection(int i) { | ||
284 | int s=m_ListCtl.GetItemCount(); | ||
285 | for(int t=0;t<s;++t) | ||
286 | if(t!=i) | ||
287 | m_ListCtl.SetItemState(t,0,LVIS_FOCUSED|LVIS_SELECTED); | ||
288 | m_ListCtl.SetItemState(i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); | ||
289 | } | ||
290 | |||