2010 January

Wordpress mime types

I wanted to expand the type of files that wordpress would allow me to upload and attach to a post.  I used a plugin called pjw-mime-config here are a few things that I figured out beyond just using this plugin to add mime types.

I originally wanted to upload and attach a powershell script to a post when wordpress responded with the following error:  File type does not meet security guidelines. Try another.  I googled the error and found that I needed to add additional mime types to be accepted by wordpress, pjw-mime-config was suggested to easily add mime types, I installed the plugin and fat fingered the mime type, I tried to remove the mime type but it failed to delete it…  I uninstalled the plugin and reinstalled thinking that would remove the mime type, no luck.  My thought at this point was that the mime types must be stored in the wordpress database  by the pjw-mime-config plugin, I worked with a test wordpress installation and exported the DB (db1.sql) installed jpw-mime-config, added a mime type (foo, text/plain) and exported the DB again (db2.sql) I then did a diff on the two SQL exports.  Sure enough there jpw-mime-config row in the wordpress DB table wp_options, I uninstalled jpw-mime-config, deleted the row and reinstalled jpw-mine-config and all was good.

After installing jpw-mime-config the wordpress uploader accepted the file but gave an error from the upload dialog that referenced functions.php @ line 2258.  To resolve the error I edited ./wp-includes/functions.php and added the ps1 mime type to the get_allowed_mime_types function (starts at appox line 2275).

By rbocchinfuso on January 31, 2010 | Tips, Wordpress | A comment?
Tags: , ,

Data Profiling with Windows PowerShell

A customer asked me the other day about a method to do some data profiling against a file system.  So I thought I would share the request, my suggestion and little PowerShell script I crafted to do some data profiling.  The request read as follows:  “Do you know of any tools that will list all files in a directory, and all subs and provide attributes like filename, path, owner, create date, modify date, last access date and maybe some other attributes in report format?”

My recommendation was a commercial product called TreeSize Professional by JAM Software the product license cost is ~ $50 and worth every penny, scan speeds are good, supports UNC paths and reporting is intuitive.  Overall an excellent product.

As an alternative below is a quick PowerShell script (also attached to post as data_profile.ps1) that will create a CSV file with data profiling information, once the CSV file is create the CSV can be opened in Excel (or your spreadsheet tool of choice) or imported into a DB and manipulated.

# Script Starts Here #

$root = "c:\\files"
$report = ".\report.csv"

$AllFiles = @()
foreach ($file in get-childitem $root  -recurse| Select-Object FullName, Root, Directory, Parent, Name, Extension, PSIsContainer, IsReadOnly, Length, CreationTime, LastAccessTime, LastWriteTime, Attributes)
{
    $acl = get-acl $file.fullname | select-object path,owner,accesstostring,group
    $obj = new-object psObject
    #$obj | Add-Member -membertype noteproperty -name FilePathandName -Value $file.FullName
    $obj | Add-Member -membertype noteproperty -name Root -Value $file.Root
    $obj | Add-Member -membertype noteproperty -name Ditrectory -Value $file.Directory
    $obj | Add-Member -membertype noteproperty -name Parent -Value $file.Parent
    $obj | Add-Member -membertype noteproperty -name Name -Value $file.Name
    $obj | Add-Member -membertype noteproperty -name Extension -Value $file.Extension
    $obj | Add-Member -membertype noteproperty -name IsDIR -Value $file.PSIsContainer
    $obj | Add-Member -membertype noteproperty -name IsReadOnly -Value $file.IsReadOnly
    $obj | Add-Member -membertype noteproperty -name Size -Value $file.Length
    $obj | Add-Member -membertype noteproperty -name CreationTime -Value $file.CreationTime
    $obj | Add-Member -MemberType noteproperty -Name LastAccessTime -Value $file.LastAccessTime
    $obj | Add-Member -MemberType noteproperty -Name LastWriteTime -Value $file.LastWriteTime
    $obj | Add-Member -MemberType noteproperty -Name Attributes -Value $file.Attributes
    #$obj | Add-Member -MemberType noteproperty -Name Path -Value $acl.path
    $obj | Add-Member -MemberType noteproperty -Name Owner -Value $acl.owner
    $obj | Add-Member -MemberType noteproperty -Name AccessToString -Value $acl.accesstostring
    $obj | Add-Member -MemberType noteproperty -Name Group -Value $acl.group
    $AllFiles += $obj
}
$AllFiles |Export-Csv $report –NoTypeInformation

# Script Ends Here #

The above script scans all files recursively starting at c:\files and outputs the results to results.csv.  One thing to note is that the scan stores all data in an array in memory, the is because the PowerShell Export-Csv function does not support appending to a CSV file (you gotta wonder what Microsoft talks about in design meetings).  I will likely create a version of the script that uses the out-file function to write each row to the csv file as the scan happens rather then storing in memory until the scan is completes and then writing the entire array to the report.csv file, goal here is to reduce the memory footprint during large scans.

The output of this file script will be similar to the following:

Parent Name Extension IsDIR IsReadOnly Size CreationTime LastAccessTime LastWriteTime Attributes Owner Group
files Program Files   TRUE     1/27/2010 13:33 1/30/2010 21:23 1/27/2010 13:33 Directory BUILTIN\Administrators NT AUTHORITY\SYSTEM
Program Files Microsoft.NET .NET TRUE     1/27/2010 13:33 1/30/2010 21:23 1/27/2010 13:33 Directory BUILTIN\Administrators NT AUTHORITY\SYSTEM
Microsoft.NET Primary Interop Assemblies   TRUE     1/27/2010 13:33 1/30/2010 21:23 1/27/2010 13:33 Directory BUILTIN\Administrators NT AUTHORITY\SYSTEM
  adodb.dll .dll FALSE FALSE 110592 10/26/2006 14:40 1/27/2010 13:33 10/26/2006 14:40 Archive BUILTIN\Administrators NT AUTHORITY\SYSTEM
  Microsoft.mshtml.dll .dll FALSE FALSE 8007680 10/26/2006 14:40 1/27/2010 13:33 10/26/2006 14:40 Archive BUILTIN\Administrators NT AUTHORITY\SYSTEM
  Microsoft.stdformat.dll .dll FALSE FALSE 13312 10/26/2006 14:40 1/27/2010 13:33 10/26/2006 14:40 Archive BUILTIN\Administrators NT AUTHORITY\SYSTEM
  msdatasrc.dll .dll FALSE FALSE 4096 10/26/2006 14:40 1/27/2010 13:33 10/26/2006 14:40 Archive BUILTIN\Administrators NT AUTHORITY\SYSTEM
  stdole.dll .dll FALSE FALSE 16384 10/26/2006 14:40 1/27/2010 13:33 10/26/2006 14:40 Archive BUILTIN\Administrators NT AUTHORITY\SYSTEM


Attached Files:

By rbocchinfuso on January 30, 2010 | General Discussion | 2 comments

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 182 items have been purified.