[Release] Kalonline Attendance Perl / Java + Source

08/16/2010 15:46 painTman#16
Jetzt gehts :) kannst du mir vieleicht sagen wie ich das unter Xp hinbekomme? Ist iwie fast das gleiche aber ich seh nirgendswo was mit Argumenten oder so
08/16/2010 15:54 Doofy#17
ich habe leider kein windows xp zur hand. eine notlösung wäre erstmal eine .bat erstellen, die dann die jar mit parametern aufruft:
  • Eine Textdatei erstellen mit dem Inhalt:
    Quote:
    java -jar C:\kal\KalAttendance2.0b.jar meineId meinPw
    Dabei natürlich den Pfad etc anpassen, logisch :-)
  • Die Textdatei in eine Bat ändern (Endung von .txt zu .bat)
  • Diese .bat-Datei dann bei der Augabenplanung auswählen
testen kannst du das ganze, indem du die .bat einfach doppelt anklickst, dann sollte sich ne cmd öffnen und dann der attendance darin ausgeführt werden.
Bei Fragen kannste gerne auch ne PM schreiben
beispiel für eine solche .bat:
[Only registered and activated users can see links. Click Here To Register...]
08/17/2010 17:23 painTman#18
Hm irgendwie funzt es bei mir wieder nicht.. hat einmal geöffnet nachdem ich es runtergeladen hab und jetzt gehts nimmer ô_Ô seltsam
08/18/2010 15:18 Doofy#19
die letzte version geht bei mir ohne probleme...
wie startest du es?
10/01/2010 23:59 hardfecx#20
schön dass es noch leute gibt die was zustande bringen und es nachher auch noch releasen (nachdem du es ja seid über einem jahr benutzt hast)!

Find die idee klasse vor allem da die inix homepage ja net grade die schnellste ist :)

von mir hast du ein TNX, mehrere sogar wenn ich könnte! Nice Work!!! Mach weiter so!!!
10/09/2010 19:26 Doofy#21
So, da ich entgültig Kal quitte, werde ich die Source-Datein veröffentlichen.
Evtl kann einer was mit Anfangen, "Bugs" fixxen, erweitern oder irgendwann nach nem Fix von Kal das Ding wieder zum laufen bekommen.

Perl:
PHP Code:
#!/usr/bin/perl
#
# (c) by Doofy 4 elitepvpers.com
#
use strict;
use 
warnings;
use 
LWP::Simple;
use 
LWP::UserAgent;
use 
HTTP::Request::Common;
use 
HTTP::Cookies;

our $ua;
my $fileName="./accounts.txt";

#Log in log.txt schreiben
###############################
#$_[0] Inhalt
sub schreibenInDatei
{
    
open(DATEI">>log.txt");
    print 
DATEI $_[0];
    
close(DATEI);
}

#Gesamt-Monats-Punkte
###################
sub getMonthPoints
{
    
my $content $ua->request(GET "http://www.inixgame.com/KalOnline/Community/Attendance.asp?btn=11")->as_string;
    
$content =~ s/(.*)<b>([0-9]{1,5}) Kal Point\(s\)(.*)/$2/igs;
    if(
length($content)<&& length($content)>0) { return $content; }
    return 
"-1";
}
#Check Value Holen
###################
sub getCheckValue
{
    
my $content $ua->request(GET "http://www.inixgame.com/KalOnline/Community/Attendance.asp?btn=11")->as_string;
    
my $oldLength=length($content);
    
$content =~ s/(.*)(AttendanceCheck.CheckValue.value..)(.*?)(.;AttendanceCheck)(.*)/$3/igs;
    if(
length($content)==32) { return $content; }
    
#Falls Dennoch Your attendance drin steht, vermutlich schon ausgeführt
    
elsif($content =~ /.*Your attendance.*/igs) { return "Attendance Check bereits durchgefuehrt"; }
    
#Wenn Login-Button angezeigt
    
elsif($content =~ /.*btn_login.gif.*/igs) { return "Login-Fehler"; }
    
    return 
"Unbekannter Fehler";
}
    
#Login ID
#############
#Loggt sich in den Account ein
#$_[0] = ID
#$_[1] = Pass
sub login
{
    
my $content $ua->request(GET "http://www.inixgame.com/");
    
$content $ua->request(POST "http://www.inixgame.com/SSL/do_login.asp" , [ "id" => $_[0], "pass" => $_[1] ] );
    
$content $ua->request(GET "http://www.inixgame.com/KalOnline/main.asp" )->as_string;
    return 
$content=~ /.*has connected.*/igs;
}

