WTF *Nix

Just another *nix Blog

Archive for March, 2009

phpMyAdmin on Fedora 10

Mar-28-2009 By WTF *Nix

Install phpMyAdmin on Fedora via Yum:

1. From the command line: # yum -y install phpMyAdmin

2. Setting up access (Security Defaults are a pain!)

# cd /etc/httpd/conf.d/

#vim /phpMyAdmin.conf

Inside this file you will find the following:

# phpMyAdmin – Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
order deny,allow
deny from all
allow from 127.0.0.1
</Directory>

# This directory does not require access over HTTP – taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries>
Order Deny,Allow
Deny from All
Allow from None
</Directory>

# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc.  This may break your mod_security implementation.
#
#<IfModule mod_security.c>
#    <Directory /usr/share/phpMyAdmin>
#        SecRuleInheritance Off
#    </Directory>
#</IfModule>

To gain access too it from another place or IP, which if you are on a network, and there are a series of workstations, you will add in the following ONE LINE if your IP Address is: 192.168.0.90

# phpMyAdmin – Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
order deny,allow
deny from all
allow from 127.0.0.1
allow from 192.168.0.90
</Directory>

# This directory does not require access over HTTP – taken from the original
# phpMyAdmin upstream tarball
#
<Directory /usr/share/phpMyAdmin/libraries>
Order Deny,Allow
Deny from All
Allow from None
</Directory>

# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc.  This may break your mod_security implementation.
#
#<IfModule mod_security.c>
#    <Directory /usr/share/phpMyAdmin>
#        SecRuleInheritance Off
#    </Directory>
#</IfModule>

3. Setting up Normal Authorization to phpMyAdmin:

Edit the following lines to ensure you can login to phpMyAdmin under /etc/phpMyAdmin/config.inc.php:

$cfg['Servers'][$i]['auth_type'] = ‘http’; // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user'] = ‘USERNAME’; // MySQL user
$cfg['Servers'][$i]['password'] = ‘PASSWORD’; // MySQL password (only needed

Replace USERNAME and PASSWORD with your MySQL username and password respectively.

By default, PHPMyadmin connects to MySQL via localhost with default port and socket. If you wish to modify these settings, change the below similar lines

$cfg['Servers'][$i]['host'] = ‘localhost’; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ”; // MySQL port – leave blank for default port
$cfg['Servers'][$i]['socket'] = ”; // Path to the socket – leave blank for default socket

4. View it via any webbrowser by going to http://localhost/phpMyAdmin or via IP or Hostname :)

See any other settings need changing to fit your requirements? If so feel free on doing so, and make sure you check out their documentation. :)

WTF phpMyAdmin it up!

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

Python is an extremely extensible language in that you can add new capabilities by importing modules.

Here are just a slim few, but a widely used all throughout the day to day process of programming within python, so here’s for anyone that needs a WTF Quick Card…

sys – Allows interaction with the Python system:

  • exit() – exit!
  • argv – access command line arguments
  • path – access the system module search path
  • ps1 – change the ‘>>>’ python prompt!

os – Allows interaction with the operating system:

  • name – the current operating system, useful for portable programs
  • system – execute a system command
  • mkdir – create a directory
  • getcwd – find the current working directory

re – Allows manipulation of strings with Unix style regular expressions

  • search – find pattern anywhere in string
  • match – find at beginning only
  • findall – find all occurences in a string
  • split – break into fields separated by pattern
  • sub,subn – string substitution

math – Allows access to many mathematical functions:

  • sin,cos etc – trigonometrical functions
  • log,log10 – natural and decimal logarithms
  • ceil,floor – ceiling and floor
  • pi, e – natural constants

time – time(and date) functions

  • time – get the current time (expressed in seconds)
  • gmtime – convert time in secs to UTC (GMT)
  • localtime – convert to local time instead
  • mktime – inverse of localtime
  • sleep – pause program for n seconds

random – random number generators – useful for games programming!

  • randint – generate random integer between inclusive end points
  • sample – generate random sublist from a bigger list
  • seed – reset the number generator key

Remember this is just a SLIM bit of what’s instore for you that Python has, there are literally dozens of modules given too you with Python, then plenty more you can download!

Remember that using these within your code, you need to first IMPORT them as such:

>>>import SimpleXMLRPCServer as s

>>>s.SimpleXMLRPCRequestHandler()

Notice the above example is a shorter way of calling this module rather than typeing out the FULL SimpleXMLRPCServer :) Just saves us time in typing, unless you have an IDE that does it all for you by autocompletion… I prefer VIM for my IDE… So WTF, get it done and >>>import WTFNix.com

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

Python URL Parsing

Mar-23-2009 By WTF *Nix

The urlparse module included with Python makes it easy to break down URLs into specific components and reassemble them. This is very useful for a number of purposes when processing HTML documents.

The urlparse(urlstring [, default_scheme [, allow_fragments]]) function takes the URL provided in urlstring and returns the tuple (scheme, netloc, path, parameters, query, fragment). The tuple can then be used to determine things such as location scheme (HTTP, FTP, and so on), server address, file path, and so on.

The urlunparse(tuple) function accepts the tuple (scheme, netloc, path, parameters, query, fragment) and reassembles it into a properly formatted URL that can be used by the other HTML parsing modules included with Python.

The urljoin(base, url [, allow_fragments]) function accepts a base URL as the first argument and then joins whatever relative URL is specified in the second argument. The urljoin function is extremely useful in processing several files in the same location by joining new filenames to the existing base URL location.

Try this example out within your PY environment yourself and see:

import urlparse
parsedTuple = urlparse.urlparse(
"http://www.google.com/search?hl=en&q=urlparse&btnG=Google+Search")
unparsedURL = urlparse.urlunparse((URLscheme, \
        URLlocation, URLpath, '', '', ''))
newURL = urlparse.urljoin(unparsedURL,
"/module-urllib2/request-objects.html")
Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

VIM Power Editor Commands :: Part II

Mar-23-2009 By WTF *Nix

Part II of VIM’s Powerful Editor (MY IDE of choice) commands:

1. To delete from the cursor up to the next word type:    dw

2. To delete from the cursor to the end of a line type:    d$

3. To delete a whole line type:    dd

4. To repeat a motion prepend it with a number:   2w

5. The format for a change command is:
operator   [number]   motion
where:
operator – is what to do, such as  d  for delete
[number] – is an optional count to repeat the motion
motion   – moves over the text to operate on, such as  w (word),
$ (to the end of line), etc.

6. To move to the start of the line use a zero:  0

7. To undo previous actions, type:            u  (lowercase u)
To undo all the changes on a line, type:  U  (capital U)
To undo the undo’s, type:               CTRL-R

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

VIM Power Editor Commands :: Part I

Mar-23-2009 By WTF *Nix

If you are looking to have a list of commands to keep handy, figured I would share these here with others that need a starting point with VIM:

1. The cursor is moved using either the arrow keys or the hjkl keys.
h (left)    j (down)       k (up)        l (right)

2. To start Vim from the shell prompt type:  vim FILENAME <ENTER>

3. To exit Vim type:       <ESC>   :q!     <ENTER>  to trash all changes.

OR type:   <ESC>   :wq     <ENTER>  to save the changes.

4. To delete the character at the cursor type:  x

5. To insert or append text type:

i   type inserted text   <ESC>        insert before the cursor
A   type appended text   <ESC>         append after the line

NOTE: Pressing <ESC> will place you in Normal mode or will cancel an unwanted and partially completed command.

Here is VIM’s Part II

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg