From 2c6ca541e0562e0c925d259be12003ba001ca4dd Mon Sep 17 00:00:00 2001 From: legendary-cookie Date: Mon, 18 Oct 2021 19:11:05 +0200 Subject: [PATCH] config support --- .../7.1/executionHistory/executionHistory.bin | Bin 30981 -> 35486 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/7.1/fileHashes/fileHashes.bin | Bin 19197 -> 19297 bytes .gradle/7.1/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .gradle/buildOutputCleanup/outputFiles.bin | Bin 19073 -> 19109 bytes .gradle/checksums/checksums.lock | Bin 17 -> 17 bytes .idea/vcs.xml | 6 ++ build.gradle | 8 +- .../de/vincentschweiger/calltoj/CallToJ.java | 85 ++++++++++++------ src/main/resources/template.yaml | 3 + 11 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 src/main/resources/template.yaml diff --git a/.gradle/7.1/executionHistory/executionHistory.bin b/.gradle/7.1/executionHistory/executionHistory.bin index e496dd7b5d9514189aad40de744d88ef5343c8ae..6f7c79e1448bc039d1cfbceac78f1437f605b09a 100644 GIT binary patch delta 1654 zcmZqu#5iv%(*zM-Mg}m5+Qh)X9==ggSVEJ1*F2%<|EkNTKxBfm|3d*&!sAaf+gVs4 z;+3qET_wuIntEZett=CL29y!A=Apqj^1LE zyTdtoilF8fGcs+530lDg^-EH73vv=mQuQhmb90ylBIMWukHqr756e_q|K3w!y9|EFe}8M;wl;ObpM4AbpECBRq!yQC<|US7=I6O&7BQ@zESMpPQ;*mYJ8FnpdI^jX3?}#N>?BV*T9wl+v8k zVqGKsv`jFqXQ&T~UQnp%7w08rr-E6AdPbJ|W+?{ADT!%GMh1okX@*9Y=BcLUCT6B) zrly7|=7uJwMkWSnW~oM|2z|QsAdPxiiABr;4lc||H-vpJubkM?lPW&xKGSj1U6!1m zo133ktecsykHj?6Gt;*)G_|laPDwLOGd4^~G)hfQH8B7>r#{sn(a|*n*j|Gn!G7(E#n7;B~^%<_Y1;oc6U^^Adp zCJ-xvumE4a9A~&xMQQ_!{)v)FTN5BUE|dTzfk5CQkU-P1{kiPKi+q}=?>V#i?BDXs z9IB%NsFD?k*^f+~?WxWjm!`b=sHX^H{k{BC0`ES*DR{Mdbyd(usa&w~xHNU3QXt?t t4kXYlh>&9sJQB8Q|GQb)b7)*)PaS`MsPLM9J7665MUDf~q delta 221 zcmaDjjq&eP#tkMCjC_+#B@8ClO5B*7D;dm~xKZ(k_(p>rVv`*`uGQzNvrgqa74#w@ zQ|Q?1PcvK?7#M4&h)(5Z00Y*yKuXUTNN57FA_xnlZcMW2Vs$n#U-L97MN=&itV60` zB2W?txXgeAnhvW~YnBC_ShJzQ{`G>B-HY!+bxZ}SWCiJ&I(fFII^bI07W}0OZX;%K!iX diff --git a/.gradle/7.1/fileHashes/fileHashes.lock b/.gradle/7.1/fileHashes/fileHashes.lock index fa4246208d3e608fe917134773239c0617387bd5..21e8a9ef821eb106498e98630b792433308e11c8 100644 GIT binary patch literal 17 TcmZP$&31FEDmYfg00F50DhdPJ literal 17 TcmZP$&31FEDmYfg00DXcDboX_ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 48c7f9c011170f60793a2d4fb47780457aac77cd..d49c790a43b978104e89b2fcd8a90c751f4390d9 100644 GIT binary patch literal 17 UcmZR!oV5N%>p$Hx1_)>Y062aH00000 literal 17 UcmZR!oV5N%>p$Hx1_*Eg060DbzyJUM diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 19645ffa6274e118968b3fced16051af649df10e..2e655e69e82777df0075abdd76482460a009988e 100644 GIT binary patch delta 100 zcmZpi%D8kY;|3E6O{JbT2eYpiFV1EF15fS$P|!Q6@R({>vo}QCYw~7S2?-_vcFvmD o%at$OgNimz4wZV%=(thwhxkT=8zP$>Jsg-O=X(iF_V*M50MH~QS^xk5 delta 51 zcmZ2Fm9cRu;|3E6L4}?+2eYpiFV1EF15fSEu@VwYlY6BeGYW20{2{*4fJ1b%qlW_% E0K;Gqd;kCd diff --git a/.gradle/checksums/checksums.lock b/.gradle/checksums/checksums.lock index 2a4982964a3bc1e66c6a9a3bca0e03306fe434a4..40d40063a3a7b428a3b5a3468caa2d6997d42435 100644 GIT binary patch literal 17 UcmZRUw%X47SaNY00|amb047TVJpcdz literal 17 TcmZRUw%X47SaNY00~7!NCO`u+ diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index cedadec..960b898 100644 --- a/build.gradle +++ b/build.gradle @@ -11,12 +11,8 @@ repositories { dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' -} - -test { - useJUnitPlatform() + implementation 'org.yaml:snakeyaml:1.29' + implementation group: 'commons-io', name: 'commons-io', version: '2.6' } jar { diff --git a/src/main/java/de/vincentschweiger/calltoj/CallToJ.java b/src/main/java/de/vincentschweiger/calltoj/CallToJ.java index e48a175..c8f0e92 100644 --- a/src/main/java/de/vincentschweiger/calltoj/CallToJ.java +++ b/src/main/java/de/vincentschweiger/calltoj/CallToJ.java @@ -1,41 +1,76 @@ package de.vincentschweiger.calltoj; +import org.apache.commons.io.IOUtils; +import org.yaml.snakeyaml.Yaml; + +import javax.swing.*; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.util.Base64; +import java.util.Map; /** * Mo. 18/10/2021 17:32 * * @author cook1e */ +@SuppressWarnings("ResultOfMethodCallIgnored") public class CallToJ { - private static String snom_webadmin_user = "admin"; - private static String snom_webadmin_pw = "x7eff15"; - private static String hostname_snom = "snom765-901777.getcom.de"; + private static final File configFile = new File(new File(System.getProperty("user.home")), ".callto.yaml"); - public static void main(String[] args) throws java.io.IOException { - String number; - if (args.length < 1) { - number = "015904183517"; - } else { - number = args[0]; - // Replace cause of firefox and callto handling stuff - number = number.replace("callto://", ""); - number = number.replace("tel://", ""); - number = number.replace("sip://", ""); - number = number.replace("+49", "0"); - number = number.replace("%20", ""); + public static void main(String[] args) { + try { + if (!configFile.exists()) { + configFile.createNewFile(); + FileOutputStream outputStream = new FileOutputStream(configFile); + InputStream inputStream = CallToJ.class.getResourceAsStream("/template.yaml"); + if (inputStream != null) { + IOUtils.copy(inputStream, outputStream); + inputStream.close(); + } else { + JOptionPane.showMessageDialog(null, "IN is null"); + outputStream.close(); + configFile.delete(); + System.exit(-1); + } + outputStream.close(); + JOptionPane.showMessageDialog(null, "You have to configure CallToJ!\n See .callto.yaml in your home directory!"); + System.exit(0); + } + + Yaml yaml = new Yaml(); + FileInputStream inputStream = new FileInputStream(configFile); + Map obj = yaml.load(inputStream); + + String snom_webadmin_user = obj.get("user").toString(); + String snom_webadmin_pw = obj.get("password").toString(); + String hostname_snom = obj.get("hostname").toString(); + + String number; + if (args.length < 1) { + number = "015904183517"; + } else { + number = args[0]; + // Replace cause of firefox and callto handling stuff + number = number.replace("callto://", ""); + number = number.replace("tel://", ""); + number = number.replace("sip://", ""); + number = number.replace("+49", "0"); + number = number.replace("%20", ""); + } + + System.out.println("Using Snom phone to dial number " + number); + + URL url = new URL("http://" + hostname_snom + "/command.htm?number=" + number + "&outgoing_uri=URI"); + String encoding = Base64.getEncoder().encodeToString((snom_webadmin_user + ":" + snom_webadmin_pw).getBytes()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(false); + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.getResponseCode(); + } catch (IOException e) { + e.printStackTrace(); } - - System.out.println("Using Snom phone to dial number " + number); - - URL url = new URL("http://" + hostname_snom + "/command.htm?number=" + number + "&outgoing_uri=URI"); - String encoding = Base64.getEncoder().encodeToString((snom_webadmin_user + ":" + snom_webadmin_pw).getBytes()); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setDoOutput(false); - connection.setRequestProperty("Authorization", "Basic " + encoding); - connection.getResponseCode(); } } diff --git a/src/main/resources/template.yaml b/src/main/resources/template.yaml new file mode 100644 index 0000000..18e6d0c --- /dev/null +++ b/src/main/resources/template.yaml @@ -0,0 +1,3 @@ +user: USERNAME +password: PASSWORD +hostname: HOSTNAME