package bdaad;
//Java Bibliotheken laden ------------------------------------------------------------
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.border.*;
import java.awt.*;
import java.util.*;
public class BDAAD extends JFrame implements ActionListener, ItemListener {
//Anlegen der Applet Komponenten (Label,Button...)------------------------------------
public static final long serialVersionUID = 1L;
JLabel label0 = new JLabel("Log_File: ");
JLabel label2 = new JLabel("Wenn Sie den Remote Access von einem anderen Rechner ausbenutzen wollen, können Sie hier die IP-Adresse angeben:");
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
JLabel label5 = new JLabel("Sie werden mit folgenden Daten angemeldet: ");
JLabel label6 = new JLabel(".");
JLabel label7 = new JLabel(".");
JLabel label8 = new JLabel(".");
JLabel label9 = new JLabel();
JTextField tf2 = new JTextField();
JTextField tf3 = new JTextField();
JTextField tf4 = new JTextField();
JTextField tf5 = new JTextField();
JButton button1 = new JButton("Login");
JButton button3 = new JButton("Login aus Liste");
JButton button2 = new JButton("Logout");
JTextArea ta1 = new JTextArea(10,10);
JScrollPane sp1 = new JScrollPane(ta1);
JComboBox ipadresse = new JComboBox();
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("Datei");
JMenu menuFile1 = new JMenu ("Hilfe");
JMenuItem end = new JMenuItem("Beenden");
JMenuItem hilfe = new JMenuItem("?");
JPanel p1 = new JPanel();
Socket socket;
PrintWriter out;
BufferedReader in;
Timer timer;
Timer timer1;
int sec;
int sec1;
public static String eingabe;
public static String ausgabe;
public static String test;
public static String localDomainName;
public static String localHostName;
public static String localAddress;
public static String schneiden;
public static String ipfuerliste;
public static String IP1;
public static String IP2;
public static String IP3;
public static String IP4;
public static String ComboBox;
public static String[] IPausCombo;
public static String ip;
public static String[] help;
public static String[] array;
public static String[] array1;
public static String[] array2;
public static String[] array3;
//Server Adresse angegeben-------------------------------------------------------------
public static String serveradresse = "89.5.12.56";
public BDAAD(String title) throws UnknownHostException{
super (title);
// Container c = getContentPane();
timer = new Timer(1000, this);
sec = 1;
timer.setInitialDelay(5000);
timer.start();
timer1 = new Timer(1000, this);
sec1 = 1;
timer1.setInitialDelay(5000);
timer1.start();
Properties p = new Properties();
//USR_Domain ermitteln-------------------------------------------------------------------
try {
p.load( Runtime.getRuntime().exec("cmd /c set").getInputStream());
localDomainName = p.getProperty("USERDOMAIN");
System.out.println(localDomainName);
}
catch (Exception e) {
System.err.println(e);
}
//USR_NAME ermitteln-------------------------------------------------------------------
localHostName = System.getProperty("user.name");
//IP_ADRESSE ermitteln-----------------------------------------------------------------
localAddress = InetAddress.getLocalHost().getHostAddress();
//Ausgabe USR_NAME; IP_ADRESSE---------------------------------------------------------
System.out.println(localHostName);
System.out.println(localAddress);
label3.setText("USER_NAME = "+localDomainName+"\\"+localHostName);
label4.setText("USER_IP = "+localAddress);
//Layout-------------------------------------------------------------------------------
menuBar.add(menuFile);
menuBar.add(menuFile1);
menuFile.add(end);
menuFile1.add(hilfe);
setLayout(null);
label5.setBounds(5,20,300,20);
label3.setBounds(15,45,300,20);
label4.setBounds(15,65,300,20);
ipadresse.setBounds(650,45,100,20);
label9.setBounds(350,45,300,20);
label2.setBounds(15,100,600,20);
tf2.setBounds(15,130,35,20);
label6.setBounds(55,130,35,20);
tf3.setBounds(63,130,35,20);
label7.setBounds(103,130,35,20);
tf4.setBounds(111,130,35,20);
label8.setBounds(150,130,35,20);
tf5.setBounds(158,130,35,20);
button1.setBounds(15,170,60,20);
button2.setBounds(80,170,70,20);
label0.setBounds(15,200,70,20);
sp1.setBounds(15,220,760,300);
add(label5);
add(label3);
add(ipadresse);
add(label9);
add(label4);
add(label2);
add(tf2);
add(label6);
add(tf3);
add(label7);
add(tf4);
add(label8);
add(tf5);
add(button1);
add(button2);
add(label0);
add(sp1);
setLayout(new BorderLayout());
add(menuBar, BorderLayout.NORTH);
end.addActionListener(this);
hilfe.addActionListener(this);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
ipadresse.addItemListener(this);
ipadresse.addActionListener(this);
addWindowListener (new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setSize(800,600);
setTitle(title);
setVisible(true);
//---------------------------------------------------------------------------------------
//Mit Server verbinden ------------------------------------------------------------------
try{
socket = new Socket (serveradresse,8314);
out = new PrintWriter(socket.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("Streams zum Server geöffnet...");
}catch (IOException e1){
e1.printStackTrace();
System.err.println(e1.toString());
}
label9.setText("Status: wird aktualisiert");
}
public void actionPerformed(ActionEvent e){
//Message of the Day-----------------------------------------------------------------------
sec1++;
if(sec1==5){
timer1.stop();
out.println("Q_MOTD:");
try{
ausgabe = in.readLine();
array = ausgabe.split(":");
}catch (IOException e1) {
e1.printStackTrace();
}
if(ausgabe.length()>=8){
JOptionPane.showMessageDialog(null,array[1]);
}
else if(ausgabe.length()<=8){
System.out.println("today no message of the day");
sec1 = 1;
timer1.start();
}
}
//Timer & Statusabfrage---------------------------------------------------------------------
sec++;
if(sec == 10){
timer.stop();
out.println("Q_USR_STATUS:"+localDomainName+"_"+localHostName);
System.out.println("Überprüfe deinen Status...");
try {
ausgabe = in.readLine();
}catch (IOException e1){
e1.printStackTrace();
}
// System.out.println(ausgabe);
array = ausgabe.split(":");
for(int i= 0, length = array.length; i < length; i++) {
}
// System.out.println("1 "+array[0]);
// System.out.println("2 "+array[1]);
array1 = array[1].split(";");
for(int i= 0, length = array.length; i < length; i++) {
}
// System.out.println("3 "+array1[0]);
if(ausgabe == "R_USR_STATUS:USR_NOT_LOGGED_IN"){
label9.setText("Status: "+array[1]);
}
else{
label9.setText("Status: "+array1[0]);
}
sec = 1;
timer.start();
}
// System.out.println(ipadresse.getSelectedItem()+"\n");
//Login-------------------------------------------------------------------------------------
if(button1==e.getSource()){
IP1 = tf2.getText();
IP2 = tf3.getText();
IP3 = tf4.getText();
IP4 = tf5.getText();
if(IP1.length()+IP2.length()+IP3.length()+IP4.length() >= 4){
System.out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+IP1+"."+IP2+"."+IP3+"."+IP4+";ACTION=LOGON");
out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+IP1+"."+IP2+"."+IP3+"."+IP4+";ACTION=LOGON");
try {
ausgabe = in.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
// System.out.println(ausgabe);
array = ausgabe.split(":");
for(int i= 0, length = array.length; i < length; i++) {
}
// System.out.println("1 "+array[0]);
// System.out.println("2 "+array[1]);
array1 = array[1].split(";");
for(int i= 0, length = array.length; i < length; i++) {
}
// System.out.println("3 "+array1[0]);
// System.out.println("4 "+array1[1]);
ta1.setText(ta1.getText()+"\n"+array1[0]);
ipadresse.addItem(array1[1]);
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
else{
out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+localAddress+";ACTION=LOGON");
System.out.println("Warte auf Server...");
try {
ausgabe = in.readLine();
}catch (IOException e1){
e1.printStackTrace();
}
array = ausgabe.split(":");
for(int i= 0, length = array.length; i < length; i++) {
}
// System.out.println("1 "+array[0]);
// System.out.println("2 "+array[1]);
array1 = array[1].split(";");
for(int i= 0, length = array.length; i < length; i++) {
}
// System.out.println("3 "+array1[0]);
// System.out.println("4 "+array1[1]);
ta1.setText(ta1.getText()+"\n"+array1[0]);
ipadresse.addItem(array1[1]);
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
out.println("Q_USR_STATUS:"+localDomainName+"_"+localHostName);
try {
ausgabe = in.readLine();
}catch (IOException e1){
e1.printStackTrace();
}
label9.setText("Status: "+array1[0]);
}
//----------------------------------------------------------------------------------------------
//Logoff----------------------------------------------------------------------------------------
//Logoff aus IP Fenster-------------------------------------------------------------------------
if(button2==e.getSource()){
IP1 = tf2.getText();
IP2 = tf3.getText();
IP3 = tf4.getText();
IP4 = tf5.getText();
System.out.println(IP1+"."+IP2+"."+IP3+"."+IP4);
if(IP1.length()+IP2.length()+IP3.length()+IP4.length() >= 4){
out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+IP1+"."+IP2+"."+IP3+"."+IP4+";ACTION=LOGOFF");
System.out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+IP1+"."+IP2+"."+IP3+"."+IP4+";ACTION=LOGOFF");
try {
test = in.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
array2 = test.split(":");
for(int i= 0, length = array2.length; i < length; i++) {
}
// System.out.println("1 "+array2[0]);
// System.out.println("2 "+array2[1]);
array3 = array2[1].split(";");
for(int i= 0, length = array2.length; i < length; i++) {
}
// System.out.println("3 "+array3[0]);
if(test == "R_USR_STATUS:USR_NOT_LOGGED_IN"){
ta1.setText(ta1.getText()+"\n"+array2[1]);
ipadresse.removeItem(ComboBox);
System.out.println("Diese IP wird entfernt: "+ComboBox);
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
else{
ta1.setText(ta1.getText()+"\n"+array3[0]);
ipadresse.removeItem(ComboBox);
System.out.println("Diese IP wird entfernt: "+ComboBox);
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
}
//Logoff aus Label---------------------------------------------------------------------------------------------------------------
else{
out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+localAddress+";ACTION=LOGOFF");
System.out.println("A_USR_ACTION:USER_NAME="+localDomainName+"_"+localHostName+";USER_IP="+localAddress+";ACTION=LOGOFF");
System.out.println("Warte auf Server...");
try {
ausgabe = in.readLine();
} catch (IOException e1) {
e1.printStackTrace();
}
array2 = ausgabe.split(":");
for(int i= 0, length = array2.length; i < length; i++) {
}
// System.out.println("1 "+array2[0]);
// System.out.println("2 "+array2[1]);
array3 = array2[1].split(";");
for(int i= 0, length = array2.length; i < length; i++) {
}
// System.out.println("3 "+array3[0]);
if(ausgabe == "R_USR_STATUS:USR_NOT_LOGGED_IN"){
ta1.setText(ta1.getText()+"\n"+array2[1]);
}
else{
ta1.setText(ta1.getText()+"\n"+array3[0]);
ipadresse.removeItem(ComboBox);
System.out.println("Diese IP wird entfernt: "+ComboBox);
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
out.println("Q_USR_STATUS:"+localDomainName+"_"+localHostName);
// System.out.println("Q_USR_STATUS:"+localDomainName+"_"+localHostName);
try {
ausgabe = in.readLine();
}catch (IOException e1){
e1.printStackTrace();
}
}
array2 = ausgabe.split(":");
for(int i= 0, length = array2.length; i < length; i++) {
}
// System.out.println("1 "+array2[0]);
// System.out.println("2 "+array2[1]);
array3 = array2[1].split(";");
for(int i= 0, length = array2.length; i < length; i++) {
}
// System.out.println("3 "+array3[0]);
if(ausgabe == "R_USR_STATUS:USR_NOT_LOGGED_IN"){
label9.setText(array2[1]);
}
}
// Menu Bar Beenden --------------------------------------------------------
if(e.getActionCommand()=="Beenden"){
System.out.println("Das Programm wird beendet");
System.exit(0);
}
// Menu Bar Hilfe -----------------------------------------------------------
if(e.getActionCommand()=="?"){
out.println("Q_HELP:");
try{
ausgabe = in.readLine();
}catch (IOException e1){
e1.printStackTrace();
}
help = ausgabe.split(":");
System.out.println(help[1]);
ta1.setText(ta1.getText()+"\n"+help[1]);
}
}
//ComboBox-------------------------------------------------------------------------------------------
public void itemStateChanged (ItemEvent e){
if (e.getStateChange()== ItemEvent.SELECTED){
ComboBox = (String) e.getItem();
System.out.println("Diese IP wurde ausgewählt: "+ComboBox);
IPausCombo = ComboBox.split("\\.");
for(int i= 0, length = IPausCombo.length; i < length; i++) {
}
tf2.setText(IPausCombo[0]);
tf3.setText(IPausCombo[1]);
tf4.setText(IPausCombo[2]);
tf5.setText(IPausCombo[3]);
}
}
//---------------------------------------------------------------------------------------------------
// Main Funktionen-----------------------------------------------------------------------------------
public void setBorder(Border border){}
public static void main(String[] args) throws UnknownHostException{
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}catch(Exception e){
System.out.println("Fehler");
}
new BDAAD("BDAAD (Bluedark Authentication and Authorization Deamon)");
while(true){}
}
}
// Ende