1
0

Configuration.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. //---------------------------------------------------------------------------
  2. #ifndef ConfigurationH
  3. #define ConfigurationH
  4. #include <set>
  5. #include "RemoteFiles.h"
  6. #include "FileBuffer.h"
  7. #include "HierarchicalStorage.h"
  8. #include "Usage.h"
  9. //---------------------------------------------------------------------------
  10. #define SET_CONFIG_PROPERTY_EX(PROPERTY, APPLY) \
  11. if (PROPERTY != value) { F ## PROPERTY = value; Changed(); APPLY; }
  12. #define SET_CONFIG_PROPERTY(PROPERTY) \
  13. SET_CONFIG_PROPERTY_EX(PROPERTY, )
  14. //---------------------------------------------------------------------------
  15. extern const wchar_t * AutoSwitchNames;
  16. extern const wchar_t * NotAutoSwitchNames;
  17. enum TAutoSwitch { asOn, asOff, asAuto }; // Has to match PuTTY FORCE_ON, FORCE_OFF, AUTO
  18. //---------------------------------------------------------------------------
  19. class TStoredSessionList;
  20. //---------------------------------------------------------------------------
  21. class TConfiguration : public TObject
  22. {
  23. private:
  24. bool FDontSave;
  25. bool FForceSave;
  26. bool FChanged;
  27. int FUpdating;
  28. TNotifyEvent FOnChange;
  29. void * FApplicationInfo;
  30. TUsage * FUsage;
  31. bool FLogging;
  32. bool FPermanentLogging;
  33. UnicodeString FLogFileName;
  34. UnicodeString FPermanentLogFileName;
  35. int FLogWindowLines;
  36. bool FLogFileAppend;
  37. bool FLogSensitive;
  38. bool FPermanentLogSensitive;
  39. __int64 FLogMaxSize;
  40. __int64 FPermanentLogMaxSize;
  41. int FLogMaxCount;
  42. int FPermanentLogMaxCount;
  43. int FLogProtocol;
  44. int FPermanentLogProtocol;
  45. int FActualLogProtocol;
  46. bool FLogActions;
  47. bool FPermanentLogActions;
  48. bool FLogActionsRequired;
  49. UnicodeString FActionsLogFileName;
  50. UnicodeString FPermanentActionsLogFileName;
  51. bool FConfirmOverwriting;
  52. bool FConfirmResume;
  53. bool FAutoReadDirectoryAfterOp;
  54. int FSessionReopenAuto;
  55. int FSessionReopenBackground;
  56. int FSessionReopenTimeout;
  57. int FSessionReopenAutoStall;
  58. UnicodeString FCustomIniFileStorageName;
  59. UnicodeString FIniFileStorageName;
  60. UnicodeString FVirtualIniFileStorageName;
  61. std::unique_ptr<TStrings> FOptionsStorage;
  62. int FProgramIniPathWrittable;
  63. int FTunnelLocalPortNumberLow;
  64. int FTunnelLocalPortNumberHigh;
  65. int FCacheDirectoryChangesMaxSize;
  66. bool FShowFtpWelcomeMessage;
  67. UnicodeString FDefaultRandomSeedFile;
  68. UnicodeString FRandomSeedFile;
  69. UnicodeString FPuttyRegistryStorageKey;
  70. UnicodeString FExternalIpAddress;
  71. bool FTryFtpWhenSshFails;
  72. int FParallelDurationThreshold;
  73. bool FScripting;
  74. UnicodeString FMimeTypes;
  75. int FDontReloadMoreThanSessions;
  76. int FScriptProgressFileNameLimit;
  77. bool FDisablePasswordStoring;
  78. bool FForceBanners;
  79. bool FDisableAcceptingHostKeys;
  80. bool FDefaultCollectUsage;
  81. TVSFixedFileInfo *__fastcall GetFixedApplicationInfo();
  82. void * __fastcall GetApplicationInfo();
  83. virtual UnicodeString __fastcall GetVersionStr();
  84. virtual UnicodeString __fastcall GetVersion();
  85. UnicodeString __fastcall GetProductVersion();
  86. UnicodeString __fastcall GetProductName();
  87. UnicodeString __fastcall GetCompanyName();
  88. UnicodeString __fastcall GetFileVersion(TVSFixedFileInfo * Info);
  89. UnicodeString __fastcall GetStoredSessionsSubKey();
  90. UnicodeString __fastcall GetPuttySessionsKey();
  91. void __fastcall SetRandomSeedFile(UnicodeString value);
  92. UnicodeString __fastcall GetRandomSeedFileName();
  93. void __fastcall SetPuttyRegistryStorageKey(UnicodeString value);
  94. UnicodeString __fastcall GetSshHostKeysSubKey();
  95. UnicodeString __fastcall GetRootKeyStr();
  96. UnicodeString __fastcall GetConfigurationSubKey();
  97. TEOLType __fastcall GetLocalEOLType();
  98. void __fastcall SetLogging(bool value);
  99. bool __fastcall GetLogging();
  100. void __fastcall SetLogFileName(UnicodeString value);
  101. UnicodeString __fastcall GetLogFileName();
  102. bool __fastcall GetLogToFile();
  103. void __fastcall SetLogFileAppend(bool value);
  104. void __fastcall SetLogSensitive(bool value);
  105. void __fastcall SetLogMaxSize(__int64 value);
  106. __int64 __fastcall GetLogMaxSize();
  107. void __fastcall SetLogMaxCount(int value);
  108. int __fastcall GetLogMaxCount();
  109. void __fastcall SetLogProtocol(int value);
  110. void __fastcall SetLogActions(bool value);
  111. bool __fastcall GetLogActions();
  112. void __fastcall SetActionsLogFileName(UnicodeString value);
  113. UnicodeString __fastcall GetPermanentActionsLogFileName();
  114. UnicodeString __fastcall GetActionsLogFileName();
  115. UnicodeString __fastcall GetDefaultLogFileName();
  116. UnicodeString __fastcall GetTimeFormat();
  117. UnicodeString __fastcall GetRegistryStorageKey();
  118. UnicodeString __fastcall GetIniFileStorageNameForReadingWriting();
  119. UnicodeString __fastcall GetIniFileStorageNameForReading();
  120. UnicodeString __fastcall GetIniFileStorageName(bool ReadingOnly);
  121. void __fastcall SetIniFileStorageName(UnicodeString value);
  122. void __fastcall SetOptionsStorage(TStrings * value);
  123. TStrings * __fastcall GetOptionsStorage();
  124. UnicodeString __fastcall GetPartialExt() const;
  125. UnicodeString __fastcall GetFileInfoString(const UnicodeString Key);
  126. void __fastcall SetSessionReopenAuto(int value);
  127. void __fastcall SetSessionReopenBackground(int value);
  128. void __fastcall SetSessionReopenTimeout(int value);
  129. void __fastcall SetSessionReopenAutoStall(int value);
  130. void __fastcall SetTunnelLocalPortNumberLow(int value);
  131. void __fastcall SetTunnelLocalPortNumberHigh(int value);
  132. void __fastcall SetCacheDirectoryChangesMaxSize(int value);
  133. void __fastcall SetShowFtpWelcomeMessage(bool value);
  134. int __fastcall GetCompoundVersion();
  135. void __fastcall UpdateActualLogProtocol();
  136. void __fastcall SetExternalIpAddress(UnicodeString value);
  137. void __fastcall SetTryFtpWhenSshFails(bool value);
  138. void __fastcall SetParallelDurationThreshold(int value);
  139. void __fastcall SetMimeTypes(UnicodeString value);
  140. bool __fastcall GetCollectUsage();
  141. void __fastcall SetCollectUsage(bool value);
  142. bool __fastcall GetIsUnofficial();
  143. bool __fastcall GetPersistent();
  144. protected:
  145. TStorage FStorage;
  146. TCriticalSection * FCriticalSection;
  147. virtual TStorage __fastcall GetStorage();
  148. virtual void __fastcall Changed();
  149. virtual void __fastcall SaveData(THierarchicalStorage * Storage, bool All);
  150. virtual void __fastcall LoadData(THierarchicalStorage * Storage);
  151. virtual void __fastcall LoadFrom(THierarchicalStorage * Storage);
  152. virtual void __fastcall CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target);
  153. virtual void __fastcall LoadAdmin(THierarchicalStorage * Storage);
  154. virtual UnicodeString __fastcall GetDefaultKeyFile();
  155. virtual void __fastcall Saved();
  156. void __fastcall CleanupRegistry(UnicodeString CleanupSubKey);
  157. UnicodeString __fastcall BannerHash(const UnicodeString & Banner);
  158. void __fastcall SetBannerData(const UnicodeString & SessionKey, const UnicodeString & BannerHash, unsigned int Params);
  159. void __fastcall GetBannerData(const UnicodeString & SessionKey, UnicodeString & BannerHash, unsigned int & Params);
  160. static UnicodeString __fastcall PropertyToKey(const UnicodeString & Property);
  161. virtual void __fastcall DoSave(bool All, bool Explicit);
  162. UnicodeString __fastcall FormatFingerprintKey(const UnicodeString & SiteKey, const UnicodeString & FingerprintType);
  163. virtual bool __fastcall GetConfirmOverwriting();
  164. virtual void __fastcall SetConfirmOverwriting(bool value);
  165. bool __fastcall GetConfirmResume();
  166. void __fastcall SetConfirmResume(bool value);
  167. bool __fastcall GetAutoReadDirectoryAfterOp();
  168. void __fastcall SetAutoReadDirectoryAfterOp(bool value);
  169. virtual bool __fastcall GetRememberPassword();
  170. UnicodeString __fastcall GetReleaseType();
  171. UnicodeString __fastcall LoadCustomIniFileStorageName();
  172. void __fastcall SaveCustomIniFileStorageName();
  173. UnicodeString __fastcall GetRegistryStorageOverrideKey();
  174. virtual UnicodeString __fastcall ModuleFileName();
  175. UnicodeString __fastcall GetFileFileInfoString(const UnicodeString Key,
  176. const UnicodeString FileName, bool AllowEmpty = false);
  177. void * __fastcall GetFileApplicationInfo(const UnicodeString FileName);
  178. UnicodeString __fastcall GetFileProductVersion(const UnicodeString FileName);
  179. UnicodeString __fastcall GetFileProductName(const UnicodeString FileName);
  180. UnicodeString __fastcall GetFileCompanyName(const UnicodeString FileName);
  181. __property bool PermanentLogging = { read=GetLogging, write=SetLogging };
  182. __property UnicodeString PermanentLogFileName = { read=GetLogFileName, write=SetLogFileName };
  183. __property bool PermanentLogActions = { read=GetLogActions, write=SetLogActions };
  184. __property UnicodeString PermanentActionsLogFileName = { read=GetPermanentActionsLogFileName, write=SetActionsLogFileName };
  185. __property int PermanentLogProtocol = { read=FPermanentLogProtocol, write=SetLogProtocol };
  186. __property bool PermanentLogSensitive = { read=FPermanentLogSensitive, write=SetLogSensitive };
  187. __property __int64 PermanentLogMaxSize = { read=GetLogMaxSize, write=SetLogMaxSize };
  188. __property int PermanentLogMaxCount = { read=GetLogMaxCount, write=SetLogMaxCount };
  189. public:
  190. __fastcall TConfiguration();
  191. virtual __fastcall ~TConfiguration();
  192. virtual void __fastcall Default();
  193. virtual void __fastcall UpdateStaticUsage();
  194. void __fastcall Load(THierarchicalStorage * Storage);
  195. void __fastcall Save();
  196. void __fastcall SaveExplicit();
  197. void __fastcall MoveStorage(TStorage AStorage, const UnicodeString & ACustomIniFileStorageName);
  198. void __fastcall ScheduleCustomIniFileStorageUse(const UnicodeString & ACustomIniFileStorageName);
  199. void __fastcall SetNulStorage();
  200. void __fastcall SetDefaultStorage();
  201. UnicodeString __fastcall GetAutomaticIniFileStorageName(bool ReadingOnly);
  202. UnicodeString __fastcall GetDefaultIniFileExportPath();
  203. void __fastcall Export(const UnicodeString & FileName);
  204. void __fastcall Import(const UnicodeString & FileName);
  205. void __fastcall CleanupConfiguration();
  206. void __fastcall CleanupIniFile();
  207. void __fastcall CleanupHostKeys();
  208. void __fastcall CleanupRandomSeedFile();
  209. void __fastcall BeginUpdate();
  210. void __fastcall EndUpdate();
  211. void __fastcall DontSave();
  212. void __fastcall LoadDirectoryChangesCache(const UnicodeString SessionKey,
  213. TRemoteDirectoryChangesCache * DirectoryChangesCache);
  214. void __fastcall SaveDirectoryChangesCache(const UnicodeString SessionKey,
  215. TRemoteDirectoryChangesCache * DirectoryChangesCache);
  216. bool __fastcall ShowBanner(const UnicodeString & SessionKey, const UnicodeString & Banner, unsigned int & Params);
  217. void __fastcall NeverShowBanner(const UnicodeString & SessionKey, const UnicodeString & Banner);
  218. void __fastcall SetBannerParams(const UnicodeString & SessionKey, unsigned int Params);
  219. void __fastcall RememberLastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType, const UnicodeString & Fingerprint);
  220. UnicodeString __fastcall LastFingerprint(const UnicodeString & SiteKey, const UnicodeString & FingerprintType);
  221. THierarchicalStorage * CreateConfigStorage();
  222. virtual THierarchicalStorage * CreateScpStorage(bool & SessionList);
  223. void __fastcall TemporaryLogging(const UnicodeString ALogFileName);
  224. void __fastcall TemporaryActionsLogging(const UnicodeString ALogFileName);
  225. void __fastcall TemporaryLogProtocol(int ALogProtocol);
  226. void __fastcall TemporaryLogSensitive(bool ALogSensitive);
  227. void __fastcall TemporaryLogMaxSize(__int64 ALogMaxSize);
  228. void __fastcall TemporaryLogMaxCount(int ALogMaxCount);
  229. virtual RawByteString __fastcall EncryptPassword(UnicodeString Password, UnicodeString Key);
  230. virtual UnicodeString __fastcall DecryptPassword(RawByteString Password, UnicodeString Key);
  231. virtual RawByteString __fastcall StronglyRecryptPassword(RawByteString Password, UnicodeString Key);
  232. UnicodeString __fastcall GetFileDescription(const UnicodeString & FileName);
  233. UnicodeString __fastcall GetFileVersion(const UnicodeString & FileName);
  234. UnicodeString __fastcall GetFileMimeType(const UnicodeString & FileName);
  235. TStoredSessionList * __fastcall SelectFilezillaSessionsForImport(
  236. TStoredSessionList * Sessions, UnicodeString & Error);
  237. bool __fastcall AnyFilezillaSessionForImport(TStoredSessionList * Sessions);
  238. TStoredSessionList * __fastcall SelectKnownHostsSessionsForImport(
  239. TStoredSessionList * Sessions, UnicodeString & Error);
  240. TStoredSessionList * __fastcall SelectKnownHostsSessionsForImport(
  241. TStrings * Lines, TStoredSessionList * Sessions, UnicodeString & Error);
  242. __property TVSFixedFileInfo *FixedApplicationInfo = { read=GetFixedApplicationInfo };
  243. __property void * ApplicationInfo = { read=GetApplicationInfo };
  244. __property TUsage * Usage = { read = FUsage };
  245. __property bool CollectUsage = { read = GetCollectUsage, write = SetCollectUsage };
  246. __property UnicodeString StoredSessionsSubKey = {read=GetStoredSessionsSubKey};
  247. __property UnicodeString PuttyRegistryStorageKey = { read=FPuttyRegistryStorageKey, write=SetPuttyRegistryStorageKey };
  248. __property UnicodeString PuttySessionsKey = { read=GetPuttySessionsKey };
  249. __property UnicodeString RandomSeedFile = { read=FRandomSeedFile, write=SetRandomSeedFile };
  250. __property UnicodeString RandomSeedFileName = { read=GetRandomSeedFileName };
  251. __property UnicodeString SshHostKeysSubKey = { read=GetSshHostKeysSubKey };
  252. __property UnicodeString RootKeyStr = { read=GetRootKeyStr };
  253. __property UnicodeString ConfigurationSubKey = { read=GetConfigurationSubKey };
  254. __property TEOLType LocalEOLType = { read = GetLocalEOLType };
  255. __property UnicodeString VersionStr = { read=GetVersionStr };
  256. __property UnicodeString Version = { read=GetVersion };
  257. __property int CompoundVersion = { read=GetCompoundVersion };
  258. __property UnicodeString ProductVersion = { read=GetProductVersion };
  259. __property UnicodeString ProductName = { read=GetProductName };
  260. __property UnicodeString CompanyName = { read=GetCompanyName };
  261. __property bool IsUnofficial = { read = GetIsUnofficial };
  262. __property bool Logging = { read=FLogging, write=SetLogging };
  263. __property UnicodeString LogFileName = { read=FLogFileName, write=SetLogFileName };
  264. __property bool LogToFile = { read=GetLogToFile };
  265. __property bool LogFileAppend = { read=FLogFileAppend, write=SetLogFileAppend };
  266. __property bool LogSensitive = { read=FLogSensitive, write=SetLogSensitive };
  267. __property __int64 LogMaxSize = { read=FLogMaxSize, write=SetLogMaxSize };
  268. __property int LogMaxCount = { read=FLogMaxCount, write=SetLogMaxCount };
  269. __property int LogProtocol = { read=FLogProtocol, write=SetLogProtocol };
  270. __property int ActualLogProtocol = { read=FActualLogProtocol };
  271. __property bool LogActions = { read=FLogActions, write=SetLogActions };
  272. __property bool LogActionsRequired = { read=FLogActionsRequired, write=FLogActionsRequired };
  273. __property UnicodeString ActionsLogFileName = { read=GetActionsLogFileName, write=SetActionsLogFileName };
  274. __property UnicodeString DefaultLogFileName = { read=GetDefaultLogFileName };
  275. __property TNotifyEvent OnChange = { read = FOnChange, write = FOnChange };
  276. __property bool ConfirmOverwriting = { read = GetConfirmOverwriting, write = SetConfirmOverwriting};
  277. __property bool ConfirmResume = { read = GetConfirmResume, write = SetConfirmResume};
  278. __property bool AutoReadDirectoryAfterOp = { read = GetAutoReadDirectoryAfterOp, write = SetAutoReadDirectoryAfterOp};
  279. __property bool RememberPassword = { read = GetRememberPassword };
  280. __property UnicodeString PartialExt = {read=GetPartialExt};
  281. __property int SessionReopenAuto = { read = FSessionReopenAuto, write = SetSessionReopenAuto };
  282. __property int SessionReopenBackground = { read = FSessionReopenBackground, write = SetSessionReopenBackground };
  283. __property int SessionReopenTimeout = { read = FSessionReopenTimeout, write = SetSessionReopenTimeout };
  284. __property int SessionReopenAutoStall = { read = FSessionReopenAutoStall, write = SetSessionReopenAutoStall };
  285. __property int TunnelLocalPortNumberLow = { read = FTunnelLocalPortNumberLow, write = SetTunnelLocalPortNumberLow };
  286. __property int TunnelLocalPortNumberHigh = { read = FTunnelLocalPortNumberHigh, write = SetTunnelLocalPortNumberHigh };
  287. __property int CacheDirectoryChangesMaxSize = { read = FCacheDirectoryChangesMaxSize, write = SetCacheDirectoryChangesMaxSize };
  288. __property bool ShowFtpWelcomeMessage = { read = FShowFtpWelcomeMessage, write = SetShowFtpWelcomeMessage };
  289. __property UnicodeString ExternalIpAddress = { read = FExternalIpAddress, write = SetExternalIpAddress };
  290. __property bool TryFtpWhenSshFails = { read = FTryFtpWhenSshFails, write = SetTryFtpWhenSshFails };
  291. __property int ParallelDurationThreshold = { read = FParallelDurationThreshold, write = SetParallelDurationThreshold };
  292. __property UnicodeString MimeTypes = { read = FMimeTypes, write = SetMimeTypes };
  293. __property int DontReloadMoreThanSessions = { read = FDontReloadMoreThanSessions, write = FDontReloadMoreThanSessions };
  294. __property int ScriptProgressFileNameLimit = { read = FScriptProgressFileNameLimit, write = FScriptProgressFileNameLimit };
  295. __property UnicodeString TimeFormat = { read = GetTimeFormat };
  296. __property TStorage Storage = { read=GetStorage };
  297. __property UnicodeString RegistryStorageKey = { read=GetRegistryStorageKey };
  298. __property UnicodeString CustomIniFileStorageName = { read=FCustomIniFileStorageName };
  299. __property UnicodeString IniFileStorageName = { read=GetIniFileStorageNameForReadingWriting, write=SetIniFileStorageName };
  300. __property UnicodeString IniFileStorageNameForReading = { read=GetIniFileStorageNameForReading };
  301. __property TStrings * OptionsStorage = { read = GetOptionsStorage, write = SetOptionsStorage };
  302. __property bool Persistent = { read = GetPersistent };
  303. __property bool ForceSave = { read = FForceSave, write = FForceSave };
  304. __property bool Scripting = { read = FScripting, write = FScripting };
  305. __property UnicodeString DefaultKeyFile = { read = GetDefaultKeyFile };
  306. __property bool DisablePasswordStoring = { read = FDisablePasswordStoring };
  307. __property bool ForceBanners = { read = FForceBanners };
  308. __property bool DisableAcceptingHostKeys = { read = FDisableAcceptingHostKeys };
  309. };
  310. //---------------------------------------------------------------------------
  311. class TShortCuts
  312. {
  313. public:
  314. void __fastcall Add(TShortCut ShortCut);
  315. bool __fastcall Has(TShortCut ShortCut) const;
  316. private:
  317. std::set<TShortCut> FShortCuts;
  318. };
  319. //---------------------------------------------------------------------------
  320. extern const UnicodeString OriginalPuttyRegistryStorageKey;
  321. extern const UnicodeString KittyRegistryStorageKey;
  322. extern const UnicodeString OriginalPuttyExecutable;
  323. extern const UnicodeString KittyExecutable;
  324. //---------------------------------------------------------------------------
  325. extern const UnicodeString Sha1ChecksumAlg;
  326. extern const UnicodeString Sha224ChecksumAlg;
  327. extern const UnicodeString Sha256ChecksumAlg;
  328. extern const UnicodeString Sha384ChecksumAlg;
  329. extern const UnicodeString Sha512ChecksumAlg;
  330. extern const UnicodeString Md5ChecksumAlg;
  331. extern const UnicodeString Crc32ChecksumAlg;
  332. //---------------------------------------------------------------------------
  333. extern const UnicodeString SshFingerprintType;
  334. extern const UnicodeString TlsFingerprintType;
  335. //---------------------------------------------------------------------------
  336. extern const UnicodeString HttpsCertificateStorageKey;
  337. //---------------------------------------------------------------------------
  338. #endif