Configuration.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. enum TAutoSwitch { asOn, asOff, asAuto };
  16. //---------------------------------------------------------------------------
  17. class TConfiguration : public TObject
  18. {
  19. private:
  20. bool FDontSave;
  21. bool FChanged;
  22. int FUpdating;
  23. TNotifyEvent FOnChange;
  24. void * FApplicationInfo;
  25. TUsage * FUsage;
  26. bool FLogging;
  27. bool FPermanentLogging;
  28. UnicodeString FLogFileName;
  29. UnicodeString FPermanentLogFileName;
  30. int FLogWindowLines;
  31. bool FLogFileAppend;
  32. bool FLogSensitive;
  33. bool FPermanentLogSensitive;
  34. int FLogProtocol;
  35. int FPermanentLogProtocol;
  36. int FActualLogProtocol;
  37. bool FLogActions;
  38. bool FPermanentLogActions;
  39. UnicodeString FActionsLogFileName;
  40. UnicodeString FPermanentActionsLogFileName;
  41. bool FConfirmOverwriting;
  42. bool FConfirmResume;
  43. bool FAutoReadDirectoryAfterOp;
  44. int FSessionReopenAuto;
  45. int FSessionReopenBackground;
  46. int FSessionReopenTimeout;
  47. int FSessionReopenAutoStall;
  48. UnicodeString FIniFileStorageName;
  49. UnicodeString FVirtualIniFileStorageName;
  50. std::unique_ptr<TStrings> FOptionsStorage;
  51. int FProgramIniPathWrittable;
  52. int FTunnelLocalPortNumberLow;
  53. int FTunnelLocalPortNumberHigh;
  54. int FCacheDirectoryChangesMaxSize;
  55. bool FShowFtpWelcomeMessage;
  56. UnicodeString FDefaultRandomSeedFile;
  57. UnicodeString FRandomSeedFile;
  58. UnicodeString FPuttyRegistryStorageKey;
  59. UnicodeString FExternalIpAddress;
  60. bool FTryFtpWhenSshFails;
  61. bool FDisablePasswordStoring;
  62. bool FForceBanners;
  63. bool FDisableAcceptingHostKeys;
  64. bool FDefaultCollectUsage;
  65. UnicodeString __fastcall GetOSVersionStr();
  66. TVSFixedFileInfo *__fastcall GetFixedApplicationInfo();
  67. void * __fastcall GetApplicationInfo();
  68. virtual UnicodeString __fastcall GetVersionStr();
  69. virtual UnicodeString __fastcall GetVersion();
  70. UnicodeString __fastcall GetProductVersion();
  71. UnicodeString __fastcall GetProductName();
  72. UnicodeString __fastcall GetCompanyName();
  73. UnicodeString __fastcall GetStoredSessionsSubKey();
  74. UnicodeString __fastcall GetPuttySessionsKey();
  75. void __fastcall SetRandomSeedFile(UnicodeString value);
  76. UnicodeString __fastcall GetRandomSeedFileName();
  77. void __fastcall SetPuttyRegistryStorageKey(UnicodeString value);
  78. UnicodeString __fastcall GetSshHostKeysSubKey();
  79. UnicodeString __fastcall GetRootKeyStr();
  80. UnicodeString __fastcall GetConfigurationSubKey();
  81. TEOLType __fastcall GetLocalEOLType();
  82. void __fastcall SetLogging(bool value);
  83. void __fastcall SetLogFileName(UnicodeString value);
  84. bool __fastcall GetLogToFile();
  85. void __fastcall SetLogWindowLines(int value);
  86. void __fastcall SetLogWindowComplete(bool value);
  87. bool __fastcall GetLogWindowComplete();
  88. void __fastcall SetLogFileAppend(bool value);
  89. void __fastcall SetLogSensitive(bool value);
  90. void __fastcall SetLogProtocol(int value);
  91. void __fastcall SetLogActions(bool value);
  92. void __fastcall SetActionsLogFileName(UnicodeString value);
  93. UnicodeString __fastcall GetDefaultLogFileName();
  94. UnicodeString __fastcall GetTimeFormat();
  95. void __fastcall SetStorage(TStorage value);
  96. UnicodeString __fastcall GetRegistryStorageKey();
  97. UnicodeString __fastcall GetIniFileStorageNameForReadingWriting();
  98. UnicodeString __fastcall GetIniFileStorageNameForReading();
  99. UnicodeString __fastcall GetIniFileStorageName(bool ReadingOnly);
  100. void __fastcall SetIniFileStorageName(UnicodeString value);
  101. void __fastcall SetOptionsStorage(TStrings * value);
  102. TStrings * __fastcall GetOptionsStorage();
  103. UnicodeString __fastcall GetPartialExt() const;
  104. UnicodeString __fastcall GetFileInfoString(const UnicodeString Key);
  105. void __fastcall SetSessionReopenAuto(int value);
  106. void __fastcall SetSessionReopenBackground(int value);
  107. void __fastcall SetSessionReopenTimeout(int value);
  108. void __fastcall SetSessionReopenAutoStall(int value);
  109. void __fastcall SetTunnelLocalPortNumberLow(int value);
  110. void __fastcall SetTunnelLocalPortNumberHigh(int value);
  111. void __fastcall SetCacheDirectoryChangesMaxSize(int value);
  112. void __fastcall SetShowFtpWelcomeMessage(bool value);
  113. int __fastcall GetCompoundVersion();
  114. void __fastcall UpdateActualLogProtocol();
  115. void __fastcall SetExternalIpAddress(UnicodeString value);
  116. void __fastcall SetTryFtpWhenSshFails(bool value);
  117. bool __fastcall GetCollectUsage();
  118. void __fastcall SetCollectUsage(bool value);
  119. bool __fastcall GetIsUnofficial();
  120. protected:
  121. TStorage FStorage;
  122. TCriticalSection * FCriticalSection;
  123. virtual TStorage __fastcall GetStorage();
  124. virtual void __fastcall Changed();
  125. virtual void __fastcall SaveData(THierarchicalStorage * Storage, bool All);
  126. virtual void __fastcall LoadData(THierarchicalStorage * Storage);
  127. virtual void __fastcall LoadFrom(THierarchicalStorage * Storage);
  128. virtual void __fastcall CopyData(THierarchicalStorage * Source, THierarchicalStorage * Target);
  129. virtual void __fastcall LoadAdmin(THierarchicalStorage * Storage);
  130. virtual UnicodeString __fastcall GetDefaultKeyFile();
  131. virtual void __fastcall Saved();
  132. void __fastcall CleanupRegistry(UnicodeString CleanupSubKey);
  133. UnicodeString __fastcall BannerHash(const UnicodeString & Banner);
  134. static UnicodeString __fastcall PropertyToKey(const UnicodeString & Property);
  135. virtual void __fastcall DoSave(bool All, bool Explicit);
  136. virtual bool __fastcall GetConfirmOverwriting();
  137. virtual void __fastcall SetConfirmOverwriting(bool value);
  138. bool __fastcall GetConfirmResume();
  139. void __fastcall SetConfirmResume(bool value);
  140. bool __fastcall GetAutoReadDirectoryAfterOp();
  141. void __fastcall SetAutoReadDirectoryAfterOp(bool value);
  142. virtual bool __fastcall GetRememberPassword();
  143. UnicodeString __fastcall GetReleaseType();
  144. virtual UnicodeString __fastcall ModuleFileName();
  145. UnicodeString __fastcall GetFileFileInfoString(const UnicodeString Key,
  146. const UnicodeString FileName, bool AllowEmpty = false);
  147. void * __fastcall GetFileApplicationInfo(const UnicodeString FileName);
  148. UnicodeString __fastcall GetFileProductVersion(const UnicodeString FileName);
  149. UnicodeString __fastcall GetFileProductName(const UnicodeString FileName);
  150. UnicodeString __fastcall GetFileCompanyName(const UnicodeString FileName);
  151. __property bool PermanentLogging = { read=FPermanentLogging, write=SetLogging };
  152. __property UnicodeString PermanentLogFileName = { read=FPermanentLogFileName, write=SetLogFileName };
  153. __property bool PermanentLogActions = { read=FPermanentLogActions, write=SetLogActions };
  154. __property UnicodeString PermanentActionsLogFileName = { read=FPermanentActionsLogFileName, write=SetActionsLogFileName };
  155. __property int PermanentLogProtocol = { read=FPermanentLogProtocol, write=SetLogProtocol };
  156. __property bool PermanentLogSensitive = { read=FPermanentLogSensitive, write=SetLogSensitive };
  157. public:
  158. __fastcall TConfiguration();
  159. virtual __fastcall ~TConfiguration();
  160. virtual void __fastcall Default();
  161. virtual void __fastcall UpdateStaticUsage();
  162. void __fastcall Load(THierarchicalStorage * Storage);
  163. void __fastcall Save();
  164. void __fastcall SaveExplicit();
  165. void __fastcall SetNulStorage();
  166. void __fastcall SetDefaultStorage();
  167. void __fastcall Export(const UnicodeString & FileName);
  168. void __fastcall Import(const UnicodeString & FileName);
  169. void __fastcall CleanupConfiguration();
  170. void __fastcall CleanupIniFile();
  171. void __fastcall CleanupHostKeys();
  172. void __fastcall CleanupRandomSeedFile();
  173. void __fastcall BeginUpdate();
  174. void __fastcall EndUpdate();
  175. void __fastcall DontSave();
  176. void __fastcall LoadDirectoryChangesCache(const UnicodeString SessionKey,
  177. TRemoteDirectoryChangesCache * DirectoryChangesCache);
  178. void __fastcall SaveDirectoryChangesCache(const UnicodeString SessionKey,
  179. TRemoteDirectoryChangesCache * DirectoryChangesCache);
  180. bool __fastcall ShowBanner(const UnicodeString SessionKey, const UnicodeString & Banner);
  181. void __fastcall NeverShowBanner(const UnicodeString SessionKey, const UnicodeString & Banner);
  182. THierarchicalStorage * CreateConfigStorage();
  183. virtual THierarchicalStorage * CreateScpStorage(bool & SessionList);
  184. void __fastcall TemporaryLogging(const UnicodeString ALogFileName);
  185. void __fastcall TemporaryActionsLogging(const UnicodeString ALogFileName);
  186. void __fastcall TemporaryLogProtocol(int ALogProtocol);
  187. void __fastcall TemporaryLogSensitive(bool ALogSensitive);
  188. virtual RawByteString __fastcall EncryptPassword(UnicodeString Password, UnicodeString Key);
  189. virtual UnicodeString __fastcall DecryptPassword(RawByteString Password, UnicodeString Key);
  190. virtual RawByteString __fastcall StronglyRecryptPassword(RawByteString Password, UnicodeString Key);
  191. UnicodeString __fastcall GetFileDescription(const UnicodeString & FileName);
  192. __property TVSFixedFileInfo *FixedApplicationInfo = { read=GetFixedApplicationInfo };
  193. __property void * ApplicationInfo = { read=GetApplicationInfo };
  194. __property TUsage * Usage = { read = FUsage };
  195. __property bool CollectUsage = { read = GetCollectUsage, write = SetCollectUsage };
  196. __property UnicodeString StoredSessionsSubKey = {read=GetStoredSessionsSubKey};
  197. __property UnicodeString PuttyRegistryStorageKey = { read=FPuttyRegistryStorageKey, write=SetPuttyRegistryStorageKey };
  198. __property UnicodeString PuttySessionsKey = { read=GetPuttySessionsKey };
  199. __property UnicodeString RandomSeedFile = { read=FRandomSeedFile, write=SetRandomSeedFile };
  200. __property UnicodeString RandomSeedFileName = { read=GetRandomSeedFileName };
  201. __property UnicodeString SshHostKeysSubKey = { read=GetSshHostKeysSubKey };
  202. __property UnicodeString RootKeyStr = { read=GetRootKeyStr };
  203. __property UnicodeString ConfigurationSubKey = { read=GetConfigurationSubKey };
  204. __property TEOLType LocalEOLType = { read = GetLocalEOLType };
  205. __property UnicodeString VersionStr = { read=GetVersionStr };
  206. __property UnicodeString Version = { read=GetVersion };
  207. __property int CompoundVersion = { read=GetCompoundVersion };
  208. __property UnicodeString ProductVersion = { read=GetProductVersion };
  209. __property UnicodeString ProductName = { read=GetProductName };
  210. __property UnicodeString CompanyName = { read=GetCompanyName };
  211. __property UnicodeString OSVersionStr = { read = GetOSVersionStr };
  212. __property bool IsUnofficial = { read = GetIsUnofficial };
  213. __property bool Logging = { read=FLogging, write=SetLogging };
  214. __property UnicodeString LogFileName = { read=FLogFileName, write=SetLogFileName };
  215. __property bool LogToFile = { read=GetLogToFile };
  216. __property bool LogFileAppend = { read=FLogFileAppend, write=SetLogFileAppend };
  217. __property bool LogSensitive = { read=FLogSensitive, write=SetLogSensitive };
  218. __property int LogProtocol = { read=FLogProtocol, write=SetLogProtocol };
  219. __property int ActualLogProtocol = { read=FActualLogProtocol };
  220. __property bool LogActions = { read=FLogActions, write=SetLogActions };
  221. __property UnicodeString ActionsLogFileName = { read=FActionsLogFileName, write=SetActionsLogFileName };
  222. __property int LogWindowLines = { read=FLogWindowLines, write=SetLogWindowLines };
  223. __property bool LogWindowComplete = { read=GetLogWindowComplete, write=SetLogWindowComplete };
  224. __property UnicodeString DefaultLogFileName = { read=GetDefaultLogFileName };
  225. __property TNotifyEvent OnChange = { read = FOnChange, write = FOnChange };
  226. __property bool ConfirmOverwriting = { read = GetConfirmOverwriting, write = SetConfirmOverwriting};
  227. __property bool ConfirmResume = { read = GetConfirmResume, write = SetConfirmResume};
  228. __property bool AutoReadDirectoryAfterOp = { read = GetAutoReadDirectoryAfterOp, write = SetAutoReadDirectoryAfterOp};
  229. __property bool RememberPassword = { read = GetRememberPassword };
  230. __property UnicodeString PartialExt = {read=GetPartialExt};
  231. __property int SessionReopenAuto = { read = FSessionReopenAuto, write = SetSessionReopenAuto };
  232. __property int SessionReopenBackground = { read = FSessionReopenBackground, write = SetSessionReopenBackground };
  233. __property int SessionReopenTimeout = { read = FSessionReopenTimeout, write = SetSessionReopenTimeout };
  234. __property int SessionReopenAutoStall = { read = FSessionReopenAutoStall, write = SetSessionReopenAutoStall };
  235. __property int TunnelLocalPortNumberLow = { read = FTunnelLocalPortNumberLow, write = SetTunnelLocalPortNumberLow };
  236. __property int TunnelLocalPortNumberHigh = { read = FTunnelLocalPortNumberHigh, write = SetTunnelLocalPortNumberHigh };
  237. __property int CacheDirectoryChangesMaxSize = { read = FCacheDirectoryChangesMaxSize, write = SetCacheDirectoryChangesMaxSize };
  238. __property bool ShowFtpWelcomeMessage = { read = FShowFtpWelcomeMessage, write = SetShowFtpWelcomeMessage };
  239. __property UnicodeString ExternalIpAddress = { read = FExternalIpAddress, write = SetExternalIpAddress };
  240. __property bool TryFtpWhenSshFails = { read = FTryFtpWhenSshFails, write = SetTryFtpWhenSshFails };
  241. __property UnicodeString TimeFormat = { read = GetTimeFormat };
  242. __property TStorage Storage = { read=GetStorage, write=SetStorage };
  243. __property UnicodeString RegistryStorageKey = { read=GetRegistryStorageKey };
  244. __property UnicodeString IniFileStorageName = { read=GetIniFileStorageNameForReadingWriting, write=SetIniFileStorageName };
  245. __property UnicodeString IniFileStorageNameForReading = { read=GetIniFileStorageNameForReading };
  246. __property TStrings * OptionsStorage = { read = GetOptionsStorage, write = SetOptionsStorage };
  247. __property UnicodeString DefaultKeyFile = { read = GetDefaultKeyFile };
  248. __property bool DisablePasswordStoring = { read = FDisablePasswordStoring };
  249. __property bool ForceBanners = { read = FForceBanners };
  250. __property bool DisableAcceptingHostKeys = { read = FDisableAcceptingHostKeys };
  251. };
  252. //---------------------------------------------------------------------------
  253. class TShortCuts
  254. {
  255. public:
  256. void __fastcall Add(TShortCut ShortCut);
  257. bool __fastcall Has(TShortCut ShortCut) const;
  258. private:
  259. std::set<TShortCut> FShortCuts;
  260. };
  261. //---------------------------------------------------------------------------
  262. extern const UnicodeString OriginalPuttyRegistryStorageKey;
  263. extern const UnicodeString KittyRegistryStorageKey;
  264. extern const UnicodeString OriginalPuttyExecutable;
  265. extern const UnicodeString KittyExecutable;
  266. //---------------------------------------------------------------------------
  267. extern const UnicodeString Sha1ChecksumAlg;
  268. extern const UnicodeString Sha224ChecksumAlg;
  269. extern const UnicodeString Sha256ChecksumAlg;
  270. extern const UnicodeString Sha384ChecksumAlg;
  271. extern const UnicodeString Sha512ChecksumAlg;
  272. extern const UnicodeString Md5ChecksumAlg;
  273. extern const UnicodeString Crc32ChecksumAlg;
  274. //---------------------------------------------------------------------------
  275. #endif