9
9
import java .io .FileWriter ;
10
10
import java .io .IOException ;
11
11
import java .nio .channels .FileChannel ;
12
+ import java .util .Scanner ;
12
13
import java .util .regex .Matcher ;
13
14
import java .util .regex .Pattern ;
14
15
20
21
import android .content .DialogInterface ;
21
22
import android .widget .CheckBox ;
22
23
import android .widget .EditText ;
24
+ import android .widget .Spinner ;
25
+ import android .widget .ArrayAdapter ;
23
26
24
27
25
28
public class updateConfActivity extends Activity {
@@ -37,6 +40,7 @@ public class updateConfActivity extends Activity {
37
40
public String InstanceID = "" ;
38
41
public boolean overrideDNS = false ;
39
42
public boolean useInstanceID = false ;
43
+ public String keyType = "" ;
40
44
41
45
@ Override
42
46
public void onCreate (Bundle savedInstanceState ) {
@@ -51,6 +55,15 @@ public void onCreate(Bundle savedInstanceState) {
51
55
createDefaultConfFile ();
52
56
}
53
57
58
+ Spinner spinner = (Spinner ) findViewById (R .id .keyTypeSpinner );
59
+ // Create an ArrayAdapter using the string array and a default spinner layout
60
+ ArrayAdapter <CharSequence > adapter = ArrayAdapter .createFromResource (this ,
61
+ R .array .keytypearray , android .R .layout .simple_spinner_item );
62
+ // Specify the layout to use when the list of choices appears
63
+ adapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
64
+ // Apply the adapter to the spinner
65
+ spinner .setAdapter (adapter );
66
+
54
67
readConfFileAndFillParameters ();
55
68
56
69
}
@@ -70,25 +83,25 @@ public void readConfFileAndFillParameters()
70
83
while ( line != null ) {
71
84
text .append (line );
72
85
text .append ("\n " );
73
- if (line .contains ("eid-address-ipv4" ) && !line .contains ("#" )) {
86
+ if (line .contains ("eid-address-ipv4" ) && !line .startsWith ("#" )) {
74
87
String [] tmp = line .split ("=" );
75
88
String [] tmp_1 = tmp [1 ].split (" " );
76
89
eidIPv4 = tmp_1 [1 ];
77
90
EditText e = (EditText ) findViewById (R .id .updateConfeid4Text );
78
91
e .setText (eidIPv4 );
79
- } else if (line .contains ("eid-address-ipv6" ) && !line .contains ("#" )) {
92
+ } else if (line .contains ("eid-address-ipv6" ) && !line .startsWith ("#" )) {
80
93
String [] tmp = line .split ("=" );
81
94
String [] tmp_1 = tmp [1 ].split (" " );
82
95
eidIPv6 = tmp_1 [1 ];
83
96
EditText e = (EditText ) findViewById (R .id .updateConfeid6Text );
84
97
e .setText (eidIPv6 );
85
- } else if (line .contains ("map-resolver" ) && !line .contains ("#" )) {
98
+ } else if (line .contains ("map-resolver" ) && !line .startsWith ("#" )) {
86
99
String [] tmp = line .split ("=" );
87
100
String [] tmp_1 = tmp [1 ].split (" " );
88
101
MR = tmp_1 [1 ];
89
102
EditText e = (EditText ) findViewById (R .id .updateConfMRText );
90
103
e .setText (MR );
91
- } else if (line .contains ("override-dns-primary" ) && !line .contains ("#" )) {
104
+ } else if (line .contains ("override-dns-primary" ) && !line .startsWith ("#" )) {
92
105
String [] tmp = line .split ("=" );
93
106
String [] tmp2 = tmp [1 ].split (" " );
94
107
DNS1 = tmp2 [1 ];
@@ -98,7 +111,7 @@ public void readConfFileAndFillParameters()
98
111
overrideDNS = true ;
99
112
CheckBox c = (CheckBox )findViewById (R .id .updateConfDNSCheck );
100
113
c .setChecked (true );
101
- } else if (line .contains ("override-dns-secondary" ) && !line .contains ("#" )) {
114
+ } else if (line .contains ("override-dns-secondary" ) && !line .startsWith ("#" )) {
102
115
String [] tmp = line .split ("=" );
103
116
String [] tmp2 = tmp [1 ].split (" " );
104
117
DNS2 = tmp2 [1 ];
@@ -108,7 +121,7 @@ public void readConfFileAndFillParameters()
108
121
overrideDNS = true ;
109
122
CheckBox c = (CheckBox )findViewById (R .id .updateConfDNSCheck );
110
123
c .setChecked (true );
111
- } else if (line .contains ("instance-id" ) && !line .contains ("#" )) {
124
+ } else if (line .contains ("instance-id" ) && !line .startsWith ("#" )) {
112
125
String [] tmp = line .split ("=" );
113
126
String [] tmp2 = tmp [1 ].split (" " );
114
127
InstanceID = tmp2 [1 ];
@@ -118,23 +131,39 @@ public void readConfFileAndFillParameters()
118
131
useInstanceID = true ;
119
132
CheckBox c = (CheckBox )findViewById (R .id .updateConfUseInstance );
120
133
c .setChecked (true );
121
- } else if (line .contains ("map-server" ) && !line .contains ("#" )) {
134
+ } else if (line .contains ("map-server" ) && !line .startsWith ("#" )) {
122
135
boolean flg1 =false , flg2 =false ;
123
136
do {
124
137
String line_1 = br .readLine ();
125
138
text .append (line_1 );
126
139
text .append ("\n " );
127
- if (line_1 .contains ("address" ) && !line_1 .contains ("#" )) {
140
+ if (line_1 .contains ("address" ) && !line_1 .startsWith ("#" )) {
128
141
String [] tmp = line_1 .split ("=" );
129
142
String [] tmp_1 = tmp [1 ].split (" " );
130
143
MS = tmp_1 [1 ];
131
144
flg1 = true ;
132
- } else if (line_1 .contains ("key" ) && !line_1 .contains ("#" )) {
145
+ } else if (line_1 .contains ("key-type" ) && !line_1 .startsWith ("#" )) {
146
+ Scanner scanner = new Scanner (line_1 );
147
+ scanner .useDelimiter ("=" );
148
+ Spinner spinner = (Spinner ) findViewById (R .id .keyTypeSpinner );
149
+ if ( scanner .hasNext () ){
150
+ String name = scanner .next ();
151
+ String value = scanner .next ();
152
+
153
+ if (value .contains ("0" )) {
154
+ spinner .setSelection (0 );
155
+ keyType = "0" ;
156
+ } else if (value .contains ("1" )) {
157
+ spinner .setSelection (1 );
158
+ keyType = "1" ;
159
+ }
160
+ }
161
+ } else if (line_1 .contains ("key" ) && !line_1 .startsWith ("#" )) {
133
162
String [] tmp = line_1 .split ("=" );
134
163
String [] tmp_1 = tmp [1 ].split (" " );
135
164
MSKey = tmp_1 [1 ];
136
165
flg2 = true ;
137
- }
166
+ }
138
167
} while (flg1 == false || flg2 == false );
139
168
140
169
EditText e = (EditText ) findViewById (R .id .updateConfMSText );
@@ -183,7 +212,7 @@ public void createDefaultConfFile()
183
212
.append ("#\n " )
184
213
.append ("map-server {\n " )
185
214
.append (" address = 198.6.255.40\n " )
186
- .append (" key-type = 0 # cleartext \n " )
215
+ .append (" key-type = 1 # SHA1 \n " )
187
216
.append (" key = chris-mn\n " )
188
217
.append (" verify = off # on --> lig(self)\n " )
189
218
.append (" proxy-reply = on # ask ms to proxy reply\n " )
@@ -448,7 +477,7 @@ public String replace_if_required_mr(String str)
448
477
449
478
public String replace_if_required_ms (String str )
450
479
{
451
- Pattern msPtrn = Pattern .compile ("^(\\ s*)(\\ S*)(\\ s*)address(\\ s*)=(\\ s*)( \\ d{1,3}).(\\ d{1,3}).(\\ d{1,3}).(\\ d{1,3})(\\ s*)" );
480
+ Pattern msPtrn = Pattern .compile ("^(\\ s*)(\\ S*)(\\ s*)address(\\ s*)=(\\ d{1,3}).(\\ d{1,3}).(\\ d{1,3}).(\\ d{1,3})(\\ s*)" );
452
481
Matcher msMtchr = msPtrn .matcher (str );
453
482
if (msMtchr .matches ()) {
454
483
String [] tmp_1 = str .split ("=" );
@@ -482,6 +511,28 @@ public String replace_ms_key(String str)
482
511
return out ;
483
512
}
484
513
514
+ public String replace_if_required_ms_keytype (String str )
515
+ {
516
+
517
+ String out = str ;
518
+
519
+ if (str .contains ("key-type" )) {
520
+ Spinner spinner = (Spinner )findViewById (R .id .keyTypeSpinner );
521
+ String value = spinner .getSelectedItem ().toString ();
522
+ String replacer = "" ;
523
+ if (value .contains ("Cleartext" )) {
524
+ replacer = "key-type = 0" ;
525
+ keyType = "0" ;
526
+ } else if (value .contains ("SHA1" )) {
527
+ replacer = "key-type = 1" ;
528
+ keyType = "1" ;
529
+ }
530
+ out = replacer ;
531
+ keyType = replacer ;
532
+ }
533
+ return out ;
534
+ }
535
+
485
536
public String replace_parameters (String str )
486
537
{
487
538
StringBuilder out = new StringBuilder ();
@@ -499,6 +550,7 @@ public String replace_parameters(String str)
499
550
tmp [i ] = replace_if_required_primary_dns (tmp [i ]);
500
551
tmp [i ] = replace_if_required_secondary_dns (tmp [i ]);
501
552
tmp [i ] = replace_if_required_instance_id (tmp [i ]);
553
+ tmp [i ] = replace_if_required_ms_keytype (tmp [i ]);
502
554
503
555
if (tmp [i ].contains ("override-dns-primary" )) {
504
556
DNSWasfound = true ;
0 commit comments