docs
[mirrors/Programs.git] / java / JChater / Chater.java
CommitLineData
f9e14e8a
H
1//////////////////////////////////////////////////////////
2// //
3// Chater 1.4 //
4// Thomas Harvie Mudrunka (C) 2006 //
5// //
6// > Czech Republic //
7// > ICQ 283-782-978 //
8// //
9//////////////////////////////////////////////////////////
10
11
12// Importy
13import java.lang.*;
14import java.io.*;
15import java.net.*;
16import javax.swing.JOptionPane;
17
18
3bf77bf5 19//Veřejná třída
f9e14e8a
H
20//-------------------------------------------------------------------------------------------------------------------------------------------------------------
21
22public class Chater {
23
24//Metoda main
25//-------------------------------------------------------------------------------------------------------------------------------------------------------------
26
27 public static void main(String[] args) throws java.io.IOException {
28 System.out.println("Chater 1.4\nby: Thomas Mudrunka (C) 2006 - Czech Rep.\nICQ: 283782978\n\nProgram Started!\nInitializing...\n");
29 int port = 12345;
30 String line, pass, goodpass, popup;
31 popup = "false";
32 goodpass = "false";
33 //InetAddress add = getLocalhost(); //Adresa localhosta
34 Runtime runtime = Runtime.getRuntime();
35 if(args[0].equals("help")){
36 System.out.println("You need help ha?!");
37 System.exit(0);
38 }
39
40 try {port = Integer.parseInt(args[0]);} catch (java.lang.ArrayIndexOutOfBoundsException ex) {System.out.println("- ERROR, YOU MUST SPECIFY PORT !!!\nSyntax: java Chater {port, popup, pass}\njava Chater help - for detail help"); System.exit(1);}
41 if(args.length > 1){popup = args[1];}
42
3bf77bf5 43 ServerSocket ss = new ServerSocket(port); //Vytvořit serverový soket
f9e14e8a
H
44 System.out.println("Server started on: localhost:" + port + "\nPopups enabled: " + popup + "\nNow waiting for incoming connection!");
45
3bf77bf5 46//Přijetí příchozího spojení
f9e14e8a
H
47//-------------------------------------------------------------------------------------------------------------------------------------------------------------
48
49 while(true){
50 Socket sckt = ss.accept();
51 System.out.println("Connected!");
3bf77bf5 52 BufferedReader br = new BufferedReader (new InputStreamReader(sckt.getInputStream())); //BufferedReader vytvoříme z InputStreamReaderu vytvořeného z InputStreamu vráceného metodou soketu vráceného přijmutím spojení serverovým soketem.
f9e14e8a
H
53
54
55/*
3bf77bf5 56//Ověření hesla
f9e14e8a
H
57//-------------------------------------------------------------------------------------------------------------------------------------------------------------
58
3bf77bf5 59 line = br.readLine(); //Přečíst další řádek z telnetu
f9e14e8a
H
60
61 System.out.println("Waiting for password.");
62
63 if(args.length > 2){
64
65 line = "ahoj";//debug
66 if(args[2].equals(line)) {goodpass = "true";}
3bf77bf5 67 line = br.readLine(); //Přečíst další řádek z telnetu
f9e14e8a
H
68 line = "ahoj";//debug
69
70 while((line != null) || (goodpass.equals("false"))){
71 if(args[2].equals(line)){goodpass = "true"; System.out.println("GOOD"}
72 System.out.println("Invalid Password! Valid=" + args[2]);
73 //if(args[2] == line){System.out.println("Good Password!");}
74 line = br.readLine();
75 line = "ahoj";//debug
76 }
77 }
78*/
3bf77bf5 79//Zpracování příkazů
f9e14e8a
H
80//-------------------------------------------------------------------------------------------------------------------------------------------------------------
81
82 System.out.println("Incoming data:");
3bf77bf5 83 line = br.readLine(); //Přečíst další řádek z telnetu
f9e14e8a
H
84
85 while(line != null){
86 if(line.equals("|exit") || line.equals("|exit1") || line.equals("|cmd") || line.equals("|popup") || line.equals("|plain")){
87 System.out.println("! Incoming command:");
88 if(line.equals("|popup"))
89 {
90 popup = "true";
91 System.out.println("- Enabling popups!");
92 }
93 if(line.equals("|plain"))
94 {
95 popup = "false";
96 System.out.println("- Disabling popups!");
97 }
98 if(line.equals("|exit"))
99 {
100 System.out.println("- Remote daemon shutdown request...\n- Exit code: 0");
101 System.exit(0);
102 }
103 if(line.equals("|exit1"))
104 {
105 System.out.println("- Remote daemon shutdown request (because of error)...\n- Exit code: 1");
106 System.exit(1);
107 }
108 if(line.equals("|cmd"))
109 {
110 try {
111 System.out.println("- Waiting for remote command line...");
112 line = br.readLine();
113 System.out.println("- Executing...");
114 runtime.exec(line);
115 System.out.println("- Done!");
116 } catch (Exception ex) {}
117 }
118
119 }
120
3bf77bf5 121//Tisk zpráv do konzole a otevírání popapek
f9e14e8a
H
122//-------------------------------------------------------------------------------------------------------------------------------------------------------------
123
124 else {
125 System.out.println(line);
126 if(popup.equals("true")){
127 JOptionPane.showMessageDialog(null, line);
128 }
129 }
3bf77bf5 130 line = br.readLine();//Přečíst další řádek z telnetu
f9e14e8a
H
131
132 }
133 System.out.print("Connection closed by client!\nNow waiting for incoming connection!");
134 }
135 }
136
137//-------------------------------------------------------------------------------------------------------------------------------------------------------------
138
3bf77bf5 139 public static void slow() { //Metoda pro zahlcení CPU.
f9e14e8a
H
140 int a, b, c;
141 a=1; b=1; c=0;
142
143 while(true) {
144 if ((a < 2147438648) && (b < 2147438648) && (c < 2147438648)) {
145 c = a + b; b = c - a;
146 }
147 else {
148 a=1; b=1; c=0;
149 }
150 }
151 }
152
3bf77bf5 153//Konec třídy
f9e14e8a
H
154//-------------------------------------------------------------------------------------------------------------------------------------------------------------
155
156 }
This page took 0.250158 seconds and 4 git commands to generate.