www in docker support

This commit is contained in:
MaddoScientisto 2026-04-22 18:41:37 +02:00
commit c227fce036
2145 changed files with 399596 additions and 58 deletions

View file

@ -0,0 +1,446 @@
package it.acxent.skebby.api;
import com.google.gson.Gson;
import it.acxent.common.Parm;
import it.acxent.common.StatusMsg;
import it.acxent.db.ApplParm;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import it.acxent.db.ResParm;
import it.acxent.mail.MailMessage;
import it.acxent.mail.MailProperties;
import java.util.Base64;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.json.JSONObject;
public class SmsSkebbyApi {
public static final String API_SMS_SKEBBY_DEFAULT_SERVER = "https://api.skebby.it/API/v1.0/REST/";
private static final String P_SMS_SKEBBY_USER = "SMS_SKEBBY_USER";
private static final String P_SMS_SKEBBY_PWD = "SMS_SKEBBY_PWD";
private static final String P_SMS_SKEBBY_API_SERVER = "SMS_SKEBBY_API_SERVER";
private static final String P_SMS_SKEBBY_DEFAULT_SENDER = "SMS_SKEBBY_DEFAULT_SENDER";
private static final String P_SMS_SKEBBY_MIN_CREDITI_ALLARME = "SMS_SKEBBY_MIN_CREDITI_ALLARME";
private static final String P_SMS_SKEBBY_MAILTO_ALLARME = "SMS_SKEBBY_MAILTO_ALLARME";
private static final String P_SMS_SKEBBY_CREDITO_RESIDUO = "SMS_SKEBBY_CREDITO_RESIDUO";
private static final String URI_CMD_LOGIN = "login/";
private static final String URI_CMD_TOKEN = "token/";
private static final String URI_CMD_SEND_SMS = "sms";
private static final String HEADER_ACCESS_TOKEN = "Access_token";
private static final String HEADER_SESSION_KEY = "Session_key";
private static final String HEADER_USER_KEY = "user_key";
public static final String SMS_TYPE_CLASSIC_PLUS = "GP";
public static final String SMS_TYPE_CLASSIC = "TI";
public static final String SMS_TYPE_BASIC = "SI";
private static boolean debug = false;
private String userKey;
private String sessionKey;
private String accessToken;
private boolean useSessionKey = true;
private ApplParmFull apFull = null;
public SmsSkebbyApi(ApplParmFull apFull) {
this.apFull = apFull;
}
public SmsSkebbyApi(ApplParmFull apFull, boolean useSessionKey) {
this.apFull = apFull;
this.useSessionKey = useSessionKey;
}
public SmsSkebbyApi() {}
public static void initApplicationParms(ApplParmFull ap) {
if (ap != null) {
DBAdapter.logDebug(true, "FACE initParms: start");
String l_tipoParm = "SMS-API-SKEBBY";
Parm bean = new Parm(ap);
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
bean.findByCodice("SMS_SKEBBY_USER");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_USER");
bean.setDescrizione("SMS_SKEBBY_USER");
if (bean.getTesto().isEmpty())
bean.setTesto("acolzi");
bean.setNota("API USER SKEBBY. DI SOLITO LA MAIL");
bean.save();
bean.findByCodice("SMS_SKEBBY_PWD");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_PWD");
bean.setDescrizione("SMS_SKEBBY_PWD");
if (bean.getTesto().isEmpty())
bean.setTesto("pio");
bean.setNota("API PWD ACCESSO SKEBBY");
bean.save();
bean.findByCodice("SMS_SKEBBY_API_SERVER");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_API_SERVER");
bean.setDescrizione("SMS_SKEBBY_API_SERVER");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("https://api.skebby.it/API/v1.0/REST/");
bean.setNota("SERVER REST SKEBBY. DI SOLITO https://api.skebby.it/API/v1.0/REST/");
bean.save();
bean.findByCodice("SMS_SKEBBY_DEFAULT_SENDER");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_DEFAULT_SENDER");
bean.setDescrizione("SMS_SKEBBY_DEFAULT_SENDER");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("INVIATO DA XXX...");
bean.setNota("SENDER SMS. PUO' ESSERE UN NUMERO O DEL TESTO?");
bean.save();
bean.findByCodice("SMS_SKEBBY_MAILTO_ALLARME");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_MAILTO_ALLARME");
bean.setDescrizione("SMS_SKEBBY_MAILTO_ALLARME");
bean.setFlgTipo(0L);
if (bean.getTesto().isEmpty())
bean.setTesto("acolzi19@gmail.com");
bean.setNota("INDIRIZZO EMAIL A CUI INVIARE IL MESSAGGIO DI ALLARME. SE VUOTO --> DISATTIVATO");
bean.save();
bean.findByCodice("SMS_SKEBBY_MIN_CREDITI_ALLARME");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_MIN_CREDITI_ALLARME");
bean.setDescrizione("SMS_SKEBBY_MIN_CREDITI_ALLARME");
bean.setFlgTipo(1L);
bean.setNumero(1000.0D);
bean.setNota("CREDITI MINIMO SOTTO IL QUALE INVIO ALLARME VIA MAIL A MAILTO_ALLARME.<BR><=0--> DISATTIVATO");
bean.save();
bean.findByCodice("SMS_SKEBBY_CREDITO_RESIDUO");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("SMS_SKEBBY_CREDITO_RESIDUO");
bean.setDescrizione("SMS_SKEBBY_MIN_CREDITI_ALLARME");
bean.setFlgTipo(1L);
bean.setNumero(0.0D);
bean.setNota("NUMERO CREDITI RESIDUI, AGGIORNATO AD OGNI INVIO");
bean.save();
DBAdapter.logDebug(true, "FACE initParms: stop");
StatusMsg.deleteMsgByTag(ap, "INIT");
}
}
public static void main(String[] args) {
String hostname = "localhost:3308";
String db = "face";
ApplParmFull ap = new ApplParmFull(new ApplParm(17, "//" + hostname + "/" + db, db, "root", "root", 1, 10, 300));
SmsSkebbyApi bean = new SmsSkebbyApi(ap, false);
SmsSkebbyMessage sms = new SmsSkebbyMessage("+393285726937", "prova 123 prova");
SmsSkebbyApiResult resF = bean._sendMessage(sms);
System.out.println(resF.getMsg() + "\n" + resF.getMsg());
}
protected String getBase64BasicCredential() {
String encoding = getApiUser() + ":" + getApiUser();
return "Basic " + Base64.getEncoder().encodeToString(encoding.getBytes());
}
public ApplParmFull getApFull() {
return this.apFull;
}
public void setApFull(ApplParmFull apFull) {
this.apFull = apFull;
}
private String getApiEndpoint() {
return this.apFull.getParm("SMS_SKEBBY_API_SERVER").getTesto().isEmpty() ? "https://api.skebby.it/API/v1.0/REST/" :
this.apFull.getParm("SMS_SKEBBY_API_SERVER").getTesto();
}
private String getApiPwd() {
return this.apFull.getParm("SMS_SKEBBY_PWD").getTesto().isEmpty() ? "G@ndalf1" :
this.apFull.getParm("SMS_SKEBBY_PWD").getTesto();
}
public SmsSkebbyApiResult _loginApache() {
SmsSkebbyApiResult resER = new SmsSkebbyApiResult();
return resER;
}
public SmsSkebbyApiResult _getSessionToken() {
SmsSkebbyApiResult resER = new SmsSkebbyApiResult();
OkHttpClient client = UnsafeOkHttpSSL.getUnsafeOkHttpClient();
RequestBody emptyBody = RequestBody.create(new byte[0], null);
Request request = new Request.Builder().url(getApiEndpoint() + "login/").header("Authorization", getBase64BasicCredential())
.header("Accept", "application/json").header("Content-Type", "application/json").header("Content-Language", "it-IT").get()
.build();
try {
if (debug)
System.out.println("SmsSkebbyApi --> trainingStop");
try (Response response = client.newCall(request).execute()) {
String content = (response.body() != null) ? response.body().string() : "";
int statusCode = response.code();
if (debug) {
System.out.println("Status Code: " + statusCode);
System.out.println("\ncontent = " + content);
}
if (statusCode >= 400) {
resER.setOk(false);
resER.setMsg("Errore! Dati login errati");
} else {
resER.setOk(true);
resER.setMsg("Login eseguito correttamente");
resER.setResult(content);
String[] parts = content.split(";");
setUserKey(parts[0]);
setSessionKey(parts[1]);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
resER.setOk(false);
resER.setMsg(e.getMessage());
}
return resER;
}
private String getApiUser() {
return this.apFull.getParm("SMS_SKEBBY_USER").getTesto().isEmpty() ? "amministrazione@misericordiarifredi.org" :
this.apFull.getParm("SMS_SKEBBY_USER").getTesto();
}
public SmsSkebbyApiResult _getAccessToken() {
SmsSkebbyApiResult resER = new SmsSkebbyApiResult();
OkHttpClient client = UnsafeOkHttpSSL.getUnsafeOkHttpClient();
RequestBody emptyBody = RequestBody.create(new byte[0], null);
Request request = new Request.Builder().url(getApiEndpoint() + "token/").header("Authorization", getBase64BasicCredential())
.header("Accept", "application/json").header("Content-Type", "application/json").header("Content-Language", "it-IT").get()
.build();
try {
if (debug)
System.out.println("SmsSkebbyApi --> _getUserToken");
try (Response response = client.newCall(request).execute()) {
String content = (response.body() != null) ? response.body().string() : "";
int statusCode = response.code();
if (debug) {
System.out.println("Status Code: " + statusCode);
System.out.println("\ncontent = " + content);
}
if (statusCode >= 400) {
resER.setOk(false);
resER.setMsg("Errore! Dati login errati. Impossibile avere il token");
} else {
resER.setOk(true);
resER.setMsg("User Token ok");
resER.setResult(content);
String[] parts = content.split(";");
setUserKey(parts[0]);
setAccessToken(parts[1]);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
resER.setOk(false);
resER.setMsg(e.getMessage());
}
return resER;
}
public SmsSkebbyApiResult _sendMessage(SmsSkebbyMessage smsMessage) {
SmsSkebbyApiResult res;
if (isUseSessionKey()) {
res = _sendMessageWithSessionKey(smsMessage);
} else {
res = _sendMessageWithAccessToken(smsMessage);
}
JSONObject joRes = res.getJsonObjectFromStringResult();
if (joRes.has("remaining_credits")) {
long remainingCredits = joRes.getLong("remaining_credits");
Parm parm = new Parm(getApFull());
parm.findByCodice("SMS_SKEBBY_CREDITO_RESIDUO");
parm.setNumero((double)remainingCredits);
parm.save();
}
return res;
}
private String getUserKey() {
return (this.userKey == null) ? "" : this.userKey.trim();
}
private void setUserKey(String userKey) {
this.userKey = userKey;
}
private String getSessionKey() {
return (this.sessionKey == null) ? "" : this.sessionKey.trim();
}
private void setSessionKey(String accessToken) {
this.sessionKey = accessToken;
}
private String getDefaultSender() {
return this.apFull.getParm("SMS_SKEBBY_DEFAULT_SENDER").getTesto().isEmpty() ? "+394390990925" :
this.apFull.getParm("SMS_SKEBBY_DEFAULT_SENDER").getTesto();
}
private String getAccessToken() {
return (this.accessToken == null) ? "" : this.accessToken.trim();
}
private void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
private boolean isUseSessionKey() {
return this.useSessionKey;
}
private void setUseSessionKey(boolean useSessionKey) {
this.useSessionKey = useSessionKey;
}
private SmsSkebbyApiResult _sendMessageWithSessionKey(SmsSkebbyMessage smsMessage) {
SmsSkebbyApiResult resER = new SmsSkebbyApiResult();
boolean debug = true;
if (getSessionKey().isEmpty())
resER = _getSessionToken();
if (resER.isOk()) {
if (debug)
DBAdapter.printDebug("SmsSkebbyApi --> _sendMessage: userkey:" + getUserKey() + " accesstoken: " + getSessionKey());
OkHttpClient client = UnsafeOkHttpSSL.getUnsafeOkHttpClient();
Gson gson = new Gson();
JSONObject joSms = new JSONObject(gson.toJson(smsMessage));
if (!joSms.has("sender"))
joSms.put("sender", getDefaultSender());
MediaType JSONmediaType = MediaType.get("application/json; charset=utf-8");
RequestBody body = RequestBody.create(joSms.toString(), MediaType.parse("application/json"));
Request request = new Request.Builder().url(getApiEndpoint() + "sms").addHeader("user_key", getUserKey())
.addHeader("Session_key", getSessionKey()).addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json").post(body).build();
try {
if (debug)
DBAdapter.printDebug("SmsSkebbyApi --> _sendMessage:\n" + joSms.toString());
try (Response response = client.newCall(request).execute()) {
String content = (response.body() != null) ? response.body().string() : "";
int statusCode = response.code();
if (debug) {
System.out.println("Status Code: " + statusCode);
System.out.println("\ncontent = " + content);
}
if (statusCode >= 400) {
resER.setOk(false);
resER.setMsg("Errore! Impossibile inviare sms. " + content);
} else {
resER.setOk(true);
resER.setMsg("SMS INVIATI CORRETTAMENTE");
resER.setResult(content);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
resER.setOk(false);
resER.setMsg(e.getMessage());
}
}
return resER;
}
private SmsSkebbyApiResult _sendMessageWithAccessToken(SmsSkebbyMessage smsMessage) {
SmsSkebbyApiResult resER = new SmsSkebbyApiResult();
boolean debug = true;
if (getAccessToken().isEmpty())
resER = _getAccessToken();
if (resER.isOk()) {
if (debug)
DBAdapter.printDebug("SmsSkebbyApi --> _sendMessage: userkey:" + getUserKey() + " accesstoken: " + getAccessToken());
OkHttpClient client = UnsafeOkHttpSSL.getUnsafeOkHttpClient();
Gson gson = new Gson();
JSONObject joSms = new JSONObject(gson.toJson(smsMessage));
if (!joSms.has("sender"))
joSms.put("sender", getDefaultSender());
MediaType JSONmediaType = MediaType.get("application/json; charset=utf-8");
RequestBody body = RequestBody.create(joSms.toString(), MediaType.parse("application/json"));
Request request = new Request.Builder().url(getApiEndpoint() + "sms").addHeader("user_key", getUserKey())
.addHeader("Access_token", getAccessToken()).addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json").post(body).build();
try {
if (debug)
DBAdapter.printDebug("SmsSkebbyApi --> _sendMessage:\n" + joSms.toString());
try (Response response = client.newCall(request).execute()) {
String content = (response.body() != null) ? response.body().string() : "";
int statusCode = response.code();
if (debug) {
System.out.println("Status Code: " + statusCode);
System.out.println("\ncontent = " + content);
}
if (statusCode >= 400) {
resER.setOk(false);
resER.setMsg("Errore! Impossibile inviare sms. ");
} else {
resER.setOk(true);
resER.setMsg("SMS INVIATI CORRETTAMENTE");
resER.setResult(content);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
resER.setOk(false);
resER.setMsg(e.getMessage());
}
}
return resER;
}
public ResParm controllaEInviaAllarme() {
ResParm rp = new ResParm();
if (getApFull().getParm("SMS_SKEBBY_MAILTO_ALLARME").getTesto().isEmpty() ||
getApFull().getParm("SMS_SKEBBY_MIN_CREDITI_ALLARME").getNumeroLong() <= 0L)
return rp;
Parm parm = new Parm(getApFull());
parm.findByCodice("SMS_SKEBBY_CREDITO_RESIDUO");
if (parm.getNumeroLong() <= getApFull().getParm("SMS_SKEBBY_MIN_CREDITI_ALLARME").getNumeroLong()) {
String mailMsg = "Attenzione!!! Credito residuo sotto la soglia di allarme di " + getApFull().getParm("SMS_SKEBBY_MIN_CREDITI_ALLARME").getNumeroLong() + " messaggi.\n\nCredito Residuo: " +
parm.getNumeroLong() + " messaggi.";
String subject = "Skebby Sms Credit Alert - " + getApFull().getDataFormat().format(DBAdapter.getToday());
MailProperties prop = new MailProperties();
prop.setProperty("TO", getApFull().getParm("SMS_SKEBBY_MAILTO_ALLARME").getTesto());
prop.setProperty("FROM", getApFull().getParm("FROM").getTesto());
prop.setProperty("SUBJECT", subject);
MailMessage mm = new MailMessage(getApFull());
mm.setTextMessage(mailMsg);
prop.setProperty("MSG", mm.getMessage());
prop.setProperty("ISHTML", "true");
mm.sendMailMessage(prop, false);
}
return rp;
}
}

View file

@ -0,0 +1,51 @@
package it.acxent.skebby.api;
import org.json.JSONObject;
public class SmsSkebbyApiResult {
private String msg;
public SmsSkebbyApiResult(String msg, boolean status, Object result) {
this.msg = msg;
this.ok = status;
this.result = result;
}
private boolean ok = true;
private Object result;
public SmsSkebbyApiResult() {}
public String getMsg() {
return (this.msg == null) ? "" : this.msg.trim();
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isOk() {
return this.ok;
}
public void setOk(boolean status) {
this.ok = status;
}
public Object getResult() {
return this.result;
}
public JSONObject getJsonObjectFromStringResult() {
return new JSONObject((String)getResult());
}
public JSONObject getJsonObjectResult() {
return (JSONObject)getResult();
}
public void setResult(Object result) {
this.result = result;
}
}

View file

@ -0,0 +1,97 @@
package it.acxent.skebby.api;
import java.util.ArrayList;
import java.util.List;
public class SmsSkebbyMessage {
public SmsSkebbyMessage(List<String> recipient, String message) {
this.message = message;
this.recipient = recipient;
}
public SmsSkebbyMessage(String recipient, String message) {
this.message = message;
this.recipient = new ArrayList<>();
this.recipient.add(recipient);
}
private String message_type = "GP";
private String message;
private List<String> recipient;
private String sender;
private String scheduled_delivery_time;
private String order_id;
private boolean returnCredits = true;
private boolean returnRemaining = true;
public String getMessage_type() {
return this.message_type;
}
public void setMessage_type(String message_type) {
this.message_type = message_type;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public List<String> getRecipient() {
return this.recipient;
}
public void setRecipient(List<String> recipient) {
this.recipient = recipient;
}
public String getSender() {
return this.sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getScheduled_delivery_time() {
return this.scheduled_delivery_time;
}
public void setScheduled_delivery_time(String scheduled_delivery_time) {
this.scheduled_delivery_time = scheduled_delivery_time;
}
public String getOrder_id() {
return this.order_id;
}
public void setOrder_id(String order_id) {
this.order_id = order_id;
}
public boolean isReturnCredits() {
return this.returnCredits;
}
public void setReturnCredits(boolean returnCredits) {
this.returnCredits = returnCredits;
}
private boolean isReturnRemaining() {
return this.returnRemaining;
}
private void setReturnRemaining(boolean returnRemaining) {
this.returnRemaining = returnRemaining;
}
}

View file

@ -0,0 +1,49 @@
package it.acxent.skebby.api;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.OkHttpClient;
public class UnsafeOkHttpSSL {
private static TrustManager[] getAllTrustingTrustManager() {
return new TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} };
}
private static SSLSocketFactory getUnsafeSslSocketFactory() {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, getAllTrustingTrustManager(), new SecureRandom());
return sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException|java.security.KeyManagementException e) {
throw new RuntimeException(e);
}
}
public static OkHttpClient getUnsafeOkHttpClient() {
try {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
TrustManager[] trustAllCerts = getAllTrustingTrustManager();
X509TrustManager trustManager = (X509TrustManager)trustAllCerts[0];
builder.sslSocketFactory(getUnsafeSslSocketFactory(), trustManager);
builder.hostnameVerifier((hostname, session) -> true);
return builder.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View file

@ -0,0 +1 @@
package it.acxent.skebby.api;