-rw-r--r-- | PumpKINDlg.cpp | 109 |
1 files changed, 101 insertions, 8 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index b6b8a36..4cb1633 100644 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp | |||
@@ -6,7 +6,9 @@ | |||
6 | #include "PumpKINDlg.h" | 6 | #include "PumpKINDlg.h" |
7 | 7 | ||
8 | #include "ACLTargetCombo.h" | ||
8 | #include "PropsServer.h" | 9 | #include "PropsServer.h" |
9 | #include "PropsNetwork.h" | 10 | #include "PropsNetwork.h" |
10 | #include "PropsSounds.h" | 11 | #include "PropsSounds.h" |
12 | #include "PropsACL.h" | ||
11 | #include "ConfirmRRQDlg.h" | 13 | #include "ConfirmRRQDlg.h" |
12 | #include "ConfirmWRQDlg.h" | 14 | #include "ConfirmWRQDlg.h" |
@@ -80,4 +82,8 @@ CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/) | |||
80 | : CDialog(CPumpKINDlg::IDD, pParent) | 82 | : CDialog(CPumpKINDlg::IDD, pParent) |
81 | { | 83 | { |
84 | m_Listener.m_Daddy = this; | ||
85 | |||
86 | m_bListen = TRUE; | ||
87 | |||
82 | m_ListenPort = 69; | 88 | m_ListenPort = 69; |
83 | m_bTFTPSubdirs = TRUE; | 89 | m_bTFTPSubdirs = TRUE; |
@@ -108,4 +114,13 @@ CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/) | |||
108 | m_Trayer = new CTrayer(this); | 114 | m_Trayer = new CTrayer(this); |
109 | ASSERT(m_Trayer); | 115 | ASSERT(m_Trayer); |
116 | /* Ensure we're backwards compatible */ | ||
117 | ASSERT(CPumpKINDlg::rrqGiveAll==0); | ||
118 | ASSERT(CPumpKINDlg::rrqAlwaysConfirm==1); | ||
119 | ASSERT(CPumpKINDlg::rrqDenyAll==2); | ||
120 | ASSERT(CPumpKINDlg::wrqTakeAll==0); | ||
121 | ASSERT(CPumpKINDlg::wrqConfirmIfExists==1); | ||
122 | ASSERT(CPumpKINDlg::wrqAlwaysConfirm==2); | ||
123 | ASSERT(CPumpKINDlg::wrqDenyAll==3); | ||
124 | /* -- */ | ||
110 | LoadSettings(); | 125 | LoadSettings(); |
111 | } | 126 | } |
@@ -115,4 +130,5 @@ void CPumpKINDlg::DoDataExchange(CDataExchange* pDX) | |||
115 | CDialog::DoDataExchange(pDX); | 130 | CDialog::DoDataExchange(pDX); |
116 | //{{AFX_DATA_MAP(CPumpKINDlg) | 131 | //{{AFX_DATA_MAP(CPumpKINDlg) |
132 | DDX_Control(pDX, IDC_LISTENING, m_ListenCtl); | ||
117 | DDX_Control(pDX, IDC_ABORT, m_AbortCtl); | 133 | DDX_Control(pDX, IDC_ABORT, m_AbortCtl); |
118 | DDX_Control(pDX, IDC_OPTIONS, m_OptionsCtl); | 134 | DDX_Control(pDX, IDC_OPTIONS, m_OptionsCtl); |
@@ -152,4 +168,6 @@ BEGIN_MESSAGE_MAP(CPumpKINDlg, CDialog) | |||
152 | ON_WM_DROPFILES() | 168 | ON_WM_DROPFILES() |
153 | ON_BN_CLICKED(ID_HELP, OnHelp) | 169 | ON_BN_CLICKED(ID_HELP, OnHelp) |
170 | ON_BN_CLICKED(IDC_LISTENING, OnListening) | ||
171 | ON_COMMAND(ID_TRAY_LISTEN, OnTrayListen) | ||
154 | //}}AFX_MSG_MAP | 172 | //}}AFX_MSG_MAP |
155 | END_MESSAGE_MAP() | 173 | END_MESSAGE_MAP() |
@@ -218,4 +236,6 @@ CRect rc, drc; | |||
218 | ShowWindow(SW_HIDE); | 236 | ShowWindow(SW_HIDE); |
219 | 237 | ||
238 | m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); | ||
239 | |||
220 | // CG: The following block was added by the ToolTips component. | 240 | // CG: The following block was added by the ToolTips component. |
221 | { | 241 | { |
@@ -325,9 +345,8 @@ int CPumpKINDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) | |||
325 | return -1; | 345 | return -1; |
326 | 346 | ||
327 | m_Listener.m_Daddy=this; | 347 | if(!m_Listener.SetListen(m_bListen)) { |
328 | if(!m_Listener.Create(m_ListenPort,SOCK_DGRAM)){ | 348 | m_bListen=FALSE; |
329 | TRACE0("Failed to create socket\n"); | 349 | TRACE0("Failed to create socket\n"); |
330 | AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); | 350 | AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); |
331 | return -1; | ||
332 | } | 351 | } |
333 | 352 | ||
@@ -665,10 +684,13 @@ CString lFile = localFile?localFile:m_FileName; | |||
665 | TurnSlashes(lFile,TRUE); | 684 | TurnSlashes(lFile,TRUE); |
666 | UpdateList(); | 685 | UpdateList(); |
667 | if(!localFile){// Check only if server | 686 | if(!localFile){// Check only for incoming requests |
668 | if(CheckBadRelativeness(m_FileName)){ | 687 | if(CheckBadRelativeness(m_FileName)){ |
669 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); | 688 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); |
670 | return TRUE; | 689 | return TRUE; |
671 | } | 690 | } |
672 | switch(m_Daddy->m_RRQMode){ | 691 | int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opRRQ,m_Peer.sin_addr.s_addr); |
692 | if(atar<0) | ||
693 | atar = m_Daddy->m_RRQMode; | ||
694 | switch(atar){ | ||
673 | case CPumpKINDlg::rrqGiveAll: | 695 | case CPumpKINDlg::rrqGiveAll: |
674 | break; | 696 | break; |
@@ -676,4 +698,6 @@ CString lFile = localFile?localFile:m_FileName; | |||
676 | if(ConfirmRequest()) | 698 | if(ConfirmRequest()) |
677 | break; | 699 | break; |
700 | default: | ||
701 | TRACE1("Unexpected access target: %d\n",atar); | ||
678 | case CPumpKINDlg::rrqDenyAll: | 702 | case CPumpKINDlg::rrqDenyAll: |
679 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); | 703 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); |
@@ -1108,5 +1132,5 @@ int i = m_Daddy->m_List.FindItem(&lvf); | |||
1108 | } | 1132 | } |
1109 | 1133 | ||
1110 | void CPumpKINDlg::LogLine(LPCTSTR str) | 1134 | void CPumpKINDlg::LogLineToScreen(LPCTSTR str) |
1111 | { | 1135 | { |
1112 | ASSERT(m_LogLength); | 1136 | ASSERT(m_LogLength); |
@@ -1164,4 +1188,5 @@ CPropsServer server; | |||
1164 | CPropsNetwork network; | 1188 | CPropsNetwork network; |
1165 | CPropsSounds sounds; | 1189 | CPropsSounds sounds; |
1190 | CPropsACL acl; | ||
1166 | 1191 | ||
1167 | server.m_RRQMode=m_RRQMode; | 1192 | server.m_RRQMode=m_RRQMode; |
@@ -1170,4 +1195,5 @@ CPropsSounds sounds; | |||
1170 | server.m_WRQMode=m_WRQMode; | 1195 | server.m_WRQMode=m_WRQMode; |
1171 | server.m_PromptTimeOut=m_PromptTimeOut; | 1196 | server.m_PromptTimeOut=m_PromptTimeOut; |
1197 | server.m_LogFile=m_LogFile; | ||
1172 | 1198 | ||
1173 | network.m_ListenPort=m_ListenPort; | 1199 | network.m_ListenPort=m_ListenPort; |
@@ -1180,7 +1206,10 @@ CPropsSounds sounds; | |||
1180 | sounds.m_Abort = m_bnwAbort; | 1206 | sounds.m_Abort = m_bnwAbort; |
1181 | 1207 | ||
1208 | acl.m_rulist = m_aclRules; | ||
1209 | |||
1182 | cps.AddPage(&server); | 1210 | cps.AddPage(&server); |
1183 | cps.AddPage(&network); | 1211 | cps.AddPage(&network); |
1184 | cps.AddPage(&sounds); | 1212 | cps.AddPage(&sounds); |
1213 | cps.AddPage(&acl); | ||
1185 | if(cps.DoModal()==IDOK){ | 1214 | if(cps.DoModal()==IDOK){ |
1186 | m_RRQMode=server.m_RRQMode; | 1215 | m_RRQMode=server.m_RRQMode; |
@@ -1189,4 +1218,5 @@ CPropsSounds sounds; | |||
1189 | m_WRQMode=server.m_WRQMode; | 1218 | m_WRQMode=server.m_WRQMode; |
1190 | m_PromptTimeOut=server.m_PromptTimeOut; | 1219 | m_PromptTimeOut=server.m_PromptTimeOut; |
1220 | m_LogFile=server.m_LogFile; | ||
1191 | 1221 | ||
1192 | m_ListenPort=network.m_ListenPort; | 1222 | m_ListenPort=network.m_ListenPort; |
@@ -1198,4 +1228,8 @@ CPropsSounds sounds; | |||
1198 | m_bnwSuccess = sounds.m_Success; | 1228 | m_bnwSuccess = sounds.m_Success; |
1199 | m_bnwAbort = sounds.m_Abort; | 1229 | m_bnwAbort = sounds.m_Abort; |
1230 | |||
1231 | m_aclRules = acl.m_rulist; | ||
1232 | |||
1233 | m_lastlogerr.Empty(); | ||
1200 | } | 1234 | } |
1201 | } | 1235 | } |
@@ -1245,6 +1279,8 @@ CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf); | |||
1245 | else | 1279 | else |
1246 | m_Rename=exists=FALSE; | 1280 | m_Rename=exists=FALSE; |
1247 | // *** m_WRQMode only if server transfer | 1281 | int atar=m_Daddy->m_aclRules.FindTarget(acl_rule::opWRQ,m_Peer.sin_addr.s_addr); |
1248 | switch(m_Daddy->m_WRQMode){ | 1282 | if(atar<0) |
1283 | atar=m_Daddy->m_WRQMode; | ||
1284 | switch(atar){ | ||
1249 | case CPumpKINDlg::wrqTakeAll: | 1285 | case CPumpKINDlg::wrqTakeAll: |
1250 | if(exists){ | 1286 | if(exists){ |
@@ -1269,4 +1305,6 @@ CString fn = localFile?ApplyRootGently(localFile):ApplyRoot(lf); | |||
1269 | break; | 1305 | break; |
1270 | } | 1306 | } |
1307 | default: | ||
1308 | TRACE1("Unexpected access target: %d\n",atar); | ||
1271 | case CPumpKINDlg::wrqDenyAll: | 1309 | case CPumpKINDlg::wrqDenyAll: |
1272 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); | 1310 | Deny(tftp::errAccessViolation,IDS_TFTP_ERROR_ACCESS); |
@@ -1796,4 +1834,5 @@ void CPumpKINDlg::LoadSettings() | |||
1796 | CWinApp *app = AfxGetApp(); | 1834 | CWinApp *app = AfxGetApp(); |
1797 | ASSERT(app); | 1835 | ASSERT(app); |
1836 | m_bListen=app->GetProfileInt("TFTPSettings","Listen",m_bListen); | ||
1798 | m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest); | 1837 | m_bnwRequest=app->GetProfileString("BellsNWhistles","Request",m_bnwRequest); |
1799 | m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess); | 1838 | m_bnwSuccess=app->GetProfileString("BellsNWhistles","Success",m_bnwSuccess); |
@@ -1806,4 +1845,5 @@ CWinApp *app = AfxGetApp(); | |||
1806 | m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); | 1845 | m_SpeakPort=app->GetProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); |
1807 | m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); | 1846 | m_TFTPRoot=app->GetProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); |
1847 | m_LogFile=app->GetProfileString("General","LogFile",m_LogFile); | ||
1808 | m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds())); | 1848 | m_TFTPTimeOut=CTimeSpan(app->GetProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds())); |
1809 | m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); | 1849 | m_BlockSize=app->GetProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); |
@@ -1817,4 +1857,5 @@ CWinApp *app = AfxGetApp(); | |||
1817 | } | 1857 | } |
1818 | ::SetCurrentDirectory(m_TFTPRoot); | 1858 | ::SetCurrentDirectory(m_TFTPRoot); |
1859 | m_aclRules.LoadProfile(app); | ||
1819 | } | 1860 | } |
1820 | 1861 | ||
@@ -1823,4 +1864,5 @@ void CPumpKINDlg::SaveSettings() | |||
1823 | CWinApp *app = AfxGetApp(); | 1864 | CWinApp *app = AfxGetApp(); |
1824 | ASSERT(app); | 1865 | ASSERT(app); |
1866 | app->WriteProfileInt("TFTPSettings","Listen",m_bListen); | ||
1825 | app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest); | 1867 | app->WriteProfileString("BellsNWhistles","Request",m_bnwRequest); |
1826 | app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess); | 1868 | app->WriteProfileString("BellsNWhistles","Success",m_bnwSuccess); |
@@ -1833,4 +1875,5 @@ CWinApp *app = AfxGetApp(); | |||
1833 | app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); | 1875 | app->WriteProfileInt("TFTPSettings","SpeakPort",m_SpeakPort); |
1834 | app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); | 1876 | app->WriteProfileString("TFTPSettings","TFTPRoot",m_TFTPRoot); |
1877 | app->WriteProfileString("General","LogFile",m_LogFile); | ||
1835 | app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()); | 1878 | app->WriteProfileInt("TFTPSettings","TFTPTimeout",m_TFTPTimeOut.GetTotalSeconds()); |
1836 | app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); | 1879 | app->WriteProfileInt("TFTPSettings","TFTPBlockSize",m_BlockSize); |
@@ -1838,4 +1881,5 @@ CWinApp *app = AfxGetApp(); | |||
1838 | app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode); | 1881 | app->WriteProfileInt("TFTPSettings","WRQMode",m_WRQMode); |
1839 | app->WriteProfileInt("UISettings","Visble",m_bShown); | 1882 | app->WriteProfileInt("UISettings","Visble",m_bShown); |
1883 | m_aclRules.SaveProfile(app); | ||
1840 | } | 1884 | } |
1841 | 1885 | ||
@@ -1985,2 +2029,51 @@ void CPumpKINDlg::OnHelp() | |||
1985 | AfxGetApp()->WinHelp(0,HELP_FINDER); | 2029 | AfxGetApp()->WinHelp(0,HELP_FINDER); |
1986 | } | 2030 | } |
2031 | |||
2032 | BOOL CListenSocket::SetListen(BOOL b) { | ||
2033 | ASSERT(m_Daddy); | ||
2034 | if(b==m_bListen) | ||
2035 | return TRUE; | ||
2036 | if(b) { | ||
2037 | if(!Create(m_Daddy->m_ListenPort,SOCK_DGRAM)) | ||
2038 | return FALSE; | ||
2039 | return m_bListen=TRUE; | ||
2040 | }else{ | ||
2041 | Close(); m_bListen=FALSE; | ||
2042 | return TRUE; | ||
2043 | } | ||
2044 | } | ||
2045 | |||
2046 | void CPumpKINDlg::OnListening() | ||
2047 | { | ||
2048 | if(!m_Listener.SetListen(m_ListenCtl.GetCheck()==1)) { | ||
2049 | TRACE0("Failed to create socket\n"); | ||
2050 | AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); | ||
2051 | } | ||
2052 | m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); | ||
2053 | m_bListen=m_Listener.m_bListen; | ||
2054 | } | ||
2055 | |||
2056 | void CPumpKINDlg::OnTrayListen() | ||
2057 | { | ||
2058 | if(!m_Listener.SetListen(!m_Listener.m_bListen)) { | ||
2059 | TRACE0("Failed to create socket\n"); | ||
2060 | AfxMessageBox(IDS_BOX_CANTBIND,MB_OK|MB_ICONEXCLAMATION); | ||
2061 | } | ||
2062 | m_ListenCtl.SetCheck(m_Listener.m_bListen?1:0); | ||
2063 | m_bListen=m_Listener.m_bListen; | ||
2064 | } | ||
2065 | |||
2066 | void CPumpKINDlg::LogLine(LPCTSTR str) | ||
2067 | { | ||
2068 | LogLineToScreen(str); | ||
2069 | if(!m_LogFile.IsEmpty()) { | ||
2070 | if(!Klever::LogRecord((LPCTSTR)m_LogFile,str)) { | ||
2071 | if(m_lastlogerr!=m_LogFile) { | ||
2072 | CString tmp; | ||
2073 | tmp.Format(IDS_LOG_LOGERROR,m_LogFile); | ||
2074 | LogLineToScreen(tmp); | ||
2075 | m_lastlogerr=m_LogFile; | ||
2076 | } | ||
2077 | } | ||
2078 | } | ||
2079 | } | ||