commit 79aa1678b20472a43498e8894950d16c7e84694c Author: Michal Date: Sat Feb 8 16:28:43 2025 +0100 diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..5761d46 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project jNetLib. + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..b8a3c25 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1771 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..f2370f8 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=237f5361 +build.xml.script.CRC32=83758712 +build.xml.stylesheet.CRC32=f85dc8f2@1.113.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=237f5361 +nbproject/build-impl.xml.script.CRC32=30659ce6 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.113.0.48 diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..57b7eae --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,105 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=jNetLib +application.vendor=cucky +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/jNetLib.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/jNetLib +endorsed.classpath= +excludes= +file.reference.apache-commons-configuration2-2.9.0.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-configuration2-2.9.0.jar +file.reference.apache-commons-lang3-3.12.0.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-lang3-3.12.0.jar +file.reference.apache-commons-logging-1.2.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-logging-1.2.jar +file.reference.argon2-jvm-nolibs-2.11.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\argon2-jvm-nolibs-2.11.jar +file.reference.spring-security-crypto-5.8.0.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\spring-security-crypto-5.8.0.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.apache-commons-configuration2-2.9.0.jar}:\ + ${file.reference.apache-commons-lang3-3.12.0.jar}:\ + ${file.reference.spring-security-crypto-5.8.0.jar}:\ + ${file.reference.apache-commons-logging-1.2.jar}:\ + ${file.reference.argon2-jvm-nolibs-2.11.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=23 +javac.target=23 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=jNetLib +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..653efe9 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + jNetLib + + + + + + + + + diff --git a/src/jnet/lib/BuilddDate.java b/src/jnet/lib/BuilddDate.java new file mode 100644 index 0000000..014da54 --- /dev/null +++ b/src/jnet/lib/BuilddDate.java @@ -0,0 +1,43 @@ +package jnet.lib; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Date; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +public class BuilddDate { + + public static Date get() { + Date d = null; + Class currentClass = new Object() { + }.getClass().getEnclosingClass(); + URL resource = currentClass.getResource(currentClass.getSimpleName() + ".class"); + if (resource != null) { + if (resource.getProtocol().equals("file")) { + try { + d = new Date(new File(resource.toURI()).lastModified()); + } catch (URISyntaxException ignored) { + } + } else if (resource.getProtocol().equals("jar")) { + String path = resource.getPath(); + d = new Date(new File(path.substring(5, path.indexOf("!"))).lastModified()); + } else if (resource.getProtocol().equals("zip")) { + String path = resource.getPath(); + File jarFileOnDisk = new File(path.substring(0, path.indexOf("!"))); + //long jfodLastModifiedLong = jarFileOnDisk.lastModified (); + //Date jfodLasModifiedDate = new Date(jfodLastModifiedLong); + try (JarFile jf = new JarFile(jarFileOnDisk)) { + ZipEntry ze = jf.getEntry(path.substring(path.indexOf("!") + 2));//Skip the ! and the / + long zeTimeLong = ze.getTime(); + Date zeTimeDate = new Date(zeTimeLong); + d = zeTimeDate; + } catch (IOException | RuntimeException ignored) { + } + } + } + return d; + } +} diff --git a/src/jnet/lib/EventComparator.java b/src/jnet/lib/EventComparator.java new file mode 100644 index 0000000..4c29eff --- /dev/null +++ b/src/jnet/lib/EventComparator.java @@ -0,0 +1,22 @@ +package jnet.lib; + +import jnet.lib.object.Event; +import java.util.Comparator; + +public class EventComparator implements Comparator { + + @Override + public int compare(Event t1, Event t2) { + /* + int fromResult = Long.compare(t1.getFrom(), t2.getFrom()); + if (fromResult == 0) { + return fromResult; + } + //return fromResult; + + return Long.compare(t1.getTo(), t2.getTo()); + */ + return Long.compare(t1.getStart(), t2.getStart()); + } + +} diff --git a/src/jnet/lib/EventManager.java b/src/jnet/lib/EventManager.java new file mode 100644 index 0000000..20243e4 --- /dev/null +++ b/src/jnet/lib/EventManager.java @@ -0,0 +1,25 @@ +package jnet.lib; + +import jnet.lib.object.Event; +import java.time.Instant; +import java.util.ArrayList; + + +public class EventManager { + + + private ArrayList events; + + public static Event startPingEvent(ArrayList events, int object) { + Instant now = Instant.now(); + long time = now.toEpochMilli(); + Event event = new Event(object, + time, + "Offline", + Event.TYPE_PING); + events.add(event); + return event; + } + + +} diff --git a/src/jnet/lib/LogFile.java b/src/jnet/lib/LogFile.java new file mode 100644 index 0000000..7c27c26 --- /dev/null +++ b/src/jnet/lib/LogFile.java @@ -0,0 +1,89 @@ +package jnet.lib; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LogFile { + + // nazev souboru + private static final String outFile = "log.log"; + // zapisovat i log do console + private static boolean consoleLog = true; + // format datumu a casu + private static String dateFormat = "dd.MM.YY HH:m:ss"; + // debug rezim + private static boolean debug = false; + + private static File out = new File(outFile); + + private static final DateFormat df = new SimpleDateFormat(dateFormat); + + private static void write(Object text, boolean line) { + + String date = df.format(new Date()); + + try { + if (!out.exists()) { + out.createNewFile(); + } + PrintWriter pwOut = new PrintWriter(new FileOutputStream(out, true), true); + pwOut.print(date); + pwOut.write("\t"); + if (line) { + pwOut.println(text); + } else { + pwOut.print(text); + } + pwOut.close(); + + LogWindow.addRow(date + "\t" + text.toString()); + + } catch (Exception ex) { + Logger.getLogger(LogFile.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + public static void printErr(String line) { + write("E\t" + line, true); + if (consoleLog) { + System.err.println(line); + } + } + + public static void printInfo(String line) { + write("I\t" + line, true); + if (consoleLog) { + System.out.println(line); + } + } + + public static void printDebug(String line) { + write("D\t" + line, true); + if (debug) { + if (consoleLog) { + System.out.println(line); + } + } + + } + + public static void clear() { + try { + out.delete(); + } catch (Exception ex) { + Logger.getLogger(LogFile.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static void setDebug(boolean b) { + debug = b; + } + +} diff --git a/src/jnet/lib/LogWindow.java b/src/jnet/lib/LogWindow.java new file mode 100644 index 0000000..b1e0a88 --- /dev/null +++ b/src/jnet/lib/LogWindow.java @@ -0,0 +1,67 @@ +package jnet.lib; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + + +public class LogWindow { + + private JFrame frame = new JFrame("Log aplikace"); + private static JTextArea logTextArea = new JTextArea(); + + public LogWindow() { + // Vytvoření hlavního okna + + frame.setSize(1000, 600); + + // Nastavení, že okno bude spuštěno minimalizované + frame.setExtendedState(JFrame.ICONIFIED); // Minimalizované okno + + // Přidání vlastního chování při zavření okna + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + // Můžete přidat vlastní logiku (např. skrytí okna místo jeho zavření) + //frame.setVisible(false); // Skrytí okna místo zavření + } + }); + + // Hlavní panel + JPanel mainPanel = new JPanel(new BorderLayout()); + + // Textová oblast pro logy + + logTextArea.setEditable(false); // Zamezení úprav uživatelem + logTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); // Monospace font pro logy + + // Posuvník pro textovou oblast + JScrollPane scrollPane = new JScrollPane(logTextArea); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + + // Přidání scrollovacího panelu do hlavního panelu + mainPanel.add(scrollPane, BorderLayout.CENTER); + + // Přidání hlavního panelu do okna + frame.add(mainPanel); + + // Zobrazení okna + frame.setVisible(true); + + } + + public static void addRow(String msg){ + logTextArea.append(msg + "\n"); + + // Automatické posunutí na konec + logTextArea.setCaretPosition(logTextArea.getDocument().getLength()); + } + + + +} diff --git a/src/jnet/lib/MapComparator.java b/src/jnet/lib/MapComparator.java new file mode 100644 index 0000000..862a1bd --- /dev/null +++ b/src/jnet/lib/MapComparator.java @@ -0,0 +1,13 @@ +package jnet.lib; + +import jnet.lib.object.Map; +import java.util.Comparator; + + +public class MapComparator implements Comparator { + + @Override + public int compare(Map obj1, Map obj2) { + return obj1.getName().compareTo(obj2.getName()); + } +} diff --git a/src/jnet/lib/Message.java b/src/jnet/lib/Message.java new file mode 100644 index 0000000..7f93654 --- /dev/null +++ b/src/jnet/lib/Message.java @@ -0,0 +1,135 @@ +package jnet.lib; + +import java.io.Serializable; + +/** + * + * @author cucky + */ +public class Message implements Serializable { + + // S->C: dotaz na verzi klient + // C->S: odeslána verze klienta + public static final int CLIENT_VERSION = 1; + + // S->C: server odesila klientovi pokyn k updatu + public static final int UPDATE = 2; + + // S->C: server posila pozadavek na autorizaci klienta + public static final int AUTH_REQUEST = 3; + + // C->S: klient odesila autorizacni udaje + public static final int AUTH = 4; + + // S->C: server odesila informaci o uspesnem prihlaseni klienta + public static final int AUTH_SUCEFULL = 5; + + // S->C: server odesila informaci o neuspesnem prihlaseni klienta + public static final int AUTH_FAIL = 6; + + // S->C: server odesila seznam pripojenych klientu + public static final int ONLINE_CLIENTS = 7; + + // S->C: server posila typ objektu + public static final int OBJECT_TYPE = 8; + + // S->C server odesila informace o prihlasenem uzivateli + public static final int USER_INFO = 9; + + // C->S: klient odesíla novy typ objektu + public static final int NEW_OBJECT_TYPE = 10; + + // S->C: odesila uzivatele + // C->S: klient pridává ukživatele + public static final int USER = 11; + + // C->S: klietn posila udaje upraveneho uzivatele + public static final int USER_EDIT = 12; + + // S->C: server posila nastaveni serveru + // C->S: klient odesila upravu serveru + public static final int SERVER_CONFIG = 13; + + //S->C: server odesila seznam objektu + public static final int OBJECT_LIST = 14; + + + + + + // S->C: server posila mapu + public static final int MAP = 100; + + // S->C: server posila aktualizace statusu + public static final int STATUS_UPDATE = 101; + + // C->S: klient posila nove souradnice objektu + public static final int OBJECT_MOVE = 102; + + // C->S: klient posila zmenu zamku mapy + public static final int SET_MAP_LOCK = 103; + + // C->S: klient posila informaci o smazání objektu + // S->C: server předává informaci o odebrání objektu + public static final int REMOVE_OBJECT = 104; + + // C->S: klient odesílá nově přidaný objekt + // S->C: server odesila klientum nově přidany objekt + public static final int ADD_OBJECT = 105; + + // C->S: klient odesíla upravený objekt + public static final int UPDATE_OBJECT = 106; + + // S->C: server odesila SNMP profil + public static final int SNMP_PROFILE = 107; + + // S->C: server odesila novy event + public static final int EVENT_NEW = 108; + + // S->C: server odesila aktualizaci eventu + public static final int EVENT_UPDATE = 109; + + // S->C server odesilam seznam udalosti + public static final int EVENT_LIST = 110; + + // C->S: klient odebira mapu + // S->C: server předává informaci o odebrani mapy + public static final int MAP_REMOVE = 111; + + // C->S: klient pridava mapu + public static final int MAP_ADD = 112; + + // C->S: klient posila požadavek na smazaní udalostí + public static final int DELETE_LOG = 113; + + + + + + + + + private int type; + private Object msg; + + public Message(int type, Object msg) { + this.type = type; + this.msg = msg; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public Object getMsg() { + return msg; + } + + public void setMsg(Object msg) { + this.msg = msg; + } +} diff --git a/src/jnet/lib/OSValidator.java b/src/jnet/lib/OSValidator.java new file mode 100644 index 0000000..7d98bf4 --- /dev/null +++ b/src/jnet/lib/OSValidator.java @@ -0,0 +1,32 @@ +package jnet.lib; + +public class OSValidator { + + private static String OS = System.getProperty("os.name").toLowerCase(); + + public static boolean isWindows() { + + return (OS.indexOf("win") >= 0); + + } + + public static boolean isMac() { + + return (OS.indexOf("mac") >= 0); + + } + + public static boolean isUnix() { + + return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 ); + + } + + public static boolean isSolaris() { + + return (OS.indexOf("sunos") >= 0); + + } + +} + diff --git a/src/jnet/lib/PasswordHashing.java b/src/jnet/lib/PasswordHashing.java new file mode 100644 index 0000000..71bfcbd --- /dev/null +++ b/src/jnet/lib/PasswordHashing.java @@ -0,0 +1,36 @@ +package jnet.lib; + +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + + + +/** + * Hash hesla a jeho kontrola + * vyžaduje knihovnu spring-security-crypto-5.8.0.jar a apache-commons-logging-1.2.jar + * @author cucky + */ +public class PasswordHashing { + + + public static String hash(String string){ + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + return passwordEncoder.encode(string); + } + + public static boolean verify(String rawPassword, String hashedPassword){ + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + return passwordEncoder.matches(rawPassword, hashedPassword); + } + +// public static String hash(String password){ +// Argon2 argon2 = Argon2Factory.create(); +// String hash = argon2.hash(10, 65536, 1, password); +// return hash; +// } +// +// public static boolean verify(String rawPassword, String hashedPassword){ +// Argon2 argon2 = Argon2Factory.create(); +// return argon2.verify(hashedPassword, rawPassword); +// +// } +} diff --git a/src/jnet/lib/PropertiesManager.java b/src/jnet/lib/PropertiesManager.java new file mode 100644 index 0000000..aba631b --- /dev/null +++ b/src/jnet/lib/PropertiesManager.java @@ -0,0 +1,101 @@ +package jnet.lib; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.ex.ConfigurationException; + +public class PropertiesManager { + + private PropertiesConfiguration config; + private String filePath; + + // Konstruktor pro inicializaci s cestou k souboru + public PropertiesManager(String filePath) { + this.filePath = filePath; + this.config = new PropertiesConfiguration(); + } + + public void load() throws FileException, ConfigException { + try { + // Načtení existující konfigurace, pokud soubor existuje + config.read(new FileReader(filePath)); + } catch (ConfigurationException ex) { + throw new ConfigException("Chyba konfigurace"); + } catch (IOException ex) { + throw new FileException("Chybný soubor"); + } + } + + // Metoda pro čtení hodnoty podle klíče + private String getProperty(String key) { + return config.getString(key, null); // Vrací null pokud klíč neexistuje + } + + // Metoda pro nastavení hodnoty podle klíče + private void setProperty(String key, String value) { + config.setProperty(key, value); + } + + // Metoda pro uložení konfigurace do souboru + public void save() { + try (FileWriter writer = new FileWriter(filePath)) { + // Použití FileWriter pro zápis do souboru + config.write(writer); + LogFile.printInfo("Konfigurace byla uspesne ulozena."); + } catch (IOException | ConfigurationException e) { + LogFile.printErr("Chyba pri ukladani konfigurace. " + e.getMessage()); + } + } + + // Metoda pro výpis všech klíčů a hodnot v konfiguraci +// public void printAllProperties() { +// Iterator keys = config.getKeys(); +// while (keys.hasNext()) { +// String key = keys.next(); +// System.out.println(key + " = " + config.getString(key)); +// } +// } + public boolean getBoolean(String key) { + return Boolean.valueOf(getProperty(key)); + } + + public String getString(String key) { + return getProperty(key); + } + + public int getInt(String key) { + return Integer.parseInt(getProperty(key)); + } + + public void setBoolean(String key, Boolean value) { + setProperty(key, value.toString()); + } + + public void setInt(String key, int value) { + setProperty(key, String.valueOf(value)); + } + + public void setString(String key, String value) { + setProperty(key, value); + } + + public class FileException extends Exception { + + public FileException(String message) { + super(message); + } + } + + public class ConfigException extends Exception { + + public ConfigException(String message) { + super(message); + } + } + +} diff --git a/src/jnet/lib/Status.java b/src/jnet/lib/Status.java new file mode 100644 index 0000000..ec461d6 --- /dev/null +++ b/src/jnet/lib/Status.java @@ -0,0 +1,13 @@ +package jnet.lib; + +import java.io.Serializable; + + +public class Status implements Serializable { + + public static final int NA = 0; + public static final int OK = 1; + public static final int WARNING = 2; + public static final int OFFLINE = 3; + +} diff --git a/src/jnet/lib/object/Event.java b/src/jnet/lib/object/Event.java new file mode 100644 index 0000000..a42395e --- /dev/null +++ b/src/jnet/lib/object/Event.java @@ -0,0 +1,86 @@ +package jnet.lib.object; + +import java.io.Serializable; + + +public class Event implements Serializable{ + + private int id; + private int object; + private long start; + private long end; + private String description; + private int type; + + public static final int TYPE_PING = 1; + public static final int TYPE_SNMP = 2; + public static final int TYPE_INFO = 3; + public static final int TYPE_PING_OFF = 4; + + public Event(int id, int object, long start, long end, String description, int type) { + this.id = id; + this.object = object; + this.start = start; + this.end = end; + this.description = description; + this.type = type; + } + + public Event(int object, long start, String description, int type) { + this.object = object; + this.start = start; + this.description = description; + this.type = type; + } + + public int getObject() { + return object; + } + + public void setObject(int object) { + this.object = object; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public long getStart() { + return start; + } + + public void setStart(long start) { + this.start = start; + } + + public long getEnd() { + return end; + } + + public void setEnd(long end) { + this.end = end; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + + +} diff --git a/src/jnet/lib/object/Map.java b/src/jnet/lib/object/Map.java new file mode 100644 index 0000000..95f96ba --- /dev/null +++ b/src/jnet/lib/object/Map.java @@ -0,0 +1,59 @@ +package jnet.lib.object; + +import jnet.lib.Status; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * + * @author cucky + */ +public class Map implements Serializable { + + private int id; + private String name; + private boolean lock; + //private ArrayList objects; + private int status; + + public Map(int id, String name, boolean lock) { + this.id = id; + this.name = name; + this.lock = lock; + this.status = Status.NA; + } + + public Map(String name) { + this.name = name; + this.lock = false; + this.status = Status.NA; + } + + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isLock() { + return lock; + } + + public void setLock(boolean lock) { + this.lock = lock; + } + + +} diff --git a/src/jnet/lib/object/MapObject.java b/src/jnet/lib/object/MapObject.java new file mode 100644 index 0000000..807ee2b --- /dev/null +++ b/src/jnet/lib/object/MapObject.java @@ -0,0 +1,333 @@ +package jnet.lib.object; + +import jnet.lib.Status; +import java.io.Serializable; +import java.util.ArrayList; + +public class MapObject implements Serializable { + + private int map; + private int status; + private int id; + private String name; + private int objectType; + private String ip; + private int x; + private int y; + private String user; + private String password; + private boolean enablePing; + private String description; + private String location; + private int snmpProfile; + private ArrayList snmpProbe; + private boolean active; + public int pingAttemp; + private boolean winbox; + private String winboxPort; + private boolean ssh; + private String sshPort; + private boolean web; + private String webPort; + private int webVerze; + private boolean telnet; + private String telnetPort; + private boolean sms; + private String smsPort; + private int smsVerze; + + public MapObject(int id, + String name, + int map, + int objectType, + String ip, + int x, + int y, + String user, + String password, + String description, + String location, + int snmpProfile, + ArrayList snmpProbe, + boolean active, + boolean winbox, + String winboxPort, + boolean ssh, + String sshPort, + boolean web, + String webPort, + int webVerze, + boolean telnet, + String telnetPort, + boolean sms, + String smsPort, + int smsVerze + ) { + this.status = Status.NA; + this.id = id; + this.name = name; + this.map = map; + this.objectType = objectType; + this.ip = ip; + this.x = x; + this.y = y; + this.user = user; + this.password = password; + this.description = description; + this.location = location; + this.snmpProfile = snmpProfile; + this.snmpProbe = snmpProbe; + this.active = active; + this.winbox = winbox; + this.winboxPort = winboxPort; + this.ssh = ssh; + this.sshPort = sshPort; + this.web = web; + this.webPort = webPort; + this.webVerze = webVerze; + this.telnet = telnet; + this.telnetPort = telnetPort; + this.sms = sms; + this.smsPort = smsPort; + this.smsVerze = smsVerze; + } + + public MapObject() { + + } + + public int getMap() { + return map; + } + + public void setMap(int map) { + this.map = map; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getObjectType() { + return objectType; + } + + public void setObjectType(int objectType) { + this.objectType = objectType; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean isEnablePing() { + return enablePing; + } + + public void setEnablePing(boolean enablePing) { + this.enablePing = enablePing; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public int getSnmpProfile() { + return snmpProfile; + } + + public void setSnmpProfile(int snmpProfile) { + this.snmpProfile = snmpProfile; + } + + public ArrayList getSnmpProbe() { + return snmpProbe; + } + + public void setSnmpProbe(ArrayList snmpProbe) { + this.snmpProbe = snmpProbe; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public int getPingAttemp() { + return pingAttemp; + } + + public void setPingAttemp(int pingAttemp) { + this.pingAttemp = pingAttemp; + } + + public boolean isWinbox() { + return winbox; + } + + public void setWinbox(boolean winbox) { + this.winbox = winbox; + } + + public String getWinboxPort() { + return winboxPort; + } + + public void setWinboxPort(String winboxPort) { + this.winboxPort = winboxPort; + } + + public boolean isSsh() { + return ssh; + } + + public void setSsh(boolean ssh) { + this.ssh = ssh; + } + + public String getSshPort() { + return sshPort; + } + + public void setSshPort(String sshPort) { + this.sshPort = sshPort; + } + + public boolean isWeb() { + return web; + } + + public void setWeb(boolean web) { + this.web = web; + } + + public String getWebPort() { + return webPort; + } + + public void setWebPort(String webPort) { + this.webPort = webPort; + } + + public int getWebVerze() { + return webVerze; + } + + public void setWebVerze(int webVerze) { + this.webVerze = webVerze; + } + + public boolean isTelnet() { + return telnet; + } + + public void setTelnet(boolean telnet) { + this.telnet = telnet; + } + + public String getTelnetPort() { + return telnetPort; + } + + public void setTelnetPort(String telnetPort) { + this.telnetPort = telnetPort; + } + + public boolean isSms() { + return sms; + } + + public void setSms(boolean sms) { + this.sms = sms; + } + + public String getSmsPort() { + return smsPort; + } + + public void setSmsPort(String smsPort) { + this.smsPort = smsPort; + } + + public int getSmsVerze() { + return smsVerze; + } + + public void setSmsVerze(int smsVerze) { + this.smsVerze = smsVerze; + } + + + +} diff --git a/src/jnet/lib/object/ObjectType.java b/src/jnet/lib/object/ObjectType.java new file mode 100644 index 0000000..39eaeb2 --- /dev/null +++ b/src/jnet/lib/object/ObjectType.java @@ -0,0 +1,50 @@ +package jnet.lib.object; + +import java.io.Serializable; + + +public class ObjectType implements Serializable{ + + int id; + String name; + String imgStr; + + public ObjectType(int id, String name, String imgStr) { + this.id = id; + this.name = name; + this.imgStr = imgStr; + } + + public ObjectType(String name, String imgStr) { + this.name = name; + this.imgStr = imgStr; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getImgStr() { + return imgStr; + } + + public void setImgStr(String imgStr) { + this.imgStr = imgStr; + } + + + + +} diff --git a/src/jnet/lib/object/OnlineClients.java b/src/jnet/lib/object/OnlineClients.java new file mode 100644 index 0000000..43fab71 --- /dev/null +++ b/src/jnet/lib/object/OnlineClients.java @@ -0,0 +1,65 @@ +package jnet.lib.object; + +import java.io.Serializable; + + +public class OnlineClients implements Serializable{ + + public static final int PLATFORM_PC = 1; + public static final int PLATFORM_MOBILE = 2; + + private String id; + private String username; + private String ip; + private String port; + private int platform; + + public OnlineClients(String id, String username, String ip, String port, int platform) { + this.id = id; + this.username = username; + this.ip = ip; + this.port = port; + this.platform = platform; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public int getPlatform() { + return platform; + } + + public void setPlatform(int platform) { + this.platform = platform; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + +} diff --git a/src/jnet/lib/object/ServerConfig.java b/src/jnet/lib/object/ServerConfig.java new file mode 100644 index 0000000..cbd7e26 --- /dev/null +++ b/src/jnet/lib/object/ServerConfig.java @@ -0,0 +1,53 @@ +package jnet.lib.object; + +import java.io.Serializable; + +public class ServerConfig implements Serializable { + + private int pingAttempt; + private int pingTimeout; + private int instabilityAttempt; + private int instabilityLimit; + + public ServerConfig(int pingAttempt, int pingTimeout, int instabilityAttempt, int instabilityLimit) { + this.pingAttempt = pingAttempt; + this.pingTimeout = pingTimeout; + this.instabilityAttempt = instabilityAttempt; + this.instabilityLimit = instabilityLimit; + } + + public int getPingAttempt() { + return pingAttempt; + } + + public void setPingAttempt(int pingAttempt) { + this.pingAttempt = pingAttempt; + } + + public int getPingTimeout() { + return pingTimeout; + } + + public void setPingTimeout(int pingTimeout) { + this.pingTimeout = pingTimeout; + } + + public int getInstabilityAttempt() { + return instabilityAttempt; + } + + public void setInstabilityAttempt(int instabilityAttempt) { + this.instabilityAttempt = instabilityAttempt; + } + + public int getInstabilityLimit() { + return instabilityLimit; + } + + public void setInstabilityLimit(int instabilityLimit) { + this.instabilityLimit = instabilityLimit; + } + + + +} diff --git a/src/jnet/lib/object/SnmpProbe.java b/src/jnet/lib/object/SnmpProbe.java new file mode 100644 index 0000000..34438d5 --- /dev/null +++ b/src/jnet/lib/object/SnmpProbe.java @@ -0,0 +1,44 @@ +package jnet.lib.object; + +import java.io.Serializable; + + +public class SnmpProbe implements Serializable { + + private int id; + private String name; + private int objId; + + public SnmpProbe(int id, String name, int objId) { + this.id = id; + this.name = name; + this.objId = objId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getObjId() { + return objId; + } + + public void setObjId(int objId) { + this.objId = objId; + } + + + +} diff --git a/src/jnet/lib/object/SnmpProfile.java b/src/jnet/lib/object/SnmpProfile.java new file mode 100644 index 0000000..b3c8708 --- /dev/null +++ b/src/jnet/lib/object/SnmpProfile.java @@ -0,0 +1,78 @@ +package jnet.lib.object; + +import java.io.Serializable; + + +public class SnmpProfile implements Serializable { + + private int id; + private String name; + private int version; + private String port; + private String communityRead; + private String communityWrite; + + public SnmpProfile(int id, String name, int version, String port, String communityRead, String communityWrite) { + this.id = id; + this.name = name; + this.version = version; + this.port = port; + this.communityRead = communityRead; + this.communityWrite = communityWrite; + } + + public SnmpProfile() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getCommunityRead() { + return communityRead; + } + + public void setCommunityRead(String communityRead) { + this.communityRead = communityRead; + } + + public String getCommunityWrite() { + return communityWrite; + } + + public void setCommunityWrite(String communityWrite) { + this.communityWrite = communityWrite; + } + + + + +} diff --git a/src/jnet/lib/object/User.java b/src/jnet/lib/object/User.java new file mode 100644 index 0000000..81110c9 --- /dev/null +++ b/src/jnet/lib/object/User.java @@ -0,0 +1,114 @@ +package jnet.lib.object; + +import java.io.Serializable; + + +public class User implements Serializable { + + private int id; + private String username; + private String password; + + private boolean addMap; + private boolean removeMap; + private boolean editMap; + private boolean addObject; + private boolean removeObject; + private boolean editObject; + private boolean editServer; + + public User(int id, String username, String password, boolean addMap, boolean removeMap, boolean editMap, boolean addObject, boolean removeObject, boolean editObject, boolean editServer) { + this.id = id; + this.username = username; + this.password = password; + this.addMap = addMap; + this.removeMap = removeMap; + this.editMap = editMap; + this.addObject = addObject; + this.removeObject = removeObject; + this.editObject = editObject; + this.editServer = editServer; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean isAddMap() { + return addMap; + } + + public void setAddMap(boolean addMap) { + this.addMap = addMap; + } + + public boolean isRemoveMap() { + return removeMap; + } + + public void setRemoveMap(boolean removeMap) { + this.removeMap = removeMap; + } + + public boolean isEditMap() { + return editMap; + } + + public void setEditMap(boolean editMap) { + this.editMap = editMap; + } + + public boolean isAddObject() { + return addObject; + } + + public void setAddObject(boolean addObject) { + this.addObject = addObject; + } + + public boolean isRemoveObject() { + return removeObject; + } + + public void setRemoveObject(boolean removeObject) { + this.removeObject = removeObject; + } + + public boolean isEditObject() { + return editObject; + } + + public void setEditObject(boolean editObject) { + this.editObject = editObject; + } + + public boolean isEditServer() { + return editServer; + } + + public void setEditServer(boolean editServer) { + this.editServer = editServer; + } + + +}