import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
// NOTE: make sure the SOA is correct!
import java.text.*;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.awt.geom.*;
import static x30_pkg.x30_util.DynamicObject;
import java.text.NumberFormat;
import se.unlogic.eagledns.EagleDNS;
class main {
static double refreshEvery = 0 /*60*/;
static int smartBotTimeOut = 60*30;
static String zone = "\r\nbotcompany.de. IN SOA ns1.stefantrades.pro. stefan\\.reich\\.maker\\.of\\.eye.gmail.com. (\r\n 20190925 ; Serial\r\n 60M ; Refresh\r\n 15M ; Retry\r\n 7D ; Expiry\r\n 30M ) ; Minimum\r\n@ IN NS ns1.stefantrades.pro.\r\n@ IN NS ns2.stefantrades.pro.\r\n@ IN A 167.86.121.181\r\nc8 IN A 167.86.121.181\r\nhome 300 IN A 2.203.147.51\r\noldmain IN A 185.183.156.46\r\ncoffee IN A 195.154.179.147\r\n*.coffee IN A 195.154.179.147\r\nvnc-coffee IN A 195.154.179.147\r\ntranspile-coffee IN A 195.154.179.147\r\navor IN A 195.154.179.147\r\nrobin-avor IN A 195.154.179.147\r\nchristian-avor IN A 195.154.179.147\r\navor-qa IN A 195.154.179.147\r\n*.avor-qa IN A 195.154.179.147\r\ncruddie IN A 195.154.179.147\r\n*.cruddie IN A 195.154.179.147\r\nstripe-test IN A 195.154.179.147\r\nmeta-bot IN A 195.154.179.147\r\nada-v2 IN A 195.154.179.147\r\nfia IN A 195.154.179.147\r\ne-buck IN A 195.154.179.147\r\nada-aws IN A 18.233.63.26\r\n; sometimes the * entry doesn't work? vnc.botcompany.de caused NXDOMAIN\r\n* IN A 167.86.121.181\r\nvnc IN A 167.86.121.181\r\ncode IN A 167.86.121.181\r\nwww IN A 167.86.121.181\r\nbutter IN A 167.86.121.181\r\nstefans-os IN A 167.86.121.181\r\nsmartbot IN A 167.86.121.181\r\ncreate IN A 167.86.121.181\r\nmail IN A 167.86.121.181\r\njavax IN A 167.86.121.181\r\nada IN A 167.86.121.181\r\nmech IN A 167.86.121.181\r\ntheadmi IN A 176.58.127.141\r\ntheadmi2 IN A 176.58.127.141\r\ntester IN A 144.126.145.56\r\ngazellebot IN A 173.212.209.120\r\n;pays5-bot IN A 173.212.209.120\r\npays5-bot IN A 195.154.179.147\r\nbea-bot IN A 173.212.209.120\r\ntlc IN A 195.154.179.147\r\nbig IN A 192.99.13.227\r\n;@ MX 10 mail1.domainssaubillig.de.\r\n@ MX 10 mail.botcompany.de.\r\nmail MX 10 mail.botcompany.de.\r\n_acme-challenge.botcompany.de. IN TXT \"aWAwa7cLpPcFoIylAqQn13tmNyfZ6H36GUt2dFyt-eM\"\r\nbotcompany.de. IN TXT \"google-site-verification=YL5Hu5zvww8np30b4LLv_fgK0rppl2uzUKe8-14Gk98\"\r\n";
// Note: zone2 not active yet
static String zone2 = "\r\ngazelle.rocks. IN SOA ns1.stefantrades.pro. stefan\\.reich\\.maker\\.of\\.eye.gmail.com. (\r\n 20190101 ; Serial\r\n 5M ; Refresh\r\n 15M ; Retry\r\n 7D ; Expiry\r\n 30M ) ; Minimum\r\n@ IN NS ns1.stefantrades.pro.\r\n@ IN NS ns2.stefantrades.pro.\r\n@ IN A 173.212.209.120\r\n* IN A 173.212.209.120\r\n;@ MX 10 mail1.domainssaubillig.de.\r\n";
// dnsjava
// EagleDNS
// log4j
static File zonesDir;
static EagleDNS eagleDNS;
public static void main(final String[] args) throws Exception {
tryToAcquirePort5000();
String conf = loadSnippet("#1010767");
zonesDir = programFile("zones");
saveZones();
conf = conf.replace(
"zones",
"" + f2s(zonesDir) + "");
File configFile = saveProgramTextFile("config.xml", conf);
//eagleDNS = nuObject("se.unlogic.eagledns.EagleDNS", f2s(configFile));
print("Making EagleDNS.");
try {
eagleDNS = new EagleDNS(f2s(configFile));
} catch (Throwable __e) { pcallFail(__e); }
// For some weird reason, on the servers, no lines are printed
// after this point... but they still execute!? (Auto-reload works.)
printAndProgramLog("Made EagleDNS." + (eagleDNS == null ? "..not" : ""));
bot("Eagle DNS.");
if (refreshEvery != 0) doEvery_daemon(refreshEvery, new Runnable() { public void run() { try { refresh();
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "refresh();"; }});
// Restart after successful transpile
print("Making SnippetUpdateConnector.");
ownResource(snippetUpdateConnector("verbose" , true));
ownResource(vmBus_onMessage("snippetUpdate", new VF1() { public void get(List l) { try {
print("Got snippet update: " + l);
String uri = getString(l, 1);
Matches m = new Matches();
if (swic(uri, "/transpileOK/", m))
if (sameSnippetID(programID(), firstIntAsString(m.rest()))) {
programLog("Restarting");
restart();
}
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "print(\"Got snippet update: \" + l);\r\n S uri = getString(l, 1);\r\n new Mat..."; }}));
}
static String answer(String s) {
final Matches m = new Matches();
if (match("test", s)) return "OK";
if (match("refresh", s)) {
refresh();
return "OK";
}
return null;
}
static void refresh() {
saveZones();
eagleDNS.reloadZones();
}
static void saveZones() {
String acmeChallenge = loadTextFileTrim(userFile("acme-challenge.txt")); // Note: not used anymore, just edit this source
if (nempty(acmeChallenge))
zone = jreplace(zone,
"_acme-challenge.botcompany.de. IN TXT ",
"_acme-challenge.botcompany.de. IN TXT " + quote(unnull(acmeChallenge)));
print(zone);
saveTextFile(newFile(zonesDir, "botcompany.de"), zone);
saveTextFile(newFile(zonesDir, "gazelle.rocks"), zone2);
}
static void tryToAcquirePort5000() {
startThread("Move to port 5000", new Runnable() { public void run() { try {
while (licensed()) { try {
if (vmPort() == 5000) return;
if (portIsFree(5000)) {
print("Trying to move to port 5000...");
restartVMAndroid();
print("...went to port: " + vmPort() + ".");
}
} catch (Throwable __e) { pcallFail(__e); } sleepSeconds(10); }
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "repeat { try {\r\n if (vmPort() == 5000) return;\r\n if (portIsFree(500..."; }});
}
static boolean preferCached = false;
static boolean loadSnippet_debug = false;
static ThreadLocal loadSnippet_silent = new ThreadLocal();
static ThreadLocal loadSnippet_publicOnly = new ThreadLocal();
static int loadSnippet_timeout = 30000;
static String loadSnippet(String snippetID) { try {
if (snippetID == null) return null;
return loadSnippet(parseSnippetID(snippetID), preferCached);
} catch (Exception __e) { throw rethrow(__e); } }
static String loadSnippet(String snippetID, boolean preferCached) throws IOException {
return loadSnippet(parseSnippetID(snippetID), preferCached);
}
static IF1 loadSnippet;
static String loadSnippet(long snippetID) { return loadSnippet != null ? loadSnippet.get(snippetID) : loadSnippet_base(snippetID); }
final static String loadSnippet_fallback(IF1 _f, long snippetID) { return _f != null ? _f.get(snippetID) : loadSnippet_base(snippetID); }
static String loadSnippet_base(long snippetID) { try {
return loadSnippet(snippetID, preferCached);
} catch (Exception __e) { throw rethrow(__e); } }
static String loadSnippet(long snippetID, boolean preferCached) throws IOException {
if (isLocalSnippetID(snippetID))
return loadLocalSnippet(snippetID);
IResourceLoader rl = vm_getResourceLoader();
if (rl != null)
return rl.loadSnippet(fsI(snippetID));
return loadSnippet_noResourceLoader(snippetID, preferCached);
}
static String loadSnippet_noResourceLoader(long snippetID, boolean preferCached) throws IOException {
String text;
// boss bot (old concept)
/*text = getSnippetFromBossBot(snippetID);
if (text != null) return text;*/
initSnippetCache();
text = DiskSnippetCache_get(snippetID);
if (preferCached && text != null)
return text;
try {
if (loadSnippet_debug && text != null) System.err.println("md5: " + md5(text));
String url = tb_mainServer() + "/getraw.php?id=" + snippetID + "&utf8=1";
if (nempty(text)) url += "&md5=" + md5(text);
if (!isTrue(loadSnippet_publicOnly.get()))
url += standardCredentials();
String text2 = loadSnippet_loadFromServer(url);
boolean same = eq(text2, "==*#*==");
if (loadSnippet_debug) print("loadSnippet: same=" + same);
if (!same) text = text2;
} catch (RuntimeException e) {
e.printStackTrace();
throw new IOException("Snippet #" + snippetID + " not found or not public");
}
try {
initSnippetCache();
DiskSnippetCache_put(snippetID, text);
} catch (IOException e) {
System.err.println("Minor warning: Couldn't save snippet to cache (" + DiskSnippetCache_getDir() + ")");
}
return text;
}
static File DiskSnippetCache_dir;
public static void initDiskSnippetCache(File dir) {
DiskSnippetCache_dir = dir;
dir.mkdirs();
}
public static synchronized String DiskSnippetCache_get(long snippetID) throws IOException {
return loadTextFile(DiskSnippetCache_getFile(snippetID).getPath(), null);
}
private static File DiskSnippetCache_getFile(long snippetID) {
return new File(DiskSnippetCache_dir, "" + snippetID);
}
public static synchronized void DiskSnippetCache_put(long snippetID, String snippet) throws IOException {
saveTextFile(DiskSnippetCache_getFile(snippetID).getPath(), snippet);
}
public static File DiskSnippetCache_getDir() {
return DiskSnippetCache_dir;
}
public static void initSnippetCache() {
if (DiskSnippetCache_dir == null)
initDiskSnippetCache(getGlobalCache());
}
static String loadSnippet_loadFromServer(String url) {
Integer oldTimeout = setThreadLocal(loadPage_forcedTimeout_byThread, loadSnippet_timeout);
try {
return isTrue(loadSnippet_silent.get()) ? loadPageSilently(url) : loadPage(url);
} finally {
loadPage_forcedTimeout_byThread.set(oldTimeout);
}
}
static File programFile(String name) {
return prepareProgramFile(name);
}
static File programFile(String progID, String name) {
return prepareProgramFile(progID, name);
}
static String f2s(File f) {
return f == null ? null : f.getAbsolutePath();
}
static String f2s(String s) { return f2s(newFile(s)); }
static String f2s(java.nio.file.Path p) {
return p == null ? null : f2s(p.toFile());
}
static File saveProgramTextFile(String name, String contents) {
return saveTextFile(getProgramFile(name), contents);
}
static File saveProgramTextFile(String progID, String name, String contents) {
return saveTextFile(getProgramFile(progID, name), contents);
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal