Skip to content

Commit 44c5f87

Browse files
committed
Webfollower: update
1 parent f6bd8e5 commit 44c5f87

File tree

6 files changed

+77
-15
lines changed

6 files changed

+77
-15
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Cmd.java

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.eveningoutpost.dexdrip.models.JoH.emptyString;
44
import static com.eveningoutpost.dexdrip.cgm.webfollow.Agent.get;
5+
import static com.eveningoutpost.dexdrip.utils.CipherUtils.getSHA256;
56

67
import com.eveningoutpost.dexdrip.models.BgReading;
78
import com.eveningoutpost.dexdrip.models.JoH;
@@ -10,6 +11,7 @@
1011

1112
import org.json.JSONObject;
1213

14+
import java.nio.charset.StandardCharsets;
1315
import java.text.ParseException;
1416
import java.text.SimpleDateFormat;
1517
import java.util.Locale;
@@ -32,6 +34,8 @@
3234
@RequiredArgsConstructor
3335
public class Cmd {
3436
private static final String PUSH_METHOD = "push";
37+
private static final String FPUSH_METHOD = "fpush";
38+
private static final String CPUSH_METHOD = "cpush";
3539
private static final String JSON_METHOD = "jput";
3640
private static final String JSON_TYPE = "application/json";
3741
private static final MediaType JSON = MediaType.parse(JSON_TYPE);
@@ -103,6 +107,18 @@ public boolean process(final String cmd) {
103107
}
104108
return true;
105109

110+
case "vSet":
111+
if (!JoH.emptyString(m.getByName(pc[2]))) {
112+
m.doAction(pc[1]);
113+
}
114+
return true;
115+
116+
case "vuSet":
117+
if (JoH.emptyString(m.getByName(pc[2]))) {
118+
m.doAction(pc[1]);
119+
}
120+
return true;
121+
106122
case "evaluate":
107123
evaluate(parts.length > 1 ? parts[1].split(";") : null);
108124
return true;
@@ -125,17 +141,28 @@ public boolean process(final String cmd) {
125141

126142
switch (p1s[0]) {
127143

144+
case FPUSH_METHOD:
145+
case CPUSH_METHOD:
128146
case PUSH_METHOD:
129147
for (val as : asn) {
130-
val ass = as.split("-");
148+
m.log("PUSH: as: " + as);
149+
val ass = as.split("-", 2);
131150
val tok = ass[1].split(";");
132-
val tick = m.getByName(tok[1]);
151+
val tick = (tok[1].charAt(0) == '\'') ? tok[1].substring(1) : m.getByName(tok[1]); // handle string literal
133152
if (tick == null) {
134153
m.loge(tok[1] + " is null in " + as);
135154
return false;
136155
}
137-
m.log("Setting: :" + ass[0] + ": to :" + String.format(tok[0], tick));
138-
cb.getClass().getMethod(ass[0], String.class).invoke(cb, String.format(tok[0], m.getByName(tok[1])));
156+
val mtick = mutate(tick, tok);
157+
m.log("Setting: :" + ass[0] + ": to :" + String.format(tok[0], mtick));
158+
if (p1s[0].equals(CPUSH_METHOD)) {
159+
m.setByName(ass[0], String.format(tok[0], mtick));
160+
} else {
161+
cb.getClass().getMethod(ass[0], String.class).invoke(cb, String.format(tok[0], mtick));
162+
}
163+
}
164+
if (!p1s[0].equals(PUSH_METHOD)) {
165+
return true;
139166
}
140167
break;
141168

@@ -177,6 +204,7 @@ public boolean process(final String cmd) {
177204
return presult;
178205
} catch (Exception e) {
179206
m.log("Pprocess exception: " + e);
207+
e.printStackTrace();
180208
return false;
181209
}
182210
} catch (com.google.gson.JsonSyntaxException e) {
@@ -193,13 +221,25 @@ public boolean process(final String cmd) {
193221
Cpref.startWithRefresh(true);
194222
}
195223
}
224+
e.printStackTrace();
196225
} else {
197226
e.printStackTrace();
198227
}
199228
}
200229
return false;
201230
}
202231

