Posts Tagged ‘gedit’

h1

Syncing Between Linux and Windows with BitTorrent

28/06/2013
Skip the insecure Cloud with BitTorrent Sync

Skip the insecure Cloud with BitTorrent Sync

I’ve always been a DIY kind of guy when it came to technology, and the idea of giving my data to cloud services such as Dropbox or Box.com (and whoever has access to that data besides them) seemed a little iffy. The cloud, as great as it is for some things, isn’t really built for too much security. Keeping data private on an internal system is hard enough, but throwing it out to the internet only multiplies these issues.

That’s where BitTorrent Sync comes in. Built by BitTorrent Labs (and using the BitTorrent Protocol), this solution boasts that it will allow you to sync between different OSes, securely, and without throwing any of it out to the cloud. This increases security incredibly, and isn’t that hard to set up. I put it on my Linux laptop (Stu) and a Windows 8 desktop (Zer0), both of which I’ve used in previous projects. It works, but it has a few caveats as you’ll see below.

Installation on Linux

Linux installation is fairly easy, if a bit obtuse. Instead of an installer of any kind, the package for BitTorrent Sync comes with a License.txt file and a single btsync binary. To start up the software, simply unpack it, navigate to the containing folder in a terminal and run the ./btsync command. That’s it.

$ cd /Location/of/File
$ ./btsync
The Linux binary can be configured through the webGUI (kinda) or the more robust sync.conf file.

The Linux binary can be configured through the webGUI (kinda) or the more robust sync.conf file.

However, unlike it’s Windows and MacOS brethren, there’s no independent GUI to use. You’ll need to open a browser and head to a webpage to administer it. In most cases you can use the address 127.0.0.1:8888

From there you can select the folder you want to sync as well as generate a secret key for said location. The key is to allow other computers on your network to access the folder securely. Barring any conflicting firewall settings on your local machine, this should just be a matter of putting in the secret when you add a folder.

If you need the key from a folder you’ve set up previously, you can get it again from the gear icon next to the listing in BitTorrent Sync. Also, if you head to the Advanced tab you can grab a “Read-Only” secret. If you use this key when setting up another computer, it will read from the folder but never write to it. This is useful if you want the updates to go only one way or you want to give someone the ability to see what’s on your machine without running the risk of them deleting or altering the files.

Installation on Windows

Next, I went to Zer0, my Windows machine, and installed the software. From what I understand, the Windows and MacOS versions are pretty much the same, so other than the intricacies of the Mac platform the installation and use should be very similar.

The Windows application is a little plain, but gets the job done.

The Windows application is a little plain, but gets the job done.

After running the installer, you’ll be presented with a page that has several tabs. Go to the “Shared Folders” tab and click on “Add”. Put in the secret from the share that we want to access and click “Okay”. It should have all the information it needs to connect and start syncing. Mine did it automatically and pulled the four or so test files with no further work on my part.

You can also add a local folder and sync it here. By default it’s the btsync folder in your Documents directory. I just left this as it is for my testing purposes.

Tweaking the System

Now that it’s set up, you can do a few more things to shape it to your preferences. As you first may have noticed you can add any number of folders to sync, for no cost unlike most cloud services. So if your primary concern is just moving files back and forth behind the scenes (as I do) then that’s probably this setup’s greatest strength beyond security.

There are further options as well that fall into the more advanced users’ category. On the Preferences page in both the Linux WebGUI and the Windows application, you can set rate limits, alter whether the software loads at boot and some other odds and ends. In the Advanced section, you can do even more. Here’s a quick rundown of these options:

The conf file has pretty good explanations for every editable line

The conf file has pretty good explanations for every editable line

disk_low_priority: If True, BitTorrent Sync will set itself to Low Priority on the system. Turn this on if you’re noticing serious speed problems when using BitTorrent Sync

lan_encrypt_data: If True, BitTorrent Sync will encrypt data sent over the local network. Turn this on if you want to hide your traffic from others who may be using the same network as you.

lan_use_tcp: If True BitTorrent Sync will use TCP instead of UDP for local transfers. Will use more bandwidth but will be (at least theoretically) more reliable.

rate_limit_local_peers: If True, BitTorrent Sync will apply rate limits (set in General Preferences) to local users. By default rate limits are only applied to external peers (those not on your network).

In Linux, these options as well as a few others are all stored in the configuration of btsync. You’ll need to go to the folder that you have btsync running in to access it. First, you’ll probably want to output a sample configuration and open it in a text editor to see all options you have. There are quite a few.

$ ./btsync --dump-sample-config > sync.conf
$ gedit sync.conf

