Saturday, March 25, 2017

TFTP

When using Busybox TFTP client

get file:
tftp -g -r filename.txt tftpserverip_or_hostname

put file:
tftp -p -l filename.txt tftpserverip_or_hostname

Getting a file not found error? It seems that the file must exist on the server first, so if you want to upload a new file, first go to the server via SSH or something and create a dummy file of the same name.

Getting permission denied error? You don't have enough permissions on the dummy file you are trying to upload over. SSH to the TFTP server and chmod 777 the file. Upload it. Then change the permissions back to 644 or something.

When using OSX
get file, launch Terminal and type these commands:
tftp
binary
connect tftpserverip_or_hostname
get filename.txt

put file, launch Terminal and type these commands:
tftp
binary
connect tftpserverip_or_hostname
put filename.txt

Thursday, August 11, 2016

After having a bit of trouble installing my own certificate on Ubiquiti's Unifi software on Linux, I though I would let you know the process I went through.

First up, in my case I had my CA Certificate + User Certificate + User Key in .p12 format.

If you have already installed the Unifi software then please, please, please make a config backup.

Install the Unifi software on your server and make sure you can get to the Management page where it will be using an untrusted certificate from ubnt.com



Download Keystore Explorer for your OS from http://www.keystore-explorer.org/ which is a GUI for some java command line tools to deal with keystores.

Create a new keystore of type JKS

Import key pair, and select your .p12 certificate.



give it password 'aircontrolenterprise' (This is the ubiquity set password on the existing keystore that we are going to replace)

When requested to give it an alias, give it an alias 'unifi'



Save it.

SSH back to the server running your Unifi.

Stop the unifi service by running the command 'sudo service unifi stop'

move the existing keystore that we are going to replace by running 'sudo mv /var/lib/unifi/keystore /var/lib/unifi/keystore.original'

Use FTP or another method to copy the keystore you created with Keystore Explorer into the same location /var/lib/unifi/keystore

restart the service by running 'sudo service unifi start'

Back on your client machine, browse to the Unifi Management to test.
You should now have your own trusted certificate and can start restoring your saved config or starting with your fresh Unifi install.


Wednesday, February 24, 2016

Resize Linux Partition

I had the case of wanting to resize a linux partition for my Raspberry pi without access to the usual raspi-config tool so had to do it manually.
The raspi-config tool doesn't require a reboot, so there are probably other ways to achieve it as well, but this way works for me.

First I had a full disk. Which you can see by running the df command with -h for human readable output.


I want to expand the space for the / mount point that is at 100%
You can see that there is a partition at /dev/mmcblk0p1 , the p1 refers to partition 1 so that is device /dev/mmcblk0 but what partition is the / mount point?

You can check the partitions on the device with the fdisk -l command which lists them. 

So you can see that we want to expand the partition /dev/mmblk0p2 on device /dev/mmblk0

You also use fdisk on the device to delete and recreate the partition, then write the results back. This is done on partition 2 even though partition 2 is the linux partition on the running system.


It says the partition was altered, but the device is busy. It also says the device is busy for the next commands so the next step was to reboot.

After the reboot, run resize2fs on the partition that changed size.


If it ran successfully, you can df -h again to see the new space that is now available.
  

The space is now available for you to use.





Wednesday, October 28, 2015

Mac OS X Automator - Convert .m4a to .mp3

I had a problem that my car stereo only plays MP3 files, but I have some music in M4A format that I wanted to listen to for a road trip.

So I wanted to convert it, and as I had a few files to do, I decided that Automator could help me out in order to repeat it.

In the end it was pretty simple.
I created a new Automator application in case I wanted to have it as an application in the future. You could do it as a workflow as well, since if you compile it as an application the paths will be set inside it and you will have to open it in Automator again to change it.


I already had ffmpeg on my system so I tested it on the command line first.

If you don't have ffmpeg installed you can install it with Macports using the command:

sudo port install ffmpeg 

Once you have the ffmpeg installed, play around with for a bit to get it converting the audio file on the command line. Once that was working all you needed to do was have your Automator application get a finder object and run a shell script using the ffmpeg command line options with a few adjustments (such as needing the ffmpeg complete path in Automator)



Here is the code:

for f in "$@"
do
b=$(basename -s .m4a "$f")
/opt/local/bin/ffmpeg -i "$f" -codec:a libmp3lame -ab 256k /Users/username/Desktop/"$b".mp3
done

