March 2006

You are currently browsing the articles from TechToolBlog written in the month of March 2006.

Using OSX VNC

I manage our MAC OS X server on a Windows XP machine from a command shell from ssh.com. I can do 98% of my task from the command line, however sometimes I need to use the MAC GUI. I have OSXVNC running on the OS X and Real VNC running on my Windows box.

For our staging server, there is no real security concerns running VNC because the box is inside of our network and can not receive outside traffic. However for our production Web Server, I don’t think it’s a good idea to have VNC running even if you change the default port. For one reason OSXVNC only does 1 part authentication, I.E. you are only challenged with a password, not a user name. Instead of running down to the server room everytime I have to use the MAC GUI, I instead have came up with this nice little tip.

I start VNC server from the command line in my shell client specifing an encrypted password file, log on to VNC, do my buisness, and then kill the VNC server thread. In security theory it goes like this: - I create a locked door on the fly, open it up (keeping it locked behind me), then destroy the door when I am done. This is how to do it.


- OSCVnc creates a directory when installed named: /OSXvnc.app/
- Inside /OSXvnc.app/ there is a utility named: storepassword
- Run this command to create your encrypted file with your password in it:

#./storepassword yourpassword yourfilename

To start OSXVnc by command line:
- Go inside the Application directory(OSXvnc.app) and launch the OSXvnc-server process.
- To change parameters you will need to give it arguments (-rfbport to set port, -rfbauth to specify a password file, etc). For usage run the command with -help. For example:

# ./OSXvnc-server -rfbauth yourfilename

This starts the OSXvnc server with your encrypted password file

Now, start your RealVNC client on your windows machine. You will be asked to autheticate. Once you are done with the MAC GUI, close RealVNC, go back to your command shell and hit: “Ctrl + X” to kill the VNC thread. This is a nice way to not worry about running VNC all the time on your production boxes exposed to the world.

Written by Tim on March 8th, 2006 with 4 comments.
Read more articles on unix.



Creating An Apple Like Search Box

I’ve gotten an email or two about how I managed to make my search box look like an Apple MAC OS X Finder. You could view source on my site and see or how about I share it with you :)

Basically it is contructed by using the method: Left Round Image -> Input Text Box with special Styles <- Right Round Image

Simple enough?

Below is the CSS you will need:


/* APPLE SEARCH BOX LOOKALIKE STYLES */
.srchimgs {margin-bottom: 1px;}
.sbox {width: 121px;}
#searchform select, #searchform input {font-size: 10px}
#searchform input.sbox {color: #80808C; height: 12px; width: 95px; border: 0; background: white url(http://images.apple.com/downloads/macosx/images/downloadssearchbg20050513.gif) repeat-x left top; padding: 3px;}
#searchform select {width: 122px; margin-top: 5px;}
#searchform .srchimgs {margin-bottom: 1px;}
html>body #searchform .srchimgs {margin-bottom: 0;}

html>body*#searchform input {font-size: 12px}
html>body*#searchform .srchimgs {display: none;}
html>body*#searchform input.sbox {width: 121px;}

Now you must set your DOCUMENT TYPE as follows:

Here is what the HTML for the box itself looks like:

img src=”/images/leftsearch.gif” alt=”" width=”16″ height=”18″ border=”0″ align=”absbottom” class=”srchimgs”>

That’s it. Notice that you will need to edit the background color of the leftsearch.gif and rightsearch.gif images. After that you should have:



Written by Tim on March 6th, 2006 with 4 comments.
Read more articles on tools.



ReadOnly Input Fields in Javascript

To do a read only input fields I normally do a:


However some older web browsers do not support this entirely. In my case I was losing the attibute tags across post back in asp.net. Anyway, I came across a different way of doing this using Javascript. I have no idea why I hadn’t thought of this earlier, it kinda makes me feel dumb ;)


I know that some people will frown on this because Javascript must be turned on. But in my case, Javascript is required to be turned on to run the application because of the AJAX stuff I am doing.

NOTE:Someone at work pointed out another way that you can do this that I never used before, by using the “disabled” attribute.


I think this is a case where you do something one way for so long (like I did the readyonly attribute) and you can miss out on other ways that have their individual advantages.

Written by Tim on March 3rd, 2006 with 1 comment.
Read more articles on web 2.0 ish.

Compressing ASP.NET 2.0 Viewstate

One thing I was looking forward with asp.net 2.0 release was improved viewstate optimization. The truth is it has improved, but for me there is still something desirable to be had.

Where I have run into the problems is a web application I am working on the must allow the user to add an infinate amount of web controls dynamically. The results below are pretty amazing. I ended up using SharpZipLib for the compressing algorithm.

Test Scenerio: One web page with that ended up with 116 asp.net web controls add to it.

Result of ViewState Size:
Before Compression: 43.3 KB
After Compression using SharpZipLib: 3.50 KB

Below is the code to get you started

Imports System.IO

Imports Zip = ICSharpCode.SharpZipLib.Zip.Compression

 

Public Class PageViewStateZip : Inherits System.Web.UI.Page

 

Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object

Dim vState As String = Me.Request.Form(“__VSTATE”)

Dim bytes As Byte() = System.Convert.FromBase64String(vState)

bytes = vioZip.Decompress(bytes)

Dim format As New LosFormatter

 

Return format.Deserialize(System.Convert.ToBase64String(bytes))

 

End Function

 

Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)

Dim format As New LosFormatter

Dim writer As New StringWriter

format.Serialize(writer, viewState)

Dim viewStateStr As String = writer.ToString()

Dim bytes As Byte() = System.Convert.FromBase64String(viewStateStr)

bytes = vioZip.Compress(bytes)

Dim vStateStr As String = System.Convert.ToBase64String(bytes)

RegisterHiddenField(“__VSTATE”, vStateStr)

 

End Sub

 

End Class

 

 

Public Class vioZip

Shared Function Compress(ByVal bytes() As Byte) As Byte()

Dim memory As New MemoryStream

Dim stream = New Zip.Streams.DeflaterOutputStream(memory, _

New Zip.Deflater(Zip.Deflater.BEST_COMPRESSION), 131072)

stream.Write(bytes, 0, bytes.Length)

stream.Close()

Return memory.ToArray()

End Function

 

Shared Function Decompress(ByVal bytes() As Byte) As Byte()

Dim stream = New Zip.Streams.InflaterInputStream(New MemoryStream(bytes))

Dim memory As New MemoryStream

Dim writeData(4096) As Byte

Dim size As Integer

While True

size = stream.Read(writeData, 0, writeData.Length)

 

If size > 0 Then memory.Write(writeData, 0, size) Else Exit While

End While

stream.Close()

Return memory.ToArray()

End Function

 

End Class

Written by Tim on March 2nd, 2006 with 29 comments.
Read more articles on asp.net.

Dynamic Placeholder that Saves Child Controls View State

One asp.net custom control that I am loving right now is Denis Baur’s Dynamic PlaceHolder. I’m having to do an web application that must allow for an infinite number of standard web controls and maintain state as these are entered. I went down the AJAX.NET Professional route for a minute but ran into some issues. Instead of recreating the controls on Page_INIT on every request to add a control, I’m able to add to the the new controls to the placeholder list.
Example:

Function AddProduct(Byval strPN as String)

Dim Count As Int32 = CType(ViewState(strPN & "Count_v"), Int32)
Count += 1 'increase viewstate count

Dim ddlProduct as New DropDownList
with ddlproduct
.id = "ddl" & strPN "Product" & Count.ToString()
dphP.Controls.Add(ddlproduct) 'add to dynamic placeholder
end with

ViewState(pn & "Count_v") = Count 'add back to viewstate count

End Function

Written by Tim on March 2nd, 2006 with 2 comments.
Read more articles on asp.net.