ForeverYoung's blog ยป gentoo/atom/gentoo/?lang=en2011-05-31T06:49:59ZAnton NovosyolovLinux, programming, etc.blohgQR-codes/post/qr-code-local/?lang=en2011-05-31T06:49:59Z2011-05-31T06:49:59ZAnton Novosyolovanton.novosyolov@gmail.com<!-- tags: gentoo,Nokia N900,QR -->
<!-- date: 1306824599 -->
<p>After <a class="reference external" href="/post/qr-code/?lang=en">post about QR-codes</a>, version without using Google Chart API.</p>
<!-- tags: gentoo,Nokia N900,QR -->
<!-- date: 1306824599 -->
<p>After <a class="reference external" href="/post/qr-code/?lang=en">post about QR-codes</a>, version without using Google Chart API.</p>
<!-- read_more -->
<p><em>qrcode</em> - to make QR-code and display it - desktop version:</p>
<pre class="brush: bash">
#!/bin/bash
qrencode -o /tmp/qr.png
feh /tmp/qr.png
rm /tmp/qr.png
</pre>
<p><em>qrcode</em> - to make QR-code and display it - N900 version:</p>
<pre class="brush: bash">
#!/bin/bash
qrencode -o /tmp/qr.png
phone-control --browse file:///tmp/qr.png
</pre>
<p>Changes between versions is minimal - different image viewer.</p>
<p>On desktop you should install media-gfx/qrencode and feh (or change script to use different viewer), on N900 - qrencode and phone-control (both from extras-devel).</p>
<p>Usage:</p>
<pre class="brush: plain">
$ qrcode < file
$ qrcode
text
text2
Ctrl-D
</pre>
<p>On N900 I added <a class="reference external" href="http://wiki.maemo.org/Desktop_Command_Execution_Widget_scripts">DCEW</a> widget to invoke qrcode.</p>
<p>Command:</p>
<pre class="brush: bash">
sh -c "osso-xterm -e /home/user/.bin/qrcode &" | echo ""
</pre>
<p>Reading of QR-codes is remained as it was.</p>
<p><strong>UPD</strong>: <em>qrcode-clip</em> - reads from clipboard, both on N900 and on desktop:</p>
<pre class="brush: bash">
#!/bin/bash
clip=`xclip -o -selection clipboard`
if [ "$clip" != "" ]; then
echo "$clip" | qrencode -o /tmp/qr.png
phone-control --browse file:///tmp/qr.png
fi
</pre>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script>About blohg/post/about-blohg/?lang=en2011-05-27T10:24:15Z2011-05-27T10:24:15ZAnton Novosyolovanton.novosyolov@gmail.com<!-- date: 1306491855 -->
<!-- tags: python,reStructuredText,mercurial,gentoo,lighttpd,blohg -->
<p><a class="reference external" href="http://blohg.org">Blohg</a> is a blog engine written in Python.</p>
<!-- date: 1306491855 -->
<!-- tags: python,reStructuredText,mercurial,gentoo,lighttpd,blohg -->
<p><a class="reference external" href="http://blohg.org">Blohg</a> is a blog engine written in Python.</p>
<!-- read_more -->
<p>It has <a class="reference external" href="http://flask.pocoo.org">Flask</a>, <a class="reference external" href="http://jinja.pocoo.org/2/">Jinja2</a>, <a class="reference external" href="http://pypi.python.org/pypi/docutils">docutils</a>, <a class="reference external" href="http://mercurial.selenic.com">Mercurial</a> in its basis.
Comment system is external, via <a class="reference external" href="http://disqus.com">disqus</a>.</p>
<p>For me it has this advantages:</p>
<ul class="simple">
<li><a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> - it has more capabilities than, for example, <a class="reference external" href="http://ru.wikipedia.org/wiki/Markdown">Markdown</a>.</li>
<li><a class="reference external" href="http://mercurial.selenic.com">Mercurial</a> - It's convinient to post - <em>edit</em>, hg commit, hg push (but there's no capability to post from browser <em>yet</em>, probably I will make this possible).</li>
</ul>
<div class="section" id="installation">
<h3>Installation</h3>
<p>I don't like to describe how to install something, but in gentoo it's just one command (<a class="reference external" href="http://rafaelmartins.eng.br">Rafael G. Martins</a> - author of blohg - is gentoo developer) (<em>while I looked at his site, I saw many goodies, I'll try to get to know them and describe here</em>):</p>
<pre class="brush: bash">
$ emerge blohg
</pre>
</div>
<div class="section" id="usage">
<h3>Usage</h3>
<p>Create repository:</p>
<pre class="brush: bash">
$ blohg initrepo --repo-path my_blohg
</pre>
<p>Set up settings in <em>config.yaml</em>, tune up templates (in <em>templates</em> directory).</p>
<p>After that, write posts (in <em>content/post</em> directory), create attachments (in <em>content/attachments</em>) and commit changes.</p>
</div>
<div class="section" id="deploy">
<h3>Deploy</h3>
<p>Clone repo to remote host:</p>
<pre class="brush: bash">
$ hg clone my_blohg ssh://user@yourdomain.tld/path/to/my_blohg/
</pre>
<p>I use <a class="reference external" href="http://www.lighttpd.net">lighttpd</a> as web-server.</p>
<p><em>mod_fastcgi.conf</em>:</p>
<pre class="brush: plain">
fastcgi.debug = 0
fastcgi.server = ("/" =>
(
"blohg" => (
"socket" => "/tmp/blohg-fcgi.sock",
"bin-path" => "/var/www/blohg.fcgi",
"check-local" => "disable",
"fix-root-scriptname" => "enable"
)
)
)
alias.url = (
"/static/" => "/var/www/blog/static"
)
url.rewrite-once = (
"^(/static.*)$" => "$1",
"^(/favicon.ico.*)$" => "/static$1",
)
</pre>
<p>Contents of <em>/var/www/blohg.fcgi</em> (python module <a class="reference external" href="http://pypi.python.org/pypi/flup">flup</a> is needed):</p>
<pre class="brush: python">
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from blohg import create_app
if __name__ == '__main__':
application = create_app('/path/to/my_blohg')
WSGIServer(application).run()
</pre>
</div>
<div class="section" id="improvements">
<h3>Improvements</h3>
<div class="class strikeout container">
<p>In <a class="reference external" href="/post/my-server/?lang=en">post about my server</a> I wanted to make strikeout text,
but sadly reStructuredText don't support that.
I patched docutils, <a class="reference external" href="http://blog.f-y.name/attachments/docutils-0.7-strikeout.patch">here's a patch</a>.
But I want to move this functionality to blohg.</p>
<p><strong>UPD</strong>: Done, <a class="reference external" href="http://hg.f-y.name/blohg/changeset/c82ba2f18ad9">changeset</a>.</p>
</div>
<p><strong>UPD2</strong>: Done properly. <a class="reference external" href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#custom-interpreted-text-roles">There is</a> standard way to define custom roles which only adds class to <span> tag:</p>
<pre class="brush: plain">
.. role:: strikeout
:class: strikeout
</pre>
<p>Or you can add a block to container with strikeout class:</p>
<pre class="brush: plain">
.. container::
:class: strikeout
</pre>
<p>I made a fork of blohg on <a class="reference external" href="http://bitbucket.org">http://bitbucket.org</a>, to publish my changes: <a class="reference external" href="http://hg.f-y.name/blohg">fork</a>.
More precisely, I made a fork of Ry4an's repository, because Rafael serves hg repository from his own server.</p>
<p>Looked at <a class="reference external" href="http://hg.rafaelmartins.eng.br/rst-resume/">rst-resume</a>, I want to publish my resume at this site.</p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script></div>
QR-codes/post/qr-code/?lang=en2011-04-11T11:06:00Z2011-04-11T11:06:00ZAnton Novosyolovanton.novosyolov@gmail.com<!-- date: 1302519960 -->
<!-- tags: gentoo,Nokia N900,QR -->
<p>I wrote pair of scripts to tranfer small pieces of text information (e.g. URLs) from notebook to phone (Nokia N900) and vice versa.</p>
<!-- date: 1302519960 -->
<!-- tags: gentoo,Nokia N900,QR -->
<p>I wrote pair of scripts to tranfer small pieces of text information (e.g. URLs) from notebook to phone (Nokia N900) and vice versa.</p>
<!-- read_more -->
<p><em>qrcode</em> - to make QR-code (using Google Chart API) and display it:</p>
<pre class="brush: python">
#!/usr/bin/python
import sys
import webbrowser
import urllib
if len(sys.argv) == 1:
s = sys.stdin.read()
else:
s = sys.argv[1]
webbrowser.open("http://chart.apis.google.com/chart?chs=300x300&cht=qr&chl=%s" % (urllib.quote(s, safe="")))
</pre>
<p>I put this script both on the phone and on the notebook.</p>
<p>Usage:</p>
<pre class="brush: plain">
$ qrcode < file
$ qrcode text
$ qrcode
text
text2
Ctrl-D
</pre>
<p>Reading of the QR-code - on the phone I use mBarCode.</p>
<p>On the notebook - <em>qrread</em>:</p>
<pre class="brush: bash">
#!/bin/bash
trap 'xclip /tmp/qr -selection clipboard' 2
zbarcam --raw -q | tee /tmp/qr
# --nodisplay
</pre>
<p>I installed "zbar" program, for gentoo it is in "bircoph" overlay.</p>
<p>If you don't want to watch image from camera, you should uncomment "--nodisplay" parameter.</p>
<p>As soon as recognized text appears in console, you should press Ctrl-C, and it will be in clipboard.
I transferred the source of qrcode from phone to notebook using this method, for example.</p>
<p>I will change scripts to not using Google (offline). <strong>UPD</strong>: <a class="reference external" href="/post/qr-code-local/?lang=en">Done</a></p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script>Scheduled ping for monitoring network health/post/ping-monitoring/?lang=en2007-10-22T07:20:00Z2007-10-22T07:20:00ZAnton Novosyolovanton.novosyolov@gmail.com<!-- tags: gentoo,monitoring,php,bash -->
<!-- date: 1193037600 -->
<p>Ping loss is appeared in our LAN recently. To monitor this I wrote a script that pings the gateway one time in 30 minutes and shows results on my site.</p>
<!-- tags: gentoo,monitoring,php,bash -->
<!-- date: 1193037600 -->
<p>Ping loss is appeared in our LAN recently. To monitor this I wrote a script that pings the gateway one time in 30 minutes and shows results on my site.</p>
<!-- read_more -->
<p>Ping script:</p>
<pre class="brush: bash">
#!/bin/bash
fn=`date +%F.%H:%M:%S`
dir=/var/www/localhost/htdocs/ping-stat
ping -i 0.3 -c 500 10.13.0.17 > $dir/$fn.txt
tail -n 3 < $dir/$fn.txt > $dir/$fn.stat.txt
</pre>
<p><em>crontab</em>:</p>
<pre class="brush: plain">
0,30 * * * * root /path/to/script
</pre>
<p>Script to show results on my site: <em>/var/www/localhost/cgi-bin</em>:</p>
<pre class="brush: bash">
#!/bin/sh
echo "Content-type: text/html; charset=cp1251"
echo
echo "<html><body>"
echo "<a href='http://$HTTP_HOST/ping-stat-graph/packetlost.php'>Chart</a><br>"
echo "<a href='http://$HTTP_HOST/ping-stat-graph/packetlost.php?t'>Timings chart</a><br>"
echo "<form action='http://$HTTP_HOST/ping-stat-graph/packetlost.php'>"
echo "Show last records, how much <input name='s'><input type='submit' value='Show'><br>"
echo "Show last records, timings, how much <input name='s'><input type='submit' value='Show'><input type='hidden' name='t'></form>"
echo "<table>"
for i in $( find /var/www/localhost/htdocs/ping-stat/ -type f -not -name "*.stat.txt" -printf "%f\n" | sort )
do
base=`expr match "$i" '\([^.]*\.[^.]*\)'`
echo "<tr><td><a href='/ping-stat/$i'>$base</a><br></td>"
if [ -e "/var/www/localhost/htdocs/ping-stat/$base.stat.txt" ]
then
echo "<td><a href='/ping-stat/$base.stat.txt'>Briefly</a></td><tr>"
else
echo "<td>Briefly</td><tr>"
fi
done
echo "</table>"
echo "</body></html>"
</pre>
<p>Script to show chart <em>/var/www/localhost/htdocs/ping-stat-graph/packetlost.php</em> (my friend mvf is author of the script):</p>
<pre class="brush: php">
<?php
$dir = "/var/www/localhost/htdocs/ping-stat/";
$filename_date_format = "%Y-%m-%d.%H:%M:%s.";
$filename_format = "^[[:punct:][:digit:]]{14,30}\.stat\.txt$";
$file_content_format ="([[:digit:]]+) packets transmitted, ([[:digit:]]+) received, [[:digit:]]+% packet loss, time [[:digit:]]+ms[[:space:]]*rtt min/avg/max/mdev = ([[:digit:]\.]+)/([[:digit:]\.]+)/([[:digit:]\.]+)/([[:digit:]\.]+) ms";
/////////////////////////////////////////////////////////////////
// Returns a date from a string based on a given format
function parseDate( $date, $format )
{
// Builds up date pattern from the given $format, keeping delimiters in place.
if( !preg_match_all( "/%([YmdHMs])([^%])*/", $format, $formatTokens, PREG_SET_ORDER ) ) {
return false;
}
$datePattern = "";
foreach( $formatTokens as $formatToken )
{
$delimiter = preg_quote( $formatToken[2], "/" );
if($formatToken[1] == 'Y') {
$datePattern .= '(.{1,4})'.$delimiter;
} else {
$datePattern .= '(.{1,2})'.$delimiter;
}
}
if( !preg_match( "/".$datePattern."/", $date, $dateTokens) ) return false;
$dateSegments = array();
for($i = 0; $i < count($formatTokens); $i++) {
$dateSegments[$formatTokens[$i][1]] = $dateTokens[$i+1];
}
return mktime ( $dateSegments["H"], $dateSegments["M"], $dateSegments["s"], $dateSegments["m"], $dateSegments["d"], $dateSegments["Y"]);
}
/////////////////////////////////////////////////////////////////
// for usort
function cmp_by_date($a, $b)
{
if ($a['time'] == $b['time']) { return 0; }
return ($a['time'] < $b['time']) ? -1 : 1;
}
////////////////////////////////////////////////////////////////
//// begin
////////////////////////////////////////////////////////////////
$filenames = scandir($dir);
$data = array();
foreach ($filenames as $filename)
{
$full_name = $dir.$filename;
if (!is_dir($full_name) && $filename != "." && $filename != ".." && ereg($filename_format, $filename))
{
$ftime = parseDate($filename, $filename_date_format);
ereg($file_content_format,file_get_contents($full_name),$res);
$data_piece['time'] = $ftime;
$data_piece['time_text'] = date("H:i",$ftime);
if ($res[1]!=0) $data_piece['lost'] = (1 - $res[2]/$res[1])*100; else $data_piece['lost'] = 100;
$data_piece['transmitted'] = $res[1]+0;
$data_piece['received'] = $res[2]+0;
$data_piece['min'] = $res[3]+0.0;
$data_piece['avg'] = $res[4]+0.0;
$data_piece['max'] = $res[5]+0.0;
$data_piece['mdev'] = $res[6]+0.0;
$data[] = $data_piece;
} // if (!is_dir ...
} // foreach ($filenames
usort($data, "cmp_by_date");
if (isset($_GET['s'])) // if "how much" is present
{
$size = count($data);
$disired_size = 0 + $_GET['s'];
$croppoint = $size - $disired_size;
if ($croppoint < 0) $croppoint = 0;
$data = array_slice($data, $croppoint);
}
require('chart.php');
$time_min = array();
$time_max = array();
$time_avg = array();
$x_axis = array();
$lost = array();
foreach ($data as $data_piece)
{
$time_min[] = $data_piece['min'];
$time_max[] = $data_piece['max'];
$time_avg[] = $data_piece['avg'];
$x_axis[] = $data_piece['time_text'];
$lost[] = $data_piece['lost'];
}
//plot (array $c1, array $c2 = false, color $color = "black",
// string $style = "lines", color $gradient_color = "black",
// int $parameter = 0)
if (isset($_GET['t']))
{
$chart = new chart(2000, 500);
$chart->set_title("Ping timing (10.13.0.17 from 10.13.200.111)");
$chart->set_x_ticks ($x_axis,"text");
$chart->set_labels ("time", "ping, ms");
$chart->set_margins ($left = 50, $right = 10, $top = 20, $bottom = 43);
$chart->plot($time_max, false, "black");
$chart->add_legend("Max");
$chart->plot($time_avg, false, "red", "gradient");
$chart->add_legend("Avg", "red");
$chart->plot($time_min, false, "blue", "gradient");
$chart->add_legend("Min", "blue");
$chart->stroke();
} else
{
$chart = new chart(2000, 500);
$chart->set_title("Packet lost (10.13.0.17 from 10.13.200.111)");
$chart->set_x_ticks ($x_axis,"text");
$chart->set_labels ("time", "lost, %");
$chart->set_margins ($left = 50, $right = 10, $top = 20, $bottom = 43);
$chart->plot($lost, false, "black");
$chart->stroke();
}
?>
</pre>
<p>Library <a class="reference external" href="http://quimby.gnus.org/circus/chart/chart-manual.php">chart</a> is used for result displaying.</p>
<p>Result you can see <a class="reference external" href="http://fyfd.homeip.net/cgi-bin/ping-stat"><span class="strikeout">here</span></a> (unneeded now).</p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script>Script to download structure of ftp-server/post/ftp-scrap/?lang=en2007-10-19T18:13:00Z2007-10-19T18:13:00ZAnton Novosyolovanton.novosyolov@gmail.com<!-- date: 1192817580 -->
<!-- tags: gentoo,bash,ftp -->
<p>I decided to write this script to look at contents (filenames) of some our rich ftp-servers, without connection.</p>
<!-- date: 1192817580 -->
<!-- tags: gentoo,bash,ftp -->
<p>I decided to write this script to look at contents (filenames) of some our rich ftp-servers, without connection.</p>
<!-- read_more -->
<p>I spent many time in "perversions" with bash, until I discovered IFS variable :)</p>
<p>Here is my script:</p>
<p><em>get_listing</em>:</p>
<pre class="brush: bash">
#!/bin/bash
if [ "$1" == "" ]
then
echo "Usage: `basename $0` server"
exit
fi
server=$1
base=$PWD
IFS=$'\n'
function get_listing()
{
local prev_dir=$PWD
local url=
if [ "$1" != "" ]
then
url=$1
echo "Creating dir: $2"
mkdir "$2"
cd "$2"
fi
echo "Retreiving file list $url"
curl ftp://$server$url/ 2 > /dev/null > listing
lst=`cat listing | grep "^d" | grep -v "\.$" | xargs -I'{}' $base/get_fname "{}"`
for f in $lst
do
get_listing "${url}/$f" "$f"
done
cd $prev_dir
}
get_listing
</pre>
<p><em>get_fname</em>:</p>
<pre class="brush: bash">
#!/bin/bash
echo `expr match "$1" '\\S*\\s*\\S*\\s*\\S*\\s*\\S*\\s*\\S*\\s*\\S*\\s*\\S*\\s*\\S*\\s*\(.*\)'`
</pre>
<p>I don't know how to insert <em>get_fname</em> into main script...
I tried $() inside ``, vise versa, nothing helped...</p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script>My server/post/my-server/?lang=en2007-10-11T21:45:00Z2007-10-11T21:45:00ZAnton Novosyolovanton.novosyolov@gmail.com<!-- date: 1192139100 -->
<!-- tags: gentoo -->
<p>That bot and many other goodies I run on my home-server.
Need of it was emerged when more than one computer was appeared at my home.</p>
<!-- date: 1192139100 -->
<!-- tags: gentoo -->
<p>That bot and many other goodies I run on my home-server.
Need of it was emerged when more than one computer was appeared at my home.</p>
<!-- read_more -->
<p>At first I bought wireless router (D-Link DI-624). Unfortunately, as it turned out later, I can't fully use my home network (Corbina-Yaroslavl): it is impossible to remain both in LAN and on the Internet at the same time (Internet is accessed via VPN, router doesn't support static routes :(, and I can't connect to VPN from more than one computer - it's limit of the provider).</p>
<p>Therefore I decided to buy old computer. I installed Linux on it, supplied it with 3 network cards and made it a router.</p>
<p>Initially I bought Pentium II, 400 MHz, 80 Gb, 128 Mb. Later I changed it to P4-2000, 512 Mb (I carried Linux with hard-disk to new computer without any problems - that's good :) ).</p>
<p>And now it's good that router was so weak - with normal home server I can do many interesting things :)</p>
<p>These thing are installed on it at this time:</p>
<ol class="arabic simple">
<li>Router - iptables, NAT</li>
<li>Web-server</li>
<li>ftp-server</li>
<li>jabber-server</li>
<li>mail-server (at this time it doesn't work, I don't need it actually, but I want to bring it to normal state)</li>
<li>IRC-bot (I had to turn it off, because inter-LAN IRC-server doesn't allow to enter more than 1 or 2 clients from one IP)</li>
<li>icq-bot</li>
<li>World of Warcraft-server (it was on P2 already, it eats about 400 megabytes of memory easily :) )</li>
<li>MySQL</li>
<li>If I remember, I will add more here...</li>
</ol>
<p>Also I plan to make:</p>
<ol class="arabic simple">
<li>Video-broadcasting (TV-tuner is installed on the server), using VLC, or something like it</li>
<li>Something about VoIP (I don't have any definite ideas)</li>
<li>Smart-house (X10-protocol)</li>
<li>I plan to move to unlimited plan, and setup web-interface for downloader (mldonkey)</li>
</ol>
<p>BTW, URL of server is <span class="strikeout">http://fyfd.homeip.net/</span> <a class="reference external" href="http://server.f-y.name">http://server.f-y.name</a></p>
ICQ-bot based on micq/post/icq-bot/?lang=en2007-10-11T08:02:00Z2007-10-11T08:02:00ZAnton Novosyolovanton.novosyolov@gmail.com<!-- date: 1192089720 -->
<!-- tags: gentoo,linux,icq,bot,perl -->
<p>I decided to make ICQ-bot, mostly for ping servers in home network using ICQ.</p>
<!-- date: 1192089720 -->
<!-- tags: gentoo,linux,icq,bot,perl -->
<p>I decided to make ICQ-bot, mostly for ping servers in home network using ICQ.</p>
<!-- read_more -->
<p>Micq has such power thing as scripting. By default, named pipe ~/.micq/scripting is created after micq has started. If you write into it, this is as if you enter into micq console. Thus we have one side of interaction. To receive commands we'll read logs of conversations from <em>history</em> dir.</p>
<p>I wrote script in perl using File::Tail module.</p>
<p>Log file has such format:</p>
<pre class="brush: plain">
# 20070629123241/ [icq8:xxxxxxxx]!icqbot@foreveryoung.yar <- xxxxxxxxx[icq8:xxxxxxxxx+10000000 online] +1
</pre>
<p>+1 - means how many lines of message follows.</p>
<p>Here is the script:</p>
<pre class="brush: perl">
#!/usr/bin/perl
$_ = 1;
exit if( $#ARGV < 2 )
name = "/home/icqbot/.micq/history/${ARGV[0]}.log"
file = File::Tail->new( name=>$name, maxinterval=>1, interval=>1, reset_tail=>0 );
open LOG, ">>${ARGV[0]}_bot.log";
$skip = 0;
$cmd = 0;
while( defined( $_ = $file->read ) )
{
if( $skip > 0 )
{
$skip--;
next;
}
# this is sent by bot, just skip
if( $_ =~ /# \d+\/ \[[^]]+\]\S+ -> [^[]*\[[^]]+\] [+](\d+)/ )
{
$skip = $1;
$cmd = 0;
next;
}
# after this maybe goes command
if( $_ =~ /# \d+\/ \[[^]]+\]\S+ <- [^[]*\[[^]]+\] [+](\d+)/ )
{
$cmd = 1;
next;
}
if( !$cmd )
{
next;
}
if( $_ =~ /^ping (.+)$/ )
{
print LOG "Pinging $1\n";
$ping = `ping -c 10 $1 2>&1`;
open OUT, ">.micq/scripting";
print OUT "/msg ${ARGV[0]}\n";
print OUT $ping;
print OUT ".\n";
close OUT;
next;
}
}
</pre>
<p>To run script: <tt class="docutils literal">script &</tt></p>
<p>micq is launched under <a class="reference external" href="http://en.wikipedia.org/wiki/GNU_Screen">screen</a>.</p>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();</script>