-
Notifications
You must be signed in to change notification settings - Fork 0
/
replicaterelay.dpr
205 lines (185 loc) · 10.8 KB
/
replicaterelay.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{
mysql-replication-relay
Copyright (C) 2023 Freedelity
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
}
program replicaterelay;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
uses
{$IFDEF FPC}
CThreads,
{$ENDIF}
Declarations in 'Declarations.pas',
ReplicationRelayStructures in 'ReplicationRelayStructures.pas',
HFNV1A in 'HFNV1A.pas',
ClassMysqlReplicationClient in 'ClassMysqlReplicationClient.pas',
ClassServer in 'ClassServer.pas',
ClassServerHandler in 'ClassServerHandler.pas',
ClassReplicationRelay in 'ClassReplicationRelay.pas',
ClassCompat in 'ClassCompat.pas',
ClassDebug in 'ClassDebug.pas',
ClassMySQL in 'ClassMySQL.pas',
IdThreadSafe in '..\..\Components\Indy10.5\Lib\Core\IdThreadSafe.pas',
IdIDN in '..\..\Components\Indy10.5\Lib\System\IdIDN.pas',
IdGlobal in '..\..\Components\Indy10.5\Lib\System\IdGlobal.pas',
IdStream in '..\..\Components\Indy10.5\Lib\System\IdStream.pas',
IdStreamVCL in '..\..\Components\Indy10.5\Lib\System\IdStreamVCL.pas',
IdResourceStrings in '..\..\Components\Indy10.5\Lib\System\IdResourceStrings.pas',
IdException in '..\..\Components\Indy10.5\Lib\System\IdException.pas',
IdBaseComponent in '..\..\Components\Indy10.5\Lib\System\IdBaseComponent.pas',
IdTCPServer in '..\..\Components\Indy10.5\Lib\Core\IdTCPServer.pas',
IdCustomTCPServer in '..\..\Components\Indy10.5\Lib\Core\IdCustomTCPServer.pas',
IdContext in '..\..\Components\Indy10.5\Lib\Core\IdContext.pas',
IdComponent in '..\..\Components\Indy10.5\Lib\System\IdComponent.pas',
IdStack in '..\..\Components\Indy10.5\Lib\System\IdStack.pas',
IdStackConsts in '..\..\Components\Indy10.5\Lib\System\IdStackConsts.pas',
IdStackBSDBase in '..\..\Components\Indy10.5\Lib\System\IdStackBSDBase.pas',
IdSocketHandle in '..\..\Components\Indy10.5\Lib\Core\IdSocketHandle.pas',
IdAntiFreezeBase in '..\..\Components\Indy10.5\Lib\System\IdAntiFreezeBase.pas',
IdTCPConnection in '..\..\Components\Indy10.5\Lib\Core\IdTCPConnection.pas',
IdExceptionCore in '..\..\Components\Indy10.5\Lib\Core\IdExceptionCore.pas',
IdIntercept in '..\..\Components\Indy10.5\Lib\Core\IdIntercept.pas',
IdResourceStringsCore in '..\..\Components\Indy10.5\Lib\Core\IdResourceStringsCore.pas',
IdBuffer in '..\..\Components\Indy10.5\Lib\Core\IdBuffer.pas',
IdIOHandler in '..\..\Components\Indy10.5\Lib\Core\IdIOHandler.pas',
IdIOHandlerSocket in '..\..\Components\Indy10.5\Lib\Core\IdIOHandlerSocket.pas',
IdCustomTransparentProxy in '..\..\Components\Indy10.5\Lib\Core\IdCustomTransparentProxy.pas',
IdSocks in '..\..\Components\Indy10.5\Lib\Core\IdSocks.pas',
IdAssignedNumbers in '..\..\Components\Indy10.5\Lib\Core\IdAssignedNumbers.pas',
IdIPAddress in '..\..\Components\Indy10.5\Lib\Core\IdIPAddress.pas',
IdTCPClient in '..\..\Components\Indy10.5\Lib\Core\IdTCPClient.pas',
IdIOHandlerStack in '..\..\Components\Indy10.5\Lib\Core\IdIOHandlerStack.pas',
IdReply in '..\..\Components\Indy10.5\Lib\Core\IdReply.pas',
IdReplyRFC in '..\..\Components\Indy10.5\Lib\Core\IdReplyRFC.pas',
IdScheduler in '..\..\Components\Indy10.5\Lib\Core\IdScheduler.pas',
IdThread in '..\..\Components\Indy10.5\Lib\Core\IdThread.pas',
IdSchedulerOfThread in '..\..\Components\Indy10.5\Lib\Core\IdSchedulerOfThread.pas',
IdServerIOHandler in '..\..\Components\Indy10.5\Lib\Core\IdServerIOHandler.pas',
IdServerIOHandlerStack in '..\..\Components\Indy10.5\Lib\Core\IdServerIOHandlerStack.pas',
IdServerIOHandlerSocket in '..\..\Components\Indy10.5\Lib\Core\IdServerIOHandlerSocket.pas',
IdGlobalCore in '..\..\Components\Indy10.5\Lib\Core\IdGlobalCore.pas',
IdSchedulerOfThreadDefault in '..\..\Components\Indy10.5\Lib\Core\IdSchedulerOfThreadDefault.pas',
IdHTTP in '..\..\Components\Indy10.5\Lib\Protocols\IdHTTP.pas',
IdHTTPServer in '..\..\Components\Indy10.5\Lib\Protocols\IdHTTPServer.pas',
IdCustomHTTPServer in '..\..\Components\Indy10.5\Lib\Protocols\IdCustomHTTPServer.pas',
IdHeaderList in '..\..\Components\Indy10.5\Lib\Protocols\IdHeaderList.pas',
IdGlobalProtocols in '..\..\Components\Indy10.5\Lib\Protocols\IdGlobalProtocols.pas',
IdCharsets in '..\..\Components\Indy10.5\Lib\Protocols\IdCharsets.pas',
IdResourceStringsProtocols in '..\..\Components\Indy10.5\Lib\Protocols\IdResourceStringsProtocols.pas',
IdHTTPHeaderInfo in '..\..\Components\Indy10.5\Lib\Protocols\IdHTTPHeaderInfo.pas',
IdAuthentication in '..\..\Components\Indy10.5\Lib\Protocols\IdAuthentication.pas',
IdCoderMIME in '..\..\Components\Indy10.5\Lib\Protocols\IdCoderMIME.pas',
IdCoder3to4 in '..\..\Components\Indy10.5\Lib\Protocols\IdCoder3to4.pas',
IdCoder in '..\..\Components\Indy10.5\Lib\Protocols\IdCoder.pas',
IdSSL in '..\..\Components\Indy10.5\Lib\Protocols\IdSSL.pas',
IdZLibCompressorBase in '..\..\Components\Indy10.5\Lib\Protocols\IdZLibCompressorBase.pas',
IdURI in '..\..\Components\Indy10.5\Lib\Protocols\IdURI.pas',
IdUriUtils in '..\..\Components\Indy10.5\Lib\Protocols\IdUriUtils.pas',
IdResourceStringsUriUtils in '..\..\Components\Indy10.5\Lib\Protocols\IdResourceStringsUriUtils.pas',
IdCookie in '..\..\Components\Indy10.5\Lib\Protocols\IdCookie.pas',
IdCookieManager in '..\..\Components\Indy10.5\Lib\Protocols\IdCookieManager.pas',
IdAuthenticationManager in '..\..\Components\Indy10.5\Lib\Protocols\IdAuthenticationManager.pas',
IdMultipartFormData in '..\..\Components\Indy10.5\Lib\Protocols\IdMultipartFormData.pas',
IdCoderHeader in '..\..\Components\Indy10.5\Lib\Protocols\IdCoderHeader.pas',
IdEMailAddress in '..\..\Components\Indy10.5\Lib\Protocols\IdEMailAddress.pas',
IdHeaderCoderBase in '..\..\Components\Indy10.5\Lib\Protocols\IdHeaderCoderBase.pas',
IdAllHeaderCoders in '..\..\Components\Indy10.5\Lib\Protocols\IdAllHeaderCoders.pas',
IdHeaderCoderPlain in '..\..\Components\Indy10.5\Lib\Protocols\IdHeaderCoderPlain.pas',
IdHeaderCoder2022JP in '..\..\Components\Indy10.5\Lib\Protocols\IdHeaderCoder2022JP.pas',
IdHeaderCoderIndy in '..\..\Components\Indy10.5\Lib\Protocols\IdHeaderCoderIndy.pas',
IdCoderQuotedPrintable in '..\..\Components\Indy10.5\Lib\Protocols\IdCoderQuotedPrintable.pas',
IdAllAuthentications in '..\..\Components\Indy10.5\Lib\Protocols\IdAllAuthentications.pas',
IdAuthenticationNTLM in '..\..\Components\Indy10.5\Lib\Protocols\IdAuthenticationNTLM.pas',
IdResourceStringsOpenSSL in '..\..\Components\Indy10.5\Lib\Protocols\IdResourceStringsOpenSSL.pas',
IdSSLOpenSSLHeaders in '..\..\Components\Indy10.5\Lib\Protocols\IdSSLOpenSSLHeaders.pas',
IdCTypes in '..\..\Components\Indy10.5\Lib\System\IdCTypes.pas',
IdFIPS in '..\..\Components\Indy10.5\Lib\Protocols\IdFIPS.pas',
IdSSLOpenSSL in '..\..\Components\Indy10.5\Lib\Protocols\IdSSLOpenSSL.pas',
IdNTLM in '..\..\Components\Indy10.5\Lib\Protocols\IdNTLM.pas',
IdStruct in '..\..\Components\Indy10.5\Lib\System\IdStruct.pas',
IdHash in '..\..\Components\Indy10.5\Lib\Protocols\IdHash.pas',
IdHashMessageDigest in '..\..\Components\Indy10.5\Lib\Protocols\IdHashMessageDigest.pas',
IdResourceStringsSSPI in '..\..\Components\Indy10.5\Lib\Protocols\IdResourceStringsSSPI.pas',
IdAuthenticationDigest in '..\..\Components\Indy10.5\Lib\Protocols\IdAuthenticationDigest.pas',
IdDNSResolver in '..\..\Components\Indy10.5\Lib\Protocols\IdDNSResolver.pas',
IdNetworkCalculator in '..\..\Components\Indy10.5\Lib\Protocols\IdNetworkCalculator.pas',
IdDNSCommon in '..\..\Components\Indy10.5\Lib\Protocols\IdDNSCommon.pas',
IdContainers in '..\..\Components\Indy10.5\Lib\Protocols\IdContainers.pas',
IdUDPClient in '..\..\Components\Indy10.5\Lib\Core\IdUDPClient.pas',
IdUDPBase in '..\..\Components\Indy10.5\Lib\Core\IdUDPBase.pas',
{$IFDEF MSWINDOWS}
IdStackWindows in '..\..\Components\Indy10.5\Lib\System\IdStackWindows.pas',
IdWinsock2 in '..\..\Components\Indy10.5\Lib\System\IdWinsock2.pas',
IdWship6 in '..\..\Components\Indy10.5\Lib\System\IdWship6.pas',
IdAuthenticationSSPI in '..\..\Components\Indy10.5\Lib\Protocols\IdAuthenticationSSPI.pas',
IdSSPI in '..\..\Components\Indy10.5\Lib\Protocols\IdSSPI.pas',
{$ELSE}
IdResourceStringsUnix in '..\..\Components\Indy10.5\Lib\System\IdResourceStringsUnix.pas',
IdStackUnix in '..\..\Components\Indy10.5\Lib\System\IdStackUnix.pas',
{$ENDIF}
IdTask in '..\..\Components\Indy10.5\Lib\Core\IdTask.pas',
IdYarn in '..\..\Components\Indy10.5\Lib\Core\IdYarn.pas',
IdHashSHA1 in '..\..\Components\Indy10.5\Lib\Protocols\IdHashSHA1.pas',
MySQL in '.\MySQL.pas',
Classes,
SyncObjs,
IniFiles,
SysUtils;
var
GRelay: TReplicationRelay;
resu: Integer;
mypid: Integer;
FOptions: TIniFile;
begin
mypid:=GetProcessID();
FOptions := TIniFile.Create('./replicaterelay.conf');
GDebugPath := '/var/log/replicaterelay/';
GDebugPrefix := 'replicate-relay';
CreatePidFile('replicate-relay');
AddToLog(llWarning, '*******************************************');
AddToLog(llWarning, '* Starting Replication Relay V 20230803e *');
AddToLog(llWarning, '*******************************************');
AddToLog(llWarning,'ProcessID : '+IntToStr(mypid));
GInstanceID:=DateTimeToUnix(Now);
AddToLog(llWarning, 'Instance ID = '+IntToHex(GInstanceID,4));
libmysql_load(nil);
GRelay:=TReplicationRelay.Create(true);
resu:=GRelay.Init(
FOptions.ReadString('Server','IPAddr', ''),
FOptions.ReadString('Server','Login', ''),
FOptions.ReadString('Server','Password', ''),
FOptions.ReadString('Server','DatabaseName', ''),
FOptions.ReadString('Server','AdminSecret', ''),
FOptions.ReadString('Server','AuthSecret', ''),
StrToInt(FOptions.ReadString('Server','ServerPort', '6001')),
FOptions.ReadString('Server','HTTPAddress', '0.0.0.0'),
StrToInt(FOptions.ReadString('Server','HTTPPort', '6081')),
FOptions.ReadString('Logger','Path', '/var/log/replicaterelay/'),
FOptions.ReadString('Logger','Schema', ''),
FOptions.ReadString('Logger','Excludes', '')
);
if(resu=0) then
begin
AddToLog(llWarning,'Replication Relay Init Failed => Exiting');
Exit;
end;
GRelay.Start;
while(true) do
begin
//AddToLog(llWarning,'Tick');
CheckSynchronize(1);
Sleep(1);
end;
GRelay.Free;
end.