Posts

Enable/Disable Output of Audio Input in Ubuntu

After hooking up my old-school turntable to the input jack on my desktop PC, I thought I’d be easily able to output the sound from my speakers. I could even see the audio playing as an input and could record it using Audacity, but not output it directly.

By default Ubuntu does not load the loopback module for Pulse, the audio manager for Ubuntu. You need to load this module to get the input audio to play out to your speakers. To enable this feature run the following command:

1
pactl unload-module module-loopback

This will load it one time, and when you reboot it will again be unloaded. To make it ‘stick’ and load on every boot, run this command:

1
sudo sh -c 'echo "load-module module-loopback" >>  /etc/pulse/default.pa'

If you want to undo the loopback module, run this command:

1
pactl unload-module module-loopback

and to disable it from running on startup:

1
sudo sh -c 'sed -i "/load-module module-loopback/d" /etc/pulse/default.pa'

This was tested in Ubuntu 13.04.

If you start getting weird audio feedback after running this command, you might want to check that you didn’t accidentally load the loopback adapter twice!

Experimenting with Pascal on Ubuntu

pascal

I’ve been busy lately on a number of projects, one of which is a programming class I am currently taking. The class itself is interesting, we are learning about the different types of programming languages. For our latest project, we were tasked with writing a simple program in Pascal. Pascal isn’t used too much any more since it lacks some of the features that most modern languages have, but it is good to know at least a little bit about it in case you ever run across some old Pascal programs in the wild.

The syntax for pascal is a bit verbose, that is the main complaint about it. There are a number of others, but that is beyond the scope of this howto.

Installing The Pascal Compiler on Ubuntu

Installing Pascal in modern Ubuntu is a cinch. The Free Pascal Compiler, or fpc, is all that you need to get started. It works great on 32-bit or 64-bit systems. Install with:

1
sudo apt-get install fpc

Any prerequisites will automatically download and install along with fpc.

Getting Started in Pascal

To test the compiler let’s start with a simple Hello World program. Open up hello.pas and enter:

1
2
3
4
5
6
7
program Hello;

begin

Writeln('Hello World');

end.

Compile with fpc hello.pas and run:

1
2
dave@cerberus:~/Pascal$ ./hello
Hello World

Selection Sort in Pascal

Now that we’ve verified it is running, I’m going to show you the code that I wrote for my program. Basically we were asked to Selection Sort two arrays of varying length. Apparently one of the (bad) features of Pascal originally was that you needed to declare the length of the array which made it a pain to work with them.

In this situation it is just two arrays so it isn’t too bad. Enter your array by creating two text files arrayA.txt and arrayB.txt. One number per line. The source code for sort.pas is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
program Sort;

var
        A: array[1..10] of Integer;
        B: array[1..20] of Integer;
        F: Text;
        i,j,k,l,m,temp: Integer;

begin
        {Read in array A}
        Assign(F, 'arrayA.txt');
        Reset(F);
        i:= 0;
        while not EOF(F) do begin
                Inc(i);
                Read(F, A[i]);
        end;

        {Read in array B}
        Assign(F, 'arrayB.txt');
        Reset(F);
        j:= 0;
        while not EOF(F) do begin
                Inc(j);
                Read(F, B[j]);
        end;
        i:=10;
        j:=20;

        {Print out the unsorted arrays}
        WriteLn('Unsorted Arrays:');
        WriteLn('Array A:');
        for k:=1 to i do
        Write(A[k], ' ');
        WriteLn();
        WriteLn('Array B:');
        for k:=1 to j do
        Write(B[k], ' ');
        WriteLn();
        WriteLn('=========================');
        WriteLn('Sorting Arrays...');
        WriteLn('=========================');

        {Selection Sort Array A}
        for l := 1 to i do
                for m := l + 1 to i do
                        if A[l] > A[m] then
                        begin
                                temp := A[l];
                                A[l] := A[m];
                                A[m] := temp;
                        end;
        {Selection Sort Array B}
        for l := 1 to j do
                for m := l + 1 to j do
                        if B[l] > B[m] then
                        begin
                                temp := B[l];
                                B[l] := B[m];
                                B[m] := temp;
                        end;

        {Print out the sorted arrays}
        WriteLn('Selection Sorted Arrays:');
        WriteLn('Array A: ');
        for k:=1 to i do
        Write(A[k], ' ');
        WriteLn();
        WriteLn('Array B: ');
        for k:=1 to j do
        Write(B[k], ' ');
        WriteLn();
end.

Compile and run (ok to ignore the compile-time errors)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
dave@cerberus:~/Pascal$ fpc sort.pas
Free Pascal Compiler version 2.4.0-2 [2010/03/06] for x86_64
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for x86-64
Compiling sort.pas
Linking sort
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
73 lines compiled, 0.1 sec
dave@cerberus:~/Pascal$ ./sort
Unsorted Arrays:
Array A:
28 24 85 55 43 6 23 13 59 71
Array B:
13 37 36 53 24 83 27 42 62 71 9 92 1 41 6 3 88 77 65 67
=========================
Sorting Arrays...
=========================
Selection Sorted Arrays:
Array A:
6 13 23 24 28 43 55 59 71 85
Array B:
1 3 6 9 13 24 27 36 37 41 42 53 62 65 67 71 77 83 88 92
dave@cerberus:~/Pascal$

And there you have it. Compiling Pascal program on Ubuntu is an easy way to get your feet wet in programming. Pascal is a great beginner’s programming language, but if you want to learn more there are a number of great resources available for learning Pascal.

UbunTOS – Ubuntu 9.10 + TinyOS 2.x VirtualBox Image

vboxubuntos

This is my admittedly minor but I hope useful contribution to the TinyOS development community. TinyOS is an Operating System and development framework for Wireless Sensor Networks and other platforms which has a small footprint and is very energy conscious.

The TinyOS source code is available for free online for many operating systems, however it takes a long time to get the environment set up and it is not portable at all. I came across XubunTOS but it did not seem to be in active development anymore, so I endeavored to install TinyOS 2.1 and 2.x from source into a regular Ubuntu image. The most help came from Matt Keally’s Blog. While doing this, I thought it might be useful to many others who wish to develop in the TinyOS framework but might not have the skills necessary to install it. Therefore, I developed this VirtualBox image so that you can install it on any system for which VirtualBox is available and supports USB passthrough for the programming of the motes. I’ve tested on Windows 7, Windows XP and it should work on any other host OS, but I would love to hear your feedback. All funny business aside, I present to the world UbunTOS: Read more

How To Reset Windows XP, Vista, Windows 7 Passwords with Ubuntu 9.10 Live Image and a USB Drive

I put this together for a project in a class I am taking, and thought it would be handy for others as well. The goal is to access a Windows filesystem and reset the password for a user, for example if someone forgot the Administrator password or the account is locked out from too many bad password login attempts. This works on all modern Windows Operating Systems: Windows 2000, 2003, XP, Vista, Win7 etc. Make sure to create a backup if you want to make sure you don’t corrupt your Windows install, as it can happen.

Tools used:

Accessing the Filesystem

First we use unetbootin to install Ubuntu 9.10 to a flash drive. The flash drive needs to be at least 1GB to install the image.

Unetbootin settings

Select “Diskimage” and then the .iso file we downloaded of the Ubuntu 9.10 image.

Select the USB Drive and Drive Letter to install the ISO onto. Click OK:

Unetbootin doing its thing

Once the program is done, click ‘exit’ and remove the USB Drive. You now have a bootable live image of Ubuntu 9.10.

Plug the usb drive into the target system. Boot off of the drive, you may need to change the boot options in the BIOS if it is set to boot off of the hard drive. Select “Default” in the unetbootin boot menu to boot into the Ubuntu OS. It will automatically log you in.

Once booted you already have access to the Windows filesystem since the ntfs filesystem driver is included in the kernel. This is nice and wasn’t the case not too long ago.

We chose two reasons to use unetbootin and Ubuntu 9.10. The first is the ease of use of installing a bootable image. After downloading the two packages, it is trivial to load the OS onto the drive, and since it includes ntfs drivers it allows us to access the unencrypted hard drive on boot. Since it is on a USB drive, any system made since 2000 or so should be able to boot this. You don’t need to lug around a CD or even access the CD drive.

To prevent easy access to the hard drive, encryption of the hard drive partition would be necessary using Microsoft EFS or TrueCrypt hard drive encryption software. After encrypting the hard drive, any live operating system running would not be able to decrypt the hard drive easily.

Furthermore, installation of a BIOS level password would ensure that any unauthorized users would not be able to boot alternative operating systems via USB, CDROM, Floppy or other method. The only way to defeat a BIOS level password would be to reset the BIOS (requiring entrance into the hardware of the system) or using an Evil Maid style attack.

The Evil Maid attack is performed by a theoretical malicious party that has access to the target PC without alerting the legitimate user. Without knowledge of the authorized; a root kit or device would be installed (for example, on the USB connector of the keyboard) to sniff out the password as entered on bootup. After the user boots the system and finishes her work, ostensibly shutting down the system securely, at least to her knowledge, the Evil Maid would then collect the password entered into the BIOS, thereby defeating the BIOS password security measure.