It’s pretty self-explanatory, but I want to direct your attention to the username/password fields. Remember that webpage we went to earlier to set up the shared folder on Linux? Well it’s actually hosted from your machine, meaning that anyone who as the access to the network can pull up your BitTorrent Sync options and mess with them. So it might behoove you to set this option.

Once you’ve organized things the way you want them in your sync.conf file, save it. Now, you can import it back into the BitTorrent Sync application by running btsync with the modified conf file as such:

$ ./btsync --config sync.conf

Worth the Effort?

And that’s pretty much the ins-and-outs of the BitTorrent Sync application. I imagine that I’ll be using this not as my primary software to sync things between machines or as backups, but I will have it move files and folders from one machine to another periodically. Perhaps one could set up a backup drive on a server that just copies one way from all the machines that are linked to it. I imagine that could be a project for a different day.

On the whole this is a nice piece of software that pretty much does what it says it’s going to do, and securely. I know it’s Linux, but the lack of a real GUI and the complication of editing advanced options by way of the .conf file is kind of a downer. I’m totally fine with using the command line (in some cases I prefer it), but that drags down the score a bit on this one because it’s not very user friendly. Still, a fine piece of software that I will definitely be utilizing in the future.

Rating: 4.5/5 – Pretty darn good. However, the Linux version takes a little work to get customized and the Windows/MacOS advanced pages are a little confusing at first.

-CJ Julius

Advertisements
h1

Creating a Simple Linux Webcam Server

31/05/2013

Whether you’re needing to create your own security camera, or you’re wanting to set up an always-on web video, having constant, recorded video feed can be useful. It’s even more so if you can access it while you’re not at home, say, over the internet. That’s what I did a few weeks ago, with an old computer (Crusher) that I’ve been using as a file server. Now it’s pulling double duty as a constantly-streaming video service that broadcasts over the internet.

See and Record from anywhere

See and Record from anywhere

Now, this setup is quite simple, and as such has a few drawbacks. There is no security implemented in this guide, though that can be done fairly easily afterwards. There is a little bit of upkeep, and it doesn’t do everything on its own (such as file cleanup). On the flipside, it’s not very resource intensive, records everything, can be set up, sent off and running in an afternoon and is extremely stable. I’d also like to mention that it’s dirt cheap, as this can be put on almost any machine made in the last decade.

If these strengths and weaknesses sound like what you’re trying to do, here’s how to put it together.

The Tools

What you’ll need:

  • A PC with at least one free USB port.
  • Ubuntu Linux 10.04LTS or later installed.
  • A Linux-compatible webcam.
  • Access to the internet (from the PC).
  • A Router that can support Virtual Servers or Port Forwarding.

The USB port can be 1.1 or higher. Most webcams don’t push through enough data to really need the higher speeds. Though if you did get a higher-resolution webcam, then make sure you’re attaching it to a port that can handle the load.

This old Dell Optiplex GX1 is enough power to run both a Linux fileserver and webcam server.

This old Dell Optiplex GX1 is enough power to run both a Linux fileserver and webcam server.

In my case, I’m assuming that you picked up a really cheap webecam. For my purposes, I chose the Logitech C200. Everything Logitech is pretty much plug-n-play (ie “It just works”) with Linux. You can pick up that cam for about $12-20, but there are even less expensive ones out there that will function just as well.

The PC that I’m showing you this on is a very old one (Pentium 3-era) with about 512MB of RAM and running Ubuntu 10.04 LTS (server repositories). Now, 10.04 is out of date as of this writing, but I’ve since migrated the repositories over to the sever versions. This guide will still work on 12.04, as I tested it on that system as well, but for the sake of consistency, I’ll be showing you everything from my actual server’s view.

The router needs to support port-forwarding or virtual servers for you to be able to get to it from the internet. If you’re not worried about that, then you can ignore this requirement. Most routers support this anyway, so you’re probably fine. In either case, your “server” will need to able to access the internet.

Motion Setup

Booting your computer with the webcam plugged in should be sufficient to register it in the system. To find out if it is indeed in the system, use the lsusb command (List USB) to see all of the devices connected to your computer via USB. You should get output that says something like the following:

cjjulius@CRUSHER:~$ lsusb
Bus 001 Device 002: ID 046d:0802 Logitech, Inc.
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

The Logitech device is being registered by the system. If you don’t see your device here, then you’re most likely looking at a hardware issue, as Logitech uses the standard uvcvideo drivers and software-wise sets up very smoothly. If you’re not using Logitech and you’re not seeing your device here, then you’ve got some troubleshooting to do.

Next, we’ll need to find out where in the system our camera is mounted so we can point our software to it. Use the following command to see where your usb device is currently mounted. Basically this command lists all the devices connected to your system, then sends that to the grep tool which in turn filters everything out but devices with the word “video” in them.

