1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
|
package uk.org.iscream.cms.server.core; |
22 |
|
|
326 |
|
Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator(); |
327 |
|
while(i.hasNext()) { |
328 |
|
String key = (String) i.next(); |
329 |
+ |
// look for a key that's a group entry |
330 |
|
if (key.startsWith("group.")) { |
331 |
+ |
// get the list of hosts in the group |
332 |
|
String group = _systemConfig.getProperty(key); |
333 |
< |
// if it is in the group |
313 |
< |
if (group.indexOf(source) != -1) { |
333 |
> |
if(groupMatch(source, group)) { |
334 |
|
groupMembership.add(key.substring(6)); |
335 |
< |
_logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in - " + key); |
316 |
< |
|
317 |
< |
// if there are wildcards in the group |
318 |
< |
} else if (group.indexOf("*") != -1) { |
319 |
< |
// check the wildcards apply to this srce |
320 |
< |
if(StringUtils.wildcardCheck(source, group)) { |
321 |
< |
groupMembership.add(key.substring(6)); |
322 |
< |
_logger.write(toString(), Logger.DEBUG, "wildcard group match found for - " + source + " in - " + key); |
323 |
< |
} |
335 |
> |
_logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in group - " + key); |
336 |
|
} |
325 |
– |
|
337 |
|
} |
338 |
|
} |
339 |
|
return groupMembership; |
340 |
+ |
} |
341 |
+ |
|
342 |
+ |
/** |
343 |
+ |
* Checks that a given source is matched within the |
344 |
+ |
* given list of hosts. For example:<br> |
345 |
+ |
* <br> |
346 |
+ |
* Given "stue5de.ukc.ac.uk"<br> |
347 |
+ |
* And "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br> |
348 |
+ |
* <br> |
349 |
+ |
* This method would return true as there is a match. |
350 |
+ |
* |
351 |
+ |
* This method will also match if the source is exactly |
352 |
+ |
* matched within the group of hosts (ie. no wildcard). |
353 |
+ |
* |
354 |
+ |
* @param source the string to look for |
355 |
+ |
* @param group the group to search for a match |
356 |
+ |
* |
357 |
+ |
* @return if there is a match |
358 |
+ |
*/ |
359 |
+ |
public static boolean groupMatch(String source, String group) { |
360 |
+ |
StringTokenizer st = new StringTokenizer(group, ";"); |
361 |
+ |
// go through all the hosts in the group |
362 |
+ |
while (st.hasMoreTokens()) { |
363 |
+ |
String host = st.nextToken(); |
364 |
+ |
if(StringUtils.wildcardMatch(source, host)) { |
365 |
+ |
return true; |
366 |
+ |
} |
367 |
+ |
} |
368 |
+ |
// not had a match |
369 |
+ |
return false; |
370 |
|
} |
371 |
|
|
372 |
|
/** |