Friday, November 3, 2017

Easy way to configure BIND 9 DNS server.

"I heard sometimes people need DNS" - anonymous

Now, there are two ways to configure DNS: easy way and hard way.
If you choose to do it hard, you have to dig manuals, search examples and go by trial and error, because neither of it is perfect.
OR
You can see example below. 

Example was made on Ubuntu, so on any other Linux some path may differ.

  1.  Go to /etc/bind/ and edit file named.conf.local
    add following in the end of file
    include "/srv/www/p0rc0-r0ss0.com/dns/zone.conf"
    /!\ In this example I assume, that we have virtual hosting on our server, and every website has it's own DNS zone in website folder. You can make your location as it is convenient to you. 
  2. Now go to your DNS zone folder (in my case it's /srv/www/p0rc0-r0ss0.com/dns/), and create file zone.conf
    /!\ Note, that rule allow-query restricts DNS usage to certain IP subnets.
    File should contain following:
    zone "p0rc0-r0ss0.zn" IN {
            type master;
            file "/srv/www/p0rc0-r0ss0.com/dns/p0rc0-r0ss0.zn";
            allow-query { 192.168.0.0/24; 127.0.0.1; };
            notify no;
    };

    zone "0.168.192.in-addr.arpa" IN {
            type master;
            file "/srv/www/p0rc0-r0ss0.com/dns/p0rc0-r0ss0.rzn";
            allow-query { 192.168.0.0/24; 127.0.0.1; };
            notify no;
    };
  3. Now create file p0rc0-r0ss0.zn and p0rc0-r0ss0.rzn here we place our DNS zones.
    Forward zone looks like this:$TTL 1W
    @               1D IN SOA       p0rc0-r0ss0. root.p0rc0-r0ss0. (
                                    2012090501      ; serial
                                    3H              ; refresh
                                    15M             ; retry
                                    1W              ; expiry
                                    1D )            ; minimum

                            IN A            192.168.0.254
                            1D IN NS        ns.p0rc0-r0ss0.
                            1D IN MX        10 mail.p0rc0-r0ss0.

    ns                       A               192.168.0.254
    mail                     A               192.168.0.254
    web                      A               192.168.0.254
    host1                    A               192.168.0.8
    host2                    A               192.168.0.15
  4. /!\ Notice, that you can only reverse lookup one DNS name per IP or names will be look up in round robin style, which is bad practice.
    and reverse zone is like this:

    $ORIGIN 0.168.192.in-addr.arpa.
    $TTL 1W
    ; /!\ Warning, trailing dots are mandatory!
    ;                           our domain  admin eMail
    @          1D IN SOA       p0rc0-r0ss0. root.p0rc0-r0ss0. (
                               2013080901      ; serial
                               3H              ; refresh
                               15M             ; retry
                               1W              ; expiry
                               1D )            ; minimum

                              1D IN NS        dns.p0rc0-r0ss0.

    ;IP host name
    8                       PTR             host1.p0rc0-r0ss0.
    15                      PTR             host2.p0rc0-r0ss0.
    254                     PTR             web.p0rc0-r0ss0.
Don't forget to check out /var/log/syslog for any late news ;)

Well, that's pretty much it. Of course you should remember, that if you want your DNS to work, client should use it for name resolve. This can be achieved either by setting your DNS as primary server in OS config, or by making delegation via global DNS registration company, but that's another story.

p.s.
It would be good idea to set our new DNS as primary for our server. 
Go to /etc/network/interfaces and set:
iface eno1 inet static
        address         192.168.0.250
        netmask         255.255.255.0
        gateway         192.168.0.1
        broadcast       192.168.0.255

        dns-nameservers 127.0.0.1


Wednesday, October 4, 2017

MySQL/MariaDB getting started.

Getting initial root permissions

/!\ Note! I assume that all actions are conducted as a superuser or via sudo command.
  1. Find out your DB version:
    #mysql --version
  2. Stop DB server
    #service mysql stop (or mariadb)
  3. Start DB instance in safe mode (yeah, there goes security...)
    #mysqld_safe --skip-grant-tables --skip-networking &
  4. Login as root
    IMPORTANT NOTE: In newer versions of mysql you can login as root into database if you are under superuser system account. Which means: you have to be root in system, to get mysql root shell.
    #mysql -u root
  5. Flush priviliges and alter permissions
    mysql> FLUSH PRIVILIGES;
    MySQL 5.7.6+ and MariaDB 10.1.20+:
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
    Prior MySQL and MariaDB versions:
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password'); 
  6. Due to restricted usage of root in newer versions, I adwise to create admin user:
    CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
    FLUSH PRIVILEGES;
  7. Kill mysqld_safe process
    Find PID in /var/run/mysql/mysql.pid or via ps aufx
    Ensure no mysql survives :)))
  8. Restart mysql (of course you can simply use "star", but I prefer that way)
    #service mysql restart
Everybody happy.

