www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,398 @@
|
|||
package it.acxent.rd;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import it.acxent.common.Parm;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.db.WcString;
|
||||
import it.acxent.util.RandomString;
|
||||
import it.acxent.util.StringTokenizer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class RemoteDevice extends DBAdapter implements Serializable {
|
||||
private static final long serialVersionUID = 1636646748813L;
|
||||
|
||||
public static final String P_RD_API_LOGIN = "RD_API_LOGIN";
|
||||
|
||||
public static final String P_RD_API_PWD = "RD_API_PWD";
|
||||
|
||||
public static final String P_RD_API_SERVER = "RD_API_SERVER";
|
||||
|
||||
public static final String P_RD_TEST_SMS = "RD_TEST_SMS";
|
||||
|
||||
private long id_remoteDevice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private String token;
|
||||
|
||||
private String imei;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private Timestamp updTmst;
|
||||
|
||||
private String tokenOld;
|
||||
|
||||
private String fcmToken;
|
||||
|
||||
private long flgAbilitato;
|
||||
|
||||
public static final String SMSGATEWAY_PROJECT_ID = "smsgateway-f05ec";
|
||||
|
||||
public RemoteDevice(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public RemoteDevice() {}
|
||||
|
||||
private String getQrTokenString() {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("uri", getRemoteDeviceApiServer());
|
||||
jo.put("token", getToken());
|
||||
return jo.toString();
|
||||
}
|
||||
|
||||
public String getRemoteDeviceApiServer() {
|
||||
return getParm("RD_API_SERVER").getTesto();
|
||||
}
|
||||
|
||||
public String getRemoteDeviceTestSms() {
|
||||
return getParm("RD_TEST_SMS").getTesto();
|
||||
}
|
||||
|
||||
public void setId_remoteDevice(long newId_remoteDevice) {
|
||||
this.id_remoteDevice = newId_remoteDevice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setToken(String newToken) {
|
||||
this.token = newToken;
|
||||
}
|
||||
|
||||
public void setImei(String newImei) {
|
||||
this.imei = newImei;
|
||||
}
|
||||
|
||||
public void setIpAddress(String newIpAddress) {
|
||||
this.ipAddress = newIpAddress;
|
||||
}
|
||||
|
||||
public void setUpdTmst(Timestamp newUpdTmst) {
|
||||
this.updTmst = newUpdTmst;
|
||||
}
|
||||
|
||||
public long getId_remoteDevice() {
|
||||
return this.id_remoteDevice;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return (this.token == null) ? "" : this.token.trim();
|
||||
}
|
||||
|
||||
public String getImei() {
|
||||
return (this.imei == null) ? "" : this.imei.trim();
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return (this.ipAddress == null) ? "" : this.ipAddress.trim();
|
||||
}
|
||||
|
||||
public Timestamp getUpdTmst() {
|
||||
return this.updTmst;
|
||||
}
|
||||
|
||||
public String getUpdTmstS() {
|
||||
return (this.updTmst == null) ? "" : this.updTmst.toString();
|
||||
}
|
||||
|
||||
protected ResParm checkDeleteCascade() {
|
||||
return new ResParm(true);
|
||||
}
|
||||
|
||||
protected void deleteCascade() {}
|
||||
|
||||
public Vectumerator<RemoteDevice> findByCR(RemoteDeviceCR CR, int pageNumber, int pageRows) {
|
||||
String s_Sql_Find = "select A.* from REMOTE_DEVICE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
if (!CR.getSearchTxt().trim().isEmpty()) {
|
||||
StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " ");
|
||||
StringBuffer txt = new StringBuffer("(");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')");
|
||||
if (st.hasMoreTokens())
|
||||
txt.append(" and ");
|
||||
}
|
||||
txt.append(")");
|
||||
wc.addWc(txt.toString());
|
||||
}
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt, pageNumber, pageRows);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public String getQRCodeTokenFullFileName() {
|
||||
if (getId_remoteDevice() > 0L) {
|
||||
String targetdir = getDocBase() + "admin/rd/_qr/";
|
||||
File fileTd = new File(targetdir);
|
||||
if (!fileTd.exists())
|
||||
fileTd.mkdirs();
|
||||
return targetdir + targetdir;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getQRCodeTokenFileName() {
|
||||
if (getId_remoteDevice() > 0L)
|
||||
return "token_" + getId_remoteDevice() + "_" + getImgTmst() + ".jpg";
|
||||
return "";
|
||||
}
|
||||
|
||||
public ResParm generaNuovoToken() {
|
||||
long l_id = getId_remoteDevice();
|
||||
ResParm rp = new ResParm();
|
||||
if (l_id > 0L) {
|
||||
new File(getQRCodeTokenFullFileName()).delete();
|
||||
setImgTmst(getTimeNameForFileUpload());
|
||||
super.save();
|
||||
String fileName = getQRCodeTokenFullFileName();
|
||||
if (new File(fileName).exists());
|
||||
RandomString randomString = new RandomString(256);
|
||||
String token = randomString.nextString();
|
||||
setToken(token);
|
||||
rp = super.save();
|
||||
if (rp.getStatus())
|
||||
rp = creaQrCodeTokenFile(fileName, getQrTokenString(), 600);
|
||||
} else {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Salvare il record prima di generare il token");
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
public ResParm creaQrCodeTokenFile(String fileName, String qrmsg, int size) {
|
||||
ResParm rp = new ResParm(true);
|
||||
if (new File(fileName).exists());
|
||||
try {
|
||||
QRCodeWriter writer = new QRCodeWriter();
|
||||
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
||||
hints.put(EncodeHintType.MARGIN, Integer.valueOf(0));
|
||||
if (size <= 0)
|
||||
size = 600;
|
||||
BitMatrix matrix = writer.encode(qrmsg, BarcodeFormat.QR_CODE, size, size, hints);
|
||||
BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);
|
||||
ImageIO.write(image, "JPEG", new File(fileName));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
rp.setException(e);
|
||||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
protected void initFields() {
|
||||
super.initFields();
|
||||
this.tokenOld = "";
|
||||
}
|
||||
|
||||
protected void fillFields(ResultSet rst) {
|
||||
super.fillFields(rst);
|
||||
this.tokenOld = getToken();
|
||||
}
|
||||
|
||||
public ResParm save() {
|
||||
String l_tokenOld = this.tokenOld;
|
||||
if (l_tokenOld != null &&
|
||||
!l_tokenOld.equals(getToken())) {
|
||||
new File(getQRCodeTokenFullFileName()).delete();
|
||||
setImgTmst(getTimeNameForFileUpload());
|
||||
}
|
||||
ResParm rp = super.save();
|
||||
if (rp.getStatus() &&
|
||||
l_tokenOld != null &&
|
||||
!l_tokenOld.equals(getToken()))
|
||||
rp.append(creaQrCodeTokenFile(getQRCodeTokenFullFileName(), getQrTokenString(), 600));
|
||||
return rp;
|
||||
}
|
||||
|
||||
public Vectumerator<RemoteDevice> findAvailable() {
|
||||
String s_Sql_Find = "select A.* from REMOTE_DEVICE AS A";
|
||||
String s_Sql_Order = " order by A.updTmst desc";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.updTmst is not null");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
return findRows(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return AB_EMPTY_VECTUMERATOR;
|
||||
}
|
||||
}
|
||||
|
||||
public void findFirstAvailable() {
|
||||
String s_Sql_Find = "select A.* from REMOTE_DEVICE AS A";
|
||||
String s_Sql_Order = " order by A.updTmst desc";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.updTmst is not null");
|
||||
wc.addWc("A.flgAbilitato=1");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void findByToken(String l_token) {
|
||||
String s_Sql_Find = "select A.* from REMOTE_DEVICE AS A";
|
||||
String s_Sql_Order = " order by A.updTmst desc";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.token='" + l_token + "'");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
findFirstRecord(stmt);
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initApplicationParms(ApplParmFull ap) {
|
||||
boolean debug = false;
|
||||
if (ap != null) {
|
||||
DBAdapter.logDebug(debug, "RemoteDevice initParms: start");
|
||||
String l_tipoParm = "";
|
||||
Parm bean = new Parm(ap);
|
||||
l_tipoParm = "REMOTE DEVICE";
|
||||
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
|
||||
bean.findByCodice("RD_API_LOGIN");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("RD_API_LOGIN");
|
||||
bean.setDescrizione("RD_API_LOGIN");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("login");
|
||||
bean.setNota("LOGIN DI SCAMBIO TRA DEVICE E SERVER");
|
||||
bean.save();
|
||||
bean.findByCodice("RD_API_PWD");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("RD_API_PWD");
|
||||
bean.setDescrizione("RD_API_PWD");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("pwd");
|
||||
bean.setNota("PASSWORD DI SCAMBIO TRA DEVICE E SERVER");
|
||||
bean.save();
|
||||
bean.findByCodice("RD_API_SERVER");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("RD_API_SERVER");
|
||||
bean.setDescrizione("RD_API_SERVER");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("http://10.10.0.50/cc/");
|
||||
bean.setNota("INDIRIZZO DEL SERVER DI REGISTRAZIONE DEI DEVICE<br>Es: http://10.10.0.50/cc/");
|
||||
bean.save();
|
||||
bean.findByCodice("RD_TEST_SMS");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("RD_TEST_SMS");
|
||||
bean.setDescrizione("RD_TEST_SMS");
|
||||
bean.setFlgTipo(0L);
|
||||
bean.setNota("NUMERO CELLULARE DI TEST PER INVIO DI PROVA SMS<BR>TUTTI I MESSAGGI VENGONO INVIATI A QUESTO CELLULARE");
|
||||
bean.save();
|
||||
bean.findByCodice("FIREBASE_SERVER_KEY");
|
||||
if (bean.getId_parm() > 0L)
|
||||
bean.delete();
|
||||
bean.findByCodice("FIREBASE_JSON_AUTH_PRIVATE_KEY");
|
||||
bean.setFlgAdmin(1L);
|
||||
bean.setTipoParm(l_tipoParm);
|
||||
bean.setCodice("FIREBASE_JSON_AUTH_PRIVATE_KEY");
|
||||
bean.setDescrizione("FIREBASE_JSON_AUTH_PRIVATE_KEY");
|
||||
bean.setFlgTipo(0L);
|
||||
if (bean.getTesto().isEmpty())
|
||||
bean.setTesto("/Users/acolzi/Downloads/smsgateway-f05ec-firebase-adminsdk-uicut-dbc52f0758.json");
|
||||
bean.setNota("PERCORSO FULL AL FILE JSON CON LA CHIAVE DI AUTORIZZAZIONE DELLA APPLICAZIONE FIREBASE.<BR>\"/Users/acolzi/Downloads/smsgateway-f05ec-firebase-adminsdk-uicut-dbc52f0758.json\"");
|
||||
bean.save();
|
||||
DBAdapter.logDebug(debug, "RemoteDevice initParms: stop");
|
||||
StatusMsg.deleteMsgByTag(ap, "INIT");
|
||||
}
|
||||
}
|
||||
|
||||
public String getFcmToken() {
|
||||
return (this.fcmToken == null) ? "" : this.fcmToken.trim();
|
||||
}
|
||||
|
||||
public void setFcmToken(String fcmToken) {
|
||||
this.fcmToken = fcmToken;
|
||||
}
|
||||
|
||||
public long getFlgAbilitato() {
|
||||
return this.flgAbilitato;
|
||||
}
|
||||
|
||||
public void setFlgAbilitato(long flgAbilitato) {
|
||||
this.flgAbilitato = flgAbilitato;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
if (getId_remoteDevice() == 0L || getFlgAbilitato() == 0L || getToken().isEmpty() || getFcmToken().isEmpty())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasDeviceActive() {
|
||||
String s_Sql_Find = "select A.* from REMOTE_DEVICE AS A";
|
||||
String s_Sql_Order = "";
|
||||
WcString wc = new WcString();
|
||||
wc.addWc("A.flgAbilitato=1");
|
||||
wc.addWc("A.token<>''");
|
||||
wc.addWc("A.fcmToken<>''");
|
||||
try {
|
||||
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
|
||||
Vectumerator<RemoteDevice> vec = findRows(stmt, 1, 1);
|
||||
if (vec.hasMoreElements())
|
||||
return true;
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
removeCPConnection();
|
||||
handleDebug(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package it.acxent.rd;
|
||||
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class RemoteDeviceCR extends CRAdapter {
|
||||
private static final long serialVersionUID = 2234878834967039209L;
|
||||
|
||||
private long id_remoteDevice;
|
||||
|
||||
private String descrizione;
|
||||
|
||||
private String token;
|
||||
|
||||
private String imei;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private Timestamp updTmst;
|
||||
|
||||
private long flgAbilitato = -1L;
|
||||
|
||||
public RemoteDeviceCR(ApplParmFull newApplParmFull) {
|
||||
super(newApplParmFull);
|
||||
}
|
||||
|
||||
public RemoteDeviceCR() {}
|
||||
|
||||
public void setId_remoteDevice(long newId_remoteDevice) {
|
||||
this.id_remoteDevice = newId_remoteDevice;
|
||||
}
|
||||
|
||||
public void setDescrizione(String newDescrizione) {
|
||||
this.descrizione = newDescrizione;
|
||||
}
|
||||
|
||||
public void setToken(String newToken) {
|
||||
this.token = newToken;
|
||||
}
|
||||
|
||||
public void setImei(String newImei) {
|
||||
this.imei = newImei;
|
||||
}
|
||||
|
||||
public void setIpAddress(String newIpAddress) {
|
||||
this.ipAddress = newIpAddress;
|
||||
}
|
||||
|
||||
public void setUpdTmst(Timestamp newUpdTmst) {
|
||||
this.updTmst = newUpdTmst;
|
||||
}
|
||||
|
||||
public long getId_remoteDevice() {
|
||||
return this.id_remoteDevice;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return (this.descrizione == null) ? "" : this.descrizione.trim();
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return (this.token == null) ? "" : this.token.trim();
|
||||
}
|
||||
|
||||
public String getImei() {
|
||||
return (this.imei == null) ? "" : this.imei.trim();
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return (this.ipAddress == null) ? "" : this.ipAddress.trim();
|
||||
}
|
||||
|
||||
public Timestamp getUpdTmst() {
|
||||
return this.updTmst;
|
||||
}
|
||||
|
||||
public long getFlgAbilitato() {
|
||||
return this.flgAbilitato;
|
||||
}
|
||||
|
||||
public void setFlgAbilitato(long flgAbilitato) {
|
||||
this.flgAbilitato = flgAbilitato;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package it.acxent.rd.json;
|
||||
|
||||
public class RdRequestJ {
|
||||
private String token;
|
||||
|
||||
private String fcmToken;
|
||||
|
||||
private String imei;
|
||||
|
||||
private String act;
|
||||
|
||||
public String getToken() {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getFcmToken() {
|
||||
return this.fcmToken;
|
||||
}
|
||||
|
||||
public void setFcmToken(String fcmToken) {
|
||||
this.fcmToken = fcmToken;
|
||||
}
|
||||
|
||||
public String getImei() {
|
||||
return this.imei;
|
||||
}
|
||||
|
||||
public void setImei(String imei) {
|
||||
this.imei = imei;
|
||||
}
|
||||
|
||||
public String getAct() {
|
||||
return this.act;
|
||||
}
|
||||
|
||||
public void setAct(String act) {
|
||||
this.act = act;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package it.acxent.rd.json;
|
||||
|
||||
public class RdResponseJ {
|
||||
public static final long STATUS_ALTRO_ERRORE = 99L;
|
||||
|
||||
public static final long STATUS_TOKEN_GIA_ASSEGNATO = 2L;
|
||||
|
||||
public static final long STATUS_TOKEN_NON_TROVATO = 1L;
|
||||
|
||||
public static final long STATUS_OK = 0L;
|
||||
|
||||
private String msg;
|
||||
|
||||
public RdResponseJ(long status, String msg) {
|
||||
this.status = status;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
private long status = 0L;
|
||||
|
||||
private String appVersion;
|
||||
|
||||
public RdResponseJ() {}
|
||||
|
||||
public String getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public long getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public void setStatus(long status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getAppVersion() {
|
||||
return this.appVersion;
|
||||
}
|
||||
|
||||
public void setAppVersion(String appVersion) {
|
||||
this.appVersion = appVersion;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.rd.json;
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package it.acxent.rd.json.smsgateway;
|
||||
|
||||
public class DataSmsMsgJ {
|
||||
private long id_codaMessaggi;
|
||||
|
||||
private long flgTipo;
|
||||
|
||||
private String cellulare;
|
||||
|
||||
private String smsToTest;
|
||||
|
||||
private String testoMessaggio;
|
||||
|
||||
public long getId_codaMessaggi() {
|
||||
return this.id_codaMessaggi;
|
||||
}
|
||||
|
||||
public void setId_codaMessaggi(long id_codaMessaggi) {
|
||||
this.id_codaMessaggi = id_codaMessaggi;
|
||||
}
|
||||
|
||||
public String getCellulare() {
|
||||
return this.cellulare;
|
||||
}
|
||||
|
||||
public void setCellulare(String cellulare) {
|
||||
this.cellulare = cellulare;
|
||||
}
|
||||
|
||||
public String getTestoMessaggio() {
|
||||
return this.testoMessaggio;
|
||||
}
|
||||
|
||||
public void setTestoMessaggio(String testoMessaggio) {
|
||||
this.testoMessaggio = testoMessaggio;
|
||||
}
|
||||
|
||||
public String getSmsToTest() {
|
||||
return this.smsToTest;
|
||||
}
|
||||
|
||||
public void setSmsToTest(String smsToTest) {
|
||||
this.smsToTest = smsToTest;
|
||||
}
|
||||
|
||||
public long getFlgTipo() {
|
||||
return this.flgTipo;
|
||||
}
|
||||
|
||||
public void setFlgTipo(long flgTipo) {
|
||||
this.flgTipo = flgTipo;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package it.acxent.rd.json.smsgateway;
|
||||
|
||||
import it.acxent.rd.json.RdRequestJ;
|
||||
import java.util.Vector;
|
||||
|
||||
public class RdRequestSmsGatewayJ extends RdRequestJ {
|
||||
private Vector<DataSmsMsgJ> data;
|
||||
|
||||
public Vector<DataSmsMsgJ> getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setData(Vector<DataSmsMsgJ> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package it.acxent.rd.json.smsgateway;
|
||||
|
||||
import it.acxent.rd.json.RdResponseJ;
|
||||
import java.util.Vector;
|
||||
|
||||
public class RdResponseSmsGatewayJ extends RdResponseJ {
|
||||
private Vector<DataSmsMsgJ> data;
|
||||
|
||||
public RdResponseSmsGatewayJ(long status, String msg) {
|
||||
super(status, msg);
|
||||
}
|
||||
|
||||
public RdResponseSmsGatewayJ() {}
|
||||
|
||||
public Vector<DataSmsMsgJ> getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setData(Vector<DataSmsMsgJ> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.rd.json.smsgateway;
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.rd;
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package it.acxent.rd.servlet.admin;
|
||||
|
||||
import it.acxent.anag.servlet._AnagAdapterSvlt;
|
||||
import it.acxent.cloudmsg.MsgJson;
|
||||
import it.acxent.cloudmsg.PushNotificationService;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.rd.RemoteDevice;
|
||||
import it.acxent.rd.RemoteDeviceCR;
|
||||
import it.acxent.servlet.AddImgSvlt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet(urlPatterns = {"/admin/rd/RemoteDevice.abl"})
|
||||
public class RemoteDeviceSvlt extends _AnagAdapterSvlt implements AddImgSvlt {
|
||||
private static final long serialVersionUID = -759824794431772574L;
|
||||
|
||||
protected void addRows(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterDetail(DBAdapter beanA, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterSearch(CRAdapter CR, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return new RemoteDevice(getApFull(req));
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return new RemoteDeviceCR(getApFull(req));
|
||||
}
|
||||
|
||||
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected boolean isSimpleServlet(HttpServletRequest req) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void _creaToken(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
ResParm rp = new ResParm();
|
||||
RemoteDevice bean = new RemoteDevice(apFull);
|
||||
long l_id = getRequestLongParameter(req, "id_remoteDevice");
|
||||
bean.findByPrimaryKey(l_id);
|
||||
if (bean.getId_remoteDevice() > 0L)
|
||||
rp = bean.generaNuovoToken();
|
||||
sendMessage(req, rp.getMsg());
|
||||
showBean(req, res);
|
||||
}
|
||||
|
||||
public void _inviaNotifica(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
ResParm rp = new ResParm();
|
||||
RemoteDevice bean = new RemoteDevice(apFull);
|
||||
long l_id = getRequestLongParameter(req, "id_remoteDevice");
|
||||
bean.findByPrimaryKey(l_id);
|
||||
if (bean.getId_remoteDevice() > 0L) {
|
||||
String fileJsonAuth = getParm("FIREBASE_JSON_AUTH_PRIVATE_KEY").getTesto();
|
||||
PushNotificationService pns = new PushNotificationService(fileJsonAuth);
|
||||
MsgJson notifica = new MsgJson("notification", "Test Remote Device Gateway", "Il tuo dispositivo e' correttamente registrato sul server " +
|
||||
bean.getRemoteDeviceApiServer() + "!");
|
||||
MsgJson data = new MsgJson("notification", "Test RDG", "Test Remote Device Gateway");
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(bean.getFcmToken());
|
||||
pns.sendPushNotification(list, notifica, data, "smsgateway-f05ec");
|
||||
}
|
||||
sendMessage(req, rp.getMsg());
|
||||
showBean(req, res);
|
||||
}
|
||||
|
||||
protected boolean isLoadImageServlet() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.rd.servlet.admin;
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
package it.acxent.rd.servlet.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.newsletter.CodaMessaggi;
|
||||
import it.acxent.newsletter.CodaMessaggiCR;
|
||||
import it.acxent.rd.RemoteDevice;
|
||||
import it.acxent.rd.json.RdRequestJ;
|
||||
import it.acxent.rd.json.RdResponseJ;
|
||||
import it.acxent.rd.json.smsgateway.DataSmsMsgJ;
|
||||
import it.acxent.rd.json.smsgateway.RdRequestSmsGatewayJ;
|
||||
import it.acxent.rd.json.smsgateway.RdResponseSmsGatewayJ;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet(urlPatterns = {"/rdRest/Ma.abl"})
|
||||
public class MobileApiSvlt extends _RdApiSvlt {
|
||||
private static final long serialVersionUID = -8266400675249237394L;
|
||||
|
||||
private static final String TAG = "MobileApiSvlt ";
|
||||
|
||||
protected boolean isSimpleServlet(HttpServletRequest req) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {
|
||||
sendHtmlMsgResponse(req, res, "ERRORE invio ");
|
||||
}
|
||||
|
||||
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {
|
||||
_recordDevice(req, res);
|
||||
}
|
||||
|
||||
protected boolean isSecureServlet(HttpServletRequest req) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showBean(HttpServletRequest req, HttpServletResponse res) {
|
||||
sendHtmlMsgResponse(req, res, "ERRORE!!");
|
||||
}
|
||||
|
||||
public void _recordDevice(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
String requestIp = req.getRemoteAddr();
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
String responseBody = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
RdRequestJ deviceRequest = (RdRequestJ)gson.fromJson(responseBody, RdRequestJ.class);
|
||||
boolean authOk = checkBasicAuth(req, res);
|
||||
if (authOk) {
|
||||
RemoteDevice rd = new RemoteDevice(apFull);
|
||||
rd.findByToken(deviceRequest.getToken());
|
||||
if (rd.getId_remoteDevice() > 0L) {
|
||||
if (rd.getFcmToken().isEmpty() || rd.getFcmToken().equals(deviceRequest.getFcmToken())) {
|
||||
rd.setImei(deviceRequest.getImei());
|
||||
rd.setToken(deviceRequest.getToken());
|
||||
rd.setFcmToken(deviceRequest.getFcmToken());
|
||||
rd.setIpAddress(requestIp);
|
||||
rd.setUpdTmst(DBAdapter.getTimestamp());
|
||||
ResParm rp = rd.save();
|
||||
System.out.println(rp.getMsg());
|
||||
if (deviceRequest.getAct().isEmpty()) {
|
||||
RdResponseJ rdJ = new RdResponseJ(0L, "Dispositivo registrato correttamente");
|
||||
String rdJson = gson.toJson(rdJ);
|
||||
System.out.println("MobileApiSvlt " + rdJson);
|
||||
sendHtmlMsgResponse(req, res, rdJson);
|
||||
} else if (deviceRequest.getAct().equals("sms")) {
|
||||
_smsGateway(req, res, responseBody, rd);
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, "Dispositivo registrato correttamente ma implementazione non trovata: " +
|
||||
deviceRequest.getAct());
|
||||
String rdJson = gson.toJson(rdJ);
|
||||
System.out.println("MobileApiSvlt " + rdJson);
|
||||
sendHtmlMsgResponse(req, res, rdJson);
|
||||
}
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(2L, "Token già assegnato");
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(1L, "Token non trovato!");
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
} else {
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, "Autenticazione fallita");
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, e.getMessage());
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
}
|
||||
|
||||
public void __templateChiamata(HttpServletRequest req, HttpServletResponse res) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
boolean debug = false;
|
||||
try {
|
||||
long l_id_user = getRequestLongParameter(req, "id_user");
|
||||
boolean authOk = checkBasicAuth(req, res);
|
||||
if (!authOk)
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello, _elencofoto");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
sendHtmlMsgResponse(req, res, "testina di vitello,_elencofoto eccezione: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void _smsGateway(HttpServletRequest req, HttpServletResponse res, String responseBody, RemoteDevice rd) {
|
||||
ApplParmFull apFull = getApFull(req);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
RdRequestSmsGatewayJ deviceRequest = (RdRequestSmsGatewayJ)gson.fromJson(responseBody, RdRequestSmsGatewayJ.class);
|
||||
RdResponseSmsGatewayJ rdJ = new RdResponseSmsGatewayJ(0L, "Dispositivo registrato correttamente: SmsGateway");
|
||||
String smsToTest = getParm("RD_TEST_SMS").getTesto();
|
||||
CodaMessaggi cm = new CodaMessaggi(apFull);
|
||||
CodaMessaggiCR cmCR = new CodaMessaggiCR();
|
||||
cmCR.setFlgTipo(99L);
|
||||
cmCR.setFlgStatoInvio(3L);
|
||||
cmCR.setId_remoteDevice(rd.getId_remoteDevice());
|
||||
Vectumerator<CodaMessaggi> vecCm = cm.findByCR(cmCR, 1, 10);
|
||||
Vector<DataSmsMsgJ> dataVector = new Vector<>();
|
||||
if (vecCm.hasMoreElements()) {
|
||||
while (vecCm.hasMoreElements()) {
|
||||
CodaMessaggi cmRow = (CodaMessaggi)vecCm.nextElement();
|
||||
DataSmsMsgJ dataJ = new DataSmsMsgJ();
|
||||
System.out.println("MobileApiSvlt invio al gateway--->" + cmRow.getId_codaMessaggi() + " " + cmRow.getCellulare());
|
||||
dataJ.setCellulare(cmRow.getCellulare());
|
||||
dataJ.setId_codaMessaggi(cmRow.getId_codaMessaggi());
|
||||
dataJ.setTestoMessaggio(cmRow.getTestoMessaggio());
|
||||
dataJ.setSmsToTest(smsToTest);
|
||||
dataJ.setFlgTipo(cmRow.getFlgTipo());
|
||||
dataVector.add(dataJ);
|
||||
cmRow.setFlgStatoInvio(4L);
|
||||
cmRow.save();
|
||||
}
|
||||
rdJ.setData(dataVector);
|
||||
}
|
||||
if (deviceRequest.getData() != null) {
|
||||
Vector<DataSmsMsgJ> vec = deviceRequest.getData();
|
||||
CodaMessaggi cmRow = new CodaMessaggi(apFull);
|
||||
for (int i = 0; i < vec.size(); i++) {
|
||||
DataSmsMsgJ row = vec.elementAt(i);
|
||||
cmRow.findByPrimaryKey(row.getId_codaMessaggi());
|
||||
if (cmRow.getId_codaMessaggi() > 0L) {
|
||||
System.out.println("MobileApiSvlt ricevuto dal gateway e imposto a inviato <----- " + cmRow.getId_codaMessaggi() + " " +
|
||||
cmRow.getCellulare());
|
||||
cmRow.setFlgStatoInvio(1L);
|
||||
cmRow.setDataInvio(DBAdapter.getToday());
|
||||
cmRow.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
String rdJson = gson.toJson(rdJ);
|
||||
System.out.println("MobileApiSvlt " + rdJson);
|
||||
sendHtmlMsgResponse(req, res, rdJson);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
RdResponseJ rdJ = new RdResponseJ(99L, e.getMessage());
|
||||
sendHtmlMsgResponse(req, res, gson.toJson(rdJ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package it.acxent.rd.servlet.api;
|
||||
|
||||
import it.acxent.anag.servlet._AnagAdapterSvlt;
|
||||
import it.acxent.db.CRAdapter;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.rd.RemoteDevice;
|
||||
import it.acxent.rd.RemoteDeviceCR;
|
||||
import java.util.Base64;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class _RdApiSvlt extends _AnagAdapterSvlt {
|
||||
private static final long serialVersionUID = 9062130951824536369L;
|
||||
|
||||
protected void addRows(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterDetail(DBAdapter bean, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected void fillComboAfterSearch(CRAdapter CR, HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected DBAdapter getBean(HttpServletRequest req) {
|
||||
return new RemoteDevice(getApFull(req));
|
||||
}
|
||||
|
||||
protected CRAdapter getBeanCR(HttpServletRequest req) {
|
||||
return new RemoteDeviceCR(getApFull(req));
|
||||
}
|
||||
|
||||
protected void prepareNewRecord(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected boolean isSimpleServlet(HttpServletRequest req) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected String getBeanPageName(HttpServletRequest req) {
|
||||
return "testTicket";
|
||||
}
|
||||
|
||||
protected void search(HttpServletRequest req, HttpServletResponse res) {}
|
||||
|
||||
protected boolean checkBasicAuth(HttpServletRequest req, HttpServletResponse res) {
|
||||
boolean authOk = true;
|
||||
String apiLogin = getApFull().getParm("RD_API_LOGIN").getTesto().trim();
|
||||
String apiPwd = getApFull().getParm("RD_API_PWD").getTesto().trim();
|
||||
apiLogin = "rd1";
|
||||
apiPwd = "rdp";
|
||||
try {
|
||||
String[] auth = getBasicAuthorizationHeaders(req, res);
|
||||
if (auth != null)
|
||||
if (auth[0].equals(apiLogin) && auth[1].equals(apiPwd))
|
||||
authOk = true;
|
||||
} catch (Exception e) {}
|
||||
return authOk;
|
||||
}
|
||||
|
||||
protected boolean allowUser(String auth) {
|
||||
try {
|
||||
if (auth == null)
|
||||
return false;
|
||||
if (!auth.toUpperCase().startsWith("BASIC "))
|
||||
return false;
|
||||
String userpassEncoded = auth.substring(6);
|
||||
String userpassDecoded = new String(Base64.getDecoder().decode(userpassEncoded));
|
||||
String[] account = userpassDecoded.split(":");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void otherCommands(HttpServletRequest req, HttpServletResponse res) {}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.rd.servlet.api;
|
||||
Loading…
Add table
Add a link
Reference in a new issue