May 3 2013

CloudUploader Tool, Updated

In my earlier post I mentioned that I put together an application called CloudUploader that can encrypt a file of our choice and upload to a remote server. I worked on this a bit more to work around some bugs I initially encountered and added couple of new enhancements to the app. Below is the new screenshot:

CloudUploader

 

So what is new in this release? :

  1. Now you can generate a random password for your encryption file.
  2. You can upload a file or a folder. If you upload a file, it will be zipped and uploaded and if you use a folder a tarball will be created. The relative extensions will be .zip.e or .tar.gz.e.
  3. The file name or folder names can now contain spaces.
  4. You can now generate a log file of what you entered if you choose to do so in /var/tmp/clouduploader.log . The typical entry would look like this:

Log for 050223202013:
———————
Hostname = machine-unix.com
Filename = /Users/drende/Downloads/Good Reads
Encryption Algorithm = des3
Encryption Password Orig = Qb3A5blw1AWG
Encryption Password Verd = Qb3A5blw1AWG
Upload Directory = /home/deniz/CloudUploader
File Uploaded = 050223202013.tar.gz.e
Username = deniz

If you do not generate a random password and don’t select the log file option, then you will have to remember the encryption password to decrypt it.

You can get the new CloudUplader from this location.

Enjoy!


Apr 28 2013

Alfred Workflow:Password Generation Tools

I’ve been using some password generation scripts and mainly it was revolving around apg. But I recently I learned about /dev/random and /dev/urandom  complimentary files that can be used for  a random number generator or as a pseudorandom number generator ( wiki ).  So I added the random number generator script into the Alfred Workflow I’ve been using for apg for a while.

The code is extremely simple for /dev/random and it does not require additional software to be installed. A simple example ( which is also in the script ) can be as follows:

$ cat /dev/random| LANG=C tr -dc ’0-9a-zA-Z!@#$%^&*_+-`’|head -c8;echo “”

This would produce something like the following:

*a4QnuRI

And with a longer character length, if we replace -c8 to say -c12, you could have a random characters of 12:

BR@w*iU#Gd_>

Couple of extra things needed to be done here with the usage, the first thing was to set the environment variable LANG to C, because otherwise I would get errors like:

$ cat /dev/random| tr -dc ’0-9a-zA-Z!@#$%^&*_+-`’|head -c12;echo “”
tr: Illegal byte sequence

LANG=C had to be added there for proper encoding in tr.

The other thing is to add ’0-9a-zA-Z!@#$%^&*_+-`’ in the script to accommodate special characters, etc.

Above was the one method to generate random passwords, and the other is to use apg ( which is also included in the workflow ). So something like this produced a neat result with readable output:

$ /usr/local/bin/apg -t -m 12 -M NCLS | head -1
in}OfhejSov2 (in-RIGHT_BRACE-Of-hej-Sov-TWO)

Notice above the output also produces spelling. The length of the characters are specified with -m.

The cool thing about Alfred V2 is that you can add multiple scripts in a single workflow, if you wanted for example to create a variety of scripts, it could look like the following:

workflow3

 

Notice I have two keywords with two different Run Scripts feeding into a “Post Notification”

Let’s see how apg looks like when called from Alfred:

apg

 

apg_result

 

and with /dev/random:

devrand

 

randresult

 

So two different methods under a single workflow, you can improve this by adding more methods in there.

Download the Workflow and enjoy!

 


Apr 28 2013

Alfred Workflow:IPv4 Reverse Resolution

The following is an Alfred Workflow to reverse an IP address with in-addr.arpa appended to it. For example to change the IP address from:

165.225.132.19

to:

132.225.165.in-addr.arpa

One might want to use a workflow like this:

Alfred-Workflow

 

 

The Run Script contains the following:

#/bin/bash
IP=”{query}”
SPLIT=`echo $IP | awk -F. ‘{print $3″.”$2″.”$1″.”"in-addr.arpa”}’`
echo $SPLIT | pbcopy
echo $SPLIT

and “Copy to Clipboard” contains just the query itself:

{query}

The “Post Notification” also contains {query} as “Text” and an appropriate Title. You enter it like this when you call Alfred:

Reverse

 

and the result in the notification center looks like this:

Result

 

The conversion is copied into your clipboard. You can get the workflow here.

Enjoy!


Apr 25 2013

A Mini Encryption and CloudUploader Tool

I’ve been playing with encryption tools on various platforms and I have put together a mini application called CloudUploader for OSX Lion. The task is very basic and simple but useful too. What it simply does is that it allows you to select a file of your choice, zips the file, allows you to specify a remote server, and applies encryption method of your liking before uploading to the server you have specified. See the image below:

 

CloudUploader

 

Below are assumed:

  1. The Directory the file being uploaded must exist in the Remote Server.
  2. The file you are going to be uploading should not have any spaces, for example …/myfile.txt is acceptable but …/my file.txt is not!
  3. It uses keys or passwords. You must specify a password if you are not using a key.
  4. In the text, I mention Joyent Server, it is because where my server is hosted ( I work for them too! ), but you can change the text in the application script
  5. This is not a supported application by Joyent at all, it came out purely out of my curiosity and on my own and:
  6. Please use it on your own risk!

The file will be uploaded with a date format ending with .e file format, for example:

FileFormat

 

In the example below the file 042422352013.zip.e indicates a file format that is zipped and encrypted. In my case, I uploaded the file in my Joyent Server and in /root directory. To decrypt and unzip the file, the following must be done either in the remote server or in locally:

[root@machine-unix ~]# openssl des3 -d -in 042422352013.zip.e -out 042422352013.zip
enter des-ede3-cbc decryption password:

[root@machine-unix ~]# unzip 042422352013.zip
Archive: 042422352013.zip
inflating: goodreads_export.csv

Now that the file is decrypted and unzipped, my .csv file is completely visible. Couple of technical details are as follows

  1. Currently openssl and most of it ciphers are supported, meaning that no gnupg yet but it is in the plans! If you find a bug in openssl cipher let me know!
  2. Only one file can be selected, no multiple files yet
  3. The password entered in the password field is for encrypting/decrypting the file, and it is not the password of your server ( DON’T DO THAT )
  4. Under the covers, scp is used to upload the file, therefore the remote server must be listening on port 22 ( same with SSH )

The tool is completely opensource and it is written in Pashua in conjunction with CocoaDialog, you can edit the script in the Resources directory however you wish!

You can download the tool here, and I wrapped it around an installer which is made with Platypus. All you need to do is to download it from the location, and run the installer. It will copy the application into your /Applications folder. From here, you can either doubleclick the app or drag and drop to your Dock.

Let me know how useful this application to you and what I can do to improve it!

Enjoy!

Icon for the application is downloaded from deviantart


Mar 18 2013

SmartMachine Tools Package

Starting from  2012Q1 pkgsrc and later, you can download a toolset, a package called smtools from the Joyent pkgsrc repository which can benefit SmartMachine users in many ways. You can find more information here.

The one currently I have in my own SmartMachine is the 20130103 package

# pkgin se smtools
smtools-20130103 = Joyent tools relevant to SmartOS and SmartMachines

and many useful tools are added overtime. After the installation the toolset through pkgin ( see here, for how to use pkgin ), all of the files in the toolset is placed in /opt/local/bin for your disposal:

[root@machine-unix /opt/local/bin]# ls sm-*
sm-cpuinfo sm-list-dbs sm-prepare-image sm-set-timezone
sm-create-db sm-list-dbusers sm-reboot sm-shutdown
sm-create-dbuser sm-list-timezones sm-rebuild-pkgsrc sm-summary
sm-create-vhost sm-lsof sm-remove-db
sm-install-drupal sm-meminfo sm-remove-dbuser
sm-install-wordpress sm-pkghelp sm-set-hostname

One of the favorite tool I use above must be the sm-summary tool, because it indeed gives you an overall picture of your smartmachine in a high level:

[root@machine-unix ~]# sm-summary
* Gathering SmartMachine summary..
SM UUID ea71ea63-c757-4222-801d-503a2300ca14
SM ID 7
Hostname machine-unix.com
SmartOS build joyent_20130111T180733Z
Image standard64 1.0.4
Base Image NA
Documentation http://wiki.joyent.com/jpc2/SmartMachine+Standard
Pkgsrc http://pkgsrc.joyent.com/sdc6/2012Q1/x86_64/All
Processes 51
Memory (RSS) Cap 1024M
Memory (RSS) Used 614M
Memory (RSS) Free 410M
Swap Cap 2048M
Swap Used 504M
/tmp Used 16K
Disk Quota 32G
% Disk Used 17%

I find the information above so useful, I ended up putting some parts of it  in a daily monitoring script I use for the SmartMachine I have and placed it in crontab so that I can get daily mails about the status of my SmartMachine. Following is the part of bash script I use for this purpose:

#!/opt/local/bin/bash

#Author : Deniz Rende
#Date : 01/14/12

#Specify an email
EMAIL_ADDRESS=”my@email.com”

#Email Body(s)
BODY1=”`date` ”

ATTACHED_FILE1=”dfh_output”

SUBJECT1=”My Machine Status ”

# Create a file to put all of your output
echo “” >> dfh_output

# Get df -h output
echo “df -h output” >> dfh_output
echo “————–” >> dfh_output
df -h >> dfh_output
echo “” >> dfh_output

echo “My Web Space” >> dfh_output
echo “————–” >> dfh_output

du -hs /Path/to/your/webspace/* | sort -hr >> dfh_output
echo “” >> dfh_output

# Get SmartMachine Summary using smtools
echo “Smart Machine Summary” >> dfh_output
echo “——————–” >> dfh_output
sm-summary >> dfh_output
echo “” >> dfh_output

#Get the space usage in your Backup Directory
echo “Your Backup Directory” >> dfh_output
echo “——————–” >> dfh_output
ls -lah /var/tmp/backups >> dfh_output
# Append the Body statement to the file and sends the output to the specified email
echo $BODY1 | cat – dfh_output > /tmp/out && mv /tmp/out dfh_output
cat $ATTACHED_FILE1 | mailx -s “$SUBJECT1″ “$EMAIL_ADDRESS”

#Temporary file is now removed
rm dfh_output

It is a very simple script but it works well for its purpose. One can improve this script by adding more smtools in there and get more detailed email every single day. Adding sm-lsof with various flags could be a very nice option for example. So check smtools out and let me know how you utilize it and I think there are many ways of doing it.


Dec 19 2012

How To Automate Your Daily Tasks with Automator – Part 2

So I have been having fun with Automator lately and started to like it very much. I think overall it works pretty well. In my previous post, I described a way of telling your chat application to send a message to a chatroom automatically everyday at a certain hour. In this post, we are going to do a similar thing but this time will use Automator’s workflow power to send an email message everyday at a certain time too.  The body of the email message is going to be read from a text file and the contents will be delivered to the recipients that are defined in the workflow.

Since this workflow is going to be also an iCal alarm, you will need to click Calendar Alarm as well:

 

Automator

Before we go on with the tutorial, let’s define what our workflow should consist of:

1 – Get to the file that consists of your email body.

2 – Open the file that consists of your email body.

3 – Get the contents of the document.

4 – Compose a new Message via Workflow

5 – Finally send your email message

1 – Get to the file that consists of your email body

After clicking iCal alarm, you will see the actions menu on the left and your workflow area on the right. To “get to the fle that consist of your email body”, you will first click “Files and Folders” on the left, then drag “Get specified Finder Items” to the workflow area as shown below:

Mail01

 

Now that your first Workflow item is added on the right side, you can click “Add” button to get to the file.

2 – Open the file that consists of your email body

Now that you have added which file to get to, you need to open it:

Mail02-1

 

You will need to choose a text editor to open the email body, so I chose TextEdit to do so above.

3 – Get the Contents of the Document

Now that we open the file, you need to tell Automator to fetch the contents of this file. You can do this by selecting “Text” in the actions menu and drag “Get Contents of TextEdit Document”:

Mail03

 

We need to tie this workflow item into composing mail, which is the next step

4 – Compose a New Message Via Workflow

This part is the heart of the operation and it is very self explanatory:

Mail04-1

 

Notice several things here:

  1. In your New Mail Message make sure to use To: for individuals and CC: section for individuals and mail groups.
  2. Set your Subject Line to whatever you wish
  3. Do not enter the Message body, since we are reading it from a file. Leave it empty

5 – Finally send your message

This will require an action workflow item from the Mail menu, called “Send outgoing messages”. If you do not add this, your message will not be sent and it will remain open. So the image below shows the last piece:

Mail05

 

When you are finished with this, click “File” and “Save”.  You can do a test run of your workflow by just clicking “Run” on the right hand side. When you click save and give it a name, Automator will open iCal automatically and let you set your date and time you want to send the message. If you run into issues, take a look at my previous post about this.


Dec 5 2012

How To Automate Your Daily Tasks with Automator

If you are spending a lot of time in front of the computer doing things, and these tasks are getting repetitive then you might find easier to use Mac’s Automator application. Whether it may be writing specific type of emails, or charting graphs, or anything. Just choose your poison and Automator will likely solve some of these repetitive tasks for you. My poison for this particular entry is Adium, and I’d like to tell my Adium application, to send a specific message to a specific chat group everyday at a certain time.

In case if you were wondering what Adium is, you can find the details here but It is my choice of Jabber client instead of using Mac’s Messages application. It is opensource, flexible and you can use variety of themes in here.

So if you are using Mountain Lion, like previous versions of it , the OS will come with an application called iCal, which is the default application for Calendar. We will use the Automator application to set what needs to be send to the Adium by utilizing AppleScript.

Let’s say I want to send a message that says “I am here indeed” to a specific chatroom in Adium every single day at 8:27 pm. Here is how you accomplish this task.

1 – Open up Automator. When you first launch the program, it will look like this:

Automator

2 – Click on “Calendar Alarm” icon. The next thing you need to do is to choose “Utilities” from Actions Menu on the left, and this will load bunch of templates on the right side for you. Like the image below, you will need to select “Run AppleScript”:

 

3 – You can find the basics of AppleScript here, which is what we are going to tell Adium what it needs to do.

The script should be as follows:

tell application “Adium”

activate

send chat “mychatroom@chatserver.myserver.com” message “I am here indeed.”

end tell

Click File -> Save, and name it like “AdiumTest”, so it should look like the following:

4 – After you click Save, iCal automatically opens up and places an event called “AdiumTest” in Today’s entry. It looks like the following:

5 – Now, all you need to do is to edit this event based on your preferences. I’d like to use this every week at 8:27 pm, so by right clicking and editing it, I have the following modified entry:

Since my Adium application is almost always open, the message is sent everyday without me typing it everytime. Also a quick note is that it takes about 14 seconds to send the message after the clock hits 8:27 pm on my machine. You may or may not get the same result but it will send it in that “minute”.

Happy Automating . . .