Another way, that just might help.

  1. Open /etc/mysql/my.cnf (or any other effective config)
  2. under
    [mysqld]
    add
    skip-grant-tables
  3. #service restart mysql
  4. #mysql -u root
  5. mysql>UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass'WHERE User = 'root' AND Host = 'localhost';
  6. /!\ Remove skip-grant-tables from my.cnf
  7. #service restart mysql

Monday, August 14, 2017

PX4FMU + PX4IO + ArduCopter firmware + some VERY useful tricks.

Basic concepts

First of all you should understand, that flight controller is basically set of inputs and outputs. Firmware lets you assign specific function to specific input or output. Remember it, it's important.

/!\ Important note. You can NOT use Arducopter firmware on PX4FMU without PX4IO extension board. (Thanks guys! This hardware is really paying for itself :) )

Hardwiring

In my case I have:
 - PX4FMU + PX4IO stacked on each other,
 - (1) 3D SimpleBGC controller,
 - (2) 3DR (clone) GPS + Compass module,
 - (3) 3DR power module,
 - (4) I2C LED + USB + Buzzer + I2C splitter module,
 - (5) FrSky TFR4: 7PPM + 1 RSSI.
* Numbers are because it's lazy for me to print names over and over again.


General considerations

It is useful to know, that your barometric sensor will work much better if no direct sunlight or wind will hit it. To achieve this, you should simply put piece of foam rubber on top of it.

/!\ IMPORTANT notice for those who assemble firmware manually.
PX4 board should be mounted "upside down", there is a sign "this side up" on the board. The thing is, that in this case sensor becomes inverted and you see ^ sign in mission planner wrong way.
To correct this you should set AHRS_ORIENTATION parameter to 8. This will flip sensor by 180 degrees roll.

(1) Is connected in very specific way

/!\ Most of people who read manuals should be aware, that SimpleBGC works better when it has feedback from flight controller (FC).
Now, I wanted to have FC feedback AND at the same time can use my Ch6 rotating knob to turn camera up and down. The thing is that either you have FC_PITCH from FC or from Ch6.
Here what I did, I put:
Mission planner (initial setup -> optional hardware -> gimbal config)
FC_ROLL -> Ch6 (Roll), stabilize roll: check
FC_PITCH -> Ch5 (Tilt), stabilize tilt: check
RC_PITCH -> Ch7 (Pan) and also Input Ch: Ch6, stabilize pan: unchek.
( i ) Ch5 and Ch7 tilt range better be the same.

Gimbal config soft (RC settings)
RC input mapping
PITCH -> RC_PITCH - PWM (this allows us to turn camera with ch6)
FC_ROLL -> EXT_ROLL - PWM
FC_PICH -> EXT_PITCH - PWM

RC control
Pitch should be in "Angle mode" to follow Ch6 knob rotation.

Basic
Then you should do External FC Gain regulation (assuming you already tuned your PIDs).

(2) Is simple

GPS goes to UART6 port on the back of PX4FMU.
Compass is connected in I2C splitter of (4).

(3) Power module is a bit tricky

Arducopter APM 2.6
Here's best picture I could find. For those who's not fluent in Russian: 4 is Voltage and 3 is current. Rest is self explanatory. 

( i ) when using PX4IO to power your FC, board reads voltage from built in BEC input. (aka pin 100).

PX4FMU + PX4IO - flight controller + expansion board
In my case, I used pin 10 to read current from power module (i.e. connected yellow wire to pin 10).
Then in mission planner -> Config tuning -> Full parameter tree, set: 
BATT_CUR_PIN: 10

I did not use Pin 101 because I could not get it to show anything. 
PX4IO - PX4 expansion board

(4) Too easy

Everything is straightforward. 
I2C -> to I2C port on PX4IO,
Buzzer to PX4FMU near SD,
Button to PX4IO near power plug.
And get rid of USB cables, because it's excessive weight.


PX4, Pixhawk, APM external RGB LED meaning


RGB LED indicationMeaning
●●Flashing blueDisarmed, no GPS lock
●●Solid blueArmed, no GPS lock
●●Flashing greenDisarmed, GPS lock acquired
●●Fast flashing greenDisarmed, SBAS GPS lock acquired (better)
●●Solid greenArmed, GPS lock acquired
●●Single flashing yellowRadio failsafe activated
●●Double flashing yellowPreArm checks failed
●●Flashing yellow with beeping toneBattery failsafe activated
Flashing yellow, blue with quick toneGPS failsafe activated
Flashing red, yellow with rising toneEKF or Inertial Nav failure
Flashing purple, yellowBaro glitch
●●Solid redError
●●Solid red with SOS toneSD card error/missing



(5) Now the "sexy" part

Connecting PPM to PPM port on PX4IO is easy. Tough task is to make RSSI work. 
Issues:
1. FrSky TFR4 claims to have RSSI (PWM) on this port, but it gives me analog voltag which is proportional to signal strength and has range of +3V to +0.05V. Although it was no problem on APM 2.6, PX4 refuses to accept this signal (at least on SBUS port).
2. With a bit of experiments I found that my PX4 accepts RSSI on pin 13 (see figure above).
The issue is that it always shows me 100% and I have a feeling that it's not linear but parabolic. I.e. when I turn off radio, signal is falling, but it really lacks resolution in top (100%) segment.


