01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with DrFTPD; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.drftpd.plugins;
19:
20: import java.util.ArrayList;
21: import java.util.Collections;
22: import java.util.List;
23: import java.util.Observable;
24: import java.util.Observer;
25:
26: import net.sf.drftpd.event.Event;
27: import net.sf.drftpd.event.FtpListener;
28: import net.sf.drftpd.master.config.FtpConfig;
29:
30: import org.drftpd.GlobalContext;
31: import org.drftpd.permissions.PathPermission;
32: import org.drftpd.remotefile.LinkedRemoteFileInterface;
33:
34: /**
35: * @author mog
36: * @version $Id: AffilManagement.java 879 2004-12-29 03:39:22Z mog $
37: */
38: public class AffilManagement extends FtpListener {
39:
40: public static class AffilPermission extends PathPermission {
41: private String _group;
42:
43: public AffilPermission(String group) {
44: super (Collections.singletonList("=" + group));
45: _group = group;
46: }
47:
48: public boolean checkPath(LinkedRemoteFileInterface path) {
49: List<LinkedRemoteFileInterface> files = path
50: .getAllParentFiles();
51: return (files.get(files.size() - 2).getName().equals(
52: "groups") && files.get(files.size() - 3).getName()
53: .equals(_group));
54: }
55: }
56:
57: public void actionPerformed(Event event) {
58: }
59:
60: public void unload() {
61: }
62:
63: public ArrayList<String> groups;
64:
65: public void init(GlobalContext gctx) {
66: super .init(gctx);
67: getGlobalContext().getConfig().addObserver(new Observer() {
68: public void update(Observable o, Object arg) {
69: FtpConfig cfg = (FtpConfig) o;
70: for (String group : groups) {
71: cfg.addPathPermission("privpath",
72: new AffilPermission(group));
73: }
74: }
75: });
76: }
77: }
|