BOServerDlg.cpp
上传用户:jinandeyu
上传日期:2007-01-05
资源大小:620k
文件大小:21k
源码类别:

远程控制编程

开发平台:

WINDOWS

  1. /*  Back Orifice 2000 - Remote Administration Suite
  2.     Copyright (C) 1999, Cult Of The Dead Cow
  3.     This program is free software; you can redistribute it and/or modify
  4.     it under the terms of the GNU General Public License as published by
  5.     the Free Software Foundation; either version 2 of the License, or
  6.     (at your option) any later version.
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.     You should have received a copy of the GNU General Public License
  12.     along with this program; if not, write to the Free Software
  13.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. The author of this program may be contacted at dildog@l0pht.com. */
  15. // BOServerDlg.cpp : implementation file
  16. //
  17. #include "stdafx.h"
  18. #include "bo2kgui.h"
  19. #include "BOServerDlg.h"
  20. #include "BODialogBar.h"
  21. #include "MainFrm.h"
  22. #include "QueryDlg.h"
  23. #include "NewMachineDlg.h"
  24. #include "resource.h"
  25. #include <auth.h>
  26. #include <iohandler.h>
  27. #include <commnet.h>
  28. #include <comm_native.h>
  29. #include <strhandle.h>
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. #define HISTORY_LENGTH 16
  36. int g_nBOServerColor=0;
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CBOServerDlg dialog
  39. CBOServerDlg::CBOServerDlg(CWnd* pParent /*=NULL*/)
  40. : CGradientDialog(CBOServerDlg::IDD, pParent)
  41. {
  42. //{{AFX_DATA_INIT(CBOServerDlg)
  43. // NOTE: the ClassWizard will add member initialization here
  44. //}}AFX_DATA_INIT
  45. m_bGrad=FALSE;
  46. m_bGenerated=FALSE;
  47. m_bIsConnected=FALSE;
  48. m_pAuthSocket=NULL;
  49. m_bHandleNetwork=TRUE;
  50. m_cwtListenThread=NULL;
  51. InitializeCriticalSection(&m_NetCritSec);
  52. }
  53. CBOServerDlg::~CBOServerDlg()
  54. {
  55. DeleteCriticalSection(&m_NetCritSec);
  56. if(m_cwtListenThread!=NULL) delete m_cwtListenThread;
  57. }
  58. void CBOServerDlg::DoDataExchange(CDataExchange* pDX)
  59. {
  60. CGradientDialog::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CBOServerDlg)
  62. // NOTE: the ClassWizard will add DDX and DDV calls here
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CBOServerDlg, CGradientDialog)
  66. //{{AFX_MSG_MAP(CBOServerDlg)
  67. ON_BN_CLICKED(IDC_DOCKING, OnAllowDocking)
  68. ON_BN_CLICKED(IDC_CONNECTCHECK, OnConnectcheck)
  69. ON_NOTIFY(TVN_SELCHANGED, IDC_SERVERCOMMANDS, OnSelchangedServercommands)
  70. ON_BN_CLICKED(IDC_SENDCOMMAND, OnSendcommand)
  71. ON_BN_CLICKED(IDC_CLEARRESPONSES, OnClearResponses)
  72. ON_WM_SIZE()
  73. ON_WM_SHOWWINDOW()
  74. ON_BN_CLICKED(IDC_SETTINGS, OnSettings)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CBOServerDlg message handlers
  79. void CBOServerDlg::OnOK()
  80. {
  81. }
  82. void CBOServerDlg::OnCancel()
  83. {
  84. }
  85. void CBOServerDlg::OnAllowDocking() 
  86. {
  87. CButton *btn;
  88. btn=(CButton *)GetDlgItem(IDC_DOCKING);
  89. if(btn->GetCheck()) {
  90. ((CBODialogBar *)GetParent())->EnableDocking(CBRS_ALIGN_ANY);
  91. } else {
  92. ((CBODialogBar *)GetParent())->EnableDocking(0);
  93. ((CBODialogBar *)GetParent())->m_pDockContext->ToggleDocking();
  94. }
  95. }
  96. BOOL CBOServerDlg::OnInitDialog() 
  97. {
  98. CGradientDialog::OnInitDialog();
  99. m_HistFont.CreatePointFont(86,"Courier New",NULL);
  100. // Subclass dialog items
  101. m_HistEdit.SubclassDlgItem(IDC_SERVERRESPONSE,this);
  102. m_HistEdit.AllowSelection(TRUE);
  103. m_HistEdit.SetFont(&m_HistFont,TRUE);
  104. // Initalize command list
  105. m_CmdDescList.SetNativeCommands();
  106. CButton *dok=(CButton *)GetDlgItem(IDC_DOCKING);
  107. dok->SetCheck(0);
  108. ((CBODialogBar *)GetParent())->EnableDocking(0);
  109. m_TreeImageList.Create(IDB_CMDTREE_IMAGELIST,16,8,RGB(0,255,0));
  110. CTreeCtrl *pTree=(CTreeCtrl *)GetDlgItem(IDC_SERVERCOMMANDS);
  111. pTree->SetImageList(&m_TreeImageList,TVSIL_NORMAL);
  112. m_CmdDescList.FillTreeCtrl(pTree);
  113. UpdateDialog();
  114. // Set Checks
  115. CButton *cqc=(CButton *)GetDlgItem(IDC_QUERYONCONNECT);
  116. cqc->SetCheck(1);
  117. // Set icons
  118. CButton *csb=(CButton *)GetDlgItem(IDC_SETTINGS);
  119. csb->SetIcon(AfxGetApp()->LoadIcon(IDI_EDITMACHINE));
  120. return TRUE;  // return TRUE unless you set the focus to a control
  121.               // EXCEPTION: OCX Property Pages should return FALSE
  122. }
  123. BOOL CBOServerDlg::DestroyWindow() 
  124. {
  125. m_bIsConnected=FALSE;
  126. if(m_cwtListenThread!=NULL) {
  127. WaitForSingleObject(m_cwtListenThread->m_hThread,INFINITE);
  128. delete m_cwtListenThread;
  129. m_cwtListenThread=NULL;
  130. }
  131. if(m_pAuthSocket) {
  132. if(m_pAuthSocket->Close()==-1) {
  133. AfxMessageBox("Could not close IOSocket.nTerminating Anyway.n");
  134. }
  135. delete m_pAuthSocket;
  136. }
  137. return CGradientDialog::DestroyWindow();
  138. }
  139. void CBOServerDlg::UpdateDialog(void)
  140. {
  141. CString txt;
  142. txt+="  Name: ";
  143. txt+=m_ServerInfo.svName;
  144. txt+="rn";
  145. txt+="  Addr: ";
  146. txt+=m_ServerInfo.svAddress;
  147. GetDlgItem(IDC_MACHINEINFO)->SetWindowText(txt);
  148. }
  149. void CBOServerDlg::UseGradient(BOOL bGrad)
  150. {
  151. m_bGrad=bGrad;
  152. if(bGrad) {
  153. if(!m_bGenerated) {
  154. COLORREF dwFace=GetSysColor(COLOR_3DFACE);
  155. COLORREF dwLight=GetSysColor(COLOR_3DHILIGHT);
  156. COLORREF dwShadow=GetSysColor(COLOR_3DSHADOW);
  157. COLORREF dwFadeFace=dwFace;
  158. COLORREF dwFadeLight=RGB(255-((255-GetRValue(dwLight))/2),
  159. 255-((255-GetGValue(dwLight))/2),
  160. 255-((255-GetBValue(dwLight))/2));
  161. COLORREF dwFadeShadow=RGB(GetRValue(dwShadow)/2,
  162. GetGValue(dwShadow)/2,
  163. GetBValue(dwShadow)/2);
  164. int nOrient;
  165. if(g_nBOServerColor==0)      { m_c1=dwFace; m_c2=dwLight; nOrient=1; }
  166. else if(g_nBOServerColor==1) { m_c1=dwShadow; m_c2=dwFace; nOrient=1; }
  167. else if(g_nBOServerColor==2) { m_c1=dwFadeFace; m_c2=dwFadeLight; nOrient=1;}
  168. else { m_c1=dwFadeShadow; m_c2=dwFadeFace; nOrient=1; }
  169. g_nBOServerColor++;
  170. if(g_nBOServerColor>3) g_nBOServerColor=0;
  171. SetGradient(m_c1,m_c2,nOrient);
  172. m_bGenerated=TRUE;
  173. }
  174. else m_bGradient=TRUE;
  175. }
  176. else m_bGradient=FALSE;
  177. }
  178. void CBOServerDlg::OnConnectcheck() 
  179. {
  180. EnterCriticalSection(&m_NetCritSec);
  181. CButton *pbCC=(CButton *)GetDlgItem(IDC_CONNECTCHECK);
  182. CButton *pbSC=(CButton *)GetDlgItem(IDC_SENDCOMMAND);
  183. if(pbCC->GetCheck()) {
  184. pbCC->EnableWindow(FALSE);
  185. pbCC->SetWindowText("Connecting...");
  186. // Create socket and connect
  187. m_pAuthSocket=ConnectAuthSocket(NULL,0,GetSafeHwnd(),
  188. m_ServerInfo.svAddress,
  189. m_ServerInfo.svConnectionType,
  190. m_ServerInfo.svEncryption,
  191. m_ServerInfo.svAuthentication);
  192. if(m_pAuthSocket==NULL) {
  193. pbCC->SetWindowText("Connect");
  194. pbCC->SetCheck(0);
  195. pbCC->EnableWindow();
  196. LeaveCriticalSection(&m_NetCritSec);
  197. return;
  198. }
  199. if(m_pAuthSocket==(CAuthSocket *)0xFFFFFFFF) {
  200. m_pAuthSocket=NULL;
  201. pbCC->SetWindowText("Connect");
  202. pbCC->SetCheck(0);
  203. pbCC->EnableWindow();
  204. MessageBox("Could not connect to remote machine.n","Connection Error",MB_ICONWARNING|MB_OK|MB_TOPMOST|MB_SETFOREGROUND);
  205. LeaveCriticalSection(&m_NetCritSec);
  206. return;
  207. }
  208. // Create socket listener thread to handle asynchronous receives.
  209. m_bIsConnected=TRUE;
  210. m_cwtListenThread=AfxBeginThread(ServerListenThread,this);
  211. m_cwtListenThread->m_bAutoDelete=FALSE;
  212. m_cwtListenThread->SetThreadPriority(THREAD_PRIORITY_LOWEST);
  213. if(m_cwtListenThread==NULL) {
  214. m_pAuthSocket->Close();
  215. m_bIsConnected=FALSE;
  216. delete m_pAuthSocket;
  217. m_pAuthSocket=NULL;
  218. pbCC->SetWindowText("Connect");
  219. pbCC->SetCheck(0);
  220. pbCC->EnableWindow();
  221. MessageBox("Could not create thread.nYour system may be misbehaving.n","System Error",MB_ICONWARNING|MB_OK|MB_TOPMOST|MB_SETFOREGROUND);
  222. LeaveCriticalSection(&m_NetCritSec);
  223. return;
  224. }
  225. // Report that we are happy
  226. pbCC->SetWindowText("Disconnect");
  227. pbCC->EnableWindow();
  228. pbSC->EnableWindow();
  229. // Check for 'Auto-Query'
  230. CButton *cqc=(CButton *)GetDlgItem(IDC_QUERYONCONNECT);
  231. if(cqc->GetCheck()==1) {
  232. if(PerformQuery()<0) {
  233. MessageBox("Error sending command. Connection to remote machine may be broken.","Network Poll Error",MB_ICONSTOP|MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
  234. }
  235. }
  236. } else {
  237. pbCC->EnableWindow(FALSE);
  238. pbCC->SetWindowText("Disconnecting...");
  239. // Close listening thread
  240. m_bIsConnected=FALSE;
  241. if(m_cwtListenThread!=NULL) {
  242. LeaveCriticalSection(&m_NetCritSec);
  243. WaitForSingleObject(m_cwtListenThread->m_hThread,INFINITE);
  244. EnterCriticalSection(&m_NetCritSec);
  245. delete m_cwtListenThread;
  246. m_cwtListenThread=NULL;
  247. }
  248. // Disconnect socket and destroy
  249. if(m_pAuthSocket->Close()==-1) {
  250. pbCC->SetWindowText("Disconnect");
  251. pbCC->SetCheck(1);
  252. pbCC->EnableWindow();
  253. MessageBox("Could not close connection.nYour network may be misbehaving, ornthe server has become unresponsive.n","Network Error",MB_ICONWARNING|MB_OK|MB_TOPMOST|MB_SETFOREGROUND);
  254. LeaveCriticalSection(&m_NetCritSec);
  255. return;
  256. }
  257. delete m_pAuthSocket;
  258. m_pAuthSocket=NULL;
  259. pbCC->SetWindowText("Connect");
  260. pbCC->EnableWindow();
  261. pbSC->EnableWindow(FALSE);
  262. }
  263. LeaveCriticalSection(&m_NetCritSec);
  264. }
  265. void CBOServerDlg::OnSelchangedServercommands(NMHDR* pNMHDR, LRESULT* pResult) 
  266. {
  267. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  268. int command;
  269. command=pNMTreeView->itemNew.lParam;
  270. if(command==-1) {
  271. GetDlgItem(IDC_STATIC_OPT1)->ShowWindow(SW_HIDE);
  272. GetDlgItem(IDC_STATIC_OPT2)->ShowWindow(SW_HIDE);
  273. GetDlgItem(IDC_STATIC_OPT3)->ShowWindow(SW_HIDE);
  274. GetDlgItem(IDC_OPT1)->ShowWindow(SW_HIDE);
  275. GetDlgItem(IDC_OPT2)->ShowWindow(SW_HIDE);
  276. GetDlgItem(IDC_OPT3)->ShowWindow(SW_HIDE);
  277. }
  278. else {
  279. char *arg;
  280. arg=m_CmdDescList.GetArgDesc1(command);
  281. if(arg) {
  282. GetDlgItem(IDC_STATIC_OPT1)->ShowWindow(SW_HIDE);
  283. GetDlgItem(IDC_STATIC_OPT1)->SetWindowText(arg);
  284. GetDlgItem(IDC_STATIC_OPT1)->ShowWindow(SW_SHOW);
  285. GetDlgItem(IDC_OPT1)->ShowWindow(SW_SHOW);
  286. } else {
  287. GetDlgItem(IDC_STATIC_OPT1)->ShowWindow(SW_HIDE);
  288. GetDlgItem(IDC_OPT1)->ShowWindow(SW_HIDE);
  289. }
  290. arg=m_CmdDescList.GetArgDesc2(command);
  291. if(arg) {
  292. GetDlgItem(IDC_STATIC_OPT2)->ShowWindow(SW_HIDE);
  293. GetDlgItem(IDC_STATIC_OPT2)->SetWindowText(arg);
  294. GetDlgItem(IDC_STATIC_OPT2)->ShowWindow(SW_SHOW);
  295. GetDlgItem(IDC_OPT2)->ShowWindow(SW_SHOW);
  296. } else {
  297. GetDlgItem(IDC_STATIC_OPT2)->ShowWindow(SW_HIDE);
  298. GetDlgItem(IDC_OPT2)->ShowWindow(SW_HIDE);
  299. }
  300. arg=m_CmdDescList.GetArgDesc3(command);
  301. if(arg) {
  302. GetDlgItem(IDC_STATIC_OPT3)->ShowWindow(SW_HIDE);
  303. GetDlgItem(IDC_STATIC_OPT3)->SetWindowText(arg);
  304. GetDlgItem(IDC_STATIC_OPT3)->ShowWindow(SW_SHOW);
  305. GetDlgItem(IDC_OPT3)->ShowWindow(SW_SHOW);
  306. } else {
  307. GetDlgItem(IDC_STATIC_OPT3)->ShowWindow(SW_HIDE);
  308. GetDlgItem(IDC_OPT3)->ShowWindow(SW_HIDE);
  309. }
  310. }
  311. *pResult = 0;
  312. }
  313. void CBOServerDlg::SetServerInfo(SERVER_INFO *si)
  314. {
  315. m_ServerInfo=*si;
  316. }
  317. void CBOServerDlg::OnSendcommand() 
  318. {
  319. EnterCriticalSection(&m_NetCritSec);
  320. if(m_bIsConnected) {
  321. CTreeCtrl *pTree;
  322. int nCommand,ret;
  323. HTREEITEM hti;
  324. pTree=(CTreeCtrl *)GetDlgItem(IDC_SERVERCOMMANDS);
  325. if(pTree==NULL) {
  326. LeaveCriticalSection(&m_NetCritSec);
  327. return;
  328. }
  329. hti=pTree->GetSelectedItem();
  330. if(hti==NULL) {
  331. AfxMessageBox("You need to select an appropriate command.n",MB_OK|MB_ICONWARNING|MB_TOPMOST|MB_SETFOREGROUND);
  332. LeaveCriticalSection(&m_NetCritSec);
  333. return;
  334. }
  335. nCommand=pTree->GetItemData(hti);
  336. if(nCommand==-1) {
  337. AfxMessageBox("You need to select an appropriate command.n",MB_OK|MB_ICONWARNING|MB_TOPMOST|MB_SETFOREGROUND);
  338. LeaveCriticalSection(&m_NetCritSec);
  339. return;
  340. }
  341. CEdit *pEBArg1;
  342. CComboBox *pCBArg2,*pCBArg3;
  343. int nArg1;
  344. char svArg1[1024],svArg2[1024],svArg3[1024];
  345. pEBArg1=(CEdit *)GetDlgItem(IDC_OPT1);
  346. pCBArg2=(CComboBox *)GetDlgItem(IDC_OPT2);
  347. pCBArg3=(CComboBox *)GetDlgItem(IDC_OPT3);
  348. // Store entries into list
  349. if(pEBArg1->IsWindowVisible() && pEBArg1->GetWindowTextLength()!=0) {
  350. pEBArg1->GetWindowText(svArg1,1024);
  351. nArg1=atoi(svArg1);
  352. }
  353. else nArg1=0;
  354. if(pCBArg2->IsWindowVisible() && pCBArg2->GetWindowTextLength()!=0) {
  355. if(pCBArg2->GetCount()==HISTORY_LENGTH) {
  356. pCBArg2->DeleteString(HISTORY_LENGTH-1);
  357. }
  358. pCBArg2->GetWindowText(svArg2,1024);
  359. pCBArg2->InsertString(0,svArg2);
  360. }
  361. else svArg2[0]='';
  362. if(pCBArg3->IsWindowVisible()) {
  363. if(pCBArg3->GetCount()==HISTORY_LENGTH) {
  364. pCBArg3->DeleteString(HISTORY_LENGTH-1);
  365. }
  366. pCBArg3->GetWindowText(svArg3,1024);
  367. pCBArg3->InsertString(0,svArg3);
  368. }
  369. else svArg3[0]='';
  370. // Send command
  371. switch(nCommand) {
  372. case BO_PING:
  373. ret=IssueAuthCommandRequest(m_pAuthSocket,BO_PING,GetTickCount(),0,m_ServerInfo.svAddress,NULL);
  374. break;
  375. case BO_QUERY:
  376. ret=PerformQuery();
  377. break;
  378. default:
  379. ret=IssueAuthCommandRequest(m_pAuthSocket,nCommand,GetTickCount(),nArg1,svArg2,svArg3);
  380. break;
  381. }
  382. if(ret<0) {
  383. AfxMessageBox("Error sending command. Connection to remote machine may be broken.",MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);
  384. }
  385. }
  386. LeaveCriticalSection(&m_NetCritSec);
  387. }
  388. void CBOServerDlg::OnClearResponses() 
  389. {
  390. // Get edit control to display response
  391. CHistoryEdit *pEdt=(CHistoryEdit *)GetDlgItem(IDC_SERVERRESPONSE);
  392. if(pEdt==NULL) return;
  393. pEdt->SetWindowText("");
  394. }
  395. UINT ServerListenThread(LPVOID pParam)
  396. {
  397. CBOServerDlg *pThis=(CBOServerDlg *)pParam;
  398. while(pThis->m_bIsConnected) {
  399. pThis->HandleNetworkPoll();
  400. Sleep(20);
  401. }
  402. return 0;
  403. }
  404. void CBOServerDlg::HandleNetworkPoll(void)
  405. {
  406. BYTE *pBuffer;
  407. int nBufLen,ret;
  408. // Check connected socket
  409. do {
  410. EnterCriticalSection(&m_NetCritSec);
  411. ret=m_pAuthSocket->Recv(&pBuffer,&nBufLen);
  412. LeaveCriticalSection(&m_NetCritSec);
  413. if(ret<0) {
  414. CButton *pbCC=(CButton *)GetDlgItem(IDC_CONNECTCHECK);
  415. pbCC->PostMessage(BM_CLICK);
  416. }
  417. if(ret>0) {
  418. // Break down command into response
  419. int cmdlen,command,comid,nArg1;
  420. char *svArg2,*svArg3;
  421. BreakDownCommand(pBuffer,&cmdlen,&command,&comid,&nArg1,&svArg2,&svArg3);
  422. if(svArg2!=NULL) {
  423. HandleCommandResponse(svArg2);
  424. }
  425. if(nArg1==2) {
  426. CButton *cqc=(CButton *)GetDlgItem(IDC_QUERYONCONNECT);
  427. if(cqc->GetCheck()==1) {
  428. EnterCriticalSection(&m_NetCritSec);
  429. if(PerformQuery()<0) {
  430. MessageBox("Error sending command. Connection to remote machine may be broken.","Network Poll Error",MB_ICONSTOP|MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
  431. }
  432. LeaveCriticalSection(&m_NetCritSec);
  433. }
  434. }
  435. m_pAuthSocket->Free(pBuffer);
  436. }
  437. } while(ret>0);
  438. }
  439. void CBOServerDlg::HandleCommandResponse(char *svArg2)
  440. {
  441. // Get edit control to display response
  442. CHistoryEdit *pEdt=(CHistoryEdit *)GetDlgItem(IDC_SERVERRESPONSE);
  443. if(pEdt==NULL) return;
  444. // Get number of lines originally
  445. int nLineOrig=pEdt->GetLineCount();
  446. // Get original window text
  447. CString strText;
  448. pEdt->GetWindowText(strText);
  449. // Put append text to the edit control
  450. pEdt->AppendString(svArg2);
  451. }
  452. int CBOServerDlg::PerformQuery()
  453. {
  454. int cmd_comid,nBufLen,ret;
  455. BYTE *pBuffer;
  456. int cmdlen,command,comid,nArg1;
  457. char *svArg2,*svArg3;
  458. cmd_comid=GetTickCount();
  459. ret=IssueAuthCommandRequest(m_pAuthSocket,BO_QUERY,cmd_comid,0,NULL,NULL);
  460. if(ret<0) {
  461. LeaveCriticalSection(&m_NetCritSec);
  462. return -1;
  463. }
  464. QueryDlg qd;
  465. qd.Create(IDD_QUERYDLG,AfxGetMainWnd());
  466. qd.ShowWindow(SW_SHOW);
  467. m_CmdDescList.SetNativeCommands();
  468. // Check connected socket
  469. nArg1=1;
  470. int nQSec=0;
  471. do {
  472. MSG msg;
  473. if(PeekMessage(&msg,qd.GetSafeHwnd(),0,0,PM_NOREMOVE)) {
  474. GetMessage(&msg,qd.GetSafeHwnd(),0,0);
  475. DispatchMessage(&msg);
  476. }
  477. ret=m_pAuthSocket->Recv(&pBuffer,&nBufLen);
  478. if(ret<0) {
  479. m_pAuthSocket->Free(pBuffer);
  480. return -1;
  481. }
  482. if(ret>0) {
  483. BreakDownCommand(pBuffer,&cmdlen,&command,&comid,&nArg1,&svArg2,&svArg3);
  484. if(svArg2==NULL) {
  485. m_pAuthSocket->Free(pBuffer);
  486. return -1;
  487. }
  488. if(command==-1 && comid==cmd_comid) {
  489. if(strncmp(svArg2,"--> Version:",12)==0) {
  490. nQSec=0;
  491. HandleCommandResponse(svArg2);
  492. } else if(strncmp(svArg2,"--> Extension Commands:",23)==0) {
  493. nQSec=1;
  494. } else if(strncmp(svArg2,"--> IO Handlers:",16)==0) {
  495. nQSec=2;
  496. } else if(strncmp(svArg2,"--> Encryption Handlers:",24)==0) {
  497. nQSec=3;
  498. } else if(strncmp(svArg2,"--> Auth Handlers:",18)==0) {
  499. nQSec=4;
  500. } else {
  501. if(nQSec==0) {
  502. } else if(nQSec==1) {
  503. if(svArg2[0]=='(') {
  504. // Parse command desc string
  505. int nCommand=atoi(svArg2+1);
  506. char *svFolder,*svName,*svDesc1,*svDesc2,*svDesc3,*svEOF;
  507. svFolder=BreakString(svArg2,")")+1;
  508. svName=BreakString(svFolder,"\");
  509. svDesc1=BreakString(svName,"|");
  510. svDesc2=BreakString(svDesc1,"|");
  511. svDesc3=BreakString(svDesc2,"|");
  512. svEOF=BreakString(svDesc3,"n");
  513. // Install command
  514. m_CmdDescList.SetDesc(nCommand, svFolder, svName, svDesc1, svDesc2, svDesc3);
  515. }
  516. } else if(nQSec==2) {
  517. } else if(nQSec==3) {
  518. } else if(nQSec==4) {
  519. }
  520. }
  521. else {
  522. HandleCommandResponse(svArg2);
  523. }
  524. m_pAuthSocket->Free(pBuffer);
  525. }
  526. } while((nArg1!=0) && !qd.m_bCanceled);
  527. CTreeCtrl *pTree=(CTreeCtrl *)GetDlgItem(IDC_SERVERCOMMANDS);
  528. pTree->SetImageList(&m_TreeImageList,TVSIL_NORMAL);
  529. m_CmdDescList.FillTreeCtrl(pTree);
  530. UpdateDialog();
  531. return 0;
  532. }
  533. void CBOServerDlg::OnSize(UINT nType, int cx, int cy) 
  534. {
  535. CGradientDialog::OnSize(nType, cx, cy);
  536. // Calculate resize parms
  537. int nHalfX,n3Qx,nMidBottom;
  538. nHalfX=cx/2;
  539. n3Qx=(cx*3)/4;
  540. nMidBottom=cy*2/3;
  541. // Resize elements appropriately
  542. CWnd *pWnd;
  543. pWnd=GetDlgItem(IDC_SERVERRESPONSE);
  544. if(pWnd) pWnd->MoveWindow(CRect(5,nMidBottom,cx-5,cy-5));
  545. pWnd=GetDlgItem(IDC_STATIC_SERVERRESPONSE);
  546. if(pWnd) pWnd->MoveWindow(CRect(5,nMidBottom-16,100,nMidBottom-4));
  547. pWnd=GetDlgItem(IDC_CLEARRESPONSES);
  548. if(pWnd) pWnd->MoveWindow(cx-5-100,nMidBottom-5-22,100,22);
  549. pWnd=GetDlgItem(IDC_STATIC_SERVERCOMMANDS);
  550. if(pWnd) pWnd->MoveWindow(CRect(5,5,100,5+12));
  551. pWnd=GetDlgItem(IDC_SERVERCOMMANDS);
  552. if(pWnd) pWnd->MoveWindow(CRect(5,5+14,nHalfX,nMidBottom-14-5));
  553. pWnd=GetDlgItem(IDC_MACHINEINFO);
  554. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,5,cx-5-28,5+28));
  555. pWnd=GetDlgItem(IDC_SETTINGS);
  556. if(pWnd) pWnd->MoveWindow(CRect(cx-5-24,5,cx-5,5+24));
  557. pWnd=GetDlgItem(IDC_DOCKING);
  558. if(pWnd) pWnd->MoveWindow(CRect(cx-5-106,5+28+5,cx-5,5+28+5+12));
  559. pWnd=GetDlgItem(IDC_CONNECTCHECK);
  560. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,5+28+5,cx-5-106-5,5+28+5+27));
  561. pWnd=GetDlgItem(IDC_QUERYONCONNECT);
  562. if(pWnd) pWnd->MoveWindow(CRect(cx-5-106,5+28+5+10,cx-5,5+28+5+22+10));
  563. pWnd=GetDlgItem(IDC_STATIC_OPT1);
  564. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,15+56,cx-5,15+56+16));
  565. pWnd=GetDlgItem(IDC_OPT1);
  566. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,15+56+12+5,n3Qx,15+56+12+5+24));
  567. pWnd=GetDlgItem(IDC_SENDCOMMAND);
  568. if(pWnd) pWnd->MoveWindow(CRect(n3Qx+5,15+56+12+5,cx-5,15+56+12+5+24));
  569. pWnd=GetDlgItem(IDC_STATIC_OPT2);
  570. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,15+56+46,cx-5,15+56+46+16));
  571. pWnd=GetDlgItem(IDC_OPT2);
  572. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,15+56+46+12+5,cx-5,15+56+46+12+5+24+75));
  573. pWnd=GetDlgItem(IDC_STATIC_OPT3);
  574. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,20+56+82,cx-5,20+56+82+16));
  575. pWnd=GetDlgItem(IDC_OPT3);
  576. if(pWnd) pWnd->MoveWindow(CRect(nHalfX+5,20+56+82+12+5,cx-5,20+56+82+12+5+24+75));
  577. Invalidate();
  578. }
  579. void CBOServerDlg::OnSettings() 
  580. {
  581. CListCtrl *list=(CListCtrl *)(((CMainFrame *)AfxGetMainWnd())->m_pWndServerList->GetDlgItem(ID_SERVERLIST));
  582. CNewMachineDlg nmd;
  583. CBOWDoc *cbd;
  584. SERVER_INFO *pSvr;
  585. cbd=(CBOWDoc *) ((CMainFrame *)theApp.GetMainWnd())->GetActiveDocument();
  586. int i;
  587. for(i=list->GetItemCount()-1;i>=0;i--) {
  588. pSvr=(SERVER_INFO *)list->GetItemData(i);
  589. if(pSvr->pServerDlg==this) break;
  590. }
  591. if(i<0) return;
  592. if(m_bIsConnected) {
  593. AfxMessageBox("The server command window is currently connected.nDisconnect it first before editing the server parameters.",MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);
  594. return;
  595. }
  596. nmd.m_strMachineName=pSvr->svName;
  597. nmd.m_strSvrAddr=pSvr->svAddress;
  598. nmd.m_strSelectedIO=pSvr->svConnectionType;
  599. nmd.m_strSelectedEnc=pSvr->svEncryption;
  600. nmd.m_strSelectedAuth=pSvr->svAuthentication;
  601. if(nmd.DoModal()==IDOK) {
  602. cbd->EditServer(pSvr,nmd.m_strMachineName,nmd.m_strSelectedIO,nmd.m_strSvrAddr,nmd.m_strSelectedEnc,nmd.m_strSelectedAuth);
  603. ((CMainFrame *)AfxGetMainWnd())->m_pWndServerList->SynchToDocument(cbd);
  604. }
  605. pSvr->pServerDlgBDB->Invalidate();
  606. pSvr->pServerDlgBDB->UpdateWindow();
  607. Invalidate();
  608. UpdateWindow();
  609. }