<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michael Landi &#124; SourceSecure</title>
	<atom:link href="http://sourcesecure.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://sourcesecure.net</link>
	<description>Software and Security Consultant</description>
	<lastBuildDate>Sat, 04 Feb 2012 21:17:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating Generic MVC Controllers</title>
		<link>http://sourcesecure.net/2011/10/creating-generic-mvc-controllers/</link>
		<comments>http://sourcesecure.net/2011/10/creating-generic-mvc-controllers/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 03:37:50 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[controllers]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=221</guid>
		<description><![CDATA[Based on my previous posting regarding Generic Repositories, I decided to take this approach a step further and create Generic Controllers. The idea is simple: create a Generic Controller which can handle all of the CRUD operations by default. If we need to override or extend these methods, we can create a controller which inherits [...]]]></description>
			<content:encoded><![CDATA[<p>Based on my previous posting regarding <a href="http://sourcesecure.net/2011/10/repository-pattern-lazy-style/" title="Generic Repositories" target="_blank">Generic Repositories</a>, I decided to take this approach a step further and create Generic Controllers.  The idea is simple: create a Generic Controller which can handle all of the CRUD operations by default.  If we need to override or extend these methods, we can create a controller which inherits from this Generic Controller.  We will also need to create a Controller Factory which will first look for a derived class, if it cannot find one, it will automatically instantiate an instance of the Generic Controller and use this instance as the controller.</p>
<p>First we must create a Generic Controller, capable of handling all of the CRUD requests.  Below is my implementation.</p>
<pre class="prettyprint lang-cs">
public class ApplicationController&lt;T&gt; : Controller&lt;T&gt; where T: class
{
        protected ApplicationRepository&lt;T&gt; Repository { get; set; }
        private string&#91;&#93; _strLockedProperties = new string&#91;&#93; {
            &#34;Id&#34;,
            &#34;CreatedOn&#34;,
            &#34;CreatedBy&#34;,
            &#34;ModifiedOn&#34;,
            &#34;ModifiedBy&#34;
        };

        protected virtual string&#91;&#93; LockedProperties
        {
            get
            {
                return _strLockedProperties;
            }
        }

        public ApplicationController()
        {
            Repository = new ApplicationRepository&lt;T&gt;();
        }

        public virtual ActionResult Index()
        {
            return View(Repository.GetAll());
        }

        public virtual ActionResult Create()
        {
            return View();
        }

        &#91;HttpPost&#93;
        public virtual ActionResult Create(T record)
        {
            if (ModelState.IsValid)
            {
                Repository.Insert(record);
                Repository.Save();
            }

            return RedirectToAction(&#34;Index&#34;);
        }

        public virtual ActionResult Details(Guid id)
        {
            return View(Repository.Get(id));
        }

        public virtual ActionResult Edit(Guid id)
        {
            return View(Repository.Get(id));
        }

        &#91;HttpPost&#93;
        public virtual ActionResult Edit(Guid id, T record)
        {
            var properties = typeof(T).GetProperties();
            var fields = new List&lt;string&gt;();
            foreach (var prop in properties)
            {
                if (!LockedProperties.Contains(prop.Name))
                {
                    fields.Add(prop.Name);
                }
            }
            var allowed = fields.ToArray();
            var existing = Repository.Get(id);

            if (TryUpdateModel(existing, allowed))
            {
                Repository.Save();
                return RedirectToAction(&#34;Index&#34;);
            }

            return View(record);
        }

        public virtual ActionResult Delete(Guid id)
        {
            return View(Repository.Get(id));
        }

        &#91;HttpPost&#93;
        public virtual ActionResult Delete(Guid id, string confirm)
        {
            Repository.Delete(Repository.Get(id));
            Repository.Save();

            return RedirectToAction(&#34;Index&#34;);
        }
</pre>
<p>This class will be able to handle all of the default CRUD operations without worrying about the actual data types.  Based on the previous posting, even the repositories will be automatically generated.</p>
<p>If you need any special functionality for a controller, simply create a derived class.</p>
<pre class="prettyprint lang-cs">
public class UserController : ApplicationController&lt;UserAccount&gt;
{
    public override ActionResult Edit(Guid id)
    {
        &#47;&#47;Special code here.
    }
}
</pre>
<p>Now lets wire up our Controller Factory.  We need to create a factory which first looks for a strongly typed controller.  If it cannot find that strongly typed controller it will automatically instantiate a new Generic Controller and return this instance.</p>
<pre class="prettyprint lang-cs">
public class ApplicationControllerFactory : IControllerFactory
    {
        private string Namespace
        {
            get
            {
                return this.GetType().Namespace;
            }
        }

        public IController CreateController(RequestContext requestContext, string controllerName)
        {
            if (string.IsNullOrEmpty(controllerName))
                throw new ArgumentNullException(&#34;controllerName&#34;);

            Type cType = Type.GetType(Namespace + &#34;.Controllers.&#34; + controllerName + &#34;Controller&#34;);

            if (cType == null)
            {
                cType = Type.GetType(Namespace + &#34;.Library.ApplicationController`1&#91;&#34; + Namespace + &#34;.Models.&#34; + controllerName + &#34;&#93;&#34;);
            }

            return Activator.CreateInstance(cType) as Controller;
        }

        public void ReleaseController(IController controller)
        {
            if (controller is IDisposable)
                (controller as IDisposable).Dispose();
            else
                controller = null;
        }

        public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
        {
            return System.Web.SessionState.SessionStateBehavior.Default;
        }
    }
</pre>
<p>Now register the Controller Factory in your Global.asax.cs file.</p>
<pre class="prettyprint lang-cs">
protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);
    ControllerBuilder.Current.SetControllerFactory(new ApplicationControllerFactory());
}
</pre>
<p>The effects on development speed of this approach is pretty profound.  Essentially you have a Controller and Repository layer which is completely dynamic, powered only by the meta data of the data layer.  All that must be done is creating the views, and overriding your controllers and repositories where necessary.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/10/creating-generic-mvc-controllers/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/10/creating-generic-mvc-controllers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL to Delete All Users from Membership Provider</title>
		<link>http://sourcesecure.net/2011/10/sql-to-delete-all-users-from-membership-provider/</link>
		<comments>http://sourcesecure.net/2011/10/sql-to-delete-all-users-from-membership-provider/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 21:32:46 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[.net framework]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[membership provider]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=217</guid>
		<description><![CDATA[The .NET Membership Provider provides us with a stored procedure &#8216;aspnet_Users_DeleteUser&#8217; to delete a user from a particular application. There are problems with this. What if you have a user who is allocated to many applications? What if you need to delete more than one user? I came up with the following script to completely [...]]]></description>
			<content:encoded><![CDATA[<p>The .NET Membership Provider provides us with a stored procedure &#8216;aspnet_Users_DeleteUser&#8217; to delete a user from a particular application.  There are problems with this.  What if you have a user who is allocated to many applications?  What if you need to delete more than one user?  I came up with the following script to completely remove all users (except the admin) from all applications.</p>
<pre class="prettyprint lang-sql">
DECLARE user_cursor CURSOR FOR
SELECT ApplicationName AS field1, Username AS field2, UserId AS field3
FROM aspnet_Users CROSS JOIN dbo.aspnet_Applications
WHERE username != &#39;admin&#39;

OPEN user_cursor
DECLARE @field1 NVARCHAR(256)
DECLARE @field2 NVARCHAR(256)
DECLARE @field3 UNIQUEIDENTIFIER

FETCH NEXT FROM user_cursor
	INTO @field1, @field2, @field3
	WHILE @@FETCH_STATUS = 0
	BEGIN
	    PRINT @field1 + &#39;:&#39; + @field2
	    DELETE FROM dbo.aspnet_UsersInRoles WHERE UserId = @field3
		EXEC dbo.aspnet_Users_DeleteUser @ApplicationName = @field1,
		    @UserName = @field2,
		    @TablesToDeleteFrom = 50,
		    @NumTablesDeletedFrom = NULL
		DELETE FROM dbo.aspnet_Users WHERE UserId = @field3
		FETCH NEXT FROM user_cursor
		INTO @field1, @field2, @field3
	END
DEALLOCATE user_cursor;
</pre>
<p>The script works by first cross-joining applications and users, giving us a full list of every user to every application.  We then use a cursor to loop the given set, and run our deletes against the set.  This saved me countless hours of manual labor.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/10/sql-to-delete-all-users-from-membership-provider/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/10/sql-to-delete-all-users-from-membership-provider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Repository Pattern, Lazy Style</title>
		<link>http://sourcesecure.net/2011/10/repository-pattern-lazy-style/</link>
		<comments>http://sourcesecure.net/2011/10/repository-pattern-lazy-style/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 23:25:43 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[.net framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[dynamic linq]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=203</guid>
		<description><![CDATA[One of the most annoying things when working with MVC is repeating the same code over and over again at each layer. We can try to abstract our classes, but it still only gets us so far, a lot of the code must still be manually typed or templated. I found myself particularly tired of [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most annoying things when working with MVC is repeating the same code over and over again at each layer.  We can try to abstract our classes, but it still only gets us so far, a lot of the code must still be manually typed or templated.  I found myself particularly tired of creating <a href="http://msdn.microsoft.com/en-us/library/ff649690.aspx" title="repository" target="_blank">repository</a> objects for each of my database tables.  Sure, I was inheriting from a generic base class, but a lot of the implementation I couldn&#8217;t get away from.</p>
<p>Using Linq2Sql was one of the reasons for my headaches.  Types aren&#8217;t so easy to get at, and queries cannot be created dynamically at runtime&#8211;or could they?  <a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx" title="Dynamic Linq" target="_blank">Dynamic Linq</a> to the rescue.  Microsoft has a seperate library available for <a href="http://msdn.microsoft.com/en-us/vcsharp/bb894665.aspx" title="download" target="_blank">download</a> which actually allows you to run dynamic queries at runtime.  Once added to your project, the dynamic functions are added through class extensions to the standard Linq classes.</p>
<p>
I decided that I would start by creating a generic, templated, repository layer which could be extended if necessary, but would by default contain all of the necessary functions to interact with the model layer.
</p>
<pre class="prettyprint lang-cs">
using System.Linq.Dynamic;

public abstract class Repository&lt;R&gt; where R : class
{
    public virtual DataContext Context { get; protected set; }

    public Repository() { }

    public Repository(DataContext context)
    {
        Context = context;
    }

    public virtual void Insert(R record)
    {
        Context.GetTable&lt;R&gt;().InsertOnSubmit(record);
    }

    public virtual void Delete(R record)
    {
        Context.GetTable&lt;R&gt;().DeleteOnSubmit(record);
    }

    public virtual void Update(R record)
    {
        return;
    }

    public virtual IEnumerable&lt;R&gt; GetAll()
    {
        var records = from r in Context.GetTable&lt;R&gt;()
                        select r;

        return records;
    }

    public virtual void Save()
    {
        Context.SubmitChanges();
    }

    public virtual void Revert(R record)
    {
        Context.Refresh(RefreshMode.OverwriteCurrentValues, record);
    }
}
</pre>
<p>
Then create a class which inherits from your template, and code in all of the functions which are application specific.
</p>
<pre class="prettyprint lang-cs">
public class ApplicationRepository&lt;R&gt; : Repository&lt;R&gt; where R: class
{
    public ApplicationDataContext AppContext
    {
        get
        {
            return AppContext as ApplicationDataContext;
        }
    }

    public ApplicationRepository()
    {
        AppContext = new ApplicationDataContext();
    }

    public virtual R Get(Guid Id)
    {
        var record = (from  r in AppContext.GetTable&lt;R&gt;().Where(&#34;Id = @0&#34;, Id)
                        select r).Single();

        return record;
    }

    public virtual IEnumerable&lt;R&gt; GetAll(string clause, params object&#91;&#93; args)
    {
        var records = from  r in AppContext.GetTable&lt;R&gt;().Where(clause, args)
                        select r;

        return records;
    }

    public override void Insert(R record)
    {
        var d = record as dynamic;
        d.Id = Guid.NewGuid();
        d.CreatedOn = DateTime.Now;
        d.CreatedBy = &#34;System&#34;;

        base.Insert(record);
    }

    public override void Update(R record)
    {
        var d = record as dynamic;
        d.ModifiedOn = DateTime.Now;
        d.ModifiedBy = &#34;System&#34;;

        base.Update(record);
    }
}
</pre>
<p>
In my case, I added a narrowing ApplicationDataContext and some additional functionality.  One of the key functions is the <i>GetAll(string, param object[])</i> function.  This allows me to essential run any queries against my database using that Dynamic Linq library.  All of the functionality that I need from a repository layer will most likely already exist in this implementation.  Anything else that is needed can be added later by inheriting from the ApplicationRepository class.  This is going to save me a great deal of time.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/10/repository-pattern-lazy-style/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/10/repository-pattern-lazy-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Controlled Aquarium</title>
		<link>http://sourcesecure.net/2011/09/arduino-controlled-aquarium/</link>
		<comments>http://sourcesecure.net/2011/09/arduino-controlled-aquarium/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 17:16:49 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[arduino]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=74</guid>
		<description><![CDATA[My Latest Project: Aquarium Temperature &#38; Lighting Control. Amtega168 Programmable IC. HD44780U 16&#215;8 Parallel LCD 1 Light Dependent Resistor DS18B20 Waterproof Digital Temperature Sensor 5 VDC SUB-MINI Relay]]></description>
			<content:encoded><![CDATA[<p><a href="http://sourcesecure.net/wp-content/uploads/2011/09/85.jpg"><img class="alignnone size-medium wp-image-73" title="85" src="http://sourcesecure.net/wp-content/uploads/2011/09/85-300x224.jpg" alt="" width="300" height="224" /></a></p>
<p>My Latest Project: Aquarium Temperature &amp; Lighting Control.</p>
<ul>
<li>Amtega168 Programmable IC.</li>
<li>HD44780U 16&#215;8 Parallel LCD</li>
<li>1 Light Dependent Resistor</li>
<li>DS18B20 Waterproof Digital Temperature Sensor</li>
<li>5 VDC SUB-MINI Relay</li>
</ul>
<p><span id="more-74"></span><a href="http://sourcesecure.net/wp-content/uploads/2011/09/7f.jpg"><img class="alignnone size-medium wp-image-72" title="7f" src="http://sourcesecure.net/wp-content/uploads/2011/09/7f-300x224.jpg" alt="" width="300" height="224" /></a></p>
<p><a href="http://sourcesecure.net/wp-content/uploads/2011/09/tumblr_lq1fmbvbkU1qfdin2o1_400.jpg"><img class="alignnone size-medium wp-image-77" title="tumblr_lq1fmbvbkU1qfdin2o1_400" src="http://sourcesecure.net/wp-content/uploads/2011/09/tumblr_lq1fmbvbkU1qfdin2o1_400-300x225.jpg" alt="" width="300" height="225" /></a></p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/09/arduino-controlled-aquarium/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/09/arduino-controlled-aquarium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoMapper</title>
		<link>http://sourcesecure.net/2011/09/automapper/</link>
		<comments>http://sourcesecure.net/2011/09/automapper/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 18:20:09 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[.net framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[automapper]]></category>
		<category><![CDATA[nuget]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=117</guid>
		<description><![CDATA[AutoMapper is a great, free library available for .NET and accessible through nuget. It allows you to map and copy property data from one class to properties of another class. It does all of this based on naming convention. Assume that we have the following the two classes: class first { public string A { [...]]]></description>
			<content:encoded><![CDATA[<p>AutoMapper is a great, free library available for .NET and accessible through nuget. It allows you to map and copy property data from one class to properties of another class. It does all of this based on naming convention.</p>
<p>Assume that we have the following the two classes:</p>
<pre class="prettyprint lang-cs">
class first
{
     public string A { get; set; }
     public string B { get; set; }
     public string X { get; set; }
}
class second
{
     public string A { get; set; }
     public string B { get; set; }
     public string Y { get; set; }
}
</pre>
<p>If we tell AutoMapper to map from an instance of class first to an instance of class second it will automatically copy the data stored in the public properties A and B from the first class into the second class. Properties Y and Z will not match, and therefore not be copied between the two classes. How does it do this? AutoMapper uses type reflection to automatically match the names of properties in the source class to the names of properties in the destination class.</p>
<p>This technique has many applications, and is available to save countless hours of mapping code. This can even be used to map properties of LINQ to SQL or Entity classes to allow for shallow copying of one object to another. Another application is for creating projection classes for use by an outside method.</p>
<p>How does it work? AutoMapper must be configured with knowledge about which classes to match. This must be done once per Application Domain.</p>
<pre class="prettyprint lang-cs">
Mapper.CreateMap&lt;first, second&gt;();
Mapper.AssertConfigurationIsValid();
</pre>
<p>For web applications it is suggested that this mapping be done in the Application_Start method of your Global.asax.cs or Global.asax.vb file. This will ensure that the mapping is only run once per domain. Now that we have told AutoMapper how to map, let’s tell AutoMapper to map something.</p>
<pre class="prettyprint lang-cs">
var fInstance = new first();
fInstance.A = “hello”;
fInstance.B = “world”;
var sInstance = Mapper.Map&lt;first, second&gt;(fInstance);
Console.WriteLine(sInstance.A + ” ” + sInstance.B);
</pre>
<p>The output of this application would be “hello world”. AutoMapper would copy the properties in first_instance.A and first_instance.B to a brand new instance of the second class.</p>
<p>At this point, if you tried to compile and run the application, you might be wondering why you are getting an exception. AutoMapper is unable to map first.X to first.Y, and therefore throws an exception. You can force AutoMapper to ignore a column when you creating your mapping using a lambda expression.</p>
<pre class="prettyprint lang-cs">
Mapper.CreateMap&lt;first, second&gt;().Ignore(a =&gt; a.X);
</pre>
<p>When you run the application again, AutoMapper will ignore that column and your output will be as expected. What happens when there are many columns you wish to ignore? Writing a lambda expression for each column would be tedious. Luckily somebody over at stackoverflow has come up with a handy extension method which you can use to ignore all columns which don’t match.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/09/automapper/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/09/automapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Javascript on UpdatePanel Response</title>
		<link>http://sourcesecure.net/2011/07/running-javascript-on-updatepanel-response/</link>
		<comments>http://sourcesecure.net/2011/07/running-javascript-on-updatepanel-response/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 17:18:51 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=81</guid>
		<description><![CDATA[I recently found the need to run a javascript function after each AJAX postback. As it turns out, the asp.net UpdatePanel supports many client side events. This makes adding a handler extremely easy. On your document.ready event, you can simply add a handler as follows: $(document).ready(function () { Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); }); The function called must have [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found the need to run a javascript function after each AJAX postback. As it turns out, the asp.net UpdatePanel supports many client side events. This makes adding a handler extremely easy. On your document.ready event, you can simply add a handler as follows:</p>
<pre class="prettyprint lang-js">$(document).ready(function () {
     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
});</pre>
<p>The function called must have the following signature:</p>
<pre class="prettyprint lang-cs">function EndRequestHandler(sender, args) {
     if (args.get_error() == undefined) {
          &#47;* Code Here *&#47;
     }
}</pre>
<p>That’s all there is to it. The function EndRequestHandler will be called on each and every post back. This could also be a good place to handle any error messages that come back from the server by accessing args.get_error().</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/07/running-javascript-on-updatepanel-response/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/07/running-javascript-on-updatepanel-response/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento Troubleshooting</title>
		<link>http://sourcesecure.net/2011/05/magento-troubleshooting/</link>
		<comments>http://sourcesecure.net/2011/05/magento-troubleshooting/#comments</comments>
		<pubDate>Fri, 20 May 2011 17:22:03 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=83</guid>
		<description><![CDATA[If your using Magento, please do yourself a favor and make sure that your server’s date/time is synchronized: rdate -s us.pool.ntp.org If your time is not correct, you will be unable to login as the admin. You will be returned to the login screen without error, and probably spend the next few hours figuring out [...]]]></description>
			<content:encoded><![CDATA[<p>If your using Magento, please do yourself a favor and make sure that your server’s date/time is synchronized:</p>
<pre class="prettyprint lang-bsh">
rdate -s us.pool.ntp.org
</pre>
<p>If your time is not correct, you will be unable to login as the admin.  You will be returned to the login screen without error, and probably spend the next few hours figuring out what went wrong.<br />
Another tip:  edit your php.ini and set your memory_limit variable to > 256M.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/05/magento-troubleshooting/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/05/magento-troubleshooting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HPDetector &#8211; Detecting Stealth Ports</title>
		<link>http://sourcesecure.net/2011/05/102/</link>
		<comments>http://sourcesecure.net/2011/05/102/#comments</comments>
		<pubDate>Tue, 10 May 2011 17:51:23 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[computer security]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[rootkit]]></category>
		<category><![CDATA[hpdetector]]></category>
		<category><![CDATA[stealth port]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=102</guid>
		<description><![CDATA[HPDetector is a free application which specializes in detecting hidden backdoor TCP/UDP ports. HPDetector uses a two step process to detect hidden ports. First, HPDetector compares the Linux Kernel or Windows Netstat exported list of ports with a list gathered from manually binding to ports. If a port caused a binding exception but is not [...]]]></description>
			<content:encoded><![CDATA[<p>HPDetector is a free application which specializes in detecting hidden backdoor TCP/UDP ports. HPDetector uses a two step process to detect hidden ports. First, HPDetector compares the Linux Kernel or Windows Netstat exported list of ports with a list gathered from manually binding to ports. If a port caused a binding exception but is not shown in the Kernel/Netstat list, then it may be a hidden port. Redundant checks are done to ensure that the port is actually hidden.  This program essentially catches the operating system in a “lie” about which ports are bound to an interface. It is available for both Windows and Linux.   The Windows version requires the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d-8edd-aab15c5e04f5&amp;displaylang=en" target="_blank">.NET 2.0 Framework</a>. The Linux version requires either the latest <a href="http://java.com/en/download/manual.jsp" target="_blank">JRE</a> or the <a href="http://gcc.gnu.org/java/" target="_blank">GNU Compiler for Java</a>.</p>
<p>What does it mean if a hidden port is detected?  A hidden port being detected simply means that an inconsistancy was found between different portions of the operating system.  This is sometimes an indication that a Rootkit is hiding a backdoor.  A hidden port being detected should be taken seriously.  It provides a starting point to conduct further investigation.  For example, after detecting a hidden TCP port, an administrator can attempt to telnet to the port to see if it is actually listening for connections.  Other rootkit tools such as <a href="http://www.microsoft.com/technet/sysinternals/utilities/rootkitrevealer.html" target="_blank">Rootkit Revealer</a> will help verify the prescense of a rootkit.</p>
<p><a href="http://sourcesecure.net/wp-content/uploads/2011/09/HPDetector.jpg"><img class="alignnone size-medium wp-image-103" title="HPDetector" src="http://sourcesecure.net/wp-content/uploads/2011/09/HPDetector-300x180.jpg" alt="HPDetector" width="300" height="180" /></a></p>
<p><strong>Version: </strong>Linux/0.1 (December 8th, 2008)<br />
<strong>License: </strong>GPL<br />
<strong>Tarball: </strong><a title="Download" href="http://sourcesecure.net/Download/hpdetector_linux.tar.gz">Download</a><br />
<strong>SHA-1: </strong>9ee1882886a153221d83ded82801cb9aafd4372d</p>
<p>&nbsp;</p>
<p><strong>Version: </strong>Windows/1.0 (January 14th, 2009)<br />
<strong>License: </strong>GPL<br />
<strong>Binary: </strong><a title="Download" href="http://sourcesecure.net/Download/HPDetector.zip">Download</a><br />
<strong>SHA-1: </strong>a2279f0f6de6f2e4f323bd1963a60f363c877a27<br />
<strong>Source: </strong><a title="Download" href="http://sourcesecure.net/Download/HPDetector_Source.zip">Download</a><br />
<strong>SHA-1: </strong>a65e58f453ec489b1d2f058692ce9683e7525919</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/05/102/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/05/102/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtual Manager over QEMU+SSH</title>
		<link>http://sourcesecure.net/2011/05/virtual-manager-over-qemussh/</link>
		<comments>http://sourcesecure.net/2011/05/virtual-manager-over-qemussh/#comments</comments>
		<pubDate>Sat, 07 May 2011 17:23:54 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[libvirt]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=85</guid>
		<description><![CDATA[Virtual Manager allows you to connect to a hypervisor over SSH. This is a really nice feature for remote administration and monitoring of virtual machines using KVM or XEN. This technique works nicely without any modification when connecting to the server as root through SSH. However, in almost any secure installation, the root user should [...]]]></description>
			<content:encoded><![CDATA[<p>Virtual Manager allows you to connect to a hypervisor over SSH. This is a really nice feature for remote administration and monitoring of virtual machines using KVM or XEN.<br />
This technique works nicely without any modification when connecting to the server as root through SSH. However, in almost any secure installation, the root user should not be allowed to log in through SSH for security reasons. What happens if you restrict the root user from logging in to the server through SSH? By default, a non-root user will not be able to connect to the libvirtd daemon, and will be notified that the connection has failed.</p>
<p>The workaround is fairly simple. First, create a new group called libvirtd.</p>
<pre class="prettyprint lang-bsh">
&#91;user@localhost ~&#93;# su -
&#91;root@localhost ~&#93;# groupadd libvirt
</pre>
<p>Modify the libvirt configuration file located at /etc/libvirt/libvirtd.conf and uncomment the following lines:</p>
<pre class="prettyprint lang-bsh">
unix_sock_group = “libvirt”
unix_sock_rw_perms = “0770”
</pre>
<p>Restart the service.</p>
<pre class="prettyprint lang-bsh">
&#91;root@localhost ~&#93;# service libvirtd restart
</pre>
<p>Lastly, add your user account to the libvirt group.</p>
<pre class="prettyprint lang-bsh">
&#91;root@localhost ~&#93;# useradd -G libvirt myusername
</pre>
<p>You will now be able to connect to the hypervisor without needing to log in as the root account.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/05/virtual-manager-over-qemussh/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/05/virtual-manager-over-qemussh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tumblr API</title>
		<link>http://sourcesecure.net/2011/05/tumblr-api/</link>
		<comments>http://sourcesecure.net/2011/05/tumblr-api/#comments</comments>
		<pubDate>Sun, 01 May 2011 17:26:58 +0000</pubDate>
		<dc:creator>mlandi</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tumblr]]></category>

		<guid isPermaLink="false">http://sourcesecure.net/?p=87</guid>
		<description><![CDATA[I’ve been doing a lot of work recently which requires integration of dynamic content, such as blogs, into existing websites. I decided to first try it out on my own website, realizing that it would make updating content a much simpler process. I am impressed by how easy the Tumblr API is to implement. They [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been doing a lot of work recently which requires integration of dynamic content, such as blogs, into existing websites. I decided to first try it out on my own website, realizing that it would make updating content a much simpler process.</p>
<p>I am impressed by how easy the Tumblr API is to implement. They basically give you two options for displaying content on your own website. The first method uses javascript to insert your blog’s content into an existing webpage:</p>
<pre class="prettyprint lang-html">
&lt;script type=”text&#47;javascript” src=”http:&#47;&#47;blog.com&#47;js” &#47;&gt;
</pre>
<p>It’s as easy as that. Your existing blog posts will show up directly on the page you inserted this into. That being said, it isn’t going to look very nice without styling the various elements. The Tumblr API assigns css classes to almost every element which is inserted, making the process of styling a breeze.</p>
<p>The second method utilizes Tumblr’s XML based API services to grab content. Every blog’s API can be accessed via the following path: /api/read/. This request will return the contents of your blog formatted as an XML document. This leaves the dirty work of parsing the XML document up to us. An easy way to do this is to parse each element and add it to an existing Literal control on your ASP.NET page:</p>
<pre class="prettyprint lang-cs">
private void Tumblr()
{
  var wc = new WebClient()
  var xml = wc.DownloadString(“http:&#47;&#47;blog.com&#47;api&#47;read”);
  var xdoc = new XmlDocument();
  xdoc.LoadXml(xml);

  foreach (var xelem in xdoc.GetElementsByTagName(“post”))
  {
        var xtitle = xelem.GetElementsByTagName(“regular-title”);
        if (xtitle.Count &lt; 1)
               continue;

          string date = xelem.GetAttribute(“date-gmt”);
          string url = xelem.GetAttribute(“url”);
          string title = xtitle&#91;0&#93;.InnerText;
          string body = xelem.GetElementsByTagName(
               ”regular-body”)&#91;0&#93;.InnerText;
          litTumbler.Text += string.Format(
                “&lt;h4&gt;&lt;a href=&#34;{0}&#34; target=&#34;_blank&#34;&gt;” +
                “({1})&nbsp;&nbsp;{2}&lt;&#47;a&gt;&lt;&#47;h4&gt;” +
                “{3}&lt;br &#47;&gt;&lt;br &#47;&gt;”,
                url,
                DateTime.Parse(date).ToString(),
                title,
                body);
     }
}
</pre>
<p>That’s all that you have to do to show some content from your blog. This has been extremely easy for me to add to use. My only concern is the scalability of that API read function. What happens if your blog contains thousands of posts? I’ll worry about that when the time comes.</p>
<div class="alignright"><div class="g-plusone" data-href="http://sourcesecure.net/2011/05/tumblr-api/" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://sourcesecure.net/2011/05/tumblr-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