Resetting the Password

We can now reset the Administrator or any other password on this system using the tool chntpw. To install this package, ensure the system has a connection to the internet (via dhcp perhaps?) and run the command:

sudo software-properties-gtk --enable-component=universe --enable-component=multiverse; sudo apt-get update; sudo apt-get install chntpw

Alternatively, you can download the executable and place it on the USB drive to give access without connecting to the internet. chntpw is the software that modifies the SAM (Security Accounts Manager) database file. Use the terminal to change directories to the password file

cd /media/path/to/disk/WINDOWS/system32/config/

Then execute the chntpw utility:

  # sudo chntpw -u username SAM SYSTEM

View the sample output:

ubuntu@ubuntu:/media/B830C9BC30C981BC/WINDOWS/system32/config$ sudo chntpw SAM SECURITY
chntpw version 0.99.5 070923 (decade), (c) Petter N Hagen
Hive <SAM> name (from header): <\SystemRoot\System32\Config\SAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c <lf>
Page at 0x7000 is not 'hbin', assuming file contains garbage at end
File size 262144 [40000] bytes, containing 6 pages (+ 1 headerpage)
Used for data: 255/20736 blocks/bytes, unused: 9/3648 blocks/bytes.

Hive <SECURITY> name (from header): <emRoot\System32\Config\SECURITY>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c <lf>
Page at 0xe000 is not 'hbin', assuming file contains garbage at end
File size 262144 [40000] bytes, containing 13 pages (+ 1 headerpage)
Used for data: 1074/49024 blocks/bytes, unused: 9/3808 blocks/bytes.

* SAM policy limits:
Failed logins before lockout is: 0
Minimum password length        : 0
Password history count         : 0
| RID -|---------- Username ------------| Admin? |- Lock? --|
| 01f4 | Administrator                  | ADMIN  | dis/lock |
| 03ec | ASPNET                         |        | dis/lock |
| 03ed | CSC603                         | ADMIN  | dis/lock |
| 01f5 | Guest                          |        | dis/lock |
| 03e8 | HelpAssistant                  |        | dis/lock |

---------------------> SYSKEY CHECK <-----------------------
SYSTEM   SecureBoot            : -1 -> Not Set (not installed, good!)
SAM      Account\F             : 1 -> key-in-registry
SECURITY PolSecretEncryptionKey: 1 -> key-in-registry

***************** SYSKEY IS ENABLED! **************
This installation very likely has the syskey passwordhash-obfuscator installed
It's currently in mode = -1, Unknown-mode
SYSKEY is on! However, DO NOT DISABLE IT UNLESS YOU HAVE TO!
This program can change passwords even if syskey is on, however
if you have lost the key-floppy or passphrase you can turn it off,
but please read the docs first!!!

** IF YOU DON'T KNOW WHAT SYSKEY IS YOU DO NOT NEED TO SWITCH IT OFF!**
NOTE: On WINDOWS 2000 it will not be possible
to turn it on again! (and other problems may also show..)

NOTE: Disabling syskey will invalidate ALL
passwords, requiring them to be reset. You should at least reset the
administrator password using this program, then the rest ought to be
done from NT.

Do you really wish to disable SYSKEY? (y/n) [n]
RID     : 0500 [01f4]
Username: Administrator
fullname:
comment : Built-in account for administering the computer/domain
homedir : 

User is member of 1 groups:
00000220 = Administrators (which has 2 members)

Account bits: 0x0210 =
[ ] Disabled        | [ ] Homedir req.    | [ ] Passwd not req. |
[ ] Temp. duplicate | [X] Normal account  | [ ] NMS account     |
[ ] Domain trust ac | [ ] Wks trust act.  | [ ] Srv trust act   |
[X] Pwd don't expir | [ ] Auto lockout    | [ ] (unknown 0x08)  |
[ ] (unknown 0x10)  | [ ] (unknown 0x20)  | [ ] (unknown 0x40)  | 

Failed login count: 1, while max tries is: 0
Total  login count: 1

- - - - User Edit Menu:
 1 - Clear (blank) user password
 2 - Edit (set new) user password (careful with this on XP or Vista)
 3 - Promote user (make user an administrator)
 4 - Unlock and enable user account [probably locked now]
 q - Quit editing user, back to user select
Select: [q] >

Depending on the status of the SYSKEY password security, you may only be able to blank the password and not actually change it. I recommend blanking the password and then resetting it once you log into the system.

You can also unlock a system if the user accounts have all been locked out due to too many login attempts or any other reason. Using these tools you can gain access to almost any unencrypted Windows system, from Windows NT up to Windows 7.

As a warning, If there is data on the hard drive you wish to keep, make sure to make a backup of the hard drive before performing this password as it can corrupt the Windows installation.

Ubuntu Server in Place Network Upgrade From 8.10 to 9.04

Ubuntu Upgrade

It is easy to do an in-place upgrade of Ubuntu Server from 8.10 ‘Intrepid Ibex‘ to 9.04 ‘Jaunty Jackalope‘. You can do this remotely over ssh or whatever you use to control your server. Best practices say to make sure to backup your server before doing the upgrade. I’ve done several servers this way with no issues!

Issue the command:

1
sudo apt-get update; sudo apt-get upgrade; sudo apt-get install update-manager-core; sudo do-release-upgrade

Follow any prompts to first upgrade the current distribution with the newest packages, then do the release upgrade.

Apt-get Update GPG Key Errors and Fix

Running sudo apt-get upgrade, I started getting this error:

1
Reading package lists... Done
1
W: GPG error: http://ppa.launchpad.net intrepid Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 313D312748A22A95
1
W: You may want to run apt-get update to correct these problems

Ah ha! But apt-get update is the command causing this problem.

The solution is to import this key from the gpg servers; I don’t know why this isn’t done automatically, but here is it:

1
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 313D312748A22A95; gpg --export --armor 313D312748A22A95 | sudo apt-key add -

Resulting in:

1
2
3
4
5
6
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com 313D312748A22A95
gpg: requesting key 48A22A95 from hkp server keyserver.ubuntu.com
gpg: key 48A22A95: public key "Launchpad PPA for Filip Brcic" imported
gpg: Total number processed: 1
gpg:              unchanged: 1
OK

Congrats! sudo apt-get update now works properly!

Using Ubuntu as a 24/7 Lobby Display Driver

I recently took upon the task of setting up a presentation display in the lobby of our building. This display had previously used an old computer running Windows 2000, and displayed a fairly simple PowerPoint presentation with a few frames, mostly a schedule for anyone coming into the building.

We did a renovation and this display moved from a desk to on the wall. Therefore we needed to figure out a way to drive this display. We had 3 main options:

  1. Run the VGA cable upstairs to a room where the PC would sit.
  2. Purchase an expensive display driver box that could show PowerPoint along with other things like RSS feeds and video streams. I quoted this out and it was about $1800 for this fancy box.
  3. Install a small computer behind the display and use that to drive the presentation.

I decided to purchase a FitPC Slim to drive this display. This computer is surprisingly small and fits right behind the monitor. It is also extremely power efficient, so that it saves you money and also helps the environment.

When it came to the OS choice, I wanted something that would run on a slower machine (It only clocks in at 500Mhz) but could handle PowerPoint. Also, of course, the budget was a concern as well. So to me,the obvious choice was to use Ubuntu for this.

The stock Ubuntu installation is great on your desktop, with a few exceptions. I thought I would list the big changes you need to make in order to turn it into a keyboardless, mouseless display driver.

The following is a list of the major modifications I made to turn an Ubuntu system into a 24/7 display driver for a lobby television display.

Modify the Power Saving Features

First think you need to do is to turn off the screensaver, and also to disable it from blanking the screen after 10 minutes.

This is done via the System->Preferences->Screensaver tab.

  • Uncheck “Activate screensaver when computer is idle”.
  • Click “Power Management”, Make sure “Put computer to sleep when inactive for:” is set to Never, and change “Put display to sleep when inactive for:” to Never.

Close to save preferences.

Replace Network Manager

This is only important if you are using a wireless card, as I was. By default, network-manager will ask for your key to turn on wireless at every boot. This is really a strange thing to do, I have no idea what they are thinking with this! I would imagine that in the future this will be turned off. But in the mean time, it is totally disabling to us in this situation since there will be no keyboard attached to this unit.

The wireless network manager wicd is the perfect replacement for Ubuntu’s network-manager. It has a lot more features and is very customizable, and most importantly, doesn’t require a password to sign on to the default wireless network.

First, add the wicd repository to your sources.lst. In the menu system, it is: System-> Administration-> Synaptic Package Manager-> Settings-> Repositories-> Third Party Software.

Add (depending on your version):

8.10: deb http://apt.wicd.net intrepid extras
8.04: deb http://apt.wicd.net hardy extras

Reload the repositories.

Go to command line and issue this command to install the GPG key:

wget -q http://apt.wicd.net/wicd.gpg -O- | sudo apt-key add -

Install wicd via Synaptic, or via command line:

sudo apt-get install wicd

This will uninstall network-manager and network-manager-gnome.

Run wicd, Applications->Internet->Wicd. This is only for the first time, it will load on boot.

Configure your network settings, and check off “Connect to this network automatically.”

In some situations, I have also had to reboot the system to get wicd working normally to control the wired or wireless connection.

Enable automatic desktop login for your user

Go to: System > Administration > Login Window > Security and check “Enable Automatic Login” with your preferred user. This is not good from a security standpoint, but it does allow the machine to start up and log in without someone being there to type in the username and password.

Install Power Point Viewer

If you want to display a power point presentation, you will need to install a viewer. OpenOffice will display a powerpoint slide, however as far as I know, you need to launch it from the desktop and it can not be launched from the command line. Since in my parameters, I knew I wanted to launch a presentation from the command line via a script, I decided to go with Powerpoint Viewer.

There is a version that already exists in the Ubuntu archives. You can install it either with Synaptic or via command line:

sudo apt-get install pptview

However, this version had some display problems that I could not seem to figure out. Namely, it would place a white box in the center of all images I had in the powerpoint presentation.

I fixed this by installing wine, then installing the 2007 version of PowerPoint viewer – PowerPointViewer.exe. This version of the program displayed my presentation much nicer.

Another small hiccup I had was that the existing presentations were done using a proprietary font – Arial Unicode MS. I fixed this issue by editing the presentation on my local desktop with Power Point 2007, and changing all fonts to vanilla “Arial”. Make sure the font you use is available in wine on your system if you have problems with that.

Install Remote Desktop Program

First thing you need to do is to allow remote logins, or desktop sharing, to your display system. Go to System-> Preferences-> Remote Desktop.

Remote Desktop Ubuntu Preferences

Remote Desktop Ubuntu Preferences

Check off “Allow other users to view your desktop” and “Allow other users to control your desktop”.

Uncheck “Ask for your confirmation”. The field “Require the user to enter this password:” does as it says, it requires a VNC password before allowing a connection to the machine. This is recommended for the security of the OS, otherwise anyone on the network has full control of the PC.

For the remote desktop server, you have a few choices here – among the best choices are VNC and NXDesktop. I prefer VNC because it allows me to control the display that is currently on the screen.

You can use this remote control to change the current display or otherwise access the machine. Its easy to install in Ubuntu with the command:

sudo apt-get install vnc4server

or use Synaptic to install.

After it is installed on the display system, go to UltraVNC and install the client on your chosen platform. For your local PC, you only need to install the VNC Viewer to control this, or any, remote system. Access your remote computer by typing in it’s IP address. Note that VNC is not considered a secure protocol, so if this display PC is located on a public network, make sure to use a VPN tunnel to secure your VNC connection. I prefer Hamachi.

Set command line to output to the main display screen

This is actually a really easy trick that doesn’t seem obvious at first. Normally if you login to a system remotely, there is no X Display variable set. This means that if you launch a program with a gui component, you will get the error: Error: Can’t open display. This is because the $DISPLAY variable is not set in a normal ssh session.

To fix this, type the following into your command prompt:

export DISPLAY=:0.0

Or, to have it apply every time you log in, add it to ~/.bashrc.

As a side note, to launch a program remotely via ssh, you use “ssh -x” to have it execute on the remote system.

Advanced: Set up a cron script to launch a daily powerpoint presentation

This probably isn’t the best script in the world to do this but it gets the job done. What it does it kill existing Powerpoint Viewer processes, then launches a new one with a slide that has the current date as it’s name. Feel free to use and modify to your uses!

#!/bin/bash
export DISPLAY=:0.0
killall PPTVIEW.EXE
DATE=`date +'%B %d'`
FILENAME="/home/lobby/lobbyschedule/"$DATE".ppt"
"/home/lobby/.wine/drive_c/Program Files/Microsoft Office/Office12/PPTVIEW.EXE" "$FILENAME" &

Add this script to a cron entry according to your schedule, and your powerpoint presentation will update even when you aren’t in the building!

sudo crontab -e

Add a line like these:

0 8 * * 1-5 /bin/su - lobby /home/lobby/launchppt.sh
30 16 * * 1-5 /bin/su - lobby /home/lobby/displayoffhours.sh

The first line will run the command under the “lobby” user at 8:00am on every weekday. The second command will launch an off-hours presentation at 4:30pm every weekday.

In summary:

The final result:

Those are about all the tips I have for now. It’s been running for a few days without problems.

Let me know if you have any tips or tricks you would like to share or if you have any success stories using Ubuntu to run a presentation on a lobby display screen!