Monday, February 6, 2012

Using ZNC to keep you signed in on an IRC channel

In my study group at the University we are using IRC to communicate with each other. We have a channel set up on irc.freenode.net, so that it is only to be used by us.

The problem with IRC is, that if you are not logged in at the time another group member posts a message, you do not receive the message.

There are basically two ways to fix this, both including having access to an external server:

  1. Have a console based IRC client running on an external server and SSH into this server.
  2. Have a 'bot' always be logged in to the channel, and record the action happening there.

Since many of the members of my study group are not comfortable with the terminal, we settled for the second solution, using a service called znc. Here Is how to set it up for several users:

Setting up ZNC for multiple users:

First you have to SSH into the server you are using to record the IRC actions and install znc on it. Assuming it's a Linux server, it should be in the distro's repositories.

Now you have to set up znc - first for a single user, since for several users editing the configuration file created. Follow the instructions on the screen. Here's how I set it up (these steps are quite obvious/individual so you can probably skip reading the bullets and follow the guidance on-screen):

  • What port would you like ZNC to listen on? 65000
  • Would you like ZNC to listen using SSL? (yes/no) [no]: no
  • Would you like ZNC to listen using ipv6? (yes/no) [yes]: yes
  • Listen Host (Blank for all ips): (blank)
  • Load global module <partyline>? (yes/no) [no]: yes
  • Load global module <webadmin>? (yes/no) [no]: no
  • Username (AlphaNumeric): myusername
    • This is the username you use when you log on to znc through your client
  • Enter Password: mypassword
  • Confirm Password: mypassword
    • Likewise, password used when you log into znc
  • Would you like this user to be an admin? (yes/no) [yes]: yes
  • Nick [myusername]: mynick
  • Alt Nick [mynick_]: mynick_
  • Ident [mynick]:mynick
  • Real Name [Got ZNC?]: My Real Name
    • Nickname, alternative nicknames and real name on IRC
  • Bind Host (optional): (blank)
  • Number of lines to buffer per channel [50]: 5000
    • Number of lines to record in channel when you're away
  • Would you like to keep buffers after replay? (yes/no) [no]: yes
  • Default channel modes [+stn]: (blank)
  • Load module <admin>? (yes/no) [no]: no
  • Load module <chansaver>? (yes/no) [no]:no
  • Load module <keepnick>? (yes/no) [no]: no
  • Load module <kickrejoin>? (yes/no) [no]: no
  • Load module <nickserv>? (yes/no) [no]: no
  • Load module <perform>? (yes/no) [no]: no
  • Load module <simple_away>? (yes/no) [no]: no
    • These modules can be added if you want to :)
  • IRC server (host only): irc.freenode.net
    • Where your IRC is hosted
  • [irc.freenode.net] Port (1 to 65535) [6667]: 6667
  • [irc.freenode.net] Password (probably empty): (blank)
  • Does this server use SSL? (yes/no) [no]: no
  • Would you like to add another server for this IRC network? (yes/no) [no]: no
  • Would you like to add a channel for ZNC to automatically join? (yes/no) [yes]: yes
  • Channel name: #archlinux
    • This is where you put your channel to connect to - i our case it's our internal IRC, but for demonstration purposes I will use the #archlinux channel.
  • Would you like to add another channel? (yes/no) [no]: no
  • Would you like to set up another user (e.g. for connecting to another network)? (yes/no) [no]: no
    • I find it easier to just copy and paste from the config file
  • Launch ZNC now? (yes/no) [yes]: no

Now we need to edit the config file, to add all users. Open the file ~/.znc/configs/znc.conf using a text editor. It should look something like this:

// WARNING
//
// Do NOT edit this file while ZNC is running!
// Use webadmin or *admin instead.
//
// Buf if you feel risky, you might want to read help on /znc saveconfig and /znc rehash.
// Also check http://en.znc.in/wiki/Configuration

Listener   = 65000
LoadModule = partyline

<User myusername>
  Pass       = sha256#8947e2b4df7bde63624258d83dea6a35004ee8b7693ec64dd941e2401bbda08e#4sCV(V3I9kP,/Qw5t(Z8#
  Admin      = true
  Nick       = mynick
  AltNick    = mynick_
  Ident      = mynick
  RealName   = My Real Name
  Buffer     = 5000
  KeepBuffer = true
  ChanModes  = +stn


  Server     = irc.freenode.net 6667 

  <Chan #archlinux>
  </Chan>
</User>

Now we just copy the whole everything between <user> and </user>, to add a new user. I will now make a user called myuser2, with the nickname mynick2 etc.

As we see, the password has been encrypted. To generate and encrypted password for the new user (his password will be password2), we need to exit the text editor, and run the command

znc --makepass

This prompts for a password, and returns the the encrypted password to be included in the config-file.

Having copied the <user>-part and inserted the new password, the znc.conf file looks like this:


// WARNING
//
// Do NOT edit this file while ZNC is running!
// Use webadmin or *admin instead.
//
// Buf if you feel risky, you might want to read help on /znc saveconfig and /znc rehash.
// Also check http://en.znc.in/wiki/Configuration

Listener   = 65000
LoadModule = partyline

<User myusername>
  Pass       = sha256#8947e2b4df7bde63624258d83dea6a35004ee8b7693ec64dd941e2401bbda08e#4sCV(V3I9kP,/Qw5t(Z8#
  Admin      = true
  Nick       = mynick
  AltNick    = mynick_
  Ident      = mynick
  RealName   = My Real Name
  Buffer     = 5000
  KeepBuffer = true
  ChanModes  = +stn


  Server     = irc.freenode.net 6667 

  <Chan #archlinux>
  </Chan>
</User>
<User myusername2>
  Pass = sha256#c1e227a2d69d258630726e161b7d9d2c0edf47b92ddfe96ed10face08fe2ac2a#s(P;8wZ-w+s8)WuOCVNF#
  Admin      = true
  Nick       = mynick2
  AltNick    = mynick2_
  Ident      = mynick2
  RealName   = My Real Name2
  Buffer     = 5000
  KeepBuffer = true
  ChanModes  = +stn


  Server     = irc.freenode.net 6667 

  <Chan #archlinux>
  </Chan>
</User>

Now we can start the znc service, and connect to our channel through any IRC client (supporting SSL). Start znc by running:

znc

Connencting to IRC channel through ZNC using IRSSI:

For demonstrations, lets say the domain, where the znc-server is hosted, is irc.mydomain.com. Then you connect to your znc in IRSSI using the following command:

/connect -ssl irc.mydomain.com 65000 myusername:mypassword

To automatically use these informations as you start IRSSI, execute the following line in IRSSI:

/server add -auto -network mynetwork -ssl irc.mydomain.com 65000 myuser:mypassword

You can of course use any client you want, but remember to use SSL for the connection. Also a weak certificate may be used, so just ignore this.

simple_away

Additionally, you can load the module simple_away. This marks the user away when he/she logs out of znc, by closing the client for example. To add the module, the following line needs to be added inside every <user>, who needs the module (it could be the line before "Server = ..." above, in the example above).

  LoadModule = simple_away -timer 0

The 0 after timer is the number of second from the user logs out 'till the /away-command is executed.

No comments:

Post a Comment