Licensed under GPLv3 or later, cleanup
This commit is contained in:
parent
ef70a0f20b
commit
77287d9e62
|
@ -1,184 +0,0 @@
|
||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
# Reconnecting to IRC-Server
|
|
||||||
# Complete switched networks
|
|
||||||
# Reduce debug output / add good output
|
|
||||||
# For more security use packet id + srcnick as key for fragmented packages
|
|
||||||
|
|
||||||
from conf import *
|
|
||||||
import pytap
|
|
||||||
from pytap import TapDevice
|
|
||||||
import select
|
|
||||||
import time
|
|
||||||
import irclib
|
|
||||||
import commands
|
|
||||||
import re
|
|
||||||
import base64
|
|
||||||
import random
|
|
||||||
|
|
||||||
dev = None
|
|
||||||
headerlen = 1 + 5 + 1 # flag + number + whitespace
|
|
||||||
packets = {}
|
|
||||||
|
|
||||||
def getMacFromIf(iface):
|
|
||||||
mac = commands.getoutput("/sbin/ifconfig %s|grep %s|egrep -o '([a-fA-F0-9]{2}(:|.)){6}'" % (iface, iface))
|
|
||||||
print "Debug: %s has mac address %s" % (iface, mac)
|
|
||||||
return mac
|
|
||||||
|
|
||||||
def getDstMacFromPkt(packet):
|
|
||||||
if len(packet) < 10:
|
|
||||||
return None
|
|
||||||
return packet[4:10]
|
|
||||||
|
|
||||||
def binToHexStr(binmac):
|
|
||||||
return "".join(["%02x" % ord(i) for i in binmac])
|
|
||||||
|
|
||||||
def isBroadcast(packet):
|
|
||||||
binmac = getDstMacFromPkt(packet)
|
|
||||||
# normal broadcast
|
|
||||||
if binmac == '\xff\xff\xff\xff\xff\xff':
|
|
||||||
return True
|
|
||||||
# v6 multicast
|
|
||||||
if binmac.startswith('\x33\x33'):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def sendToIRC(dev, server):
|
|
||||||
msg = dev.read()
|
|
||||||
oldencmsg = encmsg = base64.encodestring(msg).replace("\n", "")
|
|
||||||
slices = []
|
|
||||||
encmsglen = ircmsglen-headerlen
|
|
||||||
msgid = "%05d" % random.randint(0, 99999)
|
|
||||||
while len(encmsg) > encmsglen:
|
|
||||||
slices.append(encmsg[:encmsglen])
|
|
||||||
encmsg = encmsg[encmsglen:]
|
|
||||||
slices.append(encmsg)
|
|
||||||
|
|
||||||
# HUB or SWITCH?
|
|
||||||
if mode == "SWITCH" and not isBroadcast(package):
|
|
||||||
target = "VPN-%s" % (binToHexStr(getDstMacFromPkt(packet)),)
|
|
||||||
else:
|
|
||||||
target = broadcastchan
|
|
||||||
|
|
||||||
if len(slices) == 0:
|
|
||||||
print "DEBUG: EMPTY PACKAGE FROM DEV?"
|
|
||||||
elif len(slices) == 1:
|
|
||||||
print "Debug: Sending oneliner to dev"
|
|
||||||
server.privmsg(target, "o%s %s" % (msgid, slices[0]))
|
|
||||||
else:
|
|
||||||
print "Debug: Sending fragmented package to dev"
|
|
||||||
print " ---- COMPLETE MESSAGE BEFORE SLICES ---- "
|
|
||||||
print oldencmsg
|
|
||||||
print " ---- SLICES SLICES SLICES ---- "
|
|
||||||
print "\n".join(slices)
|
|
||||||
print " ---- SLICES SLICES SLICES ---- "
|
|
||||||
server.privmsg(target, "b%s %s" % (msgid, slices.pop(0)))
|
|
||||||
while len(slices) > 1:
|
|
||||||
server.privmsg(target, "c%s %s" % (msgid, slices.pop(0)))
|
|
||||||
server.privmsg(target, "e%s %s" % (msgid, slices.pop(0)))
|
|
||||||
|
|
||||||
def sendToDev(dev, server, isBroadcast, c, e):
|
|
||||||
parsed = pkgre.match(e.arguments()[0])
|
|
||||||
if not parsed:
|
|
||||||
print "message could not be parsed", e.arguments()[0]
|
|
||||||
return
|
|
||||||
(flag, msgid, basemsg) = parsed.groups()
|
|
||||||
print "flag: %s msgid: %s msg: %s" % (flag, msgid, basemsg)
|
|
||||||
try:
|
|
||||||
msgid = int(msgid)
|
|
||||||
except ValueError:
|
|
||||||
print "Debug: messageid was not a number"
|
|
||||||
return
|
|
||||||
if not ignoreNonMacUser:
|
|
||||||
# FIXME: ignore the non prefix-mac user
|
|
||||||
if not nickre.match():
|
|
||||||
print "is not allowed in our network"
|
|
||||||
print e.arguments(), irclib.nm_to_n(e.source()), e.target()
|
|
||||||
if flag == "o":
|
|
||||||
# oneliner!
|
|
||||||
print "Debug: Writing onliner to dev"
|
|
||||||
try:
|
|
||||||
msg = base64.decodestring(basemsg)
|
|
||||||
except base64.binascii.Error, e:
|
|
||||||
print "Debug: Error decoding base64 irc message (%s)" % e
|
|
||||||
return
|
|
||||||
#FIXME if packetAllowed(, , chan)
|
|
||||||
dev.write(msg)
|
|
||||||
elif flag == 'b':
|
|
||||||
if packets.has_key(msgid):
|
|
||||||
print "Warning: Overwriting lost package with id %s" % msgid
|
|
||||||
packets[msgid] = basemsg
|
|
||||||
elif flag in ('c', 'e'):
|
|
||||||
if not packets.has_key(msgid):
|
|
||||||
print "Error: Continue package has no matching entry in packets, discarding!"
|
|
||||||
else:
|
|
||||||
packets[msgid] += basemsg
|
|
||||||
if flag == 'e':
|
|
||||||
arrmsg = packets[msgid]
|
|
||||||
del(packets[msgid])
|
|
||||||
try:
|
|
||||||
print "arrmsg is", arrmsg.replace("\n", "\n\n\n")
|
|
||||||
msg = base64.decodestring(arrmsg)
|
|
||||||
except base64.binascii.Error, e:
|
|
||||||
print "Debug: Error decoding base64 irc message (%s)" % e
|
|
||||||
return
|
|
||||||
print "Debug: writing fragmented package to dev"
|
|
||||||
print binToHexStr(msg)
|
|
||||||
dev.write(msg)
|
|
||||||
#print "GOT in %s (broadcast %s) from %s msg %s" (e.target(), isBroadcast, irclib.nm_to_n(e.source()), e.arguments()[0])
|
|
||||||
|
|
||||||
def packetAllowed(src, nick, packet):
|
|
||||||
if not acceptNonMatchingMac:
|
|
||||||
# check if user-mac == packetmac
|
|
||||||
# FIXME if not getDstMacFromPkt(packet) ==
|
|
||||||
pass
|
|
||||||
# FIXME: Maybe move nick check to here
|
|
||||||
if mode != "HUB" and strictSwichedNetwork:
|
|
||||||
if src.startswith("#"): # its a channel
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def startup():
|
|
||||||
# setup the tap device
|
|
||||||
dev = TapDevice(pytap.IFF_TAP)
|
|
||||||
dev.ifconfig(address=ip, netmask=netmask)
|
|
||||||
if gateway != "":
|
|
||||||
print "Setting default route %s" % gateway
|
|
||||||
os.sys("route add default gw %s")
|
|
||||||
|
|
||||||
# setup IRC foo
|
|
||||||
ircnick = nickPrefix + getMacFromIf(dev.name).replace(":", "")
|
|
||||||
print "Debug: Connectiong to %s as %s" % (ircserver, ircnick)
|
|
||||||
|
|
||||||
irc = irclib.IRC()
|
|
||||||
irc.add_global_handler("privmsg", lambda c, e: sendToDev(dev, server, False, c, e), -20)
|
|
||||||
irc.add_global_handler("pubmsg", lambda c, e: sendToDev(dev, server, True, c, e), -20)
|
|
||||||
server = irc.server()
|
|
||||||
server.connect(ircserver[0], ircserver[1], ircnick)
|
|
||||||
server.join(broadcastchan)
|
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
sockets = [dev.__fd__]
|
|
||||||
# get private irc sockets :)
|
|
||||||
sockets.extend(map(lambda x: x._get_socket(), irc.connections))
|
|
||||||
sockets = filter(lambda x: x != None, sockets)
|
|
||||||
print "sockets", sockets
|
|
||||||
(readFDs, _, _) = select.select(sockets, [], [])
|
|
||||||
for readFD in readFDs:
|
|
||||||
print "EVENT BY", readFD
|
|
||||||
if readFD == dev.__fd__:
|
|
||||||
sendToIRC(dev, server)
|
|
||||||
else:
|
|
||||||
print "IRC event"
|
|
||||||
irc.process_once(0.1)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
print "Shutting down!"
|
|
||||||
server.quit("RST")
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
startup()
|
|
|
@ -1,19 +1,23 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("../../../")
|
sys.path.append("../../../")
|
||||||
|
|
||||||
from ether2any import Ether2Any
|
|
||||||
|
import base64
|
||||||
|
import irclib
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
import random
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
from conf import Conf
|
from conf import Conf
|
||||||
import time
|
from ether2any import Ether2Any
|
||||||
import irclib
|
|
||||||
import re
|
|
||||||
import base64
|
|
||||||
import random
|
|
||||||
import logging
|
|
||||||
import subprocess
|
|
||||||
from ether2any.helper import getDstMacFromPkt, isBroadcast, binToHexStr
|
from ether2any.helper import getDstMacFromPkt, isBroadcast, binToHexStr
|
||||||
|
|
||||||
class IrcVPN(Ether2Any):
|
class IrcVPN(Ether2Any):
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import irclib
|
import irclib
|
||||||
from conf import Conf
|
from conf import Conf
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import time
|
|
||||||
import struct
|
|
||||||
import base64
|
import base64
|
||||||
import StringIO
|
import gobject
|
||||||
|
import gtk
|
||||||
|
import mutex
|
||||||
import opencv
|
import opencv
|
||||||
from opencv import highgui, adaptors
|
from opencv import highgui, adaptors
|
||||||
import qrencode
|
import os
|
||||||
import zbar
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import gtk
|
import qrencode
|
||||||
import gobject
|
|
||||||
import urllib
|
|
||||||
import socket
|
|
||||||
import subprocess
|
|
||||||
import Queue
|
import Queue
|
||||||
|
import re
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
import StringIO
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import mutex
|
import time
|
||||||
|
import urllib
|
||||||
|
import zbar
|
||||||
|
|
||||||
sys.path.append("../../../")
|
sys.path.append("../../../")
|
||||||
from ether2any import Ether2Any
|
from ether2any import Ether2Any
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import pyudev
|
import pyudev
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import time
|
|
||||||
import asyncore
|
import asyncore
|
||||||
|
import email
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
import imaplib
|
||||||
import select
|
import select
|
||||||
import smtpd
|
import smtpd
|
||||||
import smtplib
|
import smtplib
|
||||||
import imaplib
|
import time
|
||||||
import email
|
|
||||||
from email.mime.text import MIMEText
|
|
||||||
import threading
|
import threading
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("../../../")
|
sys.path.append("../../../")
|
||||||
|
|
||||||
from wtbase import SpamGenerator, DecodingException
|
|
||||||
from ether2any import Ether2Any
|
from ether2any import Ether2Any
|
||||||
from ether2any.helper import getDstMacFromPkt, isBroadcast, binToHexStr
|
from ether2any.helper import getDstMacFromPkt, isBroadcast, binToHexStr
|
||||||
from conf import Conf, ENCRYPTION_NONE, ENCRYPTION_STARTTLS, ENCRYPTION_SSL
|
from conf import Conf, ENCRYPTION_NONE, ENCRYPTION_STARTTLS, ENCRYPTION_SSL
|
||||||
|
from wtbase import SpamGenerator, DecodingException
|
||||||
|
|
||||||
# Todo
|
# Todo
|
||||||
# Error checking at some places
|
# Error checking at some places
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
""" wtbase - what the base
|
""" wtbase - what the base
|
||||||
Provides classes to encode text to arbitrary bases (base 2^n supported) and
|
Provides classes to encode text to arbitrary bases (base 2^n supported) and
|
||||||
then to textual forms. """
|
then to textual forms. """
|
||||||
|
|
||||||
|
from collections import deque
|
||||||
import math
|
import math
|
||||||
from random import randint, randrange
|
from random import randint, randrange
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from collections import deque
|
|
||||||
|
|
||||||
class DecodingException(Exception):
|
class DecodingException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import pyudev
|
import pyudev
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -11,9 +14,9 @@ import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
sys.path.append("../../../")
|
sys.path.append("../../../")
|
||||||
|
|
||||||
from conf import Conf
|
from conf import Conf
|
||||||
from ether2any import Ether2Any
|
from ether2any import Ether2Any
|
||||||
|
|
||||||
class USBWriter(threading.Thread):
|
class USBWriter(threading.Thread):
|
||||||
def __init__(self, dev, networkQueue, writeLock):
|
def __init__(self, dev, networkQueue, writeLock):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import bitarray
|
import bitarray
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
from HTMLParser import HTMLParser
|
|
||||||
|
|
||||||
class PHelper():
|
class PHelper():
|
||||||
""" Packaging Helper baseclass """
|
""" Packaging Helper baseclass """
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
|
||||||
|
# Licensed under GPL v3 or later
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import collections
|
import collections
|
||||||
|
@ -11,7 +14,6 @@ import time
|
||||||
import tweepy
|
import tweepy
|
||||||
|
|
||||||
sys.path.append("../../../")
|
sys.path.append("../../../")
|
||||||
|
|
||||||
from conf import Conf
|
from conf import Conf
|
||||||
from ether2any import Ether2Any
|
from ether2any import Ether2Any
|
||||||
|
|
||||||
|
@ -24,7 +26,7 @@ class TwittStreamHandler(tweepy.StreamListener):
|
||||||
self.coder = coder
|
self.coder = coder
|
||||||
|
|
||||||
def on_status( self, status ):
|
def on_status( self, status ):
|
||||||
""" On statis, decode and reassemble packet-status-texts. If complete, write them to the tun-dev. """
|
""" On status, decode and reassemble packet-status-texts. If complete, write them to the tun-dev. """
|
||||||
|
|
||||||
sourcePacket = status.text
|
sourcePacket = status.text
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
|
Loading…
Reference in New Issue