Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

460 lines
16 KiB

  1. // ManageDialog.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ManageDialog.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // ManageDialog dialog
  12. ManageDialog::ManageDialog(CWnd* pParent /*=NULL*/)
  13. :CDialog(ManageDialog::IDD, pParent),
  14. m_watcher(NULL),
  15. m_Index(0),
  16. Port(23),
  17. lang(0),
  18. tc(0),
  19. hist(0)
  20. {
  21. //{{AFX_DATA_INIT(ManageDialog)
  22. // NOTE: the ClassWizard will add member initialization here
  23. //}}AFX_DATA_INIT
  24. }
  25. void ManageDialog::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. CEdit *ctrl;
  29. BOOL ret;
  30. //{{AFX_DATA_MAP(ManageDialog)
  31. ctrl = (CEdit *)GetDlgItem(IDC_MACHINE_NAME_MANAGE);
  32. ret = ctrl->SetReadOnly(FALSE);
  33. DDX_Text(pDX, IDC_MACHINE_NAME_MANAGE, Machine);
  34. ret = ctrl->SetReadOnly(TRUE);
  35. ctrl = (CEdit *)GetDlgItem(IDC_COMMAND_MANAGE);
  36. ret = ctrl->SetReadOnly(FALSE);
  37. DDX_Text(pDX, IDC_COMMAND_MANAGE, Command);
  38. ret = ctrl->SetReadOnly(TRUE);
  39. ctrl = (CEdit *)GetDlgItem(IDC_LOGIN_MANAGE);
  40. ret = ctrl->SetReadOnly(FALSE);
  41. DDX_Text(pDX, IDC_LOGIN_MANAGE, LoginName);
  42. ret = ctrl->SetReadOnly(TRUE);
  43. ctrl = (CEdit *)GetDlgItem(IDC_PASSWD_MANAGE);
  44. ret = ctrl->SetReadOnly(FALSE);
  45. DDX_Text(pDX, IDC_PASSWD_MANAGE, LoginPasswd);
  46. ret = ctrl->SetReadOnly(TRUE);
  47. ctrl = (CEdit *)GetDlgItem(IDC_SESSION_MANAGE);
  48. ret = ctrl->SetReadOnly(FALSE);
  49. DDX_Text(pDX, IDC_SESSION_MANAGE, Session);
  50. ret = ctrl->SetReadOnly(TRUE);
  51. ctrl = (CEdit *)GetDlgItem(IDC_PORT_MANAGE);
  52. ret = ctrl->SetReadOnly(FALSE);
  53. DDX_Text(pDX,IDC_PORT_MANAGE, Port);
  54. ret = ctrl->SetReadOnly(TRUE);
  55. ctrl = (CEdit *)GetDlgItem(IDC_CLIENT_MANAGE);
  56. ret = ctrl->SetReadOnly(FALSE);
  57. DDX_Text(pDX,IDC_CLIENT_MANAGE,tcclnt);
  58. ret = ctrl->SetReadOnly(TRUE);
  59. ctrl = (CEdit *)GetDlgItem(IDC_LANGUAGE_MANAGE);
  60. ret = ctrl->SetReadOnly(FALSE);
  61. DDX_Text(pDX,IDC_LANGUAGE_MANAGE,language);
  62. ret = ctrl->SetReadOnly(TRUE);
  63. ctrl = (CEdit *)GetDlgItem(IDC_HISTORY_MANAGE);
  64. ret = ctrl->SetReadOnly(FALSE);
  65. DDX_Text(pDX,IDC_HISTORY_MANAGE,history);
  66. ret = ctrl->SetReadOnly(TRUE);
  67. // NOTE: the ClassWizard will add DDX and DDV calls here
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(ManageDialog, CDialog)
  71. //{{AFX_MSG_MAP(ManageDialog)
  72. ON_BN_CLICKED(EDIT_BUTTON, OnEditButton)
  73. ON_BN_CLICKED(DELETE_BUTTON, OnDeleteButton)
  74. ON_BN_CLICKED(NEW_BUTTON, OnNewButton)
  75. ON_BN_CLICKED(NEXT_BUTTON, OnNextButton)
  76. ON_BN_CLICKED(PREV_BUTTON, OnPrevButton)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // ManageDialog message handlers
  81. void ManageDialog::OnEditButton()
  82. {
  83. // TODO: Add your control notification handler code here
  84. ParameterDialog pd;
  85. pd.Session = (LPCTSTR) Session;
  86. pd.Machine = (LPCTSTR) Machine;
  87. pd.Command = (LPCTSTR) Command;
  88. CString temp;
  89. pd.language = lang;
  90. pd.tcclnt = tc;
  91. pd.history = hist;
  92. pd.LoginName = (LPCTSTR) LoginName;
  93. pd.LoginPasswd = (LPCTSTR) LoginPasswd;
  94. pd.Port = Port;
  95. GetSetParameters(pd);
  96. if(m_watcher){
  97. int ret = m_watcher->GetParametersByIndex(m_Index,
  98. Session,
  99. Machine,
  100. Command,
  101. Port,
  102. lang,
  103. tc,
  104. hist,
  105. LoginName,
  106. LoginPasswd
  107. );
  108. if(ret == ERROR_SUCCESS){
  109. language.LoadString(IDS_ENGLISH + lang);
  110. tcclnt.LoadString(IDS_TELNET + tc);
  111. history.LoadString(IDS_NO + hist);
  112. }
  113. }
  114. UpdateData(FALSE);
  115. }
  116. void ManageDialog::OnDeleteButton()
  117. {
  118. // TODO: Add your control notification handler code here
  119. HKEY &m_hkey = m_watcher->GetKey();
  120. if(!m_hkey){
  121. return;
  122. }
  123. int RetVal = RegDeleteKey(m_hkey,
  124. (LPCTSTR) Session
  125. );
  126. if (RetVal == ERROR_SUCCESS){
  127. m_Index = m_Index ? m_Index -1 : 0;
  128. if(m_watcher){
  129. ParameterDialog pd;
  130. pd.Session = Session;
  131. m_watcher->Refresh(pd,TRUE);
  132. RetVal = m_watcher->GetParametersByIndex(m_Index,
  133. Session,
  134. Machine,
  135. Command,
  136. Port,
  137. lang,
  138. tc,
  139. hist,
  140. LoginName,
  141. LoginPasswd
  142. );
  143. if(RetVal == ERROR_SUCCESS){
  144. language.LoadString(IDS_ENGLISH + lang);
  145. tcclnt.LoadString(IDS_TELNET + tc);
  146. history.LoadString(IDS_NO + hist);
  147. }
  148. }
  149. }
  150. UpdateData(FALSE);
  151. }
  152. void ManageDialog::OnNewButton()
  153. {
  154. // TODO: Add your control notification handler code here
  155. ParameterDialog pd;
  156. GetSetParameters(pd);
  157. }
  158. void ManageDialog::OnNextButton()
  159. {
  160. // TODO: Add your control notification handler code here
  161. int ret = 0;
  162. m_Index ++;
  163. if(m_watcher){
  164. ret = m_watcher->GetParametersByIndex(m_Index,
  165. Session,
  166. Machine,
  167. Command,
  168. Port,
  169. lang,
  170. tc,
  171. hist,
  172. LoginName,
  173. LoginPasswd
  174. );
  175. if(ret == ERROR_SUCCESS){
  176. language.LoadString(IDS_ENGLISH + lang);
  177. tcclnt.LoadString(IDS_TELNET + tc);
  178. history.LoadString(IDS_NO + hist);
  179. }
  180. }
  181. if (ret != 0){
  182. m_Index --;
  183. if(m_watcher){
  184. ret = m_watcher->GetParametersByIndex(m_Index,
  185. Session,
  186. Machine,
  187. Command,
  188. Port,
  189. lang,
  190. tc,
  191. hist,
  192. LoginName,
  193. LoginPasswd
  194. );
  195. if(ret == ERROR_SUCCESS){
  196. language.LoadString(IDS_ENGLISH + lang);
  197. tcclnt.LoadString(IDS_TELNET + tc);
  198. history.LoadString(IDS_NO + hist);
  199. }
  200. }
  201. }
  202. UpdateData(FALSE);
  203. return;
  204. }
  205. void ManageDialog::OnPrevButton()
  206. {
  207. // TODO: Add your control notification handler code here
  208. int ret = 0;
  209. m_Index = m_Index ? m_Index -1 : 0;
  210. if(m_watcher){
  211. ret = m_watcher->GetParametersByIndex(m_Index,
  212. Session,
  213. Machine,
  214. Command,
  215. Port,
  216. lang,
  217. tc,
  218. hist,
  219. LoginName,
  220. LoginPasswd
  221. );
  222. if(ret == ERROR_SUCCESS){
  223. language.LoadString(IDS_ENGLISH + lang);
  224. tcclnt.LoadString(IDS_TELNET + tc);
  225. history.LoadString(IDS_NO + hist);
  226. }
  227. }
  228. if (ret != 0){
  229. m_Index =0;
  230. if(m_watcher){
  231. ret = m_watcher->GetParametersByIndex(m_Index,
  232. Session,
  233. Machine,
  234. Command,
  235. Port,
  236. lang,
  237. tc,
  238. hist,
  239. LoginName,
  240. LoginPasswd
  241. );
  242. if(ret == ERROR_SUCCESS){
  243. language.LoadString(IDS_ENGLISH + lang);
  244. tcclnt.LoadString(IDS_TELNET + tc);
  245. history.LoadString(IDS_NO + hist);
  246. }
  247. }
  248. }
  249. UpdateData(FALSE);
  250. return;
  251. }
  252. void ManageDialog::OnOK()
  253. {
  254. // TODO: Add extra validation here
  255. CDialog::OnOK();
  256. }
  257. void ManageDialog::SetApplicationPtr(CWatcherApp *watcher)
  258. {
  259. int ret = 0;
  260. m_watcher = watcher;
  261. if(m_watcher){
  262. ret = m_watcher->GetParametersByIndex(m_Index,
  263. Session,
  264. Machine,
  265. Command,
  266. Port,
  267. lang,
  268. tc,
  269. hist,
  270. LoginName,
  271. LoginPasswd
  272. );
  273. if(ret == ERROR_SUCCESS){
  274. language.LoadString(IDS_ENGLISH + lang);
  275. tcclnt.LoadString(IDS_TELNET + tc);
  276. history.LoadString(IDS_NO + hist);
  277. }
  278. }
  279. }
  280. void ManageDialog::GetSetParameters(ParameterDialog &pd)
  281. {
  282. HKEY m_child;
  283. INT_PTR ret = pd.DoModal();
  284. if (ret == IDOK){
  285. // Add it to the registry
  286. if(m_watcher){
  287. HKEY & m_hkey = m_watcher->GetKey();
  288. ret = RegCreateKeyEx(m_hkey,
  289. (LPCTSTR) pd.Session, // subkey name
  290. 0, // reserved
  291. NULL, // class string
  292. 0, // special options
  293. KEY_ALL_ACCESS, // desired security access
  294. NULL, // inheritance
  295. &m_child, // key handle
  296. NULL // disposition value buffer
  297. );
  298. if (ret == ERROR_SUCCESS){
  299. ret = SetParameters(pd.Machine, pd.Command,
  300. pd.LoginName, pd.LoginPasswd,
  301. pd.Port, pd.language,
  302. pd.tcclnt,pd.history,
  303. m_child
  304. );
  305. if(ret == ERROR_SUCCESS){
  306. m_watcher->Refresh(pd,FALSE);
  307. }
  308. }
  309. }else{
  310. return;
  311. }
  312. }
  313. }
  314. int ManageDialog::SetParameters(CString &mac,
  315. CString &com,
  316. CString &lgnName,
  317. CString &lgnPasswd,
  318. UINT port,
  319. int lang,
  320. int tc,
  321. int hist,
  322. HKEY &child
  323. )
  324. {
  325. DWORD lpcName;
  326. const TCHAR *lpName;
  327. int RetVal;
  328. int charSize = sizeof(TCHAR);
  329. lpcName = MAX_BUFFER_SIZE;
  330. lpName = (LPCTSTR) mac;
  331. lpcName = (mac.GetLength())*charSize;
  332. RetVal = RegSetValueEx(child,
  333. _TEXT("Machine"),
  334. NULL,
  335. REG_SZ,
  336. (LPBYTE) lpName,
  337. lpcName
  338. );
  339. if(RetVal != ERROR_SUCCESS){
  340. return RetVal;
  341. }
  342. lpName = (LPCTSTR) com;
  343. lpcName = (com.GetLength())*charSize;
  344. RetVal = RegSetValueEx(child,
  345. _TEXT("Command"),
  346. NULL,
  347. REG_SZ,
  348. (LPBYTE)lpName,
  349. lpcName
  350. );
  351. if(RetVal != ERROR_SUCCESS){
  352. return RetVal;
  353. }
  354. lpName = (LPCTSTR) lgnName;
  355. lpcName = (lgnName.GetLength())*charSize;
  356. RetVal = RegSetValueEx(child,
  357. _TEXT("User Name"),
  358. NULL,
  359. REG_SZ,
  360. (LPBYTE)lpName,
  361. lpcName
  362. );
  363. if(RetVal != ERROR_SUCCESS){
  364. return RetVal;
  365. }
  366. lpName = (LPCTSTR) lgnPasswd;
  367. lpcName = (lgnPasswd.GetLength())*charSize;
  368. RetVal = RegSetValueEx(child,
  369. _TEXT("Password"),
  370. NULL,
  371. REG_SZ,
  372. (LPBYTE)lpName,
  373. lpcName
  374. );
  375. if(RetVal != ERROR_SUCCESS){
  376. return RetVal;
  377. }
  378. lpcName = sizeof(UINT);
  379. RetVal = RegSetValueEx(child,
  380. _TEXT("Port"),
  381. NULL,
  382. REG_DWORD,
  383. (LPBYTE)&port,
  384. lpcName
  385. );
  386. if(RetVal != ERROR_SUCCESS){
  387. return RetVal;
  388. }
  389. lpcName = sizeof(DWORD);
  390. RetVal = RegSetValueEx(child,
  391. _TEXT("Client Type"),
  392. NULL,
  393. REG_DWORD,
  394. (LPBYTE)&tc,
  395. lpcName
  396. );
  397. if(RetVal != ERROR_SUCCESS){
  398. return RetVal;
  399. }
  400. lpcName = sizeof(DWORD);
  401. RetVal = RegSetValueEx(child,
  402. _TEXT("Language"),
  403. NULL,
  404. REG_DWORD,
  405. (LPBYTE)&lang,
  406. lpcName
  407. );
  408. if(RetVal != ERROR_SUCCESS){
  409. return RetVal;
  410. }
  411. lpcName = sizeof(DWORD);
  412. RetVal = RegSetValueEx(child,
  413. _TEXT("History"),
  414. NULL,
  415. REG_DWORD,
  416. (LPBYTE)&hist,
  417. lpcName
  418. );
  419. if(RetVal != ERROR_SUCCESS){
  420. return RetVal;
  421. }
  422. // Now you can refresh the application.
  423. return RetVal;
  424. }