Compare commits

..

No commits in common. "49aa06fb0314b767dc6289f8b97184a406965303" and "d7852e281df3ab5f078bc84c95ae7db9d4480a0e" have entirely different histories.

3 changed files with 7 additions and 37 deletions

View File

@ -1,9 +1,6 @@
package name.nathanmcrae.numbersstation; package name.nathanmcrae.numbersstation;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpException;
import com.leakyabstractions.result.api.Result; import com.leakyabstractions.result.api.Result;
import com.leakyabstractions.result.core.Results; import com.leakyabstractions.result.core.Results;
@ -15,8 +12,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -140,17 +135,11 @@ public class Main extends Application {
try { try {
runStation(parsedArgs); runStation(parsedArgs);
} catch (StationRunException e) { } catch (StationRunException e) {
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); // TODO: Add time of run
String message = "Attempted to run station '" +
parsedArgs.getStationName() +
"' at " +
LocalDateTime.now().format(dateFormatter) +
"\n\n" +
e.getMessage();
var notification = new NotificationController.NotificationParameters("Error running station '" + parsedArgs.getStationName() + "'", var notification = new NotificationController.NotificationParameters("Error running station '" + parsedArgs.getStationName() + "'",
message, e.getMessage(),
NotificationController.NotificationType.ERROR, NotificationController.NotificationType.ERROR,
Optional.empty()); Optional.empty());
startParams = new StartParameters(Optional.of(notification)); startParams = new StartParameters(Optional.of(notification));
launch(args); launch(args);
@ -213,30 +202,10 @@ public class Main extends Application {
messageText = new String(Files.readAllBytes(nextMessagePath)); messageText = new String(Files.readAllBytes(nextMessagePath));
} }
// Send message using appropriate method
switch (loadedStation.getMessageMethod()) { switch (loadedStation.getMessageMethod()) {
case StationSettings.MessageMethod.SFTP: case StationSettings.MessageMethod.SFTP:
//loadedStation.uploadNextMessageToSFTP(); //loadedStation.uploadNextMessageToSFTP();
JSch jsch = new JSch();
try {
Session session = jsch.getSession(loadedStation.getUsername(), loadedStation.getAddress(), 22);
session.setPassword(loadedStation.getPassword());
session.setConfig("StrictHostKeyChecking", "no");
session.connect(30000); // 30 seconds timeout
if (session.isConnected()) {
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
String localFile = loadedStation.nextMessagePath().toString();
channel.put(localFile, "www/message.txt");
channel.exit();
session.disconnect();
} else {
logger.log(Level.SEVERE, "SFTP connection failed");
}
} catch (JSchException e) {
logger.log(Level.SEVERE, "SFTP connection failed", e);
}
break; break;
case StationSettings.MessageMethod.WORDPRESS: case StationSettings.MessageMethod.WORDPRESS:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

View File

@ -121,6 +121,7 @@ public class StationSettings {
}); });
} }
public Path nextMessagePath() { public Path nextMessagePath() {
return stationPath().resolve("next-message.txt"); return stationPath().resolve("next-message.txt");
} }

View File

@ -221,7 +221,7 @@ public class WindowsScheduler {
exec.appendChild(command); exec.appendChild(command);
Element arguments = doc.createElement("Arguments"); Element arguments = doc.createElement("Arguments");
arguments.appendChild(doc.createTextNode("-Version 5 -NoProfile -File P:/personal_root/projects/numbers-station/run.ps1 --station \"" + station.getName() + "\"")); arguments.appendChild(doc.createTextNode("-Version 5 -NoProfile -File P:/personal_root/projects/numbers-station/src/main/java/run.ps1 --station \"" + station.getName() + "\""));
exec.appendChild(arguments); exec.appendChild(arguments);
return doc; return doc;