Tor: Vidalia Tor software exited unexpectedly

With the latest developments in internet censorship I too have been looking for secure alternatives and the Tor project is one of them but unfortunately I had a small problem with Vidalia, the software GUI for Tor. I discovered a solution after some reading and Google-ing.

After installing Tor on ubuntu or other Debian based distributions and running it for the first time you probably are getting the following error:

Vidalia detected that the tor software exited unexpectedly.

Please check the message log for recent warning or error messages.

Alright, now on to the solution. You best open up a terminal because it’s going to require some command-line work, first thing you should do is make sure that everything Tor isn’t running anymore, so copy/past this in your terminal:

1
sudo killall tor

and enter your password when asked after having hit the ‘enter’ button. Don’t exit the terminal window just yet because you’ll need it a bit more. Now that you have killed off all the possible running tor-processes you can fix the real problem.

Upon installation, tor will automatically starts up when booting Ubuntu. When you open Vidalia, it will first check if there is an existing tor process and try to connect to the control port of tor. All you need to do is reconfigure tor so it allows Vidalia to connect and start using the tor process correctly without throwing the error.

First step: is to open the configuration file of tor. Open a terminal and execute the following command: (note: sudo is required or you won’t be able to save the file later on)

sudo gedit /etc/tor/torrc

Gedit is standard installed on Ubuntu and a lot of other distributions, and my favorite but if you have another just replace gedit by that one in the command-line. Also check your preferences so that the editor displayed line numbers it will make this easier.

After the file opens, scroll down to line 53 to line 60 and you will see something like this:

1
## The port on which Tor will listen for local connections from Tor
2
## controller applications, as documented in control-spec.txt.
3
#ControlPort 9051
4
## If you enable the controlport, be sure to enable one of these
5
## authentication methods, to prevent attackers from accessing it.
6
#HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C #CookieAuthentication 1

Now modify this so that you have something that looks like this:

1
## The port on which Tor will listen for local connections from Tor
2
## controller applications, as documented in control-spec.txt.
3
ControlPort 9051
4
## If you enable the controlport, be sure to enable one of these
5
## authentication methods, to prevent attackers from accessing it.
6
HashedControlPassword 16:D11E80307FCD1E730083FA68F6650BDBC2FE1D3BA100C07A7895CFC4D1
7
#CookieAuthentication 1

What have you done? You set the control port so vidalia can take control of tor and you initiated the password authentication. Now you just have to run one other command, so open a secondary terminal, you’ll need it because your current one is running gedit.

1
tor --hash-password mypassword

Now the result of this command is something like this: (note: don’t past my result, make your own for security reasons)

1
webscriptz@webscriptz-hp:~$ tor --hash-password mypassword
2
May 06 12:49:45.190 [notice] Tor v0.2.2.35 (git-73ff13ab3cc9570d). This is experimental software. Do not rely on it for strong anonymity. (Running on Linux x86_64)
3
16:E499E055BC335107609A1E2A0D857422E238376BEA3B75F35E50C376A6

This part you need is :

1
16:E499E055BC335107609A1E2A0D857422E238376BEA3B75F35E50C376A6

You need to insert this on line 68 after:

1
HashedControlPassword 

Now for the final step you need to restart Tor:

1
sudo /etc/init.d/tor restart

Now open vidalia and start Tor, it should work, if not close vidalia and re-open it again and everything should be fine.


Local Web Development Environment in Ubuntu

This short guide explains how to set up a local development environment that will allow us to create new sites on the fly and automatically serve them up on our local development machine under Ubuntu. I won’t explain how to install LAMP, I’ll just suppose it’s already done and that a default installation is installed trough synaptic package manager or Ubuntu software center.

First, we need to install apache’s mod vhost. Always check it’s libapache2!

1
sudo apt-get install libapache2-mod-vhost-hash-alias

Now we need to implement the module so that Apache2 sees the module and activates it

1
sudo mv /etc/apache2/mods-available/vhost_alias.load /etc/apache2/mods-enabled/

Now, we need to configure apache to make use of the vhost module. Let’s start by creating the www directory, but normally it’s already there, if not then we don’t have apache installed or an installation problem :

1
sudo mkdir /var/www

We need to make sure that our user is owner of the www folder or is added to the right usergroup so that he has all the permissions if not we’ll have problems creating the folder

And now replace the content /etc/apache2/sites-enabled with the following

01
ServerAdmin webmaster@localhost
02
 
03
NameVirtualHost *:80
04
UseCanonicalName Off
05
DocumentRoot /var/www
06
VirtualDocumentRoot /var/www/%0.0
07
 
08
Options FollowSymLinks
09
AllowOverride None
10
 
11
Options Indexes FollowSymLinks MultiViews
12
AllowOverride None
13
Order allow,deny
14
allow from all
15
 