cjjulius@CRUSHER:~$ ls /dev/ | grep video
video1

Make a note of this device’s lotion, which in my case is: /dev/video1

Now we need to install motion, our webcam recording software. So, we’ll act as a superuser, telling aptitude to get the software from the repositories and install it:

sudo apt-get install motion

Then we’ll go to the configuration file and edit it, so we can point motion to our webcam and maybe edit a few options. First I’ll copy a backup (in case we goof) and then we’ll edit the original. You can use either nano or gedit, depending on your preference. I’ll use nano, because it is low-resource and Crusher is an old computer doing a lot of stuff. Again, we’ll need to act as a superuser to do so.

sudo cp /etc/motion/motion.conf /etc/motion/montion.conf.bak
sudo nano /etc/motion/motion.conf

In here are a lot of options, and some you’ll probably want to tweak at a later date. Right now we’re just interested in getting this thing rolling and we don’t want to get bogged down in the details. We’re looking for a line labeled “videodevice” under the “Capture Devices” heading. It should be pretty close to the top.

On the same line as videodevice, we want the /dev/video0 line to point to our webcam that we found earlier. So, in my case it reads:

videodevice /dev/video1

Your device line should look something like this in motion.conf

Your videodevice line should look something like this in motion.conf

Save the file and exit the editor. Again, there are lots of options in here (including password protection) but we’re not interested in that right now. We just want to get a simple webcam server up and going, though I encourage you to come back and tweak the settings, or at the very least see what you can do with this program.

Now, you can run motion by simply typing “motion” at the command line. Remember that motion stores video streams as .jpgs and uses the folder you run the command from to store the files. This can fill up smaller drives very quickly.

My method to deal with this is simple, but isn’t elegant. I navigate to the Trash folder and run motion from there. Then, when I want to clear the files, I just log in and empty the trash.

cd ~/.local/Trash/files/
motion

Webcam Viewing

Assuming that motion is now running successfully in your terminal, we can see what your camera is seeing. Open a browser and go to http://127.0.0.1:8081

If you go to any other computer on your network, you can simply put into your browser the following to see your webcam:

(PC's IP address):8081

If you don’t know your Webcam Server’s IP address, we can look at the interface configuration output and filter it for an internet address. You can do this by opening a terminal and typing:

ifconfig | grep "inet addr"

It should be the first one on the first line. Not the 127.0.0.1 line. In my case it’s 192.168.100.6

But, if we’re away from the building with the webcam, that’s not very helpful. We want to be able to access our server from anywhere in the world. So, we need to set up a method of getting to our home machine from elsewhere.

First, we need to forward the appropriate ports so we can see the video stream. Motion, by default, uses only the one you saw before: 8081. We just need to get our router to connect the dots between any connection that comes in from the internet on that port, with our server.

This is what mine looks like, but they're all a little bit different.

This is what mine looks like, but they’re all a little bit different.

Go into your router’s settings page, in my case it’s an Arris modem/router, and go to the Firewall/NAT page (or something like it). Look for “Port Forwarding” or “Virtual Servers”. Select that you want to “Add New”.

Use the 8081-8081 range for both incoming and local ports and then put the local PC’s IP address that we got with the ifconfig above. The description can be anything.

Now, if you go outside your network, you can put in your own home IP address with the :8081 on the end and connect to your webcam. If you don’t know your outside IP address go to a site like WhatisMyIP.com and it will tell you.

Again, this is all well and good, but your IP can change, and even if it doesn’t for a while, that number is hard to remember. So, as our last step, let’s make this more human-readable and dynamic. We’ll go get a free dynamic DNS account and use it to redirect traffic from a more user-friendly name. Keep in mind that while useful, this is still an option and you can still use the IP web address [Your Outside IP]:8081 to get to your webcam.

This is approximately what the Dynamic DNS redirect setup should look like.

This is approximately what the Dynamic DNS redirect setup should look like.

Go to a site like NoIP.com and sign up for a free account. Select that you want to Add a Host and then come up with a unique hostname and use one of the default domains; usually only a few are available for free. You should see your outside IP listed in the box.*

Set it to a port 80 redirect and that you want it to connect to port 8081. You can also mask the URL if you want, but I’ve found that rarely works. Add the host and you should be good to go. Now pointing any browser to your no-ip domain name (without the :8081 on the end) will pipe you from anywhere to your webcam server.

And that’s it, you can go to any computer that has internet access and see what’s going on wherever you set up your webcam.

*I chose NoIP because they have a Linux software package that will update the IP your redirect is associated with automatically. Eventually, your IP is going to rotate and it’s nice to have that piece of software watching that for you. See their page for instructions on how to install it.

-CJ Julius