Sunday, December 9, 2007

Give a user a new group

So, you have someone who just got a new position within your organization and now s/he needs additional permissions on the server. It makes more sense to give people permissions based on their position rather than on their user. That way, you can give and take exactly the right group of permissions for the position based on a well thought out policy rather than a spur of the moment, "I think they need x to get things done today," sort of thing.

A perfect example of this is sudoers privileges. You can give specific root-type abilities to users or groups of users in the /etc/sudoers file. Another example of this is when you make a certain folder owned by a specific group and have people write to it as *themselves.thatGroup.

You want to use usermod to add a new group to a user, but the problem is that when you use -G to add additional groups, it takes the list that you give it and erases whatever was on the list before. The solution is to add -a for append like this:

usermod -G groupname -a username

Now your user won't lose any of the old groups s/he had, but s/he will get the new one that they need.

*NB: There are a couple of notations for username and groupname for ownership on *Nix. One is username.groupname. The other is username:groupname They are often interchangeable on a single OS or distro, but sometimes you can only use one or the other for commands like chown.

Monday, November 19, 2007

Turning rpm's into deb's

The phone system we use at work right now has a program called MXIE that handles telephone call logging and other whatnotery on your computer. They are nice enough to have a Linux version of the software, but not nice enough to provide source to build it from. They have binary installation files, but only in rpm format. I'm running Kubuntu on my work laptop. Rpm's will do me no good.

Enter Alien. This nifty little utility will convert those pesky rpm's into deb packages so that you can install them easy-peasy on a Debianish system like Ubuntu.

If you don't have Alien already, make sure you have universe repositories set up, and then, from the command line
sudo apt-get install alien

Now you are ready for this
sudo alien -k name-of-rpm-file.rpm

Dun-du-dun!!! You are now ready to install your package
sudo dpkg -i name-of-deb-file.deb

Sunday, November 18, 2007

Internationalization/Localization Cheat Sheet

ISO 639-2 Language Codes live here:
http://www.loc.gov/standards/iso639-2/php/code_list.php

Command Line Tools
xgettext will collect all your strings for you from a file or set of files into a po file.

msgfmt will turn your po files into mo files.


info gettext will get you all the info you need to use the GNU gettext utility.


File Structure
Stick your po and mo files into a structure like this:

/src
/locale/en/LC_MESSAGES/messages.mo
messages.po
es/LC_MESSAGES/messages.po
messages.mo


PHP Functions
putenv ("LC_ALL=es"); sets your locale to Spanish.
bindtextdomain ("messages", "./locale"); shows where to find the translation tables.
textdomain ("messages"); says what domain we're using.

Internationalize your strings in PHP using the handy-dandy underscore operator.
print(_("Hello World"));

More info on gettext functions in PHP:
http://php.net/gettext

Thursday, November 15, 2007

Cups Printing from the Command Line

Sometimes you just need to print something without going into an application. Here's how...

First, find out what printers are available
lpstat -a

That will tell you what printers are available to you. Then you can print to one of them
lpr -P [printer_name] [file_name]

Need to find out what jobs are running right now?
lpstat -o
(that's the letter oh, not the number zero)

Need to cancel a job?
lprm [job_id]

For more information and all sorts of other CUPS goodness, check http://www.cups.org

Sunday, November 4, 2007

Modding an old Razr V3

Work gave me what is possibly the worst Motorola Razr phone ever. Not only that, they gave me a phone that someone must have bought on a trip to Thailand or something. It had no Hebrew fonts. No predictive typing. You couldn't move photos or videos that you took with the phone on to your computer using a USB cable the way that I can with the Razr v3x that I bought in New Zealand in December. Nope, none of that very basic stuff.

They told me to have the secretary call up Orange (our company's mobile provider) and ask them to upgrade the system. Celcom (my mobile provider) had no problem whatsoever in upgrading my Kiwi Razr. Orange, however, balked. They weren't going to be "responsible" for a firmware upgrade on a phone that they did not sell. Grrr...

So my boss told me to take the phone to one of the somewhat shady used phone shops that you see around town. They'll unlock phones and everyone assumed that they'd change the firmware for me, too. I tried a few places, and none would upgrade my firmware. Not one. Try here. Try there. Try the central bus station. Nope. No help at all.

So, today I buckled down and decided to do it myself. I had looked around at this before, and not found tools for linux, but today I found all the tools I needed. If you are on Linux and want to change your Motorola, add new skins, flash it with new firmware, or whatever, here are some links to get you going:


Moving Files Around:
Use moto4lin for connecting your phone to your computer with a usb cable.
http://moto4lin.sourceforge.net
I had lots of trouble at first, but this page helped me fix it all up.

Flashing (upgrading firmware on) Your Phone:
There is a nifty tool called Flasher. I used it to get my new language pack working.
http://moto4lin.sourceforge.net/wiki/Flashing

Language Packs:
http://www.motomodders.net/default.aspx?tabid=116

Monster Packs:
http://www.planetmotox.net/monster_packs.php

Useful Information:
(though written for Windows users, you will still get what you need)
http://www.motomodders.net/Default.aspx?tabid=69

Hint for Installing Skins:
Make sure that the directory name of your skin is the same as the name of the skin files. I had one skin named "Dragon's Dream" and I thought I was making it better by renaming the directory to "Dragons_Dream" but that just made my skin not work.


WARNING! MODDING YOUR PHONE CAN KILL IT!
Make sure that you have a backup. Make sure that you are using software you trust, and that you've read enough about the process that you know how it works.

Happy modding!

Tuesday, October 30, 2007

Oh How I Hate Command Line Tar

It's cuz I'm dyslexic and I always get things backwards. Which comes first? The file I'm trying to create or the one I'm trying to tar up? Here's the answer for future reference.


tar -cf [the file you want to create] [the file(s)/directory(ies) you want to tar]


The "c" stands for "create". The "f" stands for "file" (the default is to pipe the tarred stuff to stdin). You can also turn it into a gzip file in the same go with the letter "z" or into a b-zip file with the letter "j".

Something of note: man tar actually gives useful examples, unlike most man pages which give information but no examples to help the slow of brain (like me).

Here are some examples from the man page as it lives on our office Web servers which are running CentOS Linux:

EXAMPLES
tar -xvf foo.tar
verbosely extract foo.tar

tar -xzf foo.tar.gz
extract gzipped foo.tar.gz

tar -cjf foo.tar.bz2 bar/
create bzipped tar archive of the directory bar called
foo.tar.bz2

tar -xjf foo.tar.bz2 -C bar/
extract bzipped foo.tar.bz2 after changing directory to bar

tar -xzf foo.tar.gz blah.txt
extract the file blah.txt from foo.tar.bz2

Wednesday, October 17, 2007

Fixing Some Little Network Annoyances

To set your IP address for your Ethernet connection and the gateway address for the world outside your local network, run these as root or sudo them...

ifconfig eth0 [ip address]
route add default gw [gateway ip address]

Tuesday, October 9, 2007

No More IFrames!!!

So, you want to pull some information from another site into a Web page, and your fancy-pants AJAX idea won't work because you can't grab data from a different server using xmlhttprequest?

Don't reach for that IFRAME!!! Use Object instead.

<object data="frame.html" type="text/html">
If you can see this line, your browser doesn't properly support w3c standards.
</object>


Here's the low down in the HTML4.1 Spec and the XHTML 2 Spec.

Monday, October 8, 2007

Secure Copy

scp is like cp for copying files only it can securely copy files from one server to another using the ssh protocol. This is a good thing. The bad thing is that I always forget how to write the line, because I'm a ditz that way.

Here's an example of how to copy a file from a local computer to a location on a remote server:
scp index.php user@web2.websites.com:/mysite.com/httpdocs/index.php

Here's an example of how to copy a whole directory from a local computer to a remote server:
scp -r httpdocs/. user@web2.websites.com:/mysite.com/httpdocs/.

Notice the slash dot thing at the end of the directory name. That's so that everything under that directory gets moved. If you don't use the slash dot after the directory name you will end up with the directory inside the other directory (like /mysite.com/httpdocs/httpodocs/...) which is clearly not what I want.

The -r stands for recursive.

Of course, you can find more details about other options that go with scp by typing
man scp
at a linux-ish or unix-ish command prompt.

Most Israeli Web Development Sux

Why? Because they think that it's OK to develop important sites for IE only. Those of us on Linux are outa luck if we want to use a bank website or do anything at a government website or even use half the businesses in this country. It's stupid in the extreme, and if I had my way, I'd line up all the decision makers who thought that this was acceptable and slap them each upside the head one at a time. Since I don't have the opportunity, however, I have two different solutions.

The first is the petition. If you live in Israel, if you read or use Hebrew Websites, or if you ever have to do business with idiotic Israeli-based sites that are written for IE only, go sign this petition. We can hope that in time it will not be necessary to do the second step at all, and we can all live a Microsoft free life if we so choose. Wouldn't that be lovely?

The second thing to do is load IEs4Linux. Then you can run IE on your beautiful Linux machine or Mac when you really, really have to, and live in peace the rest of the time.

Of course, this also means that if you are a Web developer who works on Linux, you can still create sites that are usable for those that choose to use IE. You see, because it's all about freedom, and if one of my customers wants to use IE, that's their business, and I should not get in the way of their ability to spend money at my site just because I don't like their browser. See?

Live and let live. That's what I say.

Sunday, October 7, 2007

Unlocking the adept package db

When Ubuntu's debian-ish package manager whines about a locked package database, try this:

sudo dpkg --configure dpkg


It will return an error, but your db will be unlocked and you can get on with life.