(If you copy the above code, don't forget to change the output directory to the one you want)

That basically creates a loop that goes through all of your input files. The screenshot only had one input, but you can drag multiple files into the "get specified finder items" section. Each time the loop runs the current file it is working on gets saved into variable 'f'.

b=$(basename -s .m4a "$f") -> creates a variable 'b' and saves into it, the filename of the current file we are working on (that is "$f" dont forget) without the .m4a extension. So if you pass it '/path/to/file/music.m4a' variable 'b' will contain 'music'

Then run the ffmpeg command line. In my case I knew the input bitrate was 256kbps, so I forced ffmpeg to save in that bitrate too. Check the ffmpeg documentation for what you can do with it.

Thursday, September 17, 2015

Raspberry Pi Touchscreen Display Unboxing


I stumped up and bought a Raspbeery Pi 7" Touchscreen Display as I am planning on using it as a start/stop, status display for my radio streaming pi.


All the components it came with.



Attach the white display cable that is going to connect to the pi, attach the large screen cable to the connector on the underside of the display board. Attach the smaller ribbon to the small connector on the top of the display board (not shown)


Use the spreaders to attach the display board to the display.

Attach the pi, attach the power and boot up. (photo to come)

Tuesday, December 2, 2014

pfsense load balancing

I had the case where I wanted to access my server remotely via SSH when my server was behind my pfsense firewall.
The problem was, I often swap between a wired and wireless connection. I could port forward two different ports, one to the wired network and one to the wireless, but that is one more thing to remember. So I thought I would investigate pfsense load balancing functions so I wouldn't have to remember if I left it on wired or wireless.

First is to set static IPs for the servers wireless and wired connections so I could reference them later. You can do this in the Status > DHCP leases menu.

Second I needed to allow SSH from the WAN to the LAN network. I created a Firewall rule to allow this. You could create two rules to allow SSH to each static IP, but I have other devices on my network, so I just opened it from the WAN port to the whole network. by using the /24 address of the destination.


Now to the fun stuff, load balancing.

You need to create a pool containing the servers you want to load balance to, and a virtual server to forward a port to and use the pool.

In Services > Load Balancer > Pool, click the plus to create a new pool.
Since you wanted pfsense to know what is available, wired or wireless, and send traffic to whatever is available we want to select 'Load Balance'. Give it a description. The servers are listening on port 22 for SSH so we want to balance across that port. Add the static IPs that you set earlier and save.


Now in Services > Load Balancer > Virtual Server, click the plus to create a new virtual server.
Give it a name, the IP address is your WAN IP (or alias for the WAN IP) I wanted to use a non standard port, so chose port 1023, and you select the pool to use, in my case 'Server_SSH_Pool' and save,


Apply changes. I rebooted the server to be sure.

Now get onto the same network that your WAN connects to and try to SSH.

ssh://username@10.1.1.123:1023

where username is the username of an SSH user on the two servers in the load balancer pool.

It should ask you for the password and you should be in.
log out, change the server to connect to the LAN via its other network interface wired or wireless. Then back on machine on your WAN try to SSH again to the same address.

You should now be able to get in from your WAN by using the one IP address and port 1023, no matter if your server is connected to the LAN via wired or wireless. (or a second NIC, it doesn't have to be wired and wireless) You are just load balancing across two different IPs so those could be different servers as well - that's how you load balance HTTP web requests to different web servers to handle load, my case just needed SSH instead.


Monday, August 11, 2014

Raspberry Pi RTC Module

Well I purchased this High Precision Real Time Clock for my Raspberry Pi.

They had a nice article on how to get it working here.

I pretty much followed it exactly and it worked fine, but I am going to relist the steps here in case I need them again later or the article moves etc.


# Remove the module blacklist entry so it can be loaded on boot
sudo sed -i 's/blacklist i2c-bcm2708/#blacklist i2c-bcm2708/' /etc/modprobe.d/raspi-blacklist.conf
# Load the module now
sudo modprobe i2c-bcm2708
# Notify Linux of the Dallas RTC device
# on my 256Mb Pi I used.
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-0/new_device
# on my new Pi B+
#echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
# Test it out.
sudo hwclock

once that was done:
# Add the RTC device on boot
sudo sed -i 's#^exit 0$#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device#' /etc/rc.local
#dont forget to change i2c-0 or i2c-1
echo exit 0 | sudo tee -a /etc/rc.local
#This doesn't cover automatically setting the clock on boot and but you can do so by adding another line (above exit 0) to rc.local with;
hwclock -s