232+
private String mutate(String tick, final String[] t) throws NoSuchFieldException, IllegalAccessException {
233+
if (tick != null) {
234+
val a1 = "%sha256";
235+
if (t[0].contains(a1)) {
236+
t[0] = t[0].replace(a1, "%s");
237+
tick = getSHA256(tick.getBytes(StandardCharsets.UTF_8));
238+
}
239+
}
240+
return tick;
241+
}
242+
203243
private boolean pprocess(final String[] p3s, final Mapifier map) {
204244
for (val psa : p3s) {
205245
val pss = psa.split("-");
@@ -209,6 +249,7 @@ private boolean pprocess(final String[] p3s, final Mapifier map) {
209249
case "AZ":
210250
val psd = map.pluckDouble(pss[0]);
211251
val ret = psd == 0d;
252+
m.log("AZ ret: " + ret);
212253
if (!ret) {
213254
if (psd > 0d) {
214255
m.token = null;
@@ -220,6 +261,7 @@ private boolean pprocess(final String[] p3s, final Mapifier map) {
220261
}
221262
} catch (Exception e) {
222263
m.loge("pprocess exception: " + e);
264+
e.printStackTrace();
223265
}
224266
}
225267
return false;
@@ -228,7 +270,7 @@ private boolean pprocess(final String[] p3s, final Mapifier map) {
228270
private boolean extract(final String[] p2s, final Mapifier map) throws NoSuchFieldException, IllegalAccessException, ParseException {
229271
for (val psa : p2s) {
230272
val pss = psa.split("-");
231-
val type = pss[0].replaceAll("[a-z]", "");
273+
val type = pss[0].replaceAll("[a-z!]", "");
232274
val var = pss[0].replaceAll("[A-Z]", "");
233275

234276
switch (type) {
@@ -243,13 +285,21 @@ private boolean extract(final String[] p2s, final Mapifier map) throws NoSuchFie
243285
m.log("Setting Any: " + var + " to " + map.pluckAny(pss[1]) + " <- " + var);
244286
break;
245287
case "":
246-
val mvalue = map.pluckString(pss[1]);
247-
if (mvalue.length() < 2) {
248-
m.log("Bad value: " + mvalue);
249-
return false;
288+
try {
289+
val mvalue = map.pluckString(pss[1]);
290+
if (mvalue == null || mvalue.length() < 2) {
291+
m.log("Bad value: " + mvalue + " for " + pss[1]);
292+
return var.endsWith("!");
293+
}
294+
m.setByName(var, mvalue);
295+
m.log("Setting String: " + var + " to " + mvalue + " <- " + pss[1]);
296+
} catch (RuntimeException e) {
297+
val es = "" + e;
298+
if (es.contains("Invalid")) {
299+
m.loge(es);
300+
}
301+
throw e;
250302
}
251-
m.setByName(var, mvalue);
252-
m.log("Setting String: " + var + " to " + mvalue + " <- " + pss[1]);
253303
break;
254304
default:
255305
throw new RuntimeException("Invalid type :" + type + ": <- " + var);

app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class Config implements Exposed {
1515
public String version;
1616
public String product;
1717
public String authorization;
18+
public String hname;
19+
public String hvalue;
1820
public String query;
1921
public String contentType;
2022
public RequestBody body;

app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/MContext.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class MContext implements Exposed {
2323

2424
private static final String TAG = "WebFollow";
25-
private static final String PREF_MCONTEXT = "PREF_MCONTEXT-";
25+
private static final String PREF_MCONTEXT = "PREF_MCONTEXT2-";
2626

2727
public volatile String domain;
2828
public volatile String aUrl;
@@ -39,6 +39,7 @@ public class MContext implements Exposed {
3939
public volatile String agent;
4040
public volatile String token;
4141
public volatile String country;
42+
public volatile String userid;
4243
public volatile Double lvalue;
4344
public volatile long ltime;
4445
public volatile String[] cmd;
@@ -66,7 +67,7 @@ public String getByName(final String ref) throws NoSuchFieldException, IllegalAc
6667
}
6768

6869
public void setByName(final String ref, final Object value) throws NoSuchFieldException, IllegalAccessException {
69-
this.getClass().getDeclaredField(ref).set(this, value);
70+
this.getClass().getDeclaredField(ref.replaceAll("!$","")).set(this, value);
7071
}
7172

7273
public void save(final String id) {
@@ -126,6 +127,10 @@ public void evaluateSingle(final long ltime, final Double lvalue) {
126127
log("Inserting new value: " + lvalue + " " + JoH.dateTimeText(ltime));
127128
BgReading.bgReadingInsertFromG5(lvalue, ltime);
128129
}
130+
} else {
131+
if (lvalue != null) {
132+
loge("Value outside of range: " + lvalue + " @ " + JoH.dateTimeText(ltime));
133+
}
129134
}
130135
}
131136

app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Mapifier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public Object pluck(final String reference, final boolean singular) {
4646
val a = (ArrayList<?>) o;
4747
if (singular) {
4848
if (a.size() != 1) {
49-
throw new RuntimeException("Invalid singular");
49+
System.out.println("SINGULAR PROBLEM: array size: " + a.size());
50+
throw new RuntimeException("Invalid singular - only use one connection");
5051
}
5152
} else if (name.equals(last)) {
5253
return a;

app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/ResponseGetterImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ public String get(final Config c) {
5353
val builder = new Request.Builder();
5454
builder.url(c.url + ((c.query != null) ? "?" + c.query : ""));
5555
builder.header("User-Agent", c.agent);
56+
builder.header("cache-control", "no-cache");
5657
builder.header("version", c.version);
5758
builder.header("product", c.product);
5859
if (c.authorization != null) {
5960
builder.header("Authorization", c.authorization);
6061
}
62+
if (c.hname != null && c.hvalue != null) {
63+
builder.header(c.hname, c.hvalue);
64+
}
6165
if (c.body != null) {
6266
builder.post(c.body);
6367
}

app/src/main/java/com/eveningoutpost/dexdrip/cgm/webfollow/Template.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Template {
2424
private static final String TAG = "WebFollow" + Template.class.getSimpleName();
2525
private static final String SCHEME = "https://";
2626
private static final String PREFIX = "community-script";
27-
private static final String SUFFIX = "net";
27+
private static final String SUFFIX = "net/v2";
2828
private static final String DOT = ".";
2929

3030
private static byte[] getData() {

0 commit comments

Comments
 (0)