diff options
Diffstat (limited to 'update/plugin/subversion/trunk/src/com/fourisland')
-rw-r--r-- | update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java | 68 | ||||
-rw-r--r-- | update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java | 83 |
2 files changed, 151 insertions, 0 deletions
diff --git a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java new file mode 100644 index 0000000..0929022 --- /dev/null +++ b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/MD5.java | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | package com.fourisland.instadisc.update.svn; | ||
6 | |||
7 | import java.security.MessageDigest; | ||
8 | import java.util.logging.Level; | ||
9 | import java.util.logging.Logger; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class MD5 { | ||
16 | |||
17 | String ver; | ||
18 | |||
19 | public MD5(String ver) { | ||
20 | this.ver = ver; | ||
21 | } | ||
22 | |||
23 | public MD5(char[] password) { | ||
24 | int i=0; | ||
25 | ver=""; | ||
26 | for (i=0;i<password.length;i++) | ||
27 | { | ||
28 | ver += password[i]; | ||
29 | password[i] = 0; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | public String hash() | ||
34 | { | ||
35 | StringBuilder verify = new StringBuilder(); | ||
36 | try { | ||
37 | MessageDigest md5 = MessageDigest.getInstance("MD5"); | ||
38 | int i = 0; | ||
39 | byte[] create = new byte[ver.length()]; | ||
40 | for (i = 0; i < ver.length(); i++) { | ||
41 | create[i] = (byte) ver.charAt(i); | ||
42 | } | ||
43 | byte buffer[] = md5.digest(create); | ||
44 | for (i = 0; i < buffer.length; i++) { | ||
45 | String hex = Integer.toHexString(buffer[i]); | ||
46 | verify.append(pad(hex.substring(max(hex.length() - 2, 0)),"0",2)); | ||
47 | } | ||
48 | } catch (Exception ex) { | ||
49 | Logger.getLogger(MD5.class.getName()).log(Level.SEVERE, null, ex); | ||
50 | } | ||
51 | ver = ""; | ||
52 | return verify.toString(); | ||
53 | } | ||
54 | |||
55 | private int max(int x, int y) | ||
56 | { | ||
57 | return (x > y ? x : y); | ||
58 | } | ||
59 | |||
60 | private String pad(String in, String pad, int len) | ||
61 | { | ||
62 | while (in.length() < len) | ||
63 | { | ||
64 | in = pad + in; | ||
65 | } | ||
66 | return in; | ||
67 | } | ||
68 | } | ||
diff --git a/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java new file mode 100644 index 0000000..1bc9a07 --- /dev/null +++ b/update/plugin/subversion/trunk/src/com/fourisland/instadisc/update/svn/Main.java | |||
@@ -0,0 +1,83 @@ | |||
1 | package com.fourisland.instadisc.update.svn; | ||
2 | |||
3 | import java.io.IOException; | ||
4 | import java.net.MalformedURLException; | ||
5 | import java.net.URL; | ||
6 | import java.util.Random; | ||
7 | import java.util.logging.Level; | ||
8 | import java.util.logging.Logger; | ||
9 | import org.apache.xmlrpc.XmlRpcException; | ||
10 | import org.apache.xmlrpc.client.XmlRpcClient; | ||
11 | import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; | ||
12 | |||
13 | public class Main { | ||
14 | |||
15 | public static void main(String[] args) { | ||
16 | try | ||
17 | { | ||
18 | String username = getArg(0, args); | ||
19 | String password = getArg(1, args); | ||
20 | String centralServer = getArg(2, args); | ||
21 | String pathScheme = getArg(3, args); | ||
22 | String author = getArg(4, args); | ||
23 | String subscription = getArg(5, args); | ||
24 | String revision = getArg(6, args); | ||
25 | |||
26 | StringBuilder messBuilder = new StringBuilder(); | ||
27 | byte rs = 0; | ||
28 | |||
29 | while (rs != -1) | ||
30 | { | ||
31 | try | ||
32 | { | ||
33 | rs = (byte) System.in.read(); | ||
34 | if (rs != -1) | ||
35 | { | ||
36 | messBuilder.append(new String(new byte[]{rs})); | ||
37 | } | ||
38 | } catch (IOException ex) | ||
39 | { | ||
40 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | String message = messBuilder.toString(); | ||
45 | message = message.substring(0, message.indexOf("\n")); | ||
46 | |||
47 | Random r = new Random(); | ||
48 | int verID = r.nextInt(Integer.MAX_VALUE); | ||
49 | |||
50 | String path = pathScheme.replace("__REV__", revision); | ||
51 | |||
52 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); | ||
53 | config.setServerURL(new URL(centralServer)); | ||
54 | XmlRpcClient client = new XmlRpcClient(); | ||
55 | client.setConfig(config); | ||
56 | client.execute("InstaDisc.sendFromUpdate", new Object[]{username, | ||
57 | (new MD5(username + ":" + (new MD5(password)).hash() + ":" + verID)).hash(), | ||
58 | verID, | ||
59 | subscription, | ||
60 | message, | ||
61 | author, | ||
62 | path, | ||
63 | "a:0:{}" | ||
64 | }); | ||
65 | } catch (XmlRpcException ex) | ||
66 | { | ||
67 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
68 | } catch (MalformedURLException ex) | ||
69 | { | ||
70 | Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | public static String getArg(int arg, String[] args) { | ||
75 | if (args.length < (arg+1)) | ||
76 | { | ||
77 | System.out.println("Program requires 7 arguments and you only provided " + arg); | ||
78 | System.exit(1); | ||
79 | } | ||
80 | |||
81 | return args[arg]; | ||
82 | } | ||
83 | } | ||