Hacking

Now techie part. I had 3-d channel burned on my PX4IO, so it was pretty useless on quad or any other copter. Back then I had an idea to switch channels, say 3 to 8 and 8 to 3.
This way I could use Quad, Hexa, and gimbal configs along with many others. 
Quck search told me that people who had such problems lack programming skills or desire to share their results. 
Long story short: I found what and where to change.


Where

Happiness is in: libraries/AP_Motors/AP_Motors_Class.h
assuming you are in root dir of your Arducopter source.

What

In my case, I moved all output channels one pin forward. I.e. physically I connect 1,2,4,5,6,7,8 but logically it's 1,2,3,4,5,6,7 channels. 
physical pinlogical chan
11
22
38
43
54
65
76
87
That's why output 3 (2U) jumped to AP_MOTORS_MOT_8 position.
#define AP_MOTORS_MOT_1 0U
#define AP_MOTORS_MOT_2 1U
#define AP_MOTORS_MOT_3 3U
#define AP_MOTORS_MOT_4 4U
#define AP_MOTORS_MOT_5 5U
#define AP_MOTORS_MOT_6 6U
#define AP_MOTORS_MOT_7 7U
#define AP_MOTORS_MOT_8 2U
#define AP_MOTORS_MOT_9 8U
#define AP_MOTORS_MOT_10 9U
#define AP_MOTORS_MOT_11 10U
#define AP_MOTORS_MOT_12 11U
Pretty simple. 
Compile, upload, rock-n-roll.
A bit information on "how to compile PX4 or ArduCopter firmware" is located here: http://p0rc0-r0ss0.blogspot.com/2015/05/px4-mkbl-esc-px4-software-stack.html

Links

http://ardupilot.org/copter/docs/common-px4fmu-overview.html
http://diydrones.com/forum/topics/how-to-connect-a-current-voltage-sensor-to-px4
http://ardupilot.org/copter/docs/common-leds-pixhawk.html

Friday, July 14, 2017

Usefull atom/brackets extensions.

Quick memo on useful extensions for editor.
  • emmet - code automatic completion/generations
  • highlight selected - very comfy feature. Like in NPP.
  • color-picker - lets choose color from palette
  • minimap ?! - looks like pretty neat plugin, but it will take screen space. I'll leave it alone for now. 
  • file-icons - icons for every file type
  • linter + linter-css, php, js, html

  • remote-edit - for server side edititng.
  • pigments - to colorize #FFAABB notation in code

For fun:
  • asteroids ?! 0_o - this is like "when programmer has nothing else to do"

Sunday, June 25, 2017

Purge unnecessary locales Ubuntu

Sometimes it is annoying that ubuntu spends time generating locales we don't use, so here's the cure:

sudo locale-gen --purge


for example:
sudo locale-gen --purge en_US

will leave only US locale.

Sunday, June 4, 2017

Bulletproof samba configuration.

We all know, that sometimes it could be such a pain to get samba working. Here's configuration example that works for sure.

Let's say we want user marco to access /srv/storage and to name share stg (full url will be: ///stg )


At first you need to create system user like:
useradd -d /srv/storage -s /bin/false marco

Then we need to add this user to samba with:
smbpasswd -a marco

Now we move initial /etc/smb.conf somewhere else and fill empty one with:
/!\ WARNING! This config is bound to eno1 ethernet interface.
[global] 
# Standard config options
workgroup                    = WORKGROUP
server string                = Force is with you, young padavan!
interfaces                   = 127.0.0.0/8 eno1
bind interfaces only         = yes
log file                     = /var/log/samba/log.%m      max log size              = 1000
panic action                 = /usr/share/samba/panic-action %d
# Extra options   # AUTH
unix charset                 = UTF8
dos charset                  = 866#
domain master               = yes#
prefered master             = yes
os level                     = 77
guest account                = fj
hostname lookups             = no
netbios name                 = nvr
preserve case                = yes
short preserve case          = no
time server                  = yes
unix extensions              = no
load printers                = no
printing = bsd   printcap name = /dev/null
include = /etc/samba/stg.conf


now we should create /etc/samba/stg.conf and fill with:

[stg]
valid users             = marcocase sensitive          = auto
default case            = lower
browsable               = yes
comment                 = Everything is stashed here
create mask             = 0644
  force create mode     = 0664
directory mask          = 0775
  force directory mode  = 0775
dont descend            = /proc,/dev,/etc,/sys,/opt,/1_sys
guest ok                = no
hide dot files          = yes
hide special files      = yes
hide unreadable         = no
#hosts allow             = 192.168.1.
inherit owner           = yes
inherit permissions     = no
path                    = /srv/storage  
read only               = no
use sendfile            = yes
follow symlinks         = yes
wide links              = yes

afterwards you can type testparm and see if there are any errors. 

Babbling about "rlimit_max" is perfectly normal.

p.s. hate this crippled wysiwyg editor!

VIM cheat sheet

Basic basics :) i - start editing, current symbol a - start editing, next symbol Esc - stop editing :w - write to disk :w <filename> -...