Revision 727
Added by berkley almost 24 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
85 | 85 |
{ |
86 | 86 |
PrintWriter out = response.getWriter(); |
87 | 87 |
Hashtable params = new Hashtable(); |
88 |
Enumeration paramlist = request.getParameterNames(); |
|
88 |
Enumeration paramlist = request.getParameterNames(); |
|
89 |
String servletAction = null; |
|
89 | 90 |
|
91 |
String requestingServerIP = request.getRemoteAddr(); |
|
92 |
InetAddress iaddr = InetAddress.getByName(requestingServerIP); |
|
93 |
String requestingServer = iaddr.getHostName(); |
|
94 |
|
|
90 | 95 |
while (paramlist.hasMoreElements()) |
91 | 96 |
{ |
92 | 97 |
String name = (String)paramlist.nextElement(); |
... | ... | |
94 | 99 |
params.put(name, value); |
95 | 100 |
} |
96 | 101 |
|
102 |
servletAction = ((String[])params.get("action"))[0]; |
|
103 |
|
|
104 |
//if the requesting Server is not in the server list |
|
105 |
//reject this request |
|
106 |
//this does not protect against IP spoofing but it does |
|
107 |
//protect against simple URL parameter spoofing. |
|
108 |
//We need to add an authenticated "replication" user who can perform the |
|
109 |
//actions listed below in the !servletAction.equals calls. |
|
110 |
try |
|
111 |
{ |
|
112 |
if(getServerCode(requestingServer + "%") == 0 && |
|
113 |
!servletAction.equals("servercontrol") && |
|
114 |
!servletAction.equals("stop") && |
|
115 |
!servletAction.equals("start") && |
|
116 |
!servletAction.equals("getall")) |
|
117 |
{ |
|
118 |
System.out.println("action rejected for server: " + requestingServer); |
|
119 |
return; |
|
120 |
} |
|
121 |
System.out.println("action accepted for server: " + requestingServer); |
|
122 |
} |
|
123 |
catch(Exception e) |
|
124 |
{ |
|
125 |
System.out.println("error in MetacatReplication.handleGetOrPost" + |
|
126 |
": error authenticating server"); |
|
127 |
return; |
|
128 |
} |
|
129 |
|
|
97 | 130 |
if(params.containsKey("action")) |
98 | 131 |
{ |
99 |
if(((String[])params.get("action"))[0].equals("stop"))
|
|
132 |
if(servletAction.equals("stop"))
|
|
100 | 133 |
{ //stop the replication server |
101 | 134 |
replicationDaemon.cancel(); |
102 | 135 |
replicationDaemon = new Timer(true); |
... | ... | |
104 | 137 |
System.out.println("Replication Handler Stopped"); |
105 | 138 |
MetacatReplication.replLog("deltaT handler stopped"); |
106 | 139 |
} |
107 |
else if(((String[])params.get("action"))[0].equals("start"))
|
|
140 |
else if(servletAction.equals("start"))
|
|
108 | 141 |
{ //start the replication server |
109 | 142 |
int rate; |
110 | 143 |
if(params.containsKey("rate")) |
... | ... | |
133 | 166 |
out.println("Replication Handler Started"); |
134 | 167 |
System.out.println("Replication Handler Started"); |
135 | 168 |
} |
136 |
else if(((String[])params.get("action"))[0].equals("getall"))
|
|
169 |
else if(servletAction.equals("getall"))
|
|
137 | 170 |
{ //updates this server exactly once |
138 | 171 |
replicationDaemon.schedule(new ReplicationHandler(out), 0); |
139 | 172 |
response.setContentType("text/html"); |
140 | 173 |
out.println("<html><body>\"Get All\" Done</body></html>"); |
141 | 174 |
} |
142 |
else if(((String[])params.get("action"))[0].equals("forcereplicate"))
|
|
175 |
else if(servletAction.equals("forcereplicate"))
|
|
143 | 176 |
{ |
144 | 177 |
handleForceReplicateRequest(out, params, response); |
145 | 178 |
} |
146 |
else if(((String[])params.get("action"))[0].equals("update"))
|
|
179 |
else if(servletAction.equals("update"))
|
|
147 | 180 |
{ //request an update list from the server |
148 | 181 |
handleUpdateRequest(out, params, response); |
149 | 182 |
} |
150 |
else if(((String[])params.get("action"))[0].equals("read"))
|
|
183 |
else if(servletAction.equals("read"))
|
|
151 | 184 |
{ //request a specific document from the server |
152 | 185 |
//note that this could be replaced by a call to metacatServlet |
153 | 186 |
//handleGetDocumentAction(). |
154 | 187 |
handleGetDocumentRequest(out, params, response); |
155 | 188 |
} |
156 |
else if(((String[])params.get("action"))[0].equals("getlock"))
|
|
189 |
else if(servletAction.equals("getlock"))
|
|
157 | 190 |
{ |
158 | 191 |
handleGetLockRequest(out, params, response); |
159 | 192 |
} |
160 |
else if(((String[])params.get("action"))[0].equals("getdocumentinfo"))
|
|
193 |
else if(servletAction.equals("getdocumentinfo"))
|
|
161 | 194 |
{ |
162 | 195 |
handleGetDocumentInfoRequest(out, params, response); |
163 | 196 |
} |
164 |
else if(((String[])params.get("action"))[0].equals("gettime"))
|
|
197 |
else if(servletAction.equals("gettime"))
|
|
165 | 198 |
{ |
166 | 199 |
handleGetTimeRequest(out, params, response); |
167 | 200 |
} |
168 |
else if(((String[])params.get("action"))[0].equals("getcatalog"))
|
|
201 |
else if(servletAction.equals("getcatalog"))
|
|
169 | 202 |
{ |
170 | 203 |
handleGetCatalogRequest(out, params, response, true); |
171 | 204 |
} |
172 |
else if(((String[])params.get("action"))[0].equals("servercontrol"))
|
|
205 |
else if(servletAction.equals("servercontrol"))
|
|
173 | 206 |
{ |
174 | 207 |
handleServerControlRequest(out, params, response); |
175 | 208 |
} |
Also available in: Unified diff
added check to see if a replication server's IP matched it's DNS entry and the entry in the replication table