16
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
17
 
18
AllowOverride None
19
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
20
Order allow,deny
21
Allow from all
22
 
23
ErrorLog ${APACHE_LOG_DIR}/error.log
24
 
25
<ol>
26
<li>Possible values include: debug, info, notice, warn, error, crit,</li>
27
<li>alert, emerg.</li>
28
</ol>
29
 
30
 
31
LogLevel warn
32
 
33
CustomLog ${APACHE_LOG_DIR}/access.log combined
34
 
35
Alias /doc/ "/usr/share/doc/"
36
 
37
Options Indexes MultiViews FollowSymLinks
38
AllowOverride None
39
Order deny,allow
40
Deny from all
41
Allow from 127.0.0.0/255.0.0.0 ::1/128

This essentially says that any domain that we host locally will reside at /var/ www/domain. We can modify the virtual document root as needed to add a public_html or htdocs directory if we wish. Make sure to cycle apache with:

1
sudo apache2ctl -k graceful OR sudo /etc/init.d/apache2 restart
2

Apache should be running well enough now and we can testing this by creating a test domain directory (and adding a simple index.html file) and modifying our /etc/hosts file to point the test domain to 127.0.0.1. This works well enough on it’s own but we don’t want to add to the hosts file for every site we create. As such, we’re going to install dnsmasq and route a full block of domains for our usage.

First off, let’s install dnsmasq:

1
sudo apt-get install dnsmasq

Once installed, we will need to modify /etc/dnsmasq.conf and replace

1
#listen-address=

with:

1
listen-address=127.0.0.1

and at the end of the file add:

1
address=/loc/127.0.0.1

This will point all .loc domains to our local development environment. We can specify any extension we wish or a full domain (address=/example.com/127.0.0.1).

Now we need to modify /etc/dhcp3/dhclient.conf and uncomment the following line by removing the ‘#’:

1
address=/loc/127.0.0.1

Restart the dnsmasq service with:

1
sudo /etc/init.d/dnsmasq restart

And we should be able to create new folders with the name site.loc in our /var/www/site.loc folder and they will be available at the domain in our browser. If we use an eclipse based editor we can change our workspace to sit in /var/www/site.loc and whenever we create a new project just name it site.loc and it will be instantly available.

Note that it can be done simpler but then we would simply add to our /etc/hosts:

01
127.0.0.1 site.loc secondwebsite.loc third website
02
127.0.1.1 webscriptz-hp
03
 
04
<ol>
05
<li>The following lines are desirable for IPv6 capable hosts</li>
06
</ol>
07
 
08
 
09
::1 ip6-localhost ip6-loopback
10
fe00::0 ip6-localnet
11
ff00::0 ip6-mcastprefix
12
ff02::1 ip6-allnodes
13
ff02::2 ip6-allrouters

Know that this may require some handy work because when  switching workplaces and pi-addresses we’ll have to reinsert those websites in the hosts file or use gnome-network-manager which will keep the data in resolv.conf.


c# UserControl resize problem

Yesterday and today I’ve been having problems in Visual studio with the UserControl elements and how to get them to resize them automatically when the WinForm changes size. I’ve found all kind of workaround nearly all of them were a lot of work while the designer in Visual studio should be able to do it for you.

So my solution:

Every element that you wan to resize correctly should have the following:

  • For the UserControl:
    • dock or anchor on all 4 points
    • autoSize to true
    • autoScaleMode to inherit
  • Once you drag drop your UserControl element into your WinForm
    • Dock or anchor on all 4 point.

 

 


Using Our Models To Do Basic Queries On The DB

The application has an auto-generated model, Gii kindly provides the model once the database is created.

01
<?php
02
class Product extends CActiveRecord
03
{
04
    /**
05
     * The followings are the available columns in table 'Product':
06
     * @var integer $id
07
     * @var integer $brandId
08
     * @var string $name
09
     * @var string $price
10
     */
11
 
12
    /**
13
     * Returns the static model of the specified AR class.
14
     * @return CActiveRecord the static model class
15
     */
16
    public static function model($className=__CLASS__)
17
    {
18
        return parent::model($className);
19
    }
20
 
21
    /**
22
     * @return string the associated database table name
23
     */
24
    public function tableName()
25
    {
26
        return 'Product';
27
    }
28
 
29
    /**
30
     * @return array validation rules for model attributes.
31
     */
32
    public function rules()
33
    {
34
        return array(
35
            array('name','length','max'=>255),
36
            array('price','length','max'=>8),
37
            array('name, price', 'required'),
38
        );
39
    }
40
 
41
    /**
42
     * @return array relational rules.
43
     */
44
    public function relations()
45
    {
46
        // NOTE: you may need to adjust the relation name and the related
47
        // class name for the relations automatically generated below.
48
        return array(
49
            'brand' => array(self::BELONGS_TO, 'Brand', 'brandId'),
50
            'categories' => array(self::MANY_MANY, 'Category', 'ProductCategory(productId, categoryId)'),
51
        );
52
    }
53
 
54
    /**
55
     * @return array customized attribute labels (name=>label)
56
     */
57
    public function attributeLabels()
58
    {
59
        return array(
60
            'id'=>'Id',
61
            'brandId'=>'Brand',
62
            'name'=>'Name',
63
            'price'=>'Price',
64
        );
65
    }
66
}

Enable your weblogger: this you will find in: /yourProject/protected/config/main.php

By default your log array looks something like this: (Tip: IF you haven’t done this, and you find it hard to find you way in the file, comment everything you deem meaningful, use spaces and limit blocks of codes with comment of your choice)

1
        'log'=>array(
2
            'class'=>'CLogRouter',
3
            'routes'=>array(
4
                array(
5
                    'class'=>'CFileLogRoute',
6
                    'levels'=>'error, warning',
7
                ),
8
            ),
9
        ),

Let’s add in the CWebLogRoute so it looks like this.

01
  'log'=>array(
02
            'class'=>'CLogRouter',
03
            'routes'=>array(
04
                array(
05
                    'class'=>'CFileLogRoute',
06
                    'levels'=>'error, warning',
07
                ),
08
                array(
09
                    'class'=>'CWebLogRoute',
10
                    'levels'=>'trace,info, error, warning',
11
                ),
12
            ),
13
        ),

Visit the application and notice that at the bottom of the screen a table is shown displaying everything Yii does to make it possible for the website to be shown correctly. This is especially useful when you’re new to the Yii DB stuff.

Let’s start by getting all of our products. If you are trying this tutorial, then please create a simple new installation, config the database settings in /protected/config/main.php and create your database with the proposed columns from the model seen earlier.

You can test this in any controller, because the system already has a default SiteController in: /protected/controllers/siteController.php, this tutorial will use siteController.php with the view-file in: /protected/views/site/index.php

So we’ll first modify our SiteController::actionIndex method.

1
    public function actionIndex()
2
    {
3
        $this->render('index', array(
4
            'Products' => Product::model()->findAll(),
5
        ));
6
    }

Open the view-file related to the actionIndex() The system has an array that will be passed to our index view. This array contains ‘Products’ which will be usable as ‘$Products’ in our view: /protected/views/site/index.php

01
<?php $this->pageTitle=Yii::app()->name; ?>
02
 
03
<h1>
04
    Welcome, <?php echo Yii::app()->user->name; ?>!
05
</h1>
06
<table>
07
<?php foreach($Products AS $Product):?>
08
    <tr>
09
        <td><?php echo $Product->name;?></td>
10
        <td><?php echo $Product->price;?></td>
11
    </tr>
12
<?php endforeach;?>
13
</table>

The system (Yii) writes the SQL statements for us thanks to the AR and everything behind that, but we got back an array of product objects.

Now let’s use the ‘brand’ relation that is set in our Product model.

Without changing the controller, we can simply change the view and add the line to output the brand name.

1
<td><?php echo $Product->brand->name;?></td>

Now how did Yii do that? Look at the screen logger. You will see that it used the ‘lazy-loading’ technique to query the Brand table at that point.

1
Querying SQL: SELECT * FROM `Product`
2
 
3
Querying SQL: SELECT `Product`.`id` AS `t0_c0`, t1.`id` AS `t1_c0`,
4
t1.`name` AS `t1_c1`, t1.`website` AS `t1_c2` FROM `Product` LEFT OUTER
5
JOIN `Brand` t1 ON (`Product`.`brandId`=t1.`id`) WHERE (`Product`.`id`=3)
6
 
7
Querying SQL: SELECT `Product`.`id` AS `t0_c0`, t1.`id` AS `t1_c0`,
8
t1.`name` AS `t1_c1`, t1.`website` AS `t1_c2` FROM `Product` LEFT OUTER
9
JOIN `Brand` t1 ON (`Product`.`brandId`=t1.`id`) WHERE (`Product`.`id`=4)

This is not the best way to go so let’s change the actionIndex in siteController.php

1
    public function actionIndex()
2
    {
3
        // renders the view file 'protected/views/site/index.php'
4
        // using the default layout 'protected/views/layouts/main.php'
5
        $this->render('index', array(
6
            'Products' => Product::model()->with(array('brand'))->findAll(),
7
        ));
8
    }

One query is all that is needed for all the data to be collected.

1
Querying SQL: SELECT `Product`.`id` AS `t0_c0`, `Product`.`brandId` AS
2
`t0_c1`, `Product`.`name` AS `t0_c2`, `Product`.`price` AS `t0_c3`, t1.`id`
3
AS `t1_c0`, t1.`name` AS `t1_c1`, t1.`website` AS `t1_c2` FROM `Product` 
4
LEFT OUTER JOIN `Brand` t1 ON (`Product`.`brandId`=t1.`id`)

The view file does not have to change for this. This technique is called eager-loading and has advantages over lazyloading sometimes.

This tutorial is a modified tutorial from another website/blog that unfortunantly isn’t online anymore, domain is being sold by godaddy.com, so I search my archives to retrieve this on, and post him here, hence a few additions, deletes and rewrites from me.


YiiFramework adding functions to your models

MVC has some principals to it, like the fat model principal that I’ll show in this tutorial and which is used in a lot of frameworks. I’m going to show how to add and use functions that can be added to a model.

There are a few ways to add to a models that increase code re-usability. One way is to just add methods to the models, methods which can execute complex queries and make your controller thinner.

The first example, a query that will get all products within a price range, it will need a limit and an offset for pagination, so in the Products model, the following function can be added:

1
public function findAllByPrice($min=0, $max=1000000, $offset = 0, $limit = 30) {
2
    $Criteria = new CDbCriteria();
3
    $Criteria->condition = "price >= :min AND price <=:max";
4
    $Criteria->limit = $limit;
5
    $Criteria->offset = $offset;
6
    $Criteria->params = array ( ':min' => $min, ':max' => $max );
7
    return $this->with(array('brand'))->findAll($Criteria);
8
}

Now in any of the controlller files this method can be easily accessed and returns all of the ‘Product’ objects with a single line command:

1
$Products = Product::model()->findAllByPrice(100, 700, 0, 30);

Another way to do the same is to:

1
public function getProducts($category){
2
    return $this->findAll('categoryIdFk=:category', array(':category'=>$category));
3
}

Let’s implement the first query using two named scope methods that I’ll create.

1
// Price Between - Named Scope ---------------------------------//
2
public function scopePriceBetween($min, $max) {
3
    $Criteria = new CDbCriteria();
4
    $Criteria->condition = "$this->tableName().price BETWEEN :min AND :max";
5
    $Criteria->params = array(':min' => $min,   ':max' => $max);
6
    $this->getDbCriteria()->mergeWith($Criteria);
7
    return $this;
8
}

Now an additional named scope for the limit element

1
//  Limit - Named Scope --------------------------------------//
2
public function scopeLimit($limit = 30, $offset = 0) {
3
    $Criteria = new CDbCriteria();
4
    $Criteria->limit = $limit;
5
    $Criteria->offset = $offset;
6
    $this->getDbCriteria()->mergeWith($Criteria);
7
    return $this;
8
}

Now we can simply use our named scopes to get our data back, and then we could continue to pile on named scopes to return our data.

1
$Products = Product::model()->scopePriceBetween(0, 5000) ->scopeLimit(30, 1)->findAll();

The query that actually gets executed is simple and looks like this:

1
SELECT * FROM `Product` WHERE Product.price BETWEEN :MIN AND :MAX LIMIT 30 OFFSET 1

This tutorial is a modified tutorial from another website/blog that unfortunantly isn’t online anymore, domain is being sold by godaddy.com, so I search my archives to retrieve this on, and post him here, hence a few additions, deletes and rewrites from me.


mySQL view and YiiFramework

The sql standard gives the possibility to create a view, a view is or can be a mask of one column for a special user that only has access to some of the data and thus not all the data stored in the column? The view can also be used to regroup data from multiple column into one, this can be handy if you need to display that selection a lot.

Limitations
It might be wise to, first, learn what you can do with it as it is not a all-in-one solutions for al your troubles and ideas. You can use a view to DISPLAY data, but unless you display all the data from the column or columns, which most of the time doesn’t make sense, you can NEVER use it to insert data IF any other columns are required to be filled out.

How to create a view in mySQL
The syntax, normally, can be used in other databases to but I’m focussing on mySQL.

1
<code lang="sql[lines]">CREATE VIEW [name of the view] AS [ your query];

Best is that you make a clear distinction between the original tables and the view by for instance writing "_view" after it, this will help later when reviewing the database or using the view element with the YiiFramework.

You can in fact put everything you want in the [your query] section as long as it is valid SQL. You also need to be careful when using this that whatever query you make, you don't ask the Cartesian product, this however you need to do with every single query you ever make where joints and where clauses are involved.

YiiFramework and Views
This is the fastest part, you create your model with Gii, and you do the rest of your magic to write your application.


SQL & Yii

At school, I have a course ORACLE SQL which learned me some new tricks and options, I’ve also been testing them in MySQL and so the idea grew to see how Yii framework would interact with those tricks. I must say I didn’t expect them to work but they do so probably within the next month I’ll write some new tutorials and infos in SQL and YiiFramework.