06 maggio, 2008

OpenVpn Experience

Hi everybody, in my company we have a VPN service powered by OpenVpn, a standard configuration between a linux server and many windows client.
As you now, lately I've reinstalled Xp and I have some problems when configuring OpenVPN Client.
The problem is known (the openvpn website explain that) after installing XP ServicePack 2, there are some problem with windows firewall and TAPI network adapter in configuration with a dhcp openvpn server.
Now, I give you more information about my successful configuration.
1. Install OpenVpn 2.1 Rc7 (tha last at this time)
2. Disable Or configure firewall for TAP Interface
3. Download devcon.exe from Microsoft website http://support.microsoft.com/kb/311272
4. Rename the TAP connection in MyTap
5. Identify the interface ID on TAP interface using : devcon hwids =net @root\NET\*
In my case tap0901
6. Create two .bat file in the OpenVPN config directory:
devcon enable tap0901
devcon disable tap0901
OpenVPN Gui launch this two file when start and close the connection ( note the name of the configfile )
7. ConfigFileName
dev tap
dev-node MyTap
proto tcp
remote server 1194
resolv-retry infinite
ca ca.crt
cert client1.crt
key client1.key
tls-auth ta.key 1
cipher BF-CBC
verb 3
mute 10
route-method exe
route-delay 30
ping 5
ip-win32 netsh
8. Start OpenVpn (using ConfigFileName file of course )

Another information, if you have the same subnet network class at home and at office you have to setting the metric of a TAP interface at a lower value than Etherter connection metric.

Good VPN to all!

01 maggio, 2008

Extend ASP.NET ListBox

Hi, tonight we extend a standard ASP.NET control : the ListBox.
The ListBox have a property that allow you to specify a SelectedElement when the page is loading.. great ! . But if you have a Multiple ListBox, and you need to select many elements ?.
You can create a custom control that provide this function. You only have to set the DataSource and a list of selected item in comma separated value format.
Start with the demo code:

The new custom control derive from ListBox :
   1:  namespace MyControls
   2:  {
   3:      [DefaultProperty("Text")]
   4:      [ToolboxData("<{0}:CustomListBox runat=server></{0}:CustomListBox>")]
   5:      public class CustomListBox : ListBox
   6:      {

Now add property SelectedValues that you use to select item of the list box in comma separated values format.
   1:  private string _selectedvalues;
   3:  [Bindable(true)]
   4:  [Category("Data")]
   5:  [DefaultValue("")]
   6:  [Localizable(true)]
   7:  public string SelectedValues
   8:  {
   9:      set
  10:      {
  11:          _selectedvalues = value;
  12:      }
  13:      get
  14:      {
  15:          return _selectedvalues;
  16:      }
  18:  }

Now override the OnDataBound to selected the appropriate values on DataBound Event.

   1:  protected override void OnDataBound(EventArgs e)
   2:  {
   3:      base.OnDataBound(e);
   4:      if (_selectedvalues != null)
   5:      {
   6:          foreach (ListItem item in Items)
   7:          {
   8:              if (_selectedvalues.IndexOf(string.Format(",{0},", item.Value)) != -1)
   9:                  item.Selected = true;
  10:          }
  11:      }
  12:  }

And olso, you have to override this other two method to preserve data in postback events.

   1:  protected override void OnDataBinding(EventArgs e)
   2:  {
   3:      try
   4:      {
   5:          base.OnDataBinding(e);
   6:      }
   7:      catch (InvalidOperationException)
   8:      {
   9:          this.GetData().Select(DataSourceSelectArguments.Empty, new DataSourceViewSelectCallback(DoSelect));
  10:      }
  11:  }
  13:  private void DoSelect(IEnumerable data)
  14:  {
  15:      this.PerformDataBinding(data);
  16:  }

Build your class, and add to your project.
Insert the control in your asp.net page :
   1:  <%@ Register Assembly="MyAssembly" Namespace="MyControls" TagPrefix="cc1" %>
   2:      <cc1:CustomListBox ID="CustomListBox1" runat="server" DataSource="MyDataSource" SelectedValues=",1,2,3,5"></cc1:CustomListBox>