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

远程控制编程

开发平台:

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. // ServerList.cpp : implementation file
  16. //
  17. #include "stdafx.h"
  18. #include "bo2kgui.h"
  19. #include "ServerList.h"
  20. #include "NewMachineDlg.h"
  21. #include "MainFrm.h"
  22. #include "BOWDoc.h"
  23. #include "BODialogBar.h"
  24. #include "BOServerDlg.h"
  25. #define TIMER_UPDATE 1
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CServerList dialog
  33. CServerList::CServerList(CWnd* pParent /*=NULL*/)
  34. : CGradientDialog(CServerList::IDD, pParent)
  35. {
  36. //{{AFX_DATA_INIT(CServerList)
  37. // NOTE: the ClassWizard will add member initialization here
  38. //}}AFX_DATA_INIT
  39. m_nUpdateTimer=0;
  40. }
  41. CServerList::~CServerList()
  42. {
  43. }
  44. void CServerList::CleanUpAndClose(void)
  45. {
  46. KillTimer(m_nUpdateTimer);
  47. DeleteAllItems();
  48. DestroyWindow();
  49. }
  50. void CServerList::DoDataExchange(CDataExchange* pDX)
  51. {
  52. CGradientDialog::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(CServerList)
  54. // NOTE: the ClassWizard will add DDX and DDV calls here
  55. //}}AFX_DATA_MAP
  56. }
  57. BEGIN_MESSAGE_MAP(CServerList, CGradientDialog)
  58. //{{AFX_MSG_MAP(CServerList)
  59. ON_BN_CLICKED(ID_DETAILS, OnDetails)
  60. ON_BN_CLICKED(ID_NEWMACHINE, OnNewmachine)
  61. ON_BN_CLICKED(ID_DELETEMACHINE, OnDeletemachine)
  62. ON_WM_SIZE()
  63. ON_NOTIFY(LVN_ITEMCHANGED, ID_SERVERLIST, OnItemchangedServerlist)
  64. ON_NOTIFY(LVN_KEYDOWN, ID_SERVERLIST, OnKeydownServerlist)
  65. ON_NOTIFY(NM_DBLCLK, ID_SERVERLIST, OnDblclkServerlist)
  66. ON_BN_CLICKED(IDC_DOCKING, OnAllowDocking)
  67. ON_WM_TIMER()
  68. ON_BN_CLICKED(ID_EDITMACHINE, OnEditmachine)
  69. ON_WM_MOVE()
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CServerList message handlers
  74. void CServerList::OnCancel()
  75. {
  76. }
  77. void CServerList::OnOK()
  78. {
  79. }
  80. void CServerList::OnDetails() 
  81. {
  82. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  83. CButton *details=(CButton *)GetDlgItem(ID_DETAILS);
  84. DWORD dwStyle=GetWindowLong(list->GetSafeHwnd(),GWL_STYLE);
  85. dwStyle &= ~LVS_TYPEMASK;
  86. if(details->GetCheck()) dwStyle |= LVS_REPORT;
  87. else dwStyle |= LVS_ICON;
  88. SetWindowLong(list->GetSafeHwnd(),GWL_STYLE,dwStyle);
  89. list->RedrawWindow();
  90. }
  91. void CServerList::OnNewmachine() 
  92. {
  93. CString strSvrAddr;
  94. CNewMachineDlg nmd;
  95. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  96. if(nmd.DoModal()==IDOK) {
  97. // Add to CBOWDoc
  98. CBOWDoc *cbd;
  99. SERVER_INFO *pSvr;
  100.   cbd=(CBOWDoc *) ((CMainFrame *)theApp.GetMainWnd())->GetActiveDocument();
  101. pSvr=(SERVER_INFO *) cbd->InsertServer(nmd.m_strMachineName,nmd.m_strSelectedIO,nmd.m_strSvrAddr,nmd.m_strSelectedEnc,nmd.m_strSelectedAuth);
  102. if(pSvr==NULL) return;
  103. // Synchronize List Control
  104. SynchToDocument(cbd);
  105. }
  106. }
  107. void CServerList::OnEditmachine() 
  108. {
  109. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  110. CNewMachineDlg nmd;
  111. CBOWDoc *cbd;
  112. SERVER_INFO *pSvr;
  113. char textbuf[512];
  114. cbd=(CBOWDoc *) ((CMainFrame *)theApp.GetMainWnd())->GetActiveDocument();
  115. int i;
  116. for(i=list->GetItemCount()-1;i>=0;i--) {
  117. if(list->GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED) break;
  118. }
  119. if(i<0) return;
  120. LVITEM lvi;
  121. lvi.iItem=i;
  122. lvi.iSubItem=0;
  123. lvi.mask=LVIF_TEXT | LVIF_PARAM;
  124. lvi.pszText=textbuf;
  125. lvi.cchTextMax=512;
  126. list->GetItem(&lvi);
  127. pSvr=(SERVER_INFO *)lvi.lParam;
  128. if(pSvr->pServerDlg->m_bIsConnected) {
  129. AfxMessageBox("The server command window is currently connected.nDisconnect it first before editing the server parameters.",MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);
  130. return;
  131. }
  132. nmd.m_strMachineName=pSvr->svName;
  133. nmd.m_strSvrAddr=pSvr->svAddress;
  134. nmd.m_strSelectedIO=pSvr->svConnectionType;
  135. nmd.m_strSelectedEnc=pSvr->svEncryption;
  136. nmd.m_strSelectedAuth=pSvr->svAuthentication;
  137. if(nmd.DoModal()==IDOK) {
  138. cbd->EditServer(pSvr,nmd.m_strMachineName,nmd.m_strSelectedIO,nmd.m_strSvrAddr,nmd.m_strSelectedEnc,nmd.m_strSelectedAuth);
  139. SynchToDocument(cbd);
  140. }
  141. }
  142. void CServerList::OnDeletemachine() 
  143. {
  144. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  145. CBOWDoc *cbd;
  146. SERVER_INFO *pSvr;
  147. cbd=(CBOWDoc *) ((CMainFrame *)theApp.GetMainWnd())->GetActiveDocument();
  148. int i;
  149. for(i=list->GetItemCount()-1;i>=0;i--) {
  150. if(list->GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED) {
  151. pSvr=(SERVER_INFO *)list->GetItemData(i);
  152. DeleteItem(i);
  153. cbd->DeleteServer(pSvr);
  154. }
  155. }
  156. }
  157. void CServerList::DeleteItem(int idx)
  158. {
  159. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  160. SERVER_INFO *pSvr;
  161. pSvr=(SERVER_INFO *) list->GetItemData(idx);
  162. pSvr->pServerDlgBDB->Hide();
  163. pSvr->pServerDlg->DestroyWindow();
  164. delete pSvr->pServerDlg;
  165. pSvr->pServerDlg=NULL;
  166. pSvr->pServerDlgBDB->DestroyWindow();
  167. delete pSvr->pServerDlgBDB;
  168. pSvr->pServerDlgBDB=NULL;
  169. list->DeleteItem(idx);
  170. }
  171. void CServerList::DeleteAllItems()
  172. {
  173. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  174. int i;
  175. if(list!=NULL) {
  176. for(i=list->GetItemCount()-1;i>=0;i--) {
  177. DeleteItem(i);
  178. }
  179. }
  180. }
  181. void CServerList::OnSize(UINT nType, int cx, int cy) 
  182. {
  183. CGradientDialog::OnSize(nType, cx, cy);
  184. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  185. if(list) {
  186. RECT r;
  187. int newsize;
  188. int i;
  189. // Move window
  190. GetClientRect(&r);
  191. list->MoveWindow(36,26,(r.right-r.left)-40,(r.bottom-r.top)-30);
  192. // Resize columns
  193. list->GetClientRect(&r);
  194. newsize=r.right-r.left;
  195. for(i=0;i<5;i++) {
  196. int newwidth=newsize/5;
  197. if(newwidth<100) newwidth=100;
  198. list->SetColumnWidth(i,newwidth);
  199. }
  200. }
  201. }
  202. BOOL CServerList::OnInitDialog() 
  203. {
  204. CGradientDialog::OnInitDialog();
  205. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  206. m_NormalImageList.Create(IDB_NORMAL_BOCOMPS,32,1,RGB(255,0,0));
  207. list->SetImageList(&m_NormalImageList,LVSIL_NORMAL);
  208. m_SmallImageList.Create(IDB_LITTLE_BOCOMPS,16,1,RGB(255,0,0));
  209. list->SetImageList(&m_SmallImageList,LVSIL_SMALL);
  210. // Size columns
  211. RECT r;
  212. list->GetClientRect(&r);
  213. int newwidth=(r.right-r.left)/5;
  214. if(newwidth<100) newwidth=100;
  215. list->InsertColumn(0,"Machine",LVCFMT_LEFT,newwidth,0);
  216. list->InsertColumn(1,"Address",LVCFMT_LEFT,newwidth,1);
  217. list->InsertColumn(2,"Connection",LVCFMT_LEFT,newwidth,2);
  218. list->InsertColumn(3,"Encryption",LVCFMT_LEFT,newwidth,3);
  219. list->InsertColumn(4,"Authentication",LVCFMT_LEFT,newwidth,3);
  220. list->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  221. CButton *nmb=(CButton *)GetDlgItem(ID_NEWMACHINE);
  222. nmb->SetIcon(theApp.LoadIcon(IDI_NEWMACHINE));
  223. CButton *dmb=(CButton *)GetDlgItem(ID_DELETEMACHINE);
  224. dmb->SetIcon(theApp.LoadIcon(IDI_DELETEMACHINE));
  225. dmb->EnableWindow(FALSE);
  226. CButton *emb=(CButton *)GetDlgItem(ID_EDITMACHINE);
  227. emb->SetIcon(theApp.LoadIcon(IDI_EDITMACHINE));
  228. emb->EnableWindow(FALSE);
  229. CButton *dok=(CButton *)GetDlgItem(IDC_DOCKING);
  230. dok->SetCheck(1);
  231. CButton *ddt=(CButton *)GetDlgItem(ID_DETAILS);
  232. ddt->SetCheck(1);
  233. m_nUpdateTimer=SetTimer(TIMER_UPDATE,500,NULL);
  234. if(m_nUpdateTimer==0) return FALSE;
  235. return TRUE;  // return TRUE unless you set the focus to a control
  236.               // EXCEPTION: OCX Property Pages should return FALSE
  237. }
  238. void CServerList::OnItemchangedServerlist(NMHDR* pNMHDR, LRESULT* pResult) 
  239. {
  240. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  241. CListCtrl *list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  242. CButton *del=(CButton *)GetDlgItem(ID_DELETEMACHINE);
  243. if(list->GetSelectedCount()==0) del->EnableWindow(FALSE);
  244. else del->EnableWindow(TRUE);
  245. CButton *edt=(CButton *)GetDlgItem(ID_EDITMACHINE);
  246. if(list->GetSelectedCount()==1) edt->EnableWindow(TRUE);
  247. else edt->EnableWindow(FALSE);
  248. *pResult = 0;
  249. }
  250. void CServerList::OnKeydownServerlist(NMHDR* pNMHDR, LRESULT* pResult) 
  251. {
  252. NMLVKEYDOWN* pLVKeyDown = (NMLVKEYDOWN*)pNMHDR;
  253. CButton *butt;
  254. switch(pLVKeyDown->wVKey) {
  255. case VK_DELETE:
  256. butt=(CButton *)GetDlgItem(ID_DELETEMACHINE);
  257. if(butt->IsWindowEnabled()) OnDeletemachine();
  258. break;
  259. case VK_INSERT:
  260. OnNewmachine();
  261. break;
  262. }
  263. *pResult = 0;
  264. }
  265. void CServerList::OnDblclkServerlist(NMHDR* pNMHDR, LRESULT* pResult) 
  266. {
  267. CListCtrl *list=(CListCtrl *)GetDlgItem(pNMHDR->idFrom);
  268. int i;
  269. if(list->GetSelectedCount()>0) {
  270. for(i=(list->GetItemCount()-1);i>=0;i--) {
  271. if(list->GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED) {
  272. LVITEM lvi;
  273. SERVER_INFO *si;
  274. char svText[512];
  275. // Get item information
  276. lvi.iItem=i;
  277. lvi.iSubItem=0;
  278. lvi.mask=LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
  279. lvi.pszText=svText;
  280. lvi.cchTextMax=512;
  281. list->GetItem(&lvi);
  282. si=(SERVER_INFO *) lvi.lParam;
  283. if(si->pServerDlgBDB->IsWindowVisible()) {
  284. si->pServerDlgBDB->Hide();
  285. } else {
  286. si->pServerDlgBDB->Show();
  287. }
  288. }
  289. }
  290. }
  291. *pResult = 0;
  292. }
  293. void CServerList::OnAllowDocking() 
  294. {
  295. CButton *btn;
  296. btn=(CButton *)GetDlgItem(IDC_DOCKING);
  297. if(btn->GetCheck()) {
  298. ((CBODialogBar *)GetParent())->EnableDocking(CBRS_ALIGN_ANY);
  299. } else {
  300. ((CBODialogBar *)GetParent())->EnableDocking(0);
  301. ((CBODialogBar *)GetParent())->m_pDockContext->ToggleDocking();
  302. }
  303. }
  304. void CServerList::SynchToDocument(CBOWDoc *cbd)
  305. {
  306. SERVER_INFO *si;
  307. CListCtrl *pList;
  308. int idx;
  309. pList=(CListCtrl *) GetDlgItem(ID_SERVERLIST);
  310. // Add items that should be there and update those that are already there
  311. si=cbd->m_pHeadSI;
  312. while(si!=NULL) {
  313. BOOL bNew;
  314. LVITEM lvi;
  315. LVFINDINFO lvfi;
  316. lvfi.flags=LVFI_PARAM;
  317. lvfi.lParam=(LPARAM) si;
  318. idx=pList->FindItem(&lvfi,-1);
  319. if(idx==-1) {
  320. idx=0;
  321. lvi.mask=LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  322. lvi.pszText=si->svName;
  323. lvi.iImage=0;
  324. lvi.iItem=idx;
  325. lvi.iSubItem=0;
  326. lvi.lParam=(LPARAM) si;
  327. pList->InsertItem(&lvi);
  328. bNew=TRUE;
  329. } else {
  330. lvi.mask=LVIF_TEXT;
  331. lvi.pszText=si->svName;
  332. lvi.iItem=idx;
  333. lvi.iSubItem=0;
  334. pList->SetItem(&lvi);
  335. bNew=FALSE;
  336. }
  337. lvi.mask=LVIF_TEXT;
  338. lvi.pszText=si->svAddress;
  339. lvi.iItem=idx;
  340. lvi.iSubItem=1;
  341. pList->SetItem(&lvi);
  342. lvi.mask=LVIF_TEXT;
  343. lvi.pszText=si->svConnectionType;
  344. lvi.iItem=idx;
  345. lvi.iSubItem=2;
  346. pList->SetItem(&lvi);
  347. lvi.mask=LVIF_TEXT;
  348. lvi.pszText=si->svEncryption;
  349. lvi.iItem=idx;
  350. lvi.iSubItem=3;
  351. pList->SetItem(&lvi);
  352. lvi.mask=LVIF_TEXT;
  353. lvi.pszText=si->svAuthentication;
  354. lvi.iItem=idx;
  355. lvi.iSubItem=4;
  356. pList->SetItem(&lvi);
  357. // Create cool dialog bar
  358. if(bNew) {
  359. CSize sizeNormal(422,399);
  360. CString title("Server Command Client");
  361. si->pServerDlgBDB=new CBODialogBar;
  362. si->pServerDlgBDB->SetNormalSize(sizeNormal);
  363. si->pServerDlgBDB->Create(this->GetParentFrame(),IDD_BOSERVERDLG,title,sizeNormal);
  364. si->pServerDlgBDB->SetBarStyle((si->pServerDlgBDB->GetBarStyle() & ~CBRS_ALIGN_ANY) | CBRS_TOOLTIPS | CBRS_BORDER_ANY | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  365. si->pServerDlgBDB->EnableDockingOnSizeBar(CBRS_ALIGN_ANY);
  366. si->pServerDlg=new CBOServerDlg();
  367. si->pServerDlg->SetServerInfo(si);
  368. si->pServerDlg->Create(CBOServerDlg::IDD,si->pServerDlgBDB);
  369. si->pServerDlg->UseGradient(m_bGradient);
  370. si->pServerDlgBDB->SetDialog(si->pServerDlg);
  371. si->pServerDlgBDB->GetDockingFrame()->FloatControlBar(si->pServerDlgBDB, CPoint((GetSystemMetrics(SM_CXSCREEN)-422)/2,(GetSystemMetrics(SM_CYSCREEN)-399)/2));
  372. //si->pServerDlgBDB->Hide();
  373. }
  374. else {
  375. si->pServerDlg->SetServerInfo(si);
  376. si->pServerDlg->UpdateDialog();
  377. si->pServerDlg->Invalidate();
  378. si->pServerDlg->UpdateWindow();
  379. }
  380. si=si->next;
  381. }
  382. }
  383. void CServerList::OnTimer(UINT nIDEvent) 
  384. {
  385. if(nIDEvent==TIMER_UPDATE) {
  386. UpdateListStatus();
  387. }
  388. CGradientDialog::OnTimer(nIDEvent);
  389. }
  390. void CServerList::UpdateListStatus(void)
  391. {
  392. CListCtrl *list;
  393. list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  394. int i;
  395. for(i=(list->GetItemCount()-1);i>=0;i--) {
  396. LVITEM lvi;
  397. SERVER_INFO *si;
  398. char svText[512];
  399. // Get item information
  400. lvi.iItem=i;
  401. lvi.iSubItem=0;
  402. lvi.mask=LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
  403. lvi.pszText=svText;
  404. lvi.cchTextMax=512;
  405. list->GetItem(&lvi);
  406. si=(SERVER_INFO *) lvi.lParam;
  407. lvi.mask=LVIF_IMAGE;
  408. if(!si->pServerDlgBDB->IsFloating()) {
  409. if(si->pServerDlgBDB->m_hWnd!=NULL) {
  410. if(si->pServerDlgBDB->IsWindowVisible()) lvi.iImage=1;
  411. else lvi.iImage=0;
  412. }
  413. } else {
  414. if(si->pServerDlg->m_hWnd!=NULL) {
  415. if(si->pServerDlg->GetParent()->GetParent()->GetParent()->IsWindowVisible()) lvi.iImage=1;
  416. else lvi.iImage=0;
  417. }
  418. }
  419. list->SetItem(&lvi);
  420. }
  421. }
  422. void CServerList::UseGradient(BOOL bUse) 
  423. {
  424. CListCtrl *list;
  425. list=(CListCtrl *)GetDlgItem(ID_SERVERLIST);
  426. int i;
  427. for(i=(list->GetItemCount()-1);i>=0;i--) {
  428. LVITEM lvi;
  429. SERVER_INFO *si;
  430. char svText[512];
  431. // Get item information
  432. lvi.iItem=i;
  433. lvi.iSubItem=0;
  434. lvi.mask=LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
  435. lvi.pszText=svText;
  436. lvi.cchTextMax=512;
  437. list->GetItem(&lvi);
  438. si=(SERVER_INFO *) lvi.lParam;
  439. si->pServerDlg->UseGradient(bUse);
  440. si->pServerDlg->Invalidate();
  441. si->pServerDlg->UpdateWindow();
  442. }
  443. if(bUse)
  444. SetGradient(GetSysColor(COLOR_3DFACE),GetSysColor(COLOR_3DHILIGHT),2);
  445. else
  446. SetGradient();
  447. Invalidate();
  448. UpdateWindow();
  449. }