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.

532 lines
12 KiB

  1. /* File: D:\WACKER\tdll\telnetck.c (Created: 29-June-1998 by mpt)
  2. *
  3. * Copyright 1996 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * Description: Used to nag the user about purchasing HyperTerminal
  7. * if they are in violation of the license agreement
  8. *
  9. * $Revision: 11 $
  10. * $Date: 5/17/02 11:33a $
  11. */
  12. #include <windows.h>
  13. #pragma hdrstop
  14. #include "features.h"
  15. #ifdef INCL_NAG_SCREEN
  16. #include "assert.h"
  17. #include "stdtyp.h"
  18. #include "globals.h"
  19. #include "htchar.h"
  20. #include "registry.h"
  21. #include "serialno.h"
  22. #include <term\res.h>
  23. #include "hlptable.h"
  24. #include "tdll.h"
  25. #include "nagdlg.h"
  26. #include "errorbox.h"
  27. #include <io.h>
  28. //#include <time.h>
  29. // Control IDs for the dialog:
  30. //
  31. #define IDC_PB_YES IDOK
  32. #define IDC_PB_NO IDCANCEL
  33. #define IDC_CK_STOP_ASKING 200
  34. #define IDC_ST_QUESTION 201
  35. #define IDC_IC_EXCLAMATION 202
  36. // Registry key for HyperTerminal:
  37. //
  38. static const TCHAR g_achHyperTerminalRegKey[] =
  39. TEXT("SOFTWARE\\Hilgraeve Inc\\HyperTerminal PE\\3.0");
  40. // Registry value for telnet checking:
  41. //
  42. static const TCHAR g_achInstallDate[] = TEXT("InstallDate");
  43. static const TCHAR g_achIDate[] = TEXT("IDate");
  44. static const TCHAR g_achLicense[] = TEXT("License");
  45. static const TCHAR g_achSerial[] = TEXT("Registered");
  46. INT elapsedTime = 0;
  47. static const INT timeout = 15000;
  48. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  49. * FUNCTION:
  50. * IsEval
  51. *
  52. * DESCRIPTION:
  53. * Determines whether the user should be nagged about purchasing HT
  54. *
  55. * PARAMETERS:
  56. * None
  57. *
  58. * RETURNS:
  59. * TRUE or FALSE
  60. *
  61. * AUTHOR: Mike Thompson 06-29-98
  62. */
  63. BOOL IsEval(void)
  64. {
  65. DWORD dwLicense = TRUE;
  66. DWORD dwSize = sizeof(dwLicense);
  67. // Get registry info
  68. //
  69. htRegQueryValue(HKEY_CURRENT_USER,
  70. g_achHyperTerminalRegKey,
  71. g_achLicense,
  72. (LPBYTE) &dwLicense,
  73. &dwSize);
  74. return (dwLicense == FALSE);
  75. }
  76. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  77. * FUNCTION:
  78. * IsTimeToNag
  79. *
  80. * DESCRIPTION:
  81. * Base on the InstallDate, should we display a nag screen now?
  82. * Every 5 times the app is run, the dialog is displayed
  83. *
  84. * PARAMETERS:
  85. * None
  86. *
  87. * RETURNS:
  88. * TRUE or FALSE
  89. *
  90. * AUTHOR: Mike Thompson 06-29-98
  91. */
  92. BOOL IsTimeToNag(void)
  93. {
  94. DWORD dwNag = TRUE;
  95. DWORD dwSize = sizeof(dwNag);
  96. //check to see if we are past our 90 days
  97. if ( ExpDays() <= 0 )
  98. {
  99. return TRUE;
  100. }
  101. else
  102. {
  103. htRegQueryValue(HKEY_CURRENT_USER,
  104. g_achHyperTerminalRegKey,
  105. g_achInstallDate,
  106. (LPBYTE) &dwNag,
  107. &dwSize);
  108. regSetDwordValue(HKEY_CURRENT_USER,
  109. g_achHyperTerminalRegKey,
  110. g_achInstallDate,
  111. (dwNag == 0) ? (DWORD)4 : dwNag - (DWORD)1 );
  112. return dwNag == 0;
  113. }
  114. }
  115. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  116. * FUNCTION:
  117. * SetNagFlag
  118. *
  119. * DESCRIPTION:
  120. * Sets the "nag" flag which will either turn off
  121. * this feature the next time HyperTerminal starts.
  122. *
  123. * PARAMETERS:
  124. *
  125. * RETURNS:
  126. *
  127. * AUTHOR: Mike Thompson 06-29-98
  128. */
  129. void SetNagFlag(TCHAR *serial)
  130. {
  131. //set the license flag to true
  132. regSetDwordValue( HKEY_CURRENT_USER,
  133. g_achHyperTerminalRegKey,
  134. g_achLicense,
  135. (DWORD)1 );
  136. //store the serial number
  137. regSetStringValue( HKEY_CURRENT_USER,
  138. g_achHyperTerminalRegKey,
  139. g_achSerial,
  140. serial );
  141. }
  142. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  143. * FUNCTION:
  144. * ExpDays
  145. *
  146. * DESCRIPTION:
  147. * Returns the number of days left in the evaluation period
  148. *
  149. *
  150. * PARAMETERS:
  151. *
  152. * RETURNS:
  153. *
  154. * AUTHOR: Mike Thompson 07-20-98
  155. */
  156. int ExpDays(void)
  157. {
  158. time_t tToday, tSerial;
  159. int expDays = 15;
  160. tSerial = CalcExpirationDate();
  161. // Get the current time and then find elapsed time.
  162. time(&tToday);
  163. //return the number of days until expiration
  164. return (INT)(((tSerial - tToday + (expDays * 60 * 60 * 24) ) / (60 * 60 * 24)) + 1);
  165. }
  166. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  167. * FUNCTION:
  168. * CalcExpirationDate
  169. *
  170. * DESCRIPTION:
  171. * Returns the number of days left in the evaluation period
  172. *
  173. *
  174. * PARAMETERS:
  175. *
  176. * RETURNS:
  177. *
  178. * AUTHOR: Mike Thompson 07-20-98
  179. */
  180. time_t CalcExpirationDate(void)
  181. {
  182. TCHAR atchSerialNumber[MAX_PATH * 2];
  183. DWORD dwSize = sizeof(atchSerialNumber);
  184. struct tm stSerial;
  185. time_t tSerial;
  186. TCHAR tday[2], tmonth[2], tyear[2];
  187. //get installation date from registry
  188. htRegQueryValue(HKEY_CURRENT_USER,
  189. g_achHyperTerminalRegKey,
  190. g_achIDate,
  191. atchSerialNumber,
  192. &dwSize);
  193. // Build a partial time structure.
  194. memset(&stSerial, 0, sizeof(struct tm));
  195. //set month
  196. strncpy(tmonth, &atchSerialNumber[0], 2);
  197. tmonth[2] = TEXT('\0');
  198. //set day
  199. strncpy(tday, &atchSerialNumber[3], 2);
  200. tday[2] = TEXT('\0');
  201. //set year
  202. strncpy(tyear, &atchSerialNumber[6], 2);
  203. tyear[2] = TEXT('\0');
  204. stSerial.tm_mday = atoi(tday);
  205. stSerial.tm_mon = atoi(tmonth) - 1; // tm counts from 0
  206. stSerial.tm_year = atoi(tyear);
  207. #if 0
  208. // Expiration date is 1st day of fourth calendar month from date
  209. // of issue.
  210. stSerial.tm_mon += 3;
  211. // Check for end of year wrap around.
  212. if (stSerial.tm_mon >= 12)
  213. {
  214. stSerial.tm_mon %= 12;
  215. stSerial.tm_year += 1;
  216. }
  217. #endif
  218. // Convert into time_t time.
  219. if ((tSerial = mktime(&stSerial)) == -1)
  220. return 0;
  221. return tSerial;
  222. }
  223. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  224. * FUNCTION:
  225. * DoUpgradeDlg
  226. *
  227. * DESCRIPTION:
  228. * Displays the upgrade dialog
  229. *
  230. * PARAMETERS:
  231. * None
  232. *
  233. * RETURNS:
  234. *
  235. * AUTHOR: Mike Thompson 06-29-98
  236. */
  237. void DoUpgradeDlg(HWND hDlg)
  238. {
  239. int result;
  240. CHAR acExePath[MAX_PATH];
  241. CHAR acHTMFile[MAX_PATH];
  242. LPTSTR pszPtr;
  243. TCHAR ErrorMsg[80];
  244. struct _finddata_t c_file;
  245. long hFile;
  246. acExePath[0] = TEXT('\0');
  247. result = GetModuleFileName(glblQueryHinst(), acExePath, MAX_PATH);
  248. //strip off executable
  249. if (result != 0)
  250. {
  251. pszPtr = strrchr(acExePath, TEXT('\\'));
  252. *pszPtr = TEXT('\0');
  253. }
  254. //build path to htorder.exe
  255. acHTMFile[0] = TEXT('\0');
  256. strcat(acHTMFile, acExePath);
  257. strcat(acHTMFile, TEXT("\\"));
  258. strcat(acHTMFile, TEXT("Purchase Private Edition.exe"));
  259. //check if file exists
  260. hFile = _findfirst( acHTMFile, &c_file );
  261. if ( hFile != -1 )
  262. {
  263. ShellExecute(NULL, "open", acHTMFile, NULL, NULL, SW_SHOW);
  264. return;
  265. }
  266. else
  267. {
  268. wsprintf( ErrorMsg,
  269. "Could not find %s.\n\nThis file is needed to display purchase information.",
  270. acHTMFile );
  271. TimedMessageBox(hDlg, ErrorMsg, NULL, MB_OK | MB_ICONEXCLAMATION, 0);
  272. }
  273. }
  274. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  275. * FUNCTION:
  276. * DoRegisterDlg
  277. *
  278. * DESCRIPTION:
  279. * Displays the register dialog
  280. *
  281. * PARAMETERS:
  282. * None
  283. *
  284. * RETURNS:
  285. *
  286. * AUTHOR: Mike Thompson 06-29-98
  287. */
  288. void DoRegisterDlg(HWND hDlg)
  289. {
  290. DoDialog(glblQueryDllHinst(),
  291. MAKEINTRESOURCE(IDD_NAG_REGISTER),
  292. hDlg,
  293. NagRegisterDlgProc,
  294. 0);
  295. }
  296. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  297. * FUNCTION:
  298. * DefaultNagDlgProc
  299. *
  300. * DESCRIPTION:
  301. * The dialog procedure for the "Nag" dialog.
  302. *
  303. * PARAMETERS:
  304. * hDlg - The dialog's window handle.
  305. * wMsg - The message being sent to the window.
  306. * wPar - The message's wParam.
  307. * lPar - The message's lParam.
  308. *
  309. * RETURNS:
  310. * TRUE or FALSE
  311. *
  312. * AUTHOR: Mike Thompson 06-29-98
  313. */
  314. BOOL CALLBACK DefaultNagDlgProc(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  315. {
  316. TCHAR expString[MAX_PATH];
  317. INT exp;
  318. static DWORD aHlpTable[] = {IDCANCEL, IDH_CANCEL,
  319. IDOK, IDH_OK,
  320. 0, 0};
  321. switch (wMsg)
  322. {
  323. case WM_INITDIALOG:
  324. //initialize text on this dialog
  325. exp = ExpDays();
  326. if ( exp <= 0 )
  327. {
  328. SetDlgItemText(hDlg, IDC_NAG_EXP_DAYS, TEXT("Your evaluation period has expired."));
  329. }
  330. else
  331. {
  332. GetDlgItemText(hDlg, IDC_NAG_EXP_DAYS, expString, MAX_PATH);
  333. wsprintf(expString, expString, exp);
  334. SetDlgItemText(hDlg, IDC_NAG_EXP_DAYS, expString);
  335. }
  336. //set a timer to destroy the dialog after a while
  337. SetTimer(hDlg, 1, 1000, 0);
  338. break;
  339. case WM_TIMER:
  340. //Get rid of Window
  341. elapsedTime += 1000;
  342. if (elapsedTime >= timeout)
  343. {
  344. // Destroy the dialog
  345. EndDialog(hDlg, FALSE);
  346. }
  347. else
  348. {
  349. if (GetDlgItem(hDlg, IDC_NAG_TIME))
  350. {
  351. TCHAR temp[10];
  352. _itoa((timeout - elapsedTime + 500) / 1000, temp, 10);
  353. SetDlgItemText(hDlg, IDC_NAG_TIME, temp);
  354. }
  355. }
  356. break;
  357. case WM_DESTROY:
  358. EndDialog(hDlg, FALSE);
  359. break;
  360. case WM_HELP:
  361. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  362. break;
  363. case WM_COMMAND:
  364. switch (wPar)
  365. {
  366. case IDOK:
  367. EndDialog(hDlg, FALSE);
  368. break;
  369. case IDC_NAG_CODE:
  370. DoRegisterDlg(hDlg);
  371. break;
  372. case IDC_NAG_PURCHASE:
  373. DoUpgradeDlg(hDlg);
  374. break;
  375. default:
  376. return FALSE;
  377. }
  378. break;
  379. default:
  380. return FALSE;
  381. }
  382. return TRUE;
  383. }
  384. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  385. * FUNCTION:
  386. * NagRegisterDlgProc
  387. *
  388. * DESCRIPTION:
  389. * The dialog procedure for the "Nag Register" dialog.
  390. *
  391. * PARAMETERS:
  392. * hDlg - The dialog's window handle.
  393. * wMsg - The message being sent to the window.
  394. * wPar - The message's wParam.
  395. * lPar - The message's lParam.
  396. *
  397. * RETURNS:
  398. * TRUE or FALSE
  399. *
  400. * AUTHOR: Mike Thompson 06-29-98
  401. */
  402. BOOL CALLBACK NagRegisterDlgProc(HWND hDlg, UINT wMsg, WPARAM wPar, LPARAM lPar)
  403. {
  404. TCHAR buffer[MAX_USER_SERIAL_NUMBER + sizeof(TCHAR)];
  405. static DWORD aHlpTable[] = {IDCANCEL, IDH_CANCEL,
  406. IDOK, IDH_OK,
  407. 0, 0};
  408. switch (wMsg)
  409. {
  410. case WM_INITDIALOG:
  411. break;
  412. case WM_SHOWWINDOW:
  413. SetFocus( GetDlgItem(hDlg, IDC_REGISTER_EDIT) );
  414. //
  415. // Limit the length of text a user can enter for a registeration
  416. // code to the maximum serial number length. REV 8/27/98.
  417. //
  418. SendMessage(GetDlgItem(hDlg, IDC_REGISTER_EDIT), EM_LIMITTEXT,
  419. MAX_USER_SERIAL_NUMBER, 0);
  420. break;
  421. case WM_DESTROY:
  422. break;
  423. case WM_HELP:
  424. doContextHelp(aHlpTable, wPar, lPar, FALSE, FALSE);
  425. break;
  426. case WM_COMMAND:
  427. switch (wPar)
  428. {
  429. case IDOK:
  430. GetDlgItemText(hDlg, IDC_REGISTER_EDIT, buffer,
  431. sizeof(buffer)/sizeof(TCHAR));
  432. if ( IsValidSerialNumber(buffer) == TRUE )
  433. {
  434. SetNagFlag(buffer);
  435. elapsedTime = timeout; //get rid of parent window
  436. EndDialog(hDlg, FALSE);
  437. }
  438. else
  439. {
  440. TimedMessageBox(hDlg, "Invalid registration code.",
  441. NULL, MB_OK | MB_ICONEXCLAMATION, 0);
  442. SetFocus( GetDlgItem(hDlg, IDC_REGISTER_EDIT) );
  443. }
  444. break;
  445. case IDCANCEL:
  446. EndDialog(hDlg, FALSE);
  447. break;
  448. default:
  449. return FALSE;
  450. }
  451. break;
  452. default:
  453. return FALSE;
  454. }
  455. return TRUE;
  456. }
  457. #endif