Configuration.h 14 KB

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