Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import **.sauronsoftware.*******.********;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.net.URLEncoder;
- import javax.imageio.ImageIO;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import java.awt.AWTException;
- import java.awt.Font;
- import java.awt.HeadlessException;
- import java.awt.Image;
- import java.awt.MenuItem;
- import java.awt.PopupMenu;
- import java.awt.SystemTray;
- import java.awt.TrayIcon;
- import javax.swing.JTextField;
- import javax.swing.JPasswordField;
- import javax.swing.JButton;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class WebNotify extends JFrame {
- //promenlivi
- public static boolean newMessages = false;
- public static boolean newPosts = false;
- private JTextField textField;
- private JPasswordField passwordField;
- public static String user = "User";
- public static String pass = "pass";
- public static String mins = "2";
- public static WebNotify frame;
- public static String cookie;
- public static TrayIcon icon;
- static BufferedReader ini;
- static String read;
- private JTextField textField_1;
- //constructor na panela
- public WebNotify() {
- setResizable(false);
- getContentPane().setLayout(null);
- JLabel label = new JLabel("\u0418\u043C\u0435:");
- label.setFont(new Font("Tahoma", Font.BOLD, 16));
- label.setBounds(10, 11, 106, 25);
- getContentPane().add(label);
- JLabel label_1 = new JLabel("\u041F\u0430\u0440\u043E\u043B\u0430:");
- label_1.setFont(new Font("Tahoma", Font.BOLD, 16));
- label_1.setBounds(10, 47, 106, 25);
- getContentPane().add(label_1);
- textField = new JTextField(user);
- textField.setBounds(114, 14, 147, 22);
- getContentPane().add(textField);
- textField.setColumns(10);
- passwordField = new JPasswordField(pass);
- passwordField.setBounds(114, 47, 147, 22);
- getContentPane().add(passwordField);
- JLabel label_2 = new JLabel("\u041E\u043F\u0440\u0435\u0441\u043D\u044F\u0432\u0430\u043D\u0435(\u043C\u0438\u043D\u0443\u0442\u0438)");
- label_2.setBounds(10, 84, 147, 25);
- getContentPane().add(label_2);
- textField_1 = new JTextField(mins);
- textField_1.setBounds(180, 87, 114, 20);
- getContentPane().add(textField_1);
- textField_1.setColumns(10);
- JButton button = new JButton("\u0412\u043B\u0435\u0437");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- user=textField.getText();
- pass=passwordField.getText();
- mins=textField_1.getText();
- frame.setVisible(false);
- writeIni();
- performChecks();
- }
- });
- button.setBounds(114, 115, 89, 23);
- getContentPane().add(button);
- }
- public static void readIni() {
- try {
- ini = new BufferedReader(new FileReader("account.ini"));
- read = ini.readLine();
- if(read!=null){
- String saved = ******.decode(read);
- String[] ips = saved.split(":");
- user = ips[0];
- pass = ips[1];
- mins = ips[2];
- }
- } catch (IOException e) {
- }
- }
- public static void writeIni(){
- try {
- BufferedWriter outi = new BufferedWriter(new FileWriter(
- "account.ini"));
- outi.write(*******.encode(user + ":" + pass +":"+mins));
- outi.flush();
- outi.close();
- } catch (IOException e2) {
- e2.printStackTrace();
- }
- }
- public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
- UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
- icon = new TrayIcon(getIconGreen(),
- "antday помощник", createPopupMenu());
- try {
- SystemTray.getSystemTray().add(icon);
- } catch (AWTException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- readIni();
- frame = new WebNotify();
- frame.setBounds(200,200,330,200);
- frame.setTitle("Настройки");
- frame.setResizable(false);
- frame.setVisible(true);
- }
- private static PopupMenu createPopupMenu() throws
- HeadlessException {
- PopupMenu menu = new PopupMenu();
- MenuItem exit = new MenuItem("Изход");
- exit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- menu.add(exit);
- return menu;
- }
- //metodi za "hva6tane" na ikonkata za taskbara
- private static Image getIconGreen() throws HeadlessException {
- Image img = null;
- try {
- img = ImageIO.read(WebNotify.class.getResource("/resources/green.png"));
- } catch (IOException e2) {
- e2.printStackTrace();
- }
- return img;
- }
- private static Image getIconOrange() throws HeadlessException {
- Image img = null;
- try {
- img = ImageIO.read(WebNotify.class.getResource("/resources/orange.png"));
- } catch (IOException e2) {
- e2.printStackTrace();
- }
- return img;
- }
- private static Image getIconRed() throws HeadlessException {
- Image img = null;
- try {
- img = ImageIO.read(WebNotify.class.getResource("/resources/red.png"));
- } catch (IOException e2) {
- e2.printStackTrace();
- }
- return img;
- }
- public static void performChecks(){
- new Thread(new Runnable() {
- public void run() {
- while(true){
- try {
- // parametri za POST funkciqta za login
- String data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(user, "UTF-8");
- data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(pass, "UTF-8");
- data += "&" + URLEncoder.encode("login", "UTF-8") + "=" + URLEncoder.encode("", "UTF-8");
- // pravim vr1zkata k1m saita
- URL url = new URL("http://forum.antday.com/ucp.php");
- URLConnection conn = url.openConnection();
- //cookieto da go grabnem :D
- //da pozvolim pra6tane k1m vr1zkata
- conn.setDoOutput(true);
- //s tova 6te izpra6tame zaqvki
- OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
- wr.write(data);//POST'vame parametrite za login
- wr.flush();
- for (int i=0; ; i++) {
- String headerName = conn.getHeaderFieldKey(i);
- String headerValue = conn.getHeaderField(i);
- if (headerName == null && headerValue == null) {
- // No more headers
- break;
- }
- if ("Set-Cookie".equalsIgnoreCase(headerName)) {
- // Parse cookie
- String[] fields = headerValue.split(";\\s*");
- String cookieValue = fields[0];
- String expires = null;
- String path = null;
- String domain = null;
- boolean secure = false;
- // Parse each field
- for (int j=1; j<fields.length; j++) {
- if ("secure".equalsIgnoreCase(fields[j])) {
- secure = true;
- } else if (fields[j].indexOf('=') > 0) {
- String[] f = fields[j].split("=");
- if ("expires".equalsIgnoreCase(f[0])) {
- expires = f[1];
- } else if ("domain".equalsIgnoreCase(f[0])) {
- domain = f[1];
- } else if ("path".equalsIgnoreCase(f[0])) {
- path = f[1];
- }
- }
- }
- if(cookieValue.contains("sid")){
- cookie = cookieValue+"; "+expires+"; "+path+"; "+domain+"; "+secure;
- }
- }
- }
- // O4akvame otgovor
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- //proverki za novi li4ni s1ob6teniq
- if(line.contains("0</strong> new messages") || line.contains("0</strong> нови съобщения")){
- if(newMessages != false){
- //setTrayIcon(3);
- }
- newMessages=false;
- break;
- } else {
- newMessages=true;
- }
- }
- rd.close();
- wr.close();
- } catch (Exception e) {
- }
- newPostsCheck();
- try {
- Thread.sleep(Integer.parseInt(mins)*60000);
- } catch (InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }}).start();
- }
- public static void newPostsCheck(){
- try {
- URL url2 = new URL("http://forum.antday.com/search.php?search_id=newposts");
- URLConnection conn2 = url2.openConnection();
- conn2.setRequestProperty("Cookie", cookie);
- BufferedReader rd2 = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
- String line2;
- while ((line2 = rd2.readLine()) != null) {
- //proverki za novi li4ni s1ob6teniq
- if(line2.contains("Нищо не е намерено.") || line2.contains("No suitable matches were found.")){
- if(newPosts != false){
- //setTrayIcon(3);
- }
- newPosts=false;
- break;
- } else {
- newPosts=true;
- }
- }
- if(newPosts == false && newMessages == true){
- icon.setImage(getIconRed());
- } else if(newPosts == true && newMessages == false){
- icon.setImage(getIconOrange());
- } else if(newPosts == true && newMessages == true){
- icon.setImage(getIconRed());
- } else if(newPosts == false && newMessages == false){
- icon.setImage(getIconGreen());
- }
- rd2.close();
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement