Pages

Friday, 18 July 2014

Mikrotik SRCNAT

This is useful if you want to allow some services trough the router. There is also a DST nat have a look at this post as well:  http://yuriystanchev.blogspot.com/2014/01/mikrotik-destination-nat.html

/ip firewall nat add chain=srcnat src-address=<internal ip>  protocol=tcp dst-port=<port> action=src-nat to-addresses=<real ip> to-port=<port> 

Have fun.

Tuesday, 10 June 2014

VirtualBox and phpvirtualbox

I am using successfully Virtualbox now on more than 2 servers with phpvirtualbox interface. It is very convenient with few things you should have in mind:

1. Prepare your virtual machines on another host with Virtualbox and then export them and import them back. Because the console on phpvirtualbox didn't work out good at least for me. When you prepare the virtual machines use Bridge adapter. If you get an error before starting you can change the bridged adapter (example the adapter was wifi in my case you can change it to eth0).
2. Reserve the RAM that you need - resources are consumed regardless if the RAM is used or not.
3. After importing the virtual machines note on the network settings if it is denying the connections and correct it to Allow them.

Now to the server after installing Ubuntu Server follow this steps:

sudo apt-get update
sudo apt-get install virtualbox

Now we need to get the virtualbox version:
sudo VBoxManage --version

and get the appropriate extension pack from here:

After downloading the extension pack install it
VBoxManage extpack install

If you mess up the package:

VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"

The init script for the vbox web service is missing so we need to initialize the vboxwebsrv process. You can get the starting script from here:
http://www.virtualbox.org/svn/vbox/trunk/src/VBox/Installer/linux/vboxweb-service.sh

sudo update-rc.d vboxweb-service.sh defaults 99 01

Don't forget to edit this file:
etc/default/virtualbox
VBOXWEB_USER=vbox

Add the users:
sudo useradd -d /home/vbox -m -g vboxusers -s /bin/bash vbox
sudo passwd vbox

Install Ngnix:
sudo apt-get install nginx php5-common php5-mysql php5-fpm php-pear unzip

I modified the
/etc/nginx/sites-available/default 

Nginx seems to be very picky when it comes to configuration - however it is very fast and stable. Modify the configuration to this:

server {
        listen 80; ## listen for ipv4; this line is default and implied
  #      listen [::]:80; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                deny all;
        }

        # Only for nginx-naxsi : process denied requests
        #location /RequestDenied {
                # For example, return an error code
                #return 418;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
root /usr/share/nginx/www;
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}


Let's reload the web server:
sudo /etc/init.d/nginx reload

Download:
http://sourceforge.net/projects/phpvirtualbox/

Extract it in:
/usr/share/nginx/www

sudo cp config.php-example config.php
sudo nano config.php

Set the variables:

/* Username / Password for system user that runs VirtualBox */
var $username = 'vbox';
var $password = 'yourpassword';
var $consoleHost = 'your ip here';

Change this as well:
var $location = "http://localhost:18083";

Or you will get this:

Exception Object
(
    [message:protected] => Could not connect to host (http://127.0.0.1:18083/)
    [string:Exception:private] =>
    [code:protected] => 64
    [file:protected] => /usr/share/nginx/www/lib/ajax.php
    [line:protected] => 128
    [trace:Exception:private] => Array
        (
        )

    [previous:Exception:private] =>
)

I changed here the ip to localhost because otherwise the soap can not be connected because of ipv6.

sudo sysctl net.ipv6.bindv6only net.ipv6.bindv6only=0

How to start all VMs at boot here is a script that does the trick. Have in mind it is very important that the names of the VMs are without white spaces otherwise the VMs won't start - use it to your advantage.

#!/bin/bash
#
#This init script autostarts necessary vms at boot
#and saves running vms on shutdown

# Sed explanation: sed -e 's/^.//' -e 's/.$//'
#   1.  -e means to allow multiple arguments in a single sed command
#   2.  's/^.//' means to substitute (s) / at the beginning of the line (^), any character (.) / [substitute with nothing] /
#   3.  's/.$//' means to substitute (s) / any character (.), at the end of the line / [substitute with nothing] /

VBOXUSER=vbox
RUNNINGVMS=$(sudo -H -u $VBOXUSER vboxmanage list runningvms | cut -d " " -f1 | sed -e 's/^.//' -e 's/.$//')
STOPPEDVMS=$(sudo -H -u $VBOXUSER vboxmanage list vms | cut -d " " -f1 | sed -e 's/^.//' -e 's/.$//')

case "$1" in
  start)
        for i in $STOPPEDVMS
                do
                        echo "Starting" $i "VM"
                        sudo -H -u $VBOXUSER vboxmanage startvm $i --type headless
                        sleep 5
                done
    ;;
  stop)
        for i in $RUNNINGVMS
                do
                        echo "Saving state of" $i "VM"
                        sudo -H -u  $VBOXUSER vboxmanage controlvm $i savestate
                done
    ;;
  *)
    echo "Usage: /etc/init.d/startvm {start|stop}"
    exit 1
    ;;
esac

exit 0

This will start the script at boot:

update-rc.d [name of the script] defaults 99 01

How to add a raw disk (can be applied also to flash drives and external drives). Now log in as the vbox user and execute. In this example I add the whole disk (/dev/sdb) in raw format:

sudo usermod -a -G disk vbox
sudo chmod 777 /dev/sdb
VBoxManage internalcommands createrawvmdk -filename /home/vbox/sdb.vmdk -rawdisk /dev/sdb

If there is a partition on the disk add this to the end of the command specify the correct number of partitions:

-partitions 1 -relative

List the VMs to get the ids: 

VBoxManage list vms

Starting a vm:

/usr/bin/VBoxHeadless -startvm badc09ac-8ef4-4be9-b45b-73eb8d590b1f

Helps if for no apparent reason the home points to root. Setting vbox user home:
su vbox

VBoxManage setproperty machinefolder /home/vbox

References:
http://www.vionblog.com/virtualbox-4-3-phpvirtualbox-debian-wheezy/
http://trac.nginx.org/nginx/ticket/345
https://forums.virtualbox.org/viewtopic.php?f=7&p=181318
http://scarygliders.net/2011/11/04/virtualbox-and-iscsi-nas-how-to-linux-windows/

Wednesday, 14 May 2014

Wine .Net


I needed .Net installed on wine, however the issue is that not all install correctly if you follow this approach you will get the installation correct to .Net 3.0

1. Use Wine from the official repository:
http://www.winehq.org/download/

2. Use winetricks for the installation and read from winehq the instruction on the installation (they are below the description):
winetrick­s -q msxml3 dotnet35­sp1

3. Use the .Net Verification tool to verify the installation:
http://blogs.msdn.com/b/astebner/archive/2008/10/13/8999004.aspx

4. If something fails use the clean-up tool to uninstall the version that failed:
http://blogs.msdn.com/b/astebner/archive/2012/08/04/10336934.aspx

References:
http://blogs.msdn.com/b/astebner/archive/2008/10/13/8999004.aspx
http://appdb.winehq.org/objectManager.php?sClass=version&iId=10166
http://www.winehq.org/download/
http://blogs.msdn.com/b/astebner/archive/2012/08/04/10336934.aspx

Some thoughts on Proxmox and some linux partitioning

Proxmox turned out to be a nice virtualization option. Аt first glance it seems to me that the resources thanks to open-vz are accumulated very well.

After you install you can access the virtual infrastructure here:
https://<ip>:8006

One other thing is that I had to add another partition to the virtual environment

List all hard drives:
lsblk

sudo parted /dev/sdb <- your device here
mklabel gpt
mkpart ext3 2048s -1s
print
quit

sudo partprobe -s /dev/sdb
sudo mke2fs -t ext3 /dev/sdb1 -L "label"  
sudo tune2fs -c0 -i0 /dev/sdb1
sudo mkdir /media/partition
sudo chown root:root /media/partition
sudo chmod 777 /media/partition

add an entry in fstab

 /dev/sdb1 /media/partition ext3 defaults 0 0


and then sudo mount -a to refresh fstab.

One other thing is that the PC I installed it on did not have 64 bit virtual support, which generally is bad - not to say stronger words. Anyways I had to use templates on the proxmox because for some reason I was not able to install Ubuntu Server actually even with the template. Turnkey which is Ubuntu based was installed!? Anyway it is 32 bit and doesn't need 64 bit virtualization, but as it seems there was some issue so I was forced to install a CentOS although I wanted my environment to be as homogeneous as possible.

One other notable thing is the networking - it seems some templates pass the dhcp from my router and that the templates are configured to accept those and some as CentOS template had to be set? I set my network settings at a gateway level - so this a bit annoyed me. But you can set your networking settings through the web interface and I did not know that :D

So just dig in the gui you will find the network settings - don't do this. I did it the hard way:
ifconfig eth0 <ip> netmask <mask> broadcast <broadcast> 
route add default gw <gw ip>


Don't forget to set the DNS.

Conclusion: It's Ok to be used for 32-bit Linux based systems with the default templates. 

References:
https://pve.proxmox.com/wiki/Turnkey_Linux_Templates

Thursday, 8 May 2014

Mint on Amilo L1310G - Wifi issues

I had to install Mint 16 Petra on Amilo L1310G unfortunately with issues on the Wifi. So I read trough look at the references. And had to modify a make file from the old driver and created a package. You are free to use it.

Driver
https://drive.google.com/file/d/0B1HfGZPmAyo0d2JvNFI5Q3Z3MmM/edit?usp=sharing



make
make install
modprobe fsaa1655g
/proc/fsaa1655g/radio
echo 1 > /proc/fsaa1655g/radio
echo 0 > /proc/fsaa1655g/radio
1. Download the tar and compile the driver - don't forget to get the kernel headers:


2. Open (what I think is) your former "options"-file:
sudo nano /etc/modprobe.d/alsa-base.conf

3. Scroll down untill you find 
"# Prevent abnormal drivers from grabbing index 0". You should find some lines that start with "options". Now add the following:
options fsaa1655g radio=1
options ath_pci rfkill=0
Save it.

4. Now we'll add the module so it will load at startup, again using a terminal:
sudo nano /etc/modules

5. At the end of the file, add the following:
fsaa1655g
Save it.

Try this if the led is not blinking blue. For me this driver works.


Than you can examine the file
You can switch the radio with commands

References:

Tuesday, 29 April 2014

Windows Administration the hard way


I had several problems recently. 

Issue 1:

The issue was that the software I support was unable to install itself, due to permission. The strangest thing was that cacls was not present and had to get it from somewhere else.

After forcing the temp directory to the system user everything worked as a charm. However before rushing - delete the temporary files. It seems that the program was unable to install due to a corrupt directory and because it was not able to  write to it from the system user.
1. cacls "C:\WINDOWS\Temp" /G <adminuser>:F
otherwise I can not read the contents of the directory ...
2. Rename the corrupt directory. 3. cacls "C:\WINDOWS\Temp" /G SYSTEM:F

Note maybe there is a way to add both users from cacls but I was kind of in a hurry.

Issue 2:

I needed to remotely install the software I support so I needed Remote Registry and RPC enabled. The Firewall had to be shut - note if you haven't enabled Remote Desktop - don't disable the firewall, it is better to set it start manually. Other workaround would be to just enable the service in the firewall - in my case it was file and printer sharing see issue 5. So you can do this with this script. Check the references for further info.

net start RemoteRegistry
net start rpcss
net stop mpssvc
sc config RemoteRegistry start=auto
sc config rpcss start=auto
sc config mpssvc start=disable

Issue 3:

How do you fix a messed up installations remotely? This relates to the above Issue 2. You need 3 things only.

1. Admin rights.
2. Remote Registry you can use the connect to PC feature.
3. Services you can connect to remote PCs.

And that's it, then restart and re-install the software.

Issue 4:

How to get the built in administrator:
net user administrator /active:yes
net user administrator password


Overflow Android

Since one year or so passed I thought why not retire the classic version of Overflow for Android.

Here is the new version with the new design from Lyubina Karapeeva:




And here is the classical version:





Hope you enjoy it.