#Logt sich aus
################
sub logout
{
    print 
"LogOut - Sicher ist sicher xD\n";
    
my $content $ua->request(GET "http://www.inixgame.com/User/LogOut.asp?getURL=/KalOnline/main.asp")->as_string;    
}
#Submit Attendance Check
#############
#Führt den Check aus
#$_[0] = CheckValue
sub attendanceCheck
{
    
my $request HTTP::Request->new(POST => "http://www.inixgame.com/KalOnline/Community/Attendance.asp");
    
    
my $header ="BoardType=Attendance_Success&btn=11&CheckValue="$_[0] ;
    
$request->referer("http://www.inixgame.com/KalOnline/Community/Attendance.asp?btn=11");
    
$request->header("content-length" => length($header));
    
$request->header("content-type" => "application/x-www-form-urlencoded");
    
$request->content($header);

    
my $content $ua->request($request)->as_string;

    if(!
$content =~ /.*Attendance_Complete.*/igs) { return "0"; }
    
$content =~ s/(.*)(Point.)(.*?)(')(.*)/$3/igs;
    return $content;
}

#Start
print ("Attendance-Check by Hu5eL 1.02 (Complete)\nInizialisiere...\n\taccounts.txt -> ");
open(DATEI, "<".$fileName) || die $fileName." wurde nicht gefunden\n";
my $datei="";
while(<DATEI>){
    $datei .= $_;
}
close(DATEI);
my @accounts=split(/\n/,$datei);
if(scalar(@accounts)%2==1)
{
    print ("Error. ". $fileName ." muss eine Gerade Anzahl Zeilen enthalten (Id, Pw, Id, Pw, ...). Abbruch\n"); 
    exit;
}

print scalar(@accounts)/2 ."\n";


#User-Agent
$ua = LWP::UserAgent->new;
$ua->agent('
Mozilla/5.0 (WindowsUWindows NT 6.1derv:1.9.2.8Gecko/20100722 Firefox/3.6.8');
$ua->cookie_jar(HTTP::Cookies->new(file => "cookie.txt", 
                                autosave => 1,
                                ignore_discard => 1,));

#For Each Account.
for(my $i=0;$i<scalar(@accounts);$i=$i+2)
{
    my $id=$accounts[$i];
    my $pass=$accounts[$i+1];
    print ("ID: $id Pass: $pass\n");
    #Login
    print ("1. Login Versuch -> \n\t");
    my $erg=&login($id,$pass);
    if($erg==0) { print ("Error.\n2. Login Versuch -> \n\t"); $erg=&login($id,$pass) }
    if($erg==0) { print ("Error. Next ID\n"); &logout();next;}
    print("OK\n");
    
    #Attendance Check-Value
    print ("Try to get Check-Value -> \n\t");
    my $checkValue=&getCheckValue();
    if(length($checkValue)!=32) { print ("Error, $checkValue\n"); &logout();next; }
    print("OK\n");

    #Attendacne Check ausführen 
    print ("Execute Attendance Check -> \n\t");
    my $points=&attendanceCheck($checkValue);
    if($points eq "0") { print("Error");  }
    else { 
        print ("Success - $points KalPoints");
    }
    
    #KalPoints Auslesen
    my $anzahlPoints = &getMonthPoints();
    print (" (KalPoints this Month $anzahlPoints)\n");
    &logout();
    
}

exit; 
im Ordner der Perl-Datei muss eine accounts.txt liegen, die wie folgt aufgebaut ist:
id1
pw1
id2
pw2 etc..


Java:
Webbrowser.java
PHP Code:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class 
Webbrowser {
    private 
int debug;
    private 
Hashtable<String,Stringcookie;
    private 
String lastPage;
    private 
HttpURLConnection conn;
    public 
Webbrowser()
    {
        
debug 0;
        
lastPage "http://www.google.de";
        
cookie = new Hashtable<String,String>();
        
HttpURLConnection.setFollowRedirects(false);
    }
    
    private 
void sendCookie()
    {
        
StringBuffer cookieStringBuffer = new StringBuffer();
        
Enumeration<Stringkeys cookie.keys();
        while (
keys.hasMoreElements()) 
        {
            
String key keys.nextElement();
            
cookieStringBuffer.append(key);
            
cookieStringBuffer.append("=");
            
cookieStringBuffer.append(cookie.get(key));
            if (
keys.hasMoreElements())
                
cookieStringBuffer.append("; ");
        }
        
conn.setRequestProperty("Cookie"cookieStringBuffer.toString());
    }    
    private 
void saveCookie()
    {
        
String headerName null;
        for (
int i 1; (headerName conn.getHeaderFieldKey(i)) != nulli++) 
        {
            
//this.debug(conn.getHeaderField(i));
            
if (headerName.equalsIgnoreCase("Set-Cookie")) 
            {
                
String token = new StringTokenizer(conn.getHeaderField(i), ";").nextToken();
                
String name token.substring(0token.indexOf("="));
                
String value token.substring(token.indexOf("=") + 1token.length());
                
cookie.put(namevalue);
                
this.debug("Reci-Cookie:"name +"="+value);
            }
        }
    }

    private 
void setPost(String postthrows IOException
    
{
        if(
post == null) return;
        
conn.setDoOutput(true);
        
conn.setRequestMethod("POST");
        
conn.setRequestProperty("Content-Length"Integer.toString(post.getBytes().length));
        
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
        
wr.write(post); 
        
wr.flush();
        
wr.close();
        
this.debug("Send POST:"post);
    }
    private 
void setReferer(String url) {
        
conn.setRequestProperty("Referer"lastPage);
        
lastPage url;
    }

    private 
String getContent() throws IOException
    
{    try
        {
            
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
            
String line
            
String myReturn "";
            while ((
line rd.readLine()) != null) {
                
myReturn += line "\n";
            }  
            
rd.close(); 
            return 
myReturn;
        }
        catch(
FileNotFoundException e)
        {
            
e.printStackTrace();
        }
        return 
"";
    }
    
    public 
String open(String url)
    {
        return 
this.open(urlnull);
    }
    public 
String open(String url,String post)
    {

        try {
            
conn = (HttpURLConnection)new URL(url).openConnection();
            
this.debug("Open:"url);
            
this.setReferer(url);
            
this.sendCookie();
            
conn.setUseCaches(false);
            
this.setPost(post);
            
            
conn.connect();
            
String content this.getContent();
            
            
this.saveCookie();
            
this.debug("");
            return 
content;
        
        } catch (
MalformedURLException e) {
            
e.printStackTrace();
        } catch (
IOException e) {
            
e.printStackTrace();
        }
        return 
"Error";
    }

    private 
void debug(String text)
    {
        switch(
debug)
        {
            case 
1:
                
System.out.println("Debug:"text);
                break;
        }
    }
    public 
String toString()
    {
        
String myReturn "";
        
myReturn += "Webbrowser: \n";
        
myReturn += "Cookie: ("cookie.size() +")"cookie.toString();
        return 
myReturn;
    }
    
    public 
void setNextReferer(String url)
    {
        
this.lastPage url;
    }
    public 
void setDebug(int debug) { this.debug debug; }

KalAttendanceMain.java
PHP Code:
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


public class 
KalAttendanceMain implements Runnable{
    public static 
String version "2.0a";
    public static 
String workingDate "30.07.2010";
    private 
boolean privateVersion true;
    private 
Webbrowser webbrowser;
    private 
JTextField txtId;
    private 
JTextField txtPassword;
    private 
JLabel lblStatus;
    private 
JButton btn;
    private 
KalAttendanceMain myself;
    private 
boolean gui
    
    public 
KalAttendanceMain()
    {
        
webbrowser = new Webbrowser(){{ setDebug(0); }};
        
gui false;
        
myself this;
        
this.checkVersion();
    }
    private 
void checkVersion()
    {
        if(
privateVersion) return;
        
        
String answer webbrowser.open("http://********/kal-attendance/info.txt");
        
webbrowser.setNextReferer("http://www.google.de");
        
        if(
answer.length() == 0) return;
        
        if(
version.compareTo(answer.substring(0answer.indexOf("\n"))) == 0)
            return;
            
        
        
JOptionPane.showMessageDialog(nullanswer.substring(answer.indexOf("\n")+1answer.length()));
        
System.exit(0);
    }
    private 
void infoMessage(String message)
    {
        if(
gui)
            
lblStatus.setText(message);
        else
            
System.out.println(message);
    }
    private 
void usageMessage()
    {
        if(
gui)
        {
            
            
            return;
        }
        
System.out.println("Usage without GUI:");
        
System.out.println("\t1. Parameter: ID");
        
System.out.println("\t2. Parameter: Password");
    }
    private 
boolean login(String idString password)
    {
        
webbrowser.open("http://www.inixgame.com/");
        
String answer webbrowser.open("http://www.inixgame.com/SSL/do_login.asp","id="id +"&pass="password);
        if(
answer.contains("Logged in from other computer")) return login(id,password);
        return 
answer.contains("Object Moved");
    }
    private 
void logout()
    {
        
webbrowser.open("http://www.inixgame.com/User/LogOut.asp");
    }
    
    private 
String getAttendanceValue()
    {
        
String answer webbrowser.open("http://www.inixgame.com/KalOnline/Community/Attendance.asp?btn=11");
        
Matcher m Pattern.compile("[A-Z0-9]{32}").matcher(answer);
        if(
m.find())
            return 
answer.substring(m.start(),m.end());
        return 
null;
    }
    private 
boolean attendanceCheck(String checkValue)
    {
        
String answer webbrowser.open("http://www.inixgame.com/KalOnline/Community/Attendance.asp",
                
"BoardType=Attendance_Success&btn=11&CheckValue="checkValue);
        return 
answer.contains("Attendance_Complete");
    }
    
    public 
void executeAttendanceCheck(String idString password)
    {
        
infoMessage("Initialised");
        if(!
this.login(idpassword))
        {
            
infoMessage("Error, wrong Account-Password?");
            return;    
        }
        
        
infoMessage("Get Checksum for Today");
        
String checkValue this.getAttendanceValue();
        if(
checkValue == null)
        {
            
infoMessage("Attendance already done for Today");
            return;
        }
        
        
infoMessage("Execute Attendacne-Check");
        
boolean erg this.attendanceCheck(checkValue);
        if(
erg)
            
infoMessage("All Done fine");
        else 
            
infoMessage("Error...");
        
this.logout();
    }
    
    public 
void run() {
        
executeAttendanceCheck(txtId.getText(),txtPassword.getText());
    }
    
    public 
void grafischAnzeigen()
    {
        
this.gui true;
        
txtId = new JTextField();
        
txtPassword = new JTextField();
        
lblStatus = new JLabel("");
        
btn = new JButton("Do Attendance-Check!");
        
btn.addActionListener(new ActionListener(){
            public 
void actionPerformed(ActionEvent arg0) {
                new 
Thread(myself).start();  
            }});
        
JFrame haupt = new JFrame("Kalonline Attendance-Check by Hu5eL");
        
haupt.setLocation(350300);
        
haupt.setResizable(false);
        
haupt.setPreferredSize(new Dimension(450,150));
        
haupt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
JMenuBar menuBar = new JMenuBar();
        
JMenu credits = new JMenu("Credits");
        
        
JMenuItem about = new JMenuItem("About");
        
about.addActionListener(new ActionListener() {
            public 
void actionPerformed(ActionEvent arg0) {
                
JFrame credits = new JFrame("Credits");
                
credits.setLocation(350300);
                
credits.setPreferredSize(new Dimension(250,100));
                
                
JLabel version = new JLabel("Version:");
                
JLabel version_con = new JLabel(KalAttendanceMain.version);
                
JLabel written = new JLabel("Written by:");
                
JLabel written_con = new JLabel("Hu5eL");
                
JLabel date = new JLabel("Tested:");
                
JLabel date_con = new JLabel(KalAttendanceMain.workingDate);
                
                
credits.setLayout(new GridLayout(0,2));
                
credits.add(version);
                
credits.add(version_con);
                
credits.add(written);
                
credits.add(written_con);
                
credits.add(date);
                
credits.add(date_con);
                
credits.pack();
                
credits.setVisible(true);
            }});
        
        
menuBar.add(credits);
        
credits.add(about);
        
haupt.setJMenuBar(menuBar);
        
        
Container cp haupt.getContentPane();
        
cp.setLayout(new GridLayout(3,2));
        
cp.add(new JLabel("ID:"));
        
cp.add(txtId);
        
cp.add(new JLabel("Password"));
        
cp.add(txtPassword);
        
cp.add(btn);
        
cp.add(lblStatus);
        
haupt.pack();
        
haupt.setVisible(true);
    }
    
     
    public static 
void main(String[] args) {
        
Calendar cal Calendar.getInstance();
        
cal.setTime(new Date());
        if(
cal.get(Calendar.YEAR) > 2010)
        {
            
System.out.println("Version nur gültig bis 2010");
            return;
        }
        
        
KalAttendanceMain myAtten = new KalAttendanceMain();
        
        if(
args.length == 0)
            
myAtten.grafischAnzeigen();
        else if(
args.length == 2)
            
myAtten.executeAttendanceCheck(args[0], args[1]);
        else
            
myAtten.usageMessage();
            
    }
    



Hoffe ich konnte euch helfen, Mistrauen auslöschen und ein kleinen Teil zum großen ganzen Beitragen.
01/24/2011 16:51 Doofy#22
Little Update:
No Perl anymore, Java supports files, too. First Post updated. Sry 4 push :-/
03/09/2011 13:31 szopenfx#23
Hi
this is my version of KalOnline Attendance Checker in 32bit Delphi so don't need anything else to start program - just unpack it, check autostart in options ("Ustawienia">"Uruchom program przy starcie systemu") and that is all.
[Only registered and activated users can see links. Click Here To Register...]
I wrote it long time ago after this event appear and now I only fix parse errors from time to time. Code is wrote bad but it works.
Yes I know it's polish version but very easy and i think no one need translation (if someone want make it just send me fixed version)
03/09/2011 16:55 BorSti#24
copyright main function
Quote:
if(cal.get(Calendar.YEAR) > 2010)
{
System.out.println("Version nur gültig bis 2010");
return;
}
wont work for 2011 - iam sry


but anyway i like the source ! gj!
03/10/2011 22:23 Doofy#25
fixed, i updated first post but thx :-)
09/20/2011 00:26 rock1230#26
thxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx