Author Archives: Aron

Sending an email with Visual Basic

Imports System
Imports System.Net
Imports System.Data
Imports System.Net.Mail
Imports System.IO
Imports System.Net.NetworkCredential
Imports Microsoft.SqlServer.Dts.Runtime

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
 Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults
 Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
 Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
 End Enum

Public Sub Main()
 Dim oReader As StreamReader
 Dim sTo As String
 Dim sFrom As String = "EnterpriseAccountTeam@pdstech.com"
 Dim sCC As String
 Dim sMessage As String
 Dim sSubject As String
 Dim sJob_State As String
 Dim sJob_Status As String
 Dim sBranch As String
 Dim sRec() As String
 Dim sLine As String
 Dim linefeed As String = Constants.vbCrLf
 Try
 'open file
 oReader = New StreamReader("C:\Taleo\TCC\Prod\Export\Requisition\EmailFile.csv")
 While oReader.Peek <> -1
 sLine = oReader.ReadLine()
 sRec = sLine.Split(Convert.ToChar("|"))
 sTo = sRec(0)
 sCC = sRec(1)
 sSubject = "A new requisition has been assigned to you. Req No: " + sRec(2) + " Job title: " + sRec(3)
 sMessage = "City: " + sRec(4) + linefeed + "State: " + sRec(5) + linefeed
 sMessage += "Client: " + sRec(6) + linefeed + "Job state: " + sRec(7) + linefeed
 sMessage += "Job status: " + sRec(8) + linefeed + "Branch: " + sRec(9)
 'Send Mail
 MailSend(sTo, sCC, sFrom, sSubject, sMessage)
 End While
 oReader.Close()


Catch ex As Exception
 Dts.TaskResult = ScriptResults.Failure
 End Try
 Dts.TaskResult = ScriptResults.Success
 End Sub
 Public Sub MailSend(ByVal ToMail As String, ByVal ToCC As String, ByVal From As String, ByVal Subject As String, ByVal Message As String)

Dim smtpclient As New SmtpClient
 Dim mailmessage As New MailMessage
 Dim fromadd As New MailAddress(From)

smtpclient.Host = "10.1.0.10"
 smtpclient.Port = 25
 smtpclient.Credentials = CredentialCache.DefaultNetworkCredentials
 mailmessage.From = fromadd
 mailmessage.To.Add(ToMail)
 mailmessage.CC.Add(ToCC)
 mailmessage.Subject = CStr(Subject)
 mailmessage.Body = CStr(Message)

smtpclient.Send(mailmessage)

End Sub
End Class

Archiving a file in Visual Basic

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
 Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults
 Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
 Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
 End Enum

Public Sub Main()

Dim sOriginalFile, sArchivedFile, sDate As String

sOriginalFile = "C:\Taleo\TCC\Prod\Export\Requisition\Requisition.csv"
 sDate = Year(Date.Today()).ToString() & Right("0" & Month(Date.Today()), 2) & Right("0" & Microsoft.VisualBasic.DateAndTime.Day(Date.Today()), 2) & "_" & Hour(Now) & "_" & Minute(Now) & "_" & Second(Now)
 sArchivedFile = "C:\Taleo\TCC\Prod\Export\Requisition\Archive\ReqExport\Requisition-" & sDate & ".csv"

File.Move(sOriginalFile, sArchivedFile)

Dts.TaskResult = ScriptResults.Success
 End Sub

End Class

Checking a file for content in Visual Basic

Imports System
 Imports System.Data
 Imports System.Math
 Imports Microsoft.SqlServer.Dts.Runtime
 Imports System.IO

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
 <System.CLSCompliantAttribute(False)> _
 Partial Public Class ScriptMain
 Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults
 Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
 Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
 End Enum

Public Sub Main()
 Dim oReader As StreamReader
 Dim intLines As Integer
 Dim strLines As String

Dts.TaskResult = ScriptResults.Success
 intLines = 0
 strLines = ""
 oReader = New StreamReader("C:\Taleo\TCC\Prod\Export\Requisition\Requisition.csv")
 Do While Not oReader.EndOfStream
 strLines = oReader.ReadLine()
 intLines = intLines + 1
 Loop
 oReader.Close()
 oReader = Nothing
 If intLines < 2 Then
 File.Delete("C:\Taleo\TCC\Prod\Export\Requisition\Requisition.csv")
 Dts.TaskResult = ScriptResults.Failure

End If

End Sub

End Class

Rant about really bad software

Okay, I could have been the greatest salesman in the world if someone would provide me something worth selling.  Something that made life easier and automated or at least eased the pain of something that I was having to do all the time anyways.  My rant today involves time keeping software which for this session we’re going to call ClockMe.  Now ColckMe is web based and is basically an online time sheet.  The premise is that you log in from any internet enabled device and submit your time, your manager receives an email and clicks the link from his computer, tablet, cell phone and approves or declines the time and then the time is downloaded into the payroll system.  Short sweet and comes with a happy ending (a paycheck people, minds out of the gutter).  Let’s take a look at how bad programmers spoil happy endings…

Now ClockMe is built on PostGre SQL and is written in Python and hosted on Rack Space.  That’s three hits for me, I’m not paying a Microsoft or Oracle surtax and Rack Space is well rated.  I love open source and dependability.  That’s where this love affair ends.  After you log on the world gets really, really dark…

Let’s start from the beginning, I need to enter my time.  I log in and get to my time sheet:

My time is based on in/out – lunch – in/out and that is this entry screen:
[show how bad tab stops are]

And then there is how the time should be allocated, ideally if the employee is smart we give them access to pick their assignment, under no circumstances do you let them pick their pay type.
[show manual pay type allocation]

Now if you are doing different assignments throughout your week, odds are you have different overlords you report to for those different assignments.  This system treats every employee as they only report to one ‘approval process’ so you can only have a single manager approving time for all assignments:
[Show how this is a pain to deal with]

Group and roll selection is as bad if not worse than any program I’ve ever seen.  I’ve got 200 groups in my list and they show me 10 and I have to go through the whole thing making sure I remember to hold control to select them.  This isn’t bad programming this is sadistic.
[Screen shot of the abomination]

Manager logins, you should never include a character in your usernames that would make someone have to select it, a double click should render the username completely copyable.  Now this may have been done by us but I’m not sure why they would allow for user names like that.

MediaTomb Media Server

I bought a new 4 bedroom house that has 2 living room back in September and I’m just now getting around to furnishing it.  The one thing I got was a new Toshiba TV.  I noticed that you could plug a USB flash drive into it and so I put one in and launch the media player on the TV and was shocked to see my tablet on there.  After some investigating these new TV’s are UPnP aware and have a media player that can play from a UPnP server.  Turns out it’s incredibly easy to do this on FC16 using MediaTomb as the server.  Let me relay the steps to doing this.

  1. In this case I’m using FC16 stock install with MySQL installed, let me point out it’s the default MySQL install, see the post on starting MySQL to hear about that nightmare, this is the reason that I had to do that.
  2. Instal MediaTomb by typing ‘yum install mediatomb’.  This will also create the mediatomb user in the system that the service will use to run as (although not the home directory which is a great place to house the media, more later on this point).
  3. You’ll have to create a new MySQL database, this should be second nature but if not here is a link to the documentation on it.
  4. Now you’ll have to edit the mediatomb.conf which is located /etc/mediatomb.conf directory.  It’s nice and easy as the only thing you really need to do is bind it to an interface with the MT_INTERFACE =”[interface]”.  To find what you need to put in here, do an ifconfig and put in whatever is the active network connection is.  Oh make note of the MT_PORT number while you are here.
  5. Now we are ready to start the service, done by typing ‘service mediatomb start’ into BASH.  By extension stop, restart and status work too.
  6. You are up and running and from the server type in the following in for the URL:  http://localhost:[MT_PORT] where the port is what you made note of in the mediatomb.conf in step 4.
  7. You can now use the UI (user interface) to add directories to the server.

I would be derelict in my reporting without telling you the last steps but at this point the server is up and running so here is the rest of the story.

You’ll need to get the media over there.  I’d recommend FTP (see related post).  And you’ll need a directory to store this media.  What I did was create a /home/mediatomb and then uploaded the media via FTP.  Just chown the media to mediatomb and place it in this directory and then using the user interface specify /home/mediatomb as the directory to check, do so recrusive and I’m using the timed (I’ve heard bad things about Inotify and MP3’s set to full and recursive.  I didn’t include hidden anything and left the scan interval at 30 minutes (1800 seconds).

That’s it, you’re done.  I put about 110Gb of music into the directory and it took about 3 or 4 hours to move, and it’s now in the process of scanning them in no apparent order.  I’m not sure how long it will take but will try to update if I can figure it out.  But if you’re anything like me it’s time to go make a drink and I’ll check back on it tomorrow when I can almost guarantee that it’ll be done:)  Okay here is the update, takes about as long as it does to transfer as it does to index.

FTP on Fedora Core 16

As you know one of the important reasons that you have a Linux server is so you can use it to store and transfer files.  File Transfer Protocol is your friend in this case.  The basic flavor you get when you install FTP on FC16 is VSFTP or (very secure file transfer protocol).  Now my first glance opinion on this wasn’t favorable, this primarily stems from the fact that there is no webmin module that can control this server and  I have no idea how to use it.  Turns out I was wrong and the damn thing is so simple to use even I was shocked when I figured it out.  Here is a quick list of commands for working with the service.

Use the chkconfig command to start the service at boot:  chkcongif vsftpd on

Starting, stopping and restarting like so:
service vsftpd start
service vsftpd stop
service vsftpd restart

Viewing the status:
service vsftpd status
pgrep vsftpd (this will give you the process Id’s)

I’m going to give a shout out to http://www.linuxhomenetworking.com and the article here for shedding light on the situation.  I’ll have to do some poking around on their site.  Very helpful:)

Starting MySQL in Fedora Core 16

We’re going through a hardware upgrade at work and we were given the chance to take home our old computer when they swapped it out with a new one.  Yeah, needless to say I jumped at the chance to have my old 2.2Ghz with 4Gb of RAM dev box as my new Linux server.  I installed FC 16 and had to monkey around with MySQL to install it, eventually uninstalling the default instance and downloading it direct from MySQL.  This first gave me problems installing MediaTomb with this cryptic error:

file /usr/share/mysql/charsets/README from install of mysql-libs-5.5.18-1.fc16.i686 conflicts with file from package MySQL-server-5.5.18-1.linux2.6.i386

So by removing the default and installing the generic I managed to cause some damage.  I went into webmin and uninstalled the following:

MySQL-client 5.5.18-1.linux2.6 Applications/Databases MySQL – Client
MySQL-devel 5.5.18-1.linux2.6 Applications/Databases MySQL – Development header files and libraries
MySQL-server 5.5.18-1.linux2.6 Applications/Databases MySQL: a very fast and reliable SQL database server
MySQL-shared 5.5.18-1.linux2.6 Applications/Databases MySQL – Shared libraries

I then installed MySQL from yum.  It loaded fine but I couldn’t for the life me find out how to start it, the standard /etc/rc.d/init.d/mysqld was not to be found.

I found this in a post and it worked (logged in as root) so I figured I’d better document it so I don’t forget:

systemctl start mysqld.service

Installing a SSL certificate in a LAMP environment

Wow, if you’re reading this you are doing so over a 256 bit encrypted link.  To give you an idea of what that means my bank only uses 128 bit encryption.  Now for a while I was doing this with a self signed certificate.  But then you run into all kinds of hassles that when you send a link to your non-geek friend they get all upset because they get a warning when they try to go to it.  Aside from that hassle (which I can live with) I ran into an issue with the flash uploader on my Gallery 3 site.  It seems that if you have a self signed certificate the flash uploader will not work leaving the only way to upload anything to the server was the ‘server add’ option that would have meant I whole bunch of work that I just didn’t feel like doing right now.

The Solution?  Get a signed certificate from a CA.  Yeah that seems a little obvious but here’s the thing.  I’m not selling anything meaning I’m not making anything and I don’t really want to pay for it.  Free SSL certificates?  Turns out yes they do exist.  I went with StartSSL and was very pleased with the experience.  The first thing I had to do was start by validating my email and getting a certification for that and then it was time to get the SSL/TLS Server cert.  Here is how I did it so I’ll know how to do it next time.

Telnet into the server and issue the following command:

openssl req -new -newkey rsa:2048 -nodes -keyout myserver.key -out server.csr

This will give you two files.
myserver.key: this is your encryption key.
server.csr: this is the Certificate Signing Request that you will submit to the CA

In my case (running Fedora Core 16) I placed the myserver.key file in the /etc/pki/tls/private/ directory.
When you submit it to the CA, they will have you cut and paste the returned text into a ssl.cert file. Get that onto your server and I put it in /etc/pki/tls/certs/. Then you need to find the ssl.conf file and change the SSLCertificateFile and SSLCertificateKeyFile file locations and names. Save the file, restart Apache and you are good to go.

UPDATE
Okay, got home and got a message that I missed a couple of files.  To this end let me say these are the files that were missing:

SSLCertificateChainFile /usr/local/apache/conf/sub.class1.server.ca.pem
SSLCACertificateFile /usr/local/apache/conf/ca.pem

I put them into /etc/pki/tls and just linked them in the ssl.conf and it worked fine and seemed to fix any issues I saw so don’t forget to do this next time.

New Code Highlighter

I had a devil of a time figuring out which syntax highlighter to install but I think that I finally found one that I am happy with.  It’s SyntaxHighlighter Evolved and I’ll be using it going forward.

C# to move files in SSIS script task

Most of the time that I’m creating integration packages, I have a central working directory where all the action is taking place, at the end of the package execution is where I’ll archive files so that should they be needed to troubleshoot an issue I’ve got them in a handy place.  This is a script that I created for that process.  Note that lines 7 through 19 are generated by the Visual Studio Tools for Applications in SSIS when you create the script task.

using System;
using System.IO;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

namespace ST_218640c1eafd4eb9ab909245d34e01c7.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion

public void Main()
{
string strOriginalFileName = @"C:\TCC\20110722-UpdateCandidate\UpdateHireEmpStatus.csv";
string strArchivedFileName;
string strDate;
DateTime dtDate = DateTime.Now;

strDate = String.Format("{0:yyyyMMdd_HH_mm_ss}", dtDate);

strArchivedFileName = @"C:\TCC\20110722-UpdateCandidate\Archive\UpdateHireEmpStatus-" + strDate + ".csv";

File.Move(strOriginalFileName, strArchivedFileName);
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}