Commit 8a68abe2 8a68abe2ec035a262435a5549158d42414df4e99 by root

save

1 parent 58ec417e
Showing 25 changed files with 160 additions and 262 deletions
1 4f1d9b53c7e59b9b50ff6b896c4b75cf
...\ No newline at end of file ...\ No newline at end of file
1 2839aa01a4288378339399e730fe5b420da600a3
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>org.emercit</groupId>
6 <artifactId>ethmanager</artifactId>
7 <version>1.5</version>
8 </project>
1 a53cf425b87e9ec4de8be872bd320a5e
...\ No newline at end of file ...\ No newline at end of file
1 818d65e91e7b1179c93058c754857d9f7b2443fe
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <metadata>
3 <groupId>org.emercit</groupId>
4 <artifactId>ethmanager</artifactId>
5 <versioning>
6 <release>1.5</release>
7 <versions>
8 <version>1.5</version>
9 </versions>
10 <lastUpdated>20150728062800</lastUpdated>
11 </versioning>
12 </metadata>
1 5a844efd0332aab16cf1302d39dbf999
...\ No newline at end of file ...\ No newline at end of file
1 672cc7b82224b26ec5c356c5771488127461221a
...\ No newline at end of file ...\ No newline at end of file
1 1fda13cd28508b9d409a0ff4d74ff23f
...\ No newline at end of file ...\ No newline at end of file
1 a4499251d6c87554b464c7c3371ab40063b72ddc
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4 <modelVersion>4.0.0</modelVersion>
5 <groupId>org.emercit</groupId>
6 <artifactId>proxymanager</artifactId>
7 <version>1.5</version>
8 </project>
1 6b33a2fc800d3fc8a28a9565ba974db6
...\ No newline at end of file ...\ No newline at end of file
1 157f839ee31faa1ea298cfbeddc3c9957285bc01
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <metadata>
3 <groupId>org.emercit</groupId>
4 <artifactId>proxymanager</artifactId>
5 <versioning>
6 <release>1.5</release>
7 <versions>
8 <version>1.5</version>
9 </versions>
10 <lastUpdated>20150728070304</lastUpdated>
11 </versioning>
12 </metadata>
1 3e946c3bdf4df4bbde5990393ce07047
...\ No newline at end of file ...\ No newline at end of file
1 63cad08c472ebec8fd91bceac61f91e698ce1be3
...\ No newline at end of file ...\ No newline at end of file
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
12 <attribute name="maven.pomderived" value="true"/> 12 <attribute name="maven.pomderived" value="true"/>
13 </attributes> 13 </attributes>
14 </classpathentry> 14 </classpathentry>
15 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> 15 <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
16 <attributes> 16 <attributes>
17 <attribute name="maven.pomderived" value="true"/> 17 <attribute name="maven.pomderived" value="true"/>
18 </attributes> 18 </attributes>
19 </classpathentry> 19 </classpathentry>
20 <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> 20 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
21 <attributes> 21 <attributes>
22 <attribute name="maven.pomderived" value="true"/> 22 <attribute name="maven.pomderived" value="true"/>
23 </attributes> 23 </attributes>
......
...@@ -15,6 +15,25 @@ ...@@ -15,6 +15,25 @@
15 <java-version>1.7</java-version> 15 <java-version>1.7</java-version>
16 </properties> 16 </properties>
17 17
18 <build>
19 <plugins>
20 <plugin>
21 <groupId>org.apache.maven.plugins</groupId>
22 <artifactId>maven-compiler-plugin</artifactId>
23 <configuration>
24 <source>1.7</source>
25 <target>1.7</target>
26 <showDeprecation>true</showDeprecation>
27 <showWarnings>true</showWarnings>
28 <executable>${env.JAVA_HOME_7}/bin/javac</executable>
29 <fork>true</fork>
30 </configuration>
31 </plugin>
32 </plugins>
33
34 </build>
35
36
18 <dependencies> 37 <dependencies>
19 38
20 <dependency> 39 <dependency>
...@@ -41,9 +60,27 @@ ...@@ -41,9 +60,27 @@
41 <version>4.0.0</version> 60 <version>4.0.0</version>
42 </dependency> 61 </dependency>
43 62
44 </dependencies> 63 <dependency>
45 </project> 64 <groupId>org.emercit</groupId>
65 <artifactId>xmldbmanager</artifactId>
66 <version>1.5</version>
67 </dependency>
46 68
69 <dependency>
70 <groupId>org.emercit</groupId>
71 <artifactId>projecttools</artifactId>
72 <version>1.5</version>
73 </dependency>
47 74
48 </dependencies> 75 </dependencies>
76
77 <repositories>
78 <!--other repositories if any-->
79 <repository>
80 <id>project.local</id>
81 <name>project</name>
82 <url>file:/root/git/hardwareconfig/DevTools/repo</url>
83 </repository>
84 </repositories>
85
49 </project> 86 </project>
......
...@@ -32,103 +32,13 @@ public class App ...@@ -32,103 +32,13 @@ public class App
32 32
33 private static ProxyLinux proxyLinux=new ProxyLinux(); 33 private static ProxyLinux proxyLinux=new ProxyLinux();
34 34
35 private static String eth; //Название интерфейса 35
36 private static String param; //Параметр который нужно изменить
37 private static String method; // Метод
38 private static String value; // Значение параметра
39 private static String name; // Название интерфейса
40 36
41 public static void main( String[] args ) 37 public static void main( String[] args )
42 { 38 {
43 ArgumentParser parser = ArgumentParsers.newArgumentParser("prog");
44
45 try {
46
47 parser.description("Настройки прокси")
48 .version("Version:1.0.0.0")
49 .defaultHelp(true);
50
51 parser.addArgument("-m")
52 .type(String.class)
53 .setDefault("get")
54 .help("Методы:\n 1) get - получение параметра;\n"
55 + "2) set- установка параметра.\n");
56
57 parser.addArgument("-v")
58 .type(String.class)
59 .setDefault("")
60 .help("Значение параметра");
61
62
63 parser.addArgument("-p")
64 .type(String.class)
65 .setDefault("")
66 .help("Имя параметра\n"
67 + "Возможные параметры:\n "
68 + "1) host - адрес прокси сервера;\n"
69 + "2) port - порт прокси сервера;\n"
70 + "3) login - имя пользователя;\n"
71 + "4) pass -пароль;\n"
72 + "5) enabled - проксирование. Значение true -включено, false- выкл.\n"
73 + "6) protocol - навзание протакола (http,https,ftp);\n"
74 + "7) useauth - использовать логин и пароль. Значение true - использовать, false -нет.\n");
75
76
77 parser.addArgument("-protocol")
78 .type(String.class)
79 .setDefault("")
80 .help("Протокол");
81
82 parser.addArgument("-log")
83 .type(Integer.class)
84 .setDefault(0)
85 .help("Логирование. 0-выкл.; 1-консоль; 2-файл");
86
87
88 Logger rootLogger = Logger.getRootLogger();
89 PatternLayout layout = new PatternLayout("%d{ISO8601} [%t] %-5p %c %x - %m%n");
90
91 //rootLogger.setLevel(Level.OFF);
92 rootLogger.setLevel(Level.DEBUG);
93
94 rootLogger.addAppender(new ConsoleAppender(layout));
95 try {
96 RollingFileAppender fileAppender = new RollingFileAppender(layout, "/var/log/devtools/ProxyManager.log");
97 rootLogger.addAppender(fileAppender);
98 } catch (IOException e) {
99 log.error(e.getMessage());
100 }
101
102 Namespace res = parser.parseArgs(args);
103
104 method=res.getString("m");
105
106 if (method.equals("set")) { //Конфигурация интерфейса
107
108 name=res.getString("protocol");
109 param= res.getString("p");
110 value=res.getString("v");
111
112 proxyLinux.ApplyConfig(name, param,(Object)value );
113 39
114 }else if (method.equals("get")) { //Вывод информации из файла 40 proxyLinux.init();
115 41
116 name=res.getString("protocol");
117 proxyLinux.InfoByName(name);
118 }
119
120 }catch(Exception e){
121 log.error(e.getMessage());
122 if(e instanceof ArgumentParserException){
123 log.error(e.getMessage());
124 }
125 else {
126 parser.handleError((ArgumentParserException) e);
127 log.error(e.getMessage());
128 System.exit(1);
129 }
130
131 }
132 42
133 } 43 }
134 } 44 }
......
...@@ -6,6 +6,8 @@ package org.emercit.proxymanager.service; ...@@ -6,6 +6,8 @@ package org.emercit.proxymanager.service;
6 6
7 public void InfoByName(String name); 7 public void InfoByName(String name);
8 8
9 public void init();
10
9 11
10 12
11 } 13 }
......
1 package org.emercit.proxymanager.service;
2
3 import java.util.Vector;
4
5 import org.emercit.proxymanager.model.ProxyBean;
6
7 public interface IProxyDB {
8
9 public boolean updateDb(Vector<ProxyBean> m);
10
11 public Vector<ProxyBean> selectDb();
12
13 }
14
15
1 package org.emercit.proxymanager.service;
2
3
4
5 import java.util.Vector;
6 import java.beans.XMLEncoder;
7 import java.beans.XMLDecoder;
8 import java.io.BufferedOutputStream;
9 import java.io.BufferedInputStream;
10 import java.io.FileOutputStream;
11 import java.io.FileInputStream;
12
13 import org.apache.log4j.Logger;
14 import org.emercit.proxymanager.App;
15 import org.emercit.proxymanager.model.ProxyBean;
16
17 public class ProxyDBImpl implements IProxyDB {
18
19 private static final Logger log = Logger.getLogger(ProxyDBImpl.class);
20
21 public boolean updateDb(Vector<ProxyBean> m) {
22
23 boolean result=true;
24 try {
25 FileOutputStream fos = new FileOutputStream("/opt/devtools/beans/ProxyBeans.xml");
26 BufferedOutputStream bos = new BufferedOutputStream(fos);
27 XMLEncoder xmlEncoder = new XMLEncoder(bos);
28 xmlEncoder.writeObject(m);
29 xmlEncoder.close();
30 }catch(Exception e) {
31 log.error(e.getMessage());
32 result=false;
33 }
34 return result;
35 }
36
37 public Vector<ProxyBean> selectDb() {
38
39 Vector<ProxyBean> result=new Vector<ProxyBean>();
40
41 try {
42 XMLDecoder d = new XMLDecoder(
43 new BufferedInputStream(
44 new FileInputStream("/opt/devtools/beans/ProxyBeans.xml")));
45 result=(Vector<ProxyBean>)d.readObject();
46 d.close();
47 }catch(Exception e) {
48 log.error(e.getMessage());
49 result=null;
50 }
51 return result;
52 }
53
54 }
55
56
57
58
59
60
61
62
63
...@@ -8,99 +8,30 @@ import java.util.Vector; ...@@ -8,99 +8,30 @@ import java.util.Vector;
8 8
9 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
10 import org.emercit.proxymanager.model.ProxyBean; 10 import org.emercit.proxymanager.model.ProxyBean;
11 import org.emercit.proxymanager.service.ProxyDBImpl;
12 11
13 import com.cedarsoftware.util.io.JsonReader; 12 import com.cedarsoftware.util.io.JsonReader;
14 import com.cedarsoftware.util.io.JsonWriter; 13 import com.cedarsoftware.util.io.JsonWriter;
15 14
15 import org.emercit.xmldbmanager.service.Db;
16 import org.emercit.projecttools.constants.Paths;
17
16 public class ProxyLinux { 18 public class ProxyLinux {
17 19
18 private static final Logger log = Logger.getLogger(ProxyLinux.class); 20 private static final Logger log = Logger.getLogger(ProxyLinux.class);
19 21
20 private ProxyDBImpl proxyStore=new ProxyDBImpl(); 22 private Db db=new Db(Paths.BEAN_PROXY);
21 23
22 private Vector<ProxyBean> pbs; 24 private Vector<ProxyBean> pbs;
23 25
24 private boolean found; 26 private boolean found;
25 27
26 private String json; 28
27 29
28 private Object obj; 30 private Object obj;
29 31
30 private ProxyBean pmp; 32 private ProxyBean pmp;
31 33
32 public void ApplyConfig (String protocol, String p, Object v) {
33
34
35 pbs=proxyStore.selectDb();
36
37 found=false;
38
39 if (p.equals("object")) {
40
41 for(ProxyBean pb : pbs) {
42 if(pb.getProtocol().equals(protocol)) {
43
44 found=true;
45
46 switch(p) {
47
48 case "host":pb.setHost((String)v); break;
49 case "port":pb.setPort(Integer.valueOf((String)v)); break;
50 case "login":pb.setLogin((String)v); break;
51 case "pass":pb.setPass((String)v); break;
52 case "enabled":pb.setEnabled(Boolean.valueOf((String)v)); break;
53 case "useauth":pb.setUseAuth(Boolean.valueOf((String)v)); break;
54
55 }
56 }
57 }
58
59
60 if (!found) { // Добавляем в файл ProxyBeans
61 if (checkProrocol(protocol)) {
62
63 ProxyBean pb=new ProxyBean();
64 pb.setProtocol(protocol);
65 pb.setHost("");
66 pb.setPort(0);
67 pb.setLogin("");
68 pb.setPass("");
69 pb.setEnabled(false);
70 pb.setUseAuth(false);
71
72 pbs.add(pb);
73 }else {
74 log.error(protocol+" - неизвестный тип протокола");
75 }
76 }
77
78 } else {
79
80
81 obj = JsonReader.jsonToJava((String)json);
82 pmp = (ProxyBean) obj;
83
84 for(ProxyBean pb : pbs) {
85 if(pb.getProtocol().equals(pmp.getProtocol())) {
86
87 pb.setHost(pmp.getHost());
88 pb.setPort(pmp.getPort());
89 pb.setLogin(pmp.getLogin());
90 pb.setPass(pmp.getPass());
91 pb.setEnabled(pmp.getEnabled());
92 pb.setUseAuth(pmp.getUseAuth());
93
94 }
95 break;
96 }
97
98 }
99
100 Config(pbs);
101
102 34
103 }
104 35
105 private boolean checkProrocol(String value) { 36 private boolean checkProrocol(String value) {
106 37
...@@ -111,20 +42,7 @@ public class ProxyLinux { ...@@ -111,20 +42,7 @@ public class ProxyLinux {
111 return false; 42 return false;
112 } 43 }
113 44
114 public void InfoByName(String protocol) {
115
116 pbs=proxyStore.selectDb();
117 45
118 if (pbs!=null) {
119
120 for(ProxyBean pb : pbs) {
121 if(pb.getProtocol().equals(protocol)) {
122 json = JsonWriter.objectToJson(pb);
123 System.out.println(json);
124 }
125 }
126 }
127 }
128 private void Config(Vector<ProxyBean> pbs) { 46 private void Config(Vector<ProxyBean> pbs) {
129 try { 47 try {
130 File file = new File("/etc/environment"); 48 File file = new File("/etc/environment");
...@@ -151,7 +69,7 @@ public class ProxyLinux { ...@@ -151,7 +69,7 @@ public class ProxyLinux {
151 } 69 }
152 bw.write("\n"); 70 bw.write("\n");
153 bw.close(); 71 bw.close();
154 proxyStore.updateDb(pbs); 72 db.create(pbs);
155 73
156 } catch (IOException e) { 74 } catch (IOException e) {
157 log.error(e.getMessage()); 75 log.error(e.getMessage());
...@@ -161,5 +79,62 @@ public class ProxyLinux { ...@@ -161,5 +79,62 @@ public class ProxyLinux {
161 79
162 80
163 81
82 public void init() {
83 pbs= new Vector<ProxyBean>();
84
85
86
87
88 //HTTP PROXY
89 pmp=new ProxyBean();
90
91 pmp.setEnabled(false);
92 pmp.setProtocol("http");
93 pmp.setHost("127.0.0.1");
94 pmp.setPort(3632);
95 pmp.setLogin("root");
96 pmp.setPass("root");
97 pmp.setUseAuth(false);
98
99 pbs.add(pmp);
100
101
102 //HTTPS PROXY
103 pmp=new ProxyBean();
104
105 pmp.setEnabled(false);
106 pmp.setProtocol("https");
107 pmp.setHost("127.0.0.1");
108 pmp.setPort(3632);
109 pmp.setLogin("root");
110 pmp.setPass("root");
111 pmp.setUseAuth(false);
112
113 pbs.add(pmp);
114
115 //FTP PROXY
116 pmp=new ProxyBean();
117
118 pmp.setEnabled(false);
119 pmp.setProtocol("ftp");
120 pmp.setHost("127.0.0.1");
121 pmp.setPort(3632);
122 pmp.setLogin("root");
123 pmp.setPass("root");
124 pmp.setUseAuth(false);
125
126 pbs.add(pmp);
127
128 Config(pbs);
129
130
131
132
133
134 }
135
136
137
138
164 139
165 } 140 }
...\ No newline at end of file ...\ No newline at end of file
......