Archiv der Kategorie: Development

Setting up moin2.0 Development environment

Now this is gonna be my first article in english so please don’t be mad about
that bad spelling ;). So today im going to tell you how to setup moin2.0
Wikiengine for development. Because i had to figure it out myself i thought
its going to be easier for other people if they don’t have to reinvent the
weel once again. Okay now lets start to set things up. First you have to clone
the moin2.0 devel repository it’s hosted on bitbucket so you might have to install
mercurial first. On Debian based machines it works most of the time simply just to
apt-get the mercurial pagacket:

 sudo apt-get install mercurial

When this is done you can go ahead and clone the devel repo (you might first want to
change to the directory where you want to clone the repo e.g /home/user/Development):

hg clone ssh://hg@bitbucket.org/thomaswaldmann/moin-2.0

Generating the html doc’s

In my case i had to build the doc’s first because i needed orientation for the Moin2.0
structure and how it works internaly. So i needed to install the sphinx package first
(MoinMoin2.0 uses sphinx documentation builder for doc generation):

sudo apt-get install python-sphinx 

in my case it worked out for me so i could go ahead and generate the html doc’s.
The documentation files in the Moin2.0 repo are usually in the „docs“ directory
so you have to go into that directory and type:

make html

This builds the html doc file’s. You could also buld latex documentation and
some other’s, you can give yourself an overview just by typing:

 make help 

Output:

  dirhtml    to make HTML files named index.html in directories
  singlehtml to make a single large HTML file
  pickle     to make pickle files
  json       to make JSON files
  htmlhelp   to make HTML files and a HTML help project
  qthelp     to make HTML files and a qthelp project
  devhelp    to make HTML files and a Devhelp project
  epub       to make an epub
  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
  latexpdf   to make LaTeX files and run them through pdflatex
  text       to make text files
  man        to make manual pages
  texinfo    to make Texinfo files
  info       to make Texinfo files and run them through makeinfo
  gettext    to make PO message catalogs
  changes    to make an overview of all changed/added/deprecated items
  linkcheck  to check all external links for integrity
  doctest    to run all doctests embedded in the documentation (if enabled)

It can take a while to build the docs so be patient. Sphinx might also complains
about missing python libary’s but don’t bother about that, they might not be
nessesary for your development works with Moin. And also the moin2.0 repo comes
with all Core documentation files for generating at least the most important parts
of the documentation.

Setting up Moin2.0 for development

Just run the quickinstall.sh Script in the root of the repository, it takes
a while to get and install all the packages. Thats also because the Script
installes a virtuel environment, so that you can allways just clone the repo
set it up and start writing code. Also all the depencys are setup in the right
way. When the Script is done you can change into the virtual environment simply
by dropping this one:

source env/bin/activate

Your prompt should now look something like this:

(env)cosmo@lazerbeam ~/Development/python/moin-2.0 $

Now you are in the virtual environment and now some commands should be dropped:

moin index-create -s -i 

for creating the initial index, otherwise the wiki won’t come up. And for some
initial content:

 moin load --file contrib/serialized/items.moin 

And finally building the index you just created:

 moin index-build 

Creating a development Setup

So now i wantet to do an development setup for moin, so i wanted to enable
debugging of course. So i created two new files in the basepath of the repo,
the first file is called „wikiconfig_local.py“ and the second is called
„wikiconfig_editme.py“. The content of wikiconfig_local goes as follows:


from wikiconfig_editme import *

this simply loads the wikiconfig_editme file. The contents of the wikiconfig_editme.py
looks something like this:

from wikiconfig import *
#import wikiconfig.py

class LocalConfig(Config):
    configuration_item_1 = 'value1'

MOINCFG = LocalConfig
DEBUG = True

(Taken from the original wikiconfig.py file). So now we have our development setup
ready we can try to start the local moin development server (usually runs on 127.0.0.1:8080)
Wich is quite easy just run the „moin“ command and the server should come up. Alternatively
you also can pass the moin command the help key word so some help should come up:


$ moin help
  account_create              This command allows you to create a user account
  account_disable             This command allows you to disable user accounts.
  account_password            This command allows you to set a user password.
  import19                    Import data from a moin 1.9 wiki.
  index-build                 Build the indexes.
  index-create                Create empty indexes.
  index-destroy               Destroy the indexes.
  index-dump                  Dump the indexes in readable form to stdout.
  index-move                  Move the indexes from the temporary to the normal location.
  index-optimize              Optimize the indexes.
  index-update                Update the indexes.
  item-get                    Get an item revision from the wiki.
  item-put                    Put an item revision into the wiki.
  ... 
 

When you want to start development actively a good starting point in the docs is:

docs/_build/html/devel/development.html

Wich holds all the neccesary information for upcoming devlopers.

Weblinks

MoinMoin Homepage
Moin2.0 Dev repository: http://hg.moinmo.in/moin/2.0
Online docs‘: http://readthedocs.org/docs/moin-20/en/latest/
Issue tracker: http://bitbucket.org/thomaswaldmann/moin-2.0/issues
And for code reviews use http://codereview.appspot.com/

Getaggt mit , , , , ,

Spass mit notify

Heute schreibe ich ein wenig über die Python Bibliothek pyinotify, welche das Inotify Kernel Feature aufsetzt. Inotify ist ein Mechanismus welcher seit demKernel release 2.6.13 in den Vanilla Kernel Quellen vorhanden ist. Welcher eine permanente Überwachung von Dateien und Verzeichnissen ermöglicht. Ändert sich eine überwachte Datei oder Verzeichnis gibt Inotify eine Meldung aus, welche andere Programme zu bestimmten Tätigkeiten veranlassen kann.Quelle:Wikipedia.

Im folgenden wird Benutzung von pyinotify anhand eines kleinen Skriptes erklärt, welches Änderungen an der Datei “/proc/net/arp” überwacht. Sobald sich der Inhalt der Datei ändert wird ein Prozess des “arp” Tools gespawnt das die Änderung in die Arp-Tabelle einträgt. Das Skript benutzt scapy2.2.0 so wie den Pyinotify wrapper zum Skripten der Events.

Bei den neuesten Ubuntu Versionen sollte ein

sudo apt-get install python-scapy python-pyinotify

seinen Zweck erfüllen.

Auf älteren Systemen (Lucid Lynx) rate ich dazu Scapy aus dem Netz zu laden und selber zu Installieren.Das Skript auf welches ich mich hier beziehe besteht im Grunde aus zwei simplen Methoden und dem Konstruktor. Fangen wir mit der Erklärung des Konstruktors an:

class secMyass(object):

        def __init__(self):
               self.router = conf.route.routes[-1][-3]
	       self.mask = pyinotify.IN_MODIFY | pyinotify.IN_OPEN

Wie man sieht gestaltet sich der Konstruktor ziemlich simpel, self.router ruft conf.route.routes auf. Dies stellt ein Zweidimensionales Array da welches die Routen der Kernel-routingtabelle abbildet. Der Zweck des Aufrufes ist den Standard Gateway für des lokalen Netzwerkes zu ermitteln. Die self.mask Zuweisung gibt an auf welche notify Ereignisse später Überwacht werden soll. Die Methode set_gw_mac beschreibt das setzen des Gateway Eintrags. Entscheidend ist die erste Zeile nach dem Funktionskopf:

def set_gw_mac(self):
                child = pexpect.spawn("arp -s %s %s " % (self.router,getmacbyip(self.router)))
                child.logfile = sys.stderr
                child.readline()
                child.expect(pexpect.EOF)

child ist eine Zuweisung auf den Aufruf der pexpect Methode spawnt, welche das arp Programm im Hintergrund als Prozess spawnt. Der Formatstring formatiert die erste Stelle zu self.router welche die Standard Gateway IP zurück gibt. Die Zweite Stelle ruft die getmacbyip() Methode von scapy auf der nochmals self.router übergeben wird, was in der Rückgabe der Gateway MAC Adresse endet. Die übrigen drei Zeilen der Methode sollten relativ selbst sprechend sein.

Nun der interessante Teil welcher die Benutzung von pyinotify beschreibt:

        def fileWatcher(self):
                wm = pyinotify.WatchManager()
                notifier = pyinotify.ThreadedNotifier(wm)
                wm.add_watch('/proc/net/arp', self.mask,rec=False)
                if notifier.check_events():
                        self.set_gw_mac()
                        print "Gateway Mac changed!"

wm ist eine Zuweisung des Methoden Aufrufers WatchManager() die Operationen und Optionen anbietet für die Überwachung von Dateien und Verzeichnissen. Notifier ruft den ThreadedNotiefier auf und übergibt WachManager an diesen. Der ThreadedNotifier Klasse werden von Threading und der Notifier Klasse Methoden und Objekte vererbt. Die folgende Zeile welche über WatchManager die add_watch Methode aufruft definiert den eigentlichen Watchevent. Welcher das zu überwachende Verzeichnis übergeben bekommt und self.mask des Konstruktors, in dem die Events angegeben wurden auf die Überwacht werden sollen. Die if Verzweigung ruft über den Notifier die check_events Methode auf und geht den darauf folgenden Anweisungs Block durch wenn check_events “True” zurück gibt. Der Anweisungsblock startet den Überwachungsprozess. Und im Falle des Auftretens eines der im Konstruktor definierten Events, wird die set_gw_mac Methode ausgeführt sowie eine kurze Nachricht über die Änderung ausgegeben.

Natürlich gibt es noch zahllose andere Möglichkeiten was mit Inotify noch alles möglich ist, doch das würde den Rahmen dieses Artikels sprengen.

In diesem Sinne viel Spaß noch am Gerät…

Weblinks:

Pyinotify Homepage
Pyinotify Developer Repository
Bitbucket Repo Link zum Arp-Entry watch Skript

Getaggt mit , , ,
VALEAT

Und tu nicht mehr in Worten kramen. Goethe, Faust 1

Leadership Freak

Empowering Leaders 300 Words at a Time

If you cannot jump, you'll fall through!

Programming, reversing engineering and what not...

Deep Thoughts by Raymond Hettinger

Ruminations on Computers, Programming and Life

Gigaom

Technology news, trends and analysis covering mobile, big data, cloud, science, energy and media

All About Ruby

Ruby newbie view on the web development using Ruby on Rails

WebstersProdigy

Colored Hat Stuff. New post about once a month

0x0e.org | pentesting perspective

braindump on pentesting, QA, metasploit, constant learning