slitaz-forge rev 91

Add source for irc.slitaz.org.
author Christopher Rogers <slaxemulator@gmail.com>
date Wed Feb 29 16:00:42 2012 -0500 (2012-02-29)
parents eb61f687607b
children 0b330079dcc9
files irc/README irc/src/config.ini irc/src/html/index.php irc/src/html/logo.png irc/src/html/style.css irc/src/org/jibble/logbot/LogBot.java irc/src/org/jibble/logbot/LogBotMain.java
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/irc/README	Wed Feb 29 16:00:42 2012 -0500
     1.3 @@ -0,0 +1,1 @@
     1.4 +Source for irc.slitaz.org
     1.5 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/irc/src/config.ini	Wed Feb 29 16:00:42 2012 -0500
     2.3 @@ -0,0 +1,9 @@
     2.4 +#
     2.5 +# Config file for the Java IRC LogBot
     2.6 +# http://www.jibble.org/logbot/
     2.7 +#
     2.8 +Nick = TazLog
     2.9 +Server = irc.freenode.org
    2.10 +Channel = #slitaz
    2.11 +JoinMessage = This channel is being logged @ http://irc.slitaz.org/
    2.12 +OutputDir = /home/slitaz/public_html
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/irc/src/html/index.php	Wed Feb 29 16:00:42 2012 -0500
     3.3 @@ -0,0 +1,79 @@
     3.4 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     3.5 +<?php
     3.6 +    include("config.inc.php");
     3.7 +?>
     3.8 +<html>
     3.9 +<head>
    3.10 +	<title>IRC Logs for SliTaz</title>
    3.11 +	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    3.12 +	<meta name="description" content="IRC Logs for SliTaz" />
    3.13 +	<meta name="keywords" content="IRC Logs for SliTaz" />
    3.14 +	<link rel="stylesheet" href="style.css" type="text/css" />
    3.15 +</head>
    3.16 +<body>
    3.17 +	<div id="header">
    3.18 +		<div id="logo"></div>
    3.19 +		<div id="network">
    3.20 +			<a href="http://www.slitaz.org/">
    3.21 +				<img src="http://www.slitaz.org/images/network.png" alt="network.png" /></a>
    3.22 +			<a href="http://scn.slitaz.org/">Community</a>
    3.23 +			<a href="http://doc.slitaz.org/">Doc</a>
    3.24 +			<a href="http://forum.slitaz.org/">Forum</a>
    3.25 +			<a href="http://bugs.slitaz.org">Bugs</a>
    3.26 +			<a href="http://hg.slitaz.org/">Hg</a>
    3.27 +		</div>
    3.28 +		<h1><a href="./">IRC Logs for SliTaz</a></h1>
    3.29 +	</div>
    3.30 +	<?php
    3.31 +		$date = $_GET['date'];
    3.32 +		if (isset($date) && preg_match("/^\d\d\d\d-\d\d-\d\d$/", $date)) {
    3.33 +	?>
    3.34 +	<div id="contentbox">
    3.35 +		<h2>Log for <?php echo($date); ?></h2>
    3.36 +		<p>Timestamps are GMT-7</p>
    3.37 +		<p><a href="./"><< Back to Index</a></p>
    3.38 +	</div>
    3.39 +	<div id="content">
    3.40 +	<?php
    3.41 +			readfile($date . ".log");
    3.42 +	?>
    3.43 +	</div>
    3.44 +	<?php
    3.45 +		}
    3.46 +		else {
    3.47 +			$dir = opendir(".");
    3.48 +			while (false !== ($file = readdir($dir))) {
    3.49 +				if (strpos($file, ".log") == 10) {
    3.50 +					$filearray[] = $file;
    3.51 +				}
    3.52 +			}
    3.53 +			closedir($dir);
    3.54 +			rsort($filearray);
    3.55 +	?>
    3.56 +	<div id="contentbox">
    3.57 +		<ul>
    3.58 +	<?php
    3.59 +			foreach ($filearray as $file) {
    3.60 +				$file = substr($file, 0, 10);
    3.61 +	?>
    3.62 +			<li><a href="<?php echo($file); ?>"><?php echo($file); ?></a></li>
    3.63 +	<?php
    3.64 +			}
    3.65 +	?>
    3.66 +		</ul>
    3.67 +	</div>
    3.68 +	<?php
    3.69 +		}
    3.70 +	?>
    3.71 +	<div id="footer">
    3.72 +		<p>SliTaz @
    3.73 +			<a href="http://twitter.com/slitaz">Twitter</a>
    3.74 +			<a href="http://www.facebook.com/slitaz">Facebook</a>
    3.75 +			<a href="http://distrowatch.com/slitaz">Distrowatch</a>
    3.76 +			<a href="http://en.wikipedia.org/wiki/SliTaz">Wikipedia</a>
    3.77 +			<a href="http://flattr.com/profile/slitaz">Flattr</a></p>
    3.78 +		<p>These logs were automatically created by <b><?php echo($nick); ?></b> 
    3.79 +		using <a href="http://www.jibble.org/logbot/">LogBot</a></p>
    3.80 +	<div/>
    3.81 +</body>
    3.82 +</html>
     4.1 Binary file irc/src/html/logo.png has changed
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/irc/src/html/style.css	Wed Feb 29 16:00:42 2012 -0500
     5.3 @@ -0,0 +1,96 @@
     5.4 +body {
     5.5 +    margin: 0;
     5.6 +    padding: 0;
     5.7 +    background: #000;
     5.8 +    font: 11px sans-serif, vernada, arial;    
     5.9 +    color: #fff;
    5.10 +}
    5.11 +
    5.12 +.irc-date { color: grey; }
    5.13 +.irc-green { color: green; }
    5.14 +.irc-white { color: lightgrey; }
    5.15 +.irc-orange { color: orange; }
    5.16 +.irc-yellow { color: yellow; }
    5.17 +.irc-grey { color: grey; }
    5.18 +.irc-red { color: red; }
    5.19 +a {text-decoration: none; color: #335A8F;}
    5.20 +a:hover {text-decoration: underline; color: #335A8F;}
    5.21 +img { border: 0pt none; vertical-align: middle; }
    5.22 +
    5.23 +/* Header */
    5.24 +#header { 
    5.25 +	height: 40px; 
    5.26 +	background: #351a0a;
    5.27 +}
    5.28 +#header h1 {
    5.29 +	margin: 0;
    5.30 +	padding: 5px 0 0 42px;
    5.31 +	width: 250px;
    5.32 +	clear: none;
    5.33 +}
    5.34 +#header h1 a { 
    5.35 +	color: white; 
    5.36 +	text-decoration: none;
    5.37 +	font-size: 20px;
    5.38 +	font-style: italic;
    5.39 +}
    5.40 +#header h1 a:hover, #network a:hover { 
    5.41 +	color: #d66018;
    5.42 +}
    5.43 +
    5.44 +/* Logo */
    5.45 +#logo {
    5.46 +	background: url(logo.png) no-repeat left;
    5.47 +	position: absolute;
    5.48 +	float: left;
    5.49 +	left: 0px;
    5.50 +	top: 0px;
    5.51 +	width: 40px;
    5.52 +	height: 40px;
    5.53 +}
    5.54 +
    5.55 +/* SliTaz Network */
    5.56 +#network { 
    5.57 +	float: right; 
    5.58 +	padding: 10px 5px 0; 
    5.59 +	font-size: 12px;
    5.60 +}
    5.61 +#network a { 
    5.62 +	padding: 0 6px; 
    5.63 +	color: #fff; 
    5.64 +	font-weight: bold;
    5.65 +	text-decoration: none;
    5.66 +}
    5.67 +
    5.68 +#content {
    5.69 +	padding-top: 10px;
    5.70 +	padding-left: 80px;
    5.71 +	padding-bottom: 10px;
    5.72 +	padding-right: 20px;
    5.73 +	font-size: 13px;
    5.74 +}
    5.75 +
    5.76 +#contentbox {
    5.77 +	padding-left: 80px;
    5.78 +	padding-top: 1px;
    5.79 +	padding-bottom: 1px;
    5.80 +	font-size: 13px;
    5.81 +	background: #d66018; 
    5.82 +	color: #333;
    5.83 +}
    5.84 +#contentbox a { 
    5.85 +	color: #fff;
    5.86 +	text-decoration: none;
    5.87 +}
    5.88 +#contentbox a:hover { 
    5.89 +	text-decoration: underline;
    5.90 +}
    5.91 +
    5.92 +#footer {
    5.93 +	background: #AF9E9E;
    5.94 +	text-align: center;
    5.95 +	padding: 5px;
    5.96 +	color: #151515;
    5.97 +}
    5.98 +#footer a { color: #151515; padding: 0 2px; text-decoration: underline; }
    5.99 +#footer a:hover { text-decoration: none; }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/irc/src/org/jibble/logbot/LogBot.java	Wed Feb 29 16:00:42 2012 -0500
     6.3 @@ -0,0 +1,143 @@
     6.4 +package org.jibble.logbot;
     6.5 +
     6.6 +import java.util.*;
     6.7 +import java.util.regex.*;
     6.8 +import java.io.*;
     6.9 +import java.text.SimpleDateFormat;
    6.10 +import org.jibble.pircbot.*;
    6.11 +
    6.12 +public class LogBot extends PircBot {
    6.13 +
    6.14 +    private static final Pattern urlPattern = Pattern.compile("(?i:\\b((http|https|ftp|irc)://[^\\s]+))");
    6.15 +    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    6.16 +    private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
    6.17 +    
    6.18 +    public static final String GREEN = "irc-green";
    6.19 +    public static final String WHITE = "irc-white";
    6.20 +    public static final String ORANGE = "irc-orange";
    6.21 +    public static final String YELLOW = "irc-yellow";
    6.22 +    public static final String GREY = "irc-grey";
    6.23 +    public static final String RED = "irc-red";
    6.24 +    
    6.25 +    public LogBot(String name, File outDir, String joinMessage) {
    6.26 +        setName(name);
    6.27 +        setVerbose(true);
    6.28 +        this.outDir = outDir;
    6.29 +        this.joinMessage = joinMessage;
    6.30 +    }
    6.31 +    
    6.32 +    public void append(String color, String line) {
    6.33 +        line = Colors.removeFormattingAndColors(line);
    6.34 +        
    6.35 +        line = line.replaceAll("&", "&amp;");
    6.36 +        line = line.replaceAll("<", "&lt;");
    6.37 +        line = line.replaceAll(">", "&gt;");
    6.38 +        
    6.39 +        Matcher matcher = urlPattern.matcher(line);
    6.40 +        line = matcher.replaceAll("<a href=\"$1\">$1</a>");
    6.41 +        
    6.42 +                
    6.43 +        try {
    6.44 +            Date now = new Date();
    6.45 +            String date = DATE_FORMAT.format(now);
    6.46 +            String time = TIME_FORMAT.format(now);
    6.47 +            File file = new File(outDir, date + ".log");
    6.48 +            BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
    6.49 +            String entry = "<span class=\"irc-date\">(" + time + ")</span> <span class=\"" + color + "\">" + line + "</span><br />";
    6.50 +            writer.write(entry);
    6.51 +            writer.newLine();
    6.52 +            writer.flush();
    6.53 +            writer.close();
    6.54 +        }
    6.55 +        catch (IOException e) {
    6.56 +            System.out.println("Could not write to log: " + e);
    6.57 +        }
    6.58 +    }
    6.59 +    
    6.60 +    public void onAction(String sender, String login, String hostname, String target, String action) {
    6.61 +        append(YELLOW, "* " + sender + " " + action);
    6.62 +    }
    6.63 +    
    6.64 +    public void onJoin(String channel, String sender, String login, String hostname) {
    6.65 +        append(GREEN, "*** " + sender + " (" + login + "@" + hostname + ") has joined " + channel);
    6.66 +    }
    6.67 +    
    6.68 +    public void onMessage(String channel, String sender, String login, String hostname, String message) {
    6.69 +        append(WHITE, "[" + sender + "] " + message);
    6.70 +        
    6.71 +        message = message.toLowerCase();
    6.72 +        if (message.startsWith(getNick().toLowerCase()) && message.indexOf("help") > 0) {
    6.73 +            sendMessage(channel, joinMessage);
    6.74 +        }
    6.75 +    }
    6.76 +    
    6.77 +    public void onMode(String channel, String sourceNick, String sourceLogin, String sourceHostname, String mode) {
    6.78 +        append(ORANGE, "*** " + sourceNick + " sets mode " + mode);
    6.79 +    }
    6.80 +    
    6.81 +    public void onNickChange(String oldNick, String login, String hostname, String newNick) {
    6.82 +        append(ORANGE, "*** " + oldNick + " is now known as " + newNick);
    6.83 +    }
    6.84 +    
    6.85 +    public void onPart(String channel, String sender, String login, String hostname) {
    6.86 +        append(GREY, "*** " + sender + " (" + login + "@" + hostname + ") has left " + channel);
    6.87 +    }
    6.88 +
    6.89 +    public void onQuit(String sourceNick, String sourceLogin, String sourceHostname, String reason) {
    6.90 +         append(RED, "*** " + sourceNick + " (" + sourceLogin + "@" + sourceHostname + ") has quit (" + reason + ")");
    6.91 +    }
    6.92 +    
    6.93 +    public void onTopic(String channel, String topic, String setBy, long date, boolean changed) {
    6.94 +        if (changed) {
    6.95 +            append(GREEN, "*** " + setBy + " changes topic to '" + topic + "'");
    6.96 +        }
    6.97 +        else {
    6.98 +            append(GREEN, "*** Topic is '" + topic + "'");
    6.99 +            append(GREEN, "*** Set by " + setBy + " on " + new Date(date));
   6.100 +        }
   6.101 +    }
   6.102 +    
   6.103 +    public void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target) {
   6.104 +    }
   6.105 +    
   6.106 +    public void onKick(String channel, String kickerNick, String kickerLogin, String kickerHostname, String recipientNick, String reason) {
   6.107 +        append(GREY, "*** " + recipientNick + " was kicked from " + channel + " by " + kickerNick);
   6.108 +        if (recipientNick.equalsIgnoreCase(getNick())) {
   6.109 +            joinChannel(channel);
   6.110 +        }
   6.111 +    }
   6.112 +    
   6.113 +    public void onDisconnect() {
   6.114 +        append(RED, "*** Disconnected.");
   6.115 +        while (!isConnected()) {
   6.116 +            try {
   6.117 +                reconnect();
   6.118 +            }
   6.119 +            catch (Exception e) {
   6.120 +                try {
   6.121 +                    Thread.sleep(10000);
   6.122 +                }
   6.123 +                catch (Exception anye) {
   6.124 +                    // Do nothing.
   6.125 +                }
   6.126 +            }
   6.127 +        }
   6.128 +    }
   6.129 +    
   6.130 +    public static void copy(File source, File target) throws IOException {
   6.131 +        BufferedInputStream input = new BufferedInputStream(new FileInputStream(source));
   6.132 +        BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(target));
   6.133 +        int bytesRead = 0;
   6.134 +        byte[] buffer = new byte[1024];
   6.135 +        while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1) {
   6.136 +            output.write(buffer, 0, bytesRead);
   6.137 +        }
   6.138 +        output.flush();
   6.139 +        output.close();
   6.140 +        input.close();
   6.141 +    }
   6.142 +    
   6.143 +    private File outDir;
   6.144 +    private String joinMessage;
   6.145 +    
   6.146 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/irc/src/org/jibble/logbot/LogBotMain.java	Wed Feb 29 16:00:42 2012 -0500
     7.3 @@ -0,0 +1,46 @@
     7.4 +package org.jibble.logbot;
     7.5 +
     7.6 +import java.io.*;
     7.7 +import java.util.*;
     7.8 +
     7.9 +public class LogBotMain {
    7.10 +    
    7.11 +    public static void main(String[] args) throws Exception {
    7.12 +        
    7.13 +        Properties p = new Properties();
    7.14 +        p.load(new FileInputStream(new File("./config.ini")));
    7.15 +        
    7.16 +        String server = p.getProperty("Server", "localhost");
    7.17 +        String channel = p.getProperty("Channel", "#test");
    7.18 +        String nick = p.getProperty("Nick", "LogBot");
    7.19 +        String joinMessage = p.getProperty("JoinMessage", "This channel is logged.");
    7.20 +        
    7.21 +        File outDir = new File(p.getProperty("OutputDir", "./output/"));
    7.22 +        outDir.mkdirs();
    7.23 +        if (!outDir.isDirectory()) {
    7.24 +            System.out.println("Cannot make output directory (" + outDir + ")");
    7.25 +            System.exit(1);
    7.26 +        }
    7.27 +
    7.28 +        LogBot.copy(new File("html/style.css"), new File(outDir, "style.css"));
    7.29 +		LogBot.copy(new File("html/index.php"), new File(outDir, "index.php"));
    7.30 +        
    7.31 +        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outDir, "config.inc.php")));
    7.32 +        writer.write("<?php");
    7.33 +        writer.newLine();
    7.34 +        writer.write("    $server = \"" + server + "\";");
    7.35 +        writer.newLine();
    7.36 +        writer.write("    $channel = \"" + channel + "\";");
    7.37 +        writer.newLine();
    7.38 +        writer.write("    $nick = \"" + nick + "\";");
    7.39 +        writer.newLine();
    7.40 +        writer.write("?>");
    7.41 +        writer.flush();
    7.42 +        writer.close();
    7.43 +        
    7.44 +        LogBot bot = new LogBot(nick, outDir, joinMessage);
    7.45 +        bot.connect(server);
    7.46 +        bot.joinChannel(channel);
    7.47 +    }
    7.48 +    
    7.49 +}