Find DrewDahl on Facebook! Find DrewDahl on Twitter! View Andrew Dahl's Profile Drew's Blog

Author Archive

Firefox Plugin for Todoist

by Drew Dahl on May.25, 2011, under Projects, Todoist Firefox Plugin

I ran across the Firefox plug-in on Todoist’s website and noticed that they put it up on Mozilla’s add-on area. I’ve had a number of people ask me to update the altered plug-in that I released earlier; however, installing the official plug-in would be a much better idea at this point! It seems they have the compatibility listed as up to Firefox 6.0a, so it should be good for a while.

Here’s the link: https://addons.mozilla.org/en-US/firefox/addon/todoist/

Enjoy!

Leave a Comment :, more...

Using NetworkManager to run scripts after connecting

by Drew Dahl on May.03, 2011, under HowTo, Linux

For years now, I’ve had to run vpnc after connecting my school’s wireless. Truly, it never bothered me; however, at my new job, I need to run route after I connect to their wireless. For whatever reason, that got to me. I didn’t really want to run route when I wasn’t on their network (it likely wouldn’t have screwed anything up, but still…). So, I went about putting a quick bit in /etc/sysconfig/network-scripts/ifup-wireless, and it didn’t work… =\ So, after some digging, I’ve found another way using NetworkManager. Here’s what I did:

Because I hate hacking up scripts that services use, I wrote a quick script and put it in /usr/local/bin/wireless.sh:

#!/bin/bash

if iwconfig|grep -c MY-WORK-ESSID
then
        route add -net 111.111.111.111/22 gw 222.222.222.222
fi

if iwconfig|grep -c msum-wireless
then
        vpnc
fi

Once that was done, I ran:

chmod +x /usr/local/bin/wireless.sh

and added the line:

/usr/local/bin/wireless.sh

to the file /etc/NetworkManager/dispatcher.d/00-netreport right before the exit.

And that’s it! It would be neat if NetworkManager added in similar functionality through the GUI, but until that day, this should work fine. Also, to note, those scripts are run as root, so be careful!

Update!

Upon upgrading from Fedora 14 to 15, the file 00-netreport was overwritten. I’ve done updates to NetworkManager, so that had nothing to do with it. In any case, if you end up upgrading your distro, there’s a chance that’ll get overwritten. In the event it does, you’ll just have to paste the line to the script again. (Another good reason to use a script!)

There may be a better way than what I’m doing above, but it works for me, so I’m not going to bother looking for another way. Hope this helps!

Leave a Comment :, , , more...

Using Ruby to run commands on a lab of Linux machines

by Drew Dahl on Feb.24, 2011, under Linux, Programming

Lately, I’ve been getting acquainted with Rails development at work. It’s been a pretty steep learning curve (for that matter, I guess it still is), but I’ve enjoyed it thus far. So, with my new found Ruby skills (or, I guess more-so my new found need to learn Ruby), I wrote a script that uses SSH to iteratively connect to every computer in a lab and update them. This could be used for just about anything, but for my instance it was updating a lab. There was a bit more to my script as I needed to recompile some device drivers when there was a new kernel, but for simplicities sake, I’ve ripped them out. Hope this helps someone else!

First, you’ll need to install the ruby-ssh library.

sudo gem install net-ssh
sudo gem install highline

And, the script is:

#!/usr/bin/ruby

require 'rubygems'
require 'net/ssh'
require 'highline/import'

hosts=[ "host1",
            "host2" ]

cmds = ["yum -y update",
             "init 6"]

username = "root"

# Assuming that all hosts have the same password
password = ask("Enter Password: ") { |q| q.echo = false }

hosts.each do |host|
    Net::SSH.start( host , username, :password => password) do |ssh|
        puts "Connected to #{host}"
        cmds.each do |cmd|
            puts "Performing #{cmd} on #{host}"
            output = ssh.exec! cmd do |ch, stream, data|
                if stream == :stderr
                    puts "Error: #{data}"
                else
                    puts data
                end
            end
        end
    end
end

And, that’s all there is to it! There’s a real lack of comments, but I feel it’s pretty self-explanatory. Enjoy!

2 Comments :, , , , , more...

Simple Shell in C

by Drew Dahl on Dec.02, 2010, under Linux, Programming

Well, life has been a 24/7 hell for the last few months. As an example of how much free time I’ve had, I haven’t seen a couple of my really good friends since July or August. Hopefully they haven’t forgotten about me ;-)

In any case, I wrote a pretty good simple shell in C for my Operating Systems class. I finished it back in October, but haven’t posted it until now as several students just recently finished theirs.  Wouldn’t want them to cheat. ;-)

Less rambling.  The reason I’m posting this is that I think it is a really good example of using some basic system calls, such as malloc(), printf(), fgets(), strtok(), strcmp(), strcpy(), sprintf(), free(), chdir(), fork(), execpe(), opendir(), and wait(). Hopefully someone finds this useful :-)

#include <stdio .h>
#include <stdlib .h>
#include <unistd .h>
#include <string .h>
#include <sys /types.h>
#include <dirent .h>

const int SIZE=100;
const int ARGSIZE=10;

void cd(char *dir)
{
    int ret = 0;

    //Check to see if directory argument is blank
    if(dir == '\0')
        dir = getenv("HOME");
    //Check to see if directory argument starts with ~ and replace it with $HOME
    else if(dir[0] == '~')
    {
        char* temp = malloc(SIZE);
        strcpy(temp,dir+1);
        sprintf(dir,"%s%s",getenv("HOME"),temp);
        free(temp);
    }

    //Change Directory
    ret = chdir(dir);
           
    if(ret != 0)
        fprintf(stderr,"Failed to enter directory: %s\n",dir);
    else
        printf("%s\n",dir);
}

void ls(char *dir)
{
    DIR* open_dir;
    struct dirent* drent;

    if(dir == '\0') //See if dir is valid, if not set it to current directory
        dir = (char*)".";

    if((open_dir = opendir(dir)) != NULL) //open dir
    {
        while((drent = readdir(open_dir)) != NULL) //get contents of directory
        {
            printf("%s\n",drent->d_name); //print contents
        }
   
        closedir(open_dir); //close dir
    }
}

void execute(char *args[])
{
    int status;
    pid_t pid;

    //fork and execute the command   
    if((pid = fork()) == 0)
    {
        execvp(args[0],args);
        //execvp should only return if there was an error

        fprintf(stderr,"Unknown command\n");
        exit(0);
    }
    else if(pid < 0)
    {
        fprintf(stderr,"Failed to fork(): %s\n", args[0]);
        status = -1;
    }
    //Wait for child so stdin and stdout aren't fighting for use   
    else
        while(wait(&status) != pid)
           continue;
}

int main(int argc, char *argv[], char *envp[])
{
    char *temp;
    char *line;
    char *args[ARGSIZE];
    char argIndex = 0;

    for(;;)
    {
        line = malloc(SIZE); //Allocate memory for line
        argIndex = 0; //Initialize argIndex

        printf("\n[SHELL ] ");

        fgets(line, SIZE, stdin); //Get Input

        temp = strtok(line, " \n"); //Get input into an array to use w/ execve

        while(temp != NULL)
        {
            args[argIndex] = temp;
            argIndex++;
            temp = strtok(NULL, " \n");
        }

        args[argIndex] = (char*) 0; //Set the end of the arguments list

        if(strcmp(args[0], "quit") == 0 || strcmp(args[0], "exit") == 0)
            break; //break out for for(;;) loop

        if(line== "\n")
            printf("[SHELL ] ");
        else if ((strcmp(args[0], "ls") ==0))
            ls(args[1]); //run ls
        else if ((strcmp(args[0], "cd") == 0))
            cd(args[1]); //run cd
        else
            execute(args); //Fork and Execute command

        free(line); //Free memory from line
    }

    printf("\n");
    return 0;
}

And, in case you want a Makefile (I know I do!):

CC = gcc
OBJECTS =
PROC = shell

CFLAGS =
LFLAGS =

$(PROC):
$(CC) $(CFLAGS) simpleshell.c -o $(PROC) $(LFLAGS)
all:
$(CC) $(CFLAGS) simpleshell.c -o $(PROC) $(LFLAGS)
clean:
rm -rf *.o *.c~ $(PROC)

Enjoy!

(P.S… Todoist-for-Android updates will follow! I promise! The holidays are coming after all! :-] )

2 Comments more...

TODOIST For Android — Some development updates and screenshots

by Drew Dahl on Jul.11, 2010, under Projects, Todoist for Android

Well, the first beta release is looking like it’ll be today or tomorrow. It will incorporate only a 7-day view (with overdue tasks as well) and at current, you won’t be able to “complete” tasks with it, but if you’re lucky, I’ll be able to squeeze that in before I release it ;)

There are just a few bugs here and there to fix, but I don’t foresee any major issues. As always, here is a current screen shot of the app in action:

TODOIST for Android Screenshot

If you have any suggestions on the current interface, please be sure to let me know! I’m thinking a little vertical spacing is needed and the project listings on the right should have a bit of padding, but that’s all I can say for sure.

Anyway, on to development updates! We’ve switched repositories from a locally hosted Mercurial repo to a github hosted Git repository. You can see the repository here.

And the final update! We’ve moved from our trac installation to using bugzilla to handle all of our issue tracking. That said, once the application is out, if you notice any issues with it, feel free to submit a bug report through the interface, or create an account on our bugzilla installation and report it! You can find out bugzilla installation here.

That’s all for today! If you don’t see our first beta release tonight, expect one on Monday (Tuesday at the latest!)

8 Comments more...

TODOIST For Android Update

by Drew Dahl on Jul.07, 2010, under Projects, Todoist for Android

Well, it’s been a little while, but I’ve been making some slow progress towards my goal. Right now, I have log-ins working (it also stores your API key if you want it to be stored, thus never needing to login again). There’s a “Report” feature in the event you find bugs. And, as of right now, I have a fairly dirty interface that it opens up to (shows you a 7 day listing and overdue tasks). In the images below, I hacked the times together, so it’s actually showing you a week in the past, but it’s all good. I also don’t have the overdue tasks feature built-in quite yet, but that shouldn’t take more than an hour to write.

My goal? A beta release by this weekend.

Here are some screen shots. They’re kind of poor, but it happens. Also, the number on the app is the number of the project it’s related to (I need get a lookup working):

So, where do I go from here? Well, I’m going to try to spiff up the interface a tiny bit, so it’s not so crappy looking (More TODOIST like). Then after the Beta release, I’m going to move on to Project listing (viewing only) and probably do another beta release once that’s complete. After that, I’ll add the ability to add tasks to projects and release another beta. And after that, fix a few bugs, add local storage of data (until then, it will look-up data from the Internet for each request and will be slower), and release it on the Market. Once it’s up on the Market, I’ll keep adding features to it (and if you think of any features you’d love to see, let me know and I’ll make note!)

Let me know what you think and I’ll post again with the beta this weekend *fingers crossed*

5 Comments more...

Todoist for Android Update — Feedback Appreciated!

by Drew Dahl on Jun.16, 2010, under Projects, Todoist for Android

Well, this has been a fairly slow process due to work and a laundry list of other things. But, in any case… I’m writing this for multiple reasons. The first is to let everyone know that someone has beaten me to releasing a Todoist application for the Android. Now, while I was slightly disheartened to find this out, I’m also glad to hear this since mine was taking so long. The name of this app is TodoistDroid and you can find their app on the Market. You can also find their site here.

Now, while I urge you all to go and check it out, I also hope that you all return to check out my app once it is completed. Better yet, I’d love it to hear your feedback once beta testing starts. I also hope that you all share the same feelings as I when I say that I’m not a fan for paying for apps. The TodoistDroid app has a “Lite” version and a “Regular” version. The latter of course costs money.

Now, while paying the money is surely justified, I don’t believe in it. This is why I will be releasing my application with only one version, which will be free. Their list of features and planned features are mostly composed of ideas that I’ve already had for my app (as well as a few they haven’t listed yet ;-) ). And lastly, I can’t say I liked their interface all that much. Now, while mine probably wont’ be 100% different (for the most part at least), I was planning to design everything around querying (main screen giving you your weekly list and that sort of thing).

That is why, I would love for you all to comment on how YOU use TODOIST. I would rather not design this for how I use it, as that may not be how everyone uses it. So please, in the comments section below, tell me about how you use it!

Now, on to the app. I’m running short on time at current, so I don’t have any screenshots for you today (Sorry! :-( ). The login is working great, I have a support page where you can easily file bugs working, and the main section is able to display tasks. My first beta release will come before the end of the month and will show you a query of overdue items as well as items due in the next seven (7) days.

That is all for today, and please, tell me how you use TODOIST so I can design it around what you want to see :-)

4 Comments more...

HowTo Setup Authenticated Postfix

by Drew Dahl on May.15, 2010, under HowTo, Linux, Mail

I recently had the experience of setting up Postfix. It works really well, in my opinion; however, setting it up wasn’t the simplest for what I wanted. But, at least it was simpler than sendmail :-)

Reading through several articles on the Internet, everyone was giving steps on how to setup postfix to handle e-mail for any FQDN (Fully-Qualified Domain Name). Well, we don’t want to be handling someone else’s e-mail, so we decided to set it up with authentication. All of the guides on setting up Postfix with SASL authentication are great and all; however, they don’t address the issue of, what if you want to receive mail as well. That’s a simple fix, but moreover, what if you have a service like mailman running? Mailman isn’t easily configured to authenticate against the SMTP server to send mail. So, the following are the configurations that I’ve come up with to solve all of these problems:

For the file /etc/postfix/main.cf

<strong>queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = hostname.domain.tld
mydomain = domain.tld
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, localhost.localdomain, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 192.168.0.0/24, 127.0.0.1/32
relay_domains = $mydestination
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
alias_maps = hash:/etc/aliases, hash:/etc/mailman/aliases
alias_database = hash:/etc/aliases
recipient_delimiter = +
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.5/samples
readme_directory = /usr/share/doc/postfix-2.6.5/README_FILES</strong>

Now keep in mind, your values for some of the above WILL be different. This configuration is on a machine that’s running mailman as well (thus the /etc/mailman/aliases file).

And lastly, for SASL auth, edit the file: /usr/lib64/sasl2/smtpd.conf

<strong>pwcheck_method: saslauthd
mech_list: plain login</strong>

Your lib64 directory may just be lib, depending on the architecture of your box. All of these edits were made a 64-bit Fedora 12 machine, but they should work for every machine.

And last note. After all of the edits have been made, make sure to restart postfix and restart saslauthd with the following:

/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

For questions on what some of the postfix settings mean, you can check out one of the following:

postconf man-page by running “man postconf” or visit http://www.postfix.org/postconf.5.html

Postfix Documentation at: http://www.postfix.org/documentation.html

Postfix HowTo’s at: http://www.postfix.org/docs.html

Postfix is definition the easiest MTA I’ve ever had the pleasure of working with, as far as configuration goes. I hope this helps :-)

Leave a Comment :, , , more...

Forefront Client Security – MOM Installation Failure

by Drew Dahl on May.02, 2010, under Forefront, HowTo, Windows

Well, I’m working on installing Forefront Client Security at my work and after configuring all of the prerequisites, nobody could figure out why it wasn’t installing. So, I setup a test machine and started playing with it. After about an hour of searching google, it seems nobody really has an answer for why MOM fails to install… but, I just figured it out!

If you check the installation logs in C:\Program Files\Microsoft Forefront\Client Security\Logs\MOMDB.log, you should notice there’s a line in there about an error running a query that results in an ERROR 112. The error is something like “There is not enough space on disk.” Well, in my case I had 60GB free on the disk, so this can’t be right… The database to be created was only 1GB in size.

Well, turns out the Quota on the disk was preventing the file from being created. To change the Quota (or in my case, turn it off for the duration of the install) go to Computer -> Right click on the drive you’re installing on -> Select “Properties” -> Click on the “Quota” tab. Once here you can either uncheck “Enable Quota Management” to completely disable it, or just select the radio button that reads “Do not limit disk usage”.

This should hopefully solve the problem :-)

Leave a Comment more...

ISP Change

by Drew Dahl on Apr.24, 2010, under Random, Rants, Site News

Well, come this Thursday, we will be going offline due to an ISP Change. Recently Midcontinent Communications start serving our area, and I must say I’ve been waiting for this for the last three years :-) (Fargo’s out of luck though. Poor guys.) Anyway, I’m switching from Cable One who’s been throttling the connection

Comparison:

Cable One vs. Midcontinent

Contracts?

Yes vs No

Throttling?

Yes vs No

Price?

$56.99 vs $56.99

Down Speed?

5Mb vs 25Mb

Up Speed?

0.5Mb vs 2Mb

Personally, I hope they give Cable One a run for their money. Their television and phone is way better for the price, but we won’t get into that here ^_-

Anyway, what does this mean for us? Well, they’re running new cables starting at 5pm CST, and as long as everything goes well, we’re looking at a 2-3hr downtime, so we should be back up and on-line by 8pm CST with a much faster speed :-) . Should really notice it on your ends! Enjoy!

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!