• Finding diffs between clean and modified versions of WordPress

    We have an issue where our developers try to update the core WordPress files. I wanted to find a way to keep them honest. here is my script:

    
    # get WordPress
    cd ~/src/
    rm -f ~/src/latest.tar.gz
    rm -rf ~/src/wordpress/
    wget -q http://wordpress.org/latest.tar.gz
    tar -xzf latest.tar.gz
    CURRENTVERSION=$(grep "wp_version =" ~/src/wordpress/wp-includes/version.php | cut -f 3 -d " " | sed "s/;//" | sed "s/'//g")
    # find WordPress installs and compare
    for installpath in $(find $SEARCHPATH -name wp-config.php)
    	do
    		BASEDIR=$(dirname $installpath)
    		INSTALLEDVERSION=$(grep "wp_version =" $BASEDIR/wp-includes/version.php | cut -f 3 -d " " | sed "s/;//" | sed "s/'//g")
    		if [ $CURRENTVERSION == $INSTALLEDVERSION ]; then
    		echo "====Comparing $BASEDIR to Source====" 
    		diff -rq --exclude="wp-content" ~/src/wordpress  $BASEDIR #| grep differ
    		fi
    done
    

  • Pseudo workflow approval with out SharePoint Workflows.

    I wanted to have a form that a person would submit (for an example a request of some type) and then it would be approved by the appropriate people. I find the built in workflow functionality too limiting and too difficult for users, so this is what I came up with:

    I would have one list that contained fields for both the user to enter data and for each approver to approve or disapprove. In addition, there would be a “Final Approval” field that cold only be set once everyone approved or disapproved and an “I agree” to terms checkbox.

    First up, I hid all the fileds on the NewForm.aspx that were related to the approval process. Just the data that was to be collected was shown. I did this with jquery and a CEWP:

    <script type="text/javascript">
    $(document).ready(function(){
    $('tr:has(select[title="User 1"])').not('tr:has(tr)').hide();
    $('tr:has(select[title="User 2"])').not('tr:has(tr)').hide();
    $('tr:has(select[title="User 3"])').not('tr:has(tr)').hide();
    $('tr:has(select[title="User 4"])').not('tr:has(tr)').hide();
    $('tr:has(select[title="User 5"])').not('tr:has(tr)').hide();
    $('tr:has(select[title="Final Status"])').not('tr:has(tr)').hide();
    $('nobr:contains("User 1 Comments")').closest('tr').hide();
    $('nobr:contains("User 2 Comments")').closest('tr').hide();
    $('nobr:contains("User 3 Comments")').closest('tr').hide();
    $('nobr:contains("User 4 Comments")').closest('tr').hide();
    $('nobr:contains("User 5 Comments")').closest('tr').hide();
    });
    </script>
    

    Once this is submitted by the user, and email is sent by a SharePoint workflow (I still don’t like them) telling the approvers to look at the request and approve it (link to the edit page in the email)

    Then on the edit page, I used the jquery below to hide the “I agree” so the user could not go back and change it. Also I hid the final approval until all drop downs (Approvals) have changed from “Pending” to Approved or Declined. Obviously there would be security issues, but this is a small use case and we weren’t worried about malicious users (famous last words) – people were on their honor.

    <script type="text/javascript">
    $(document).ready(function(){
    $('tr:has(select[title=IAgree])').not('tr:has(tr)').hide();
    $('tr:has(select[title=IAgree])').not('tr:has(tr)').append('<tr><td nowrap="true" valign="top" width="190px" class="ms-formlabel"><H3 class="ms-standardheader">I Agree</H3></TD><td valign="top" class="ms-formbody" width="400px">'+$('select[title=IAgree] :selected').text()+'</td></tr>');
    
    $('select :selected').each(function(){
    if($(this).text() == "Pending") {
    $('tr:has(select[title=Final Status])').not('tr:has(tr)').hide();
    }
    });
    
    });
    </script
    

  • Powershell script to find and run advertisements that are set to run when NoUserLoggedOn

    I have been thinking about how to launch a SCCM package/program before logon. If the user logs on before SCCM executes (like right after a reboot), the NoUserLoggedOn requirement will not be met. GPO software deployment handles this by not allowing the user to log in until the software is installed.

    What happens if you combine both software deployment via GPO and SCCM?

    So my theory is that I could execute a script wrapped in a MSI and deployed via GPO software deployment. This script would then search for advertisements that are set to run “when no one is logged in” and execute them. Below is that script, not sure if the rest of my theory will work, but this is the first piece.

    $AdvNoLogOn = (gwmi -Namespace ROOT\CCM\Policy\Machine\ActualConfig -Class CCM_SoftwareDistribution | where {$_.ADV_MandatoryAssignments -eq $true} | where {$_.PRG_PRF_UserLogonRequirement -eq "NoUserLoggedOn"})
    $SMSCli = [wmiclass] "\root\ccm:SMS_Client"
    foreach ($Adv in $AdvNoLogOn)
    {
    $PKGID= $Adv.PKG_PackageID
    write-host $PKGID
    $SCHEDMESS=(gwmi -Namespace ROOT\CCM\Policy\Machine\ActualConfig -Class CCM_Scheduler_ScheduledMessage | where {$_.ActiveMessage -like "*$PKGID*"})
    write-host $SCHEDMESS.ScheduledMessageID
    $SMSCLI.TriggerSchedule($SCHEDMESS.ScheduledMessageID)
    }
    

  • WMI query to find if the SCCM client is running a program

    Using PowerShell, this will tell you if the SCCM client is running a program and its state:

    gwmi -Namespace ROOT\CCM\SoftMgmtAgent -Class CCM_ExecutionRequestEx
    

  • CentOS: HowTo install ruby, rubygems and passenger for a redmine install

    I like to put my complied software in /opt vs /usr/local. Make sure rpm version is not installed.

    install ruby:

    wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz
    ./configure --prefix=/opt/ruby-1.8.7-p174
    sudo make &amp;&amp; sudo make install
    

    user alternatvies to create sym links:

    /usr/sbin/alternatives --install /usr/bin/ruby ruby /opt/ruby-1.8.7-p174/bin/ruby 1 \
    --slave /usr/bin/rdoc rdoc /opt/ruby-1.8.7-p174/bin/rdoc \
    --slave /usr/bin/ri ri /opt/ruby-1.8.7-p174/bin/ri \
    --slave /usr/bin/irb irb /opt/ruby-1.8.7-p174/bin/irb \
    --slave /usr/bin/erb erb /opt/ruby-1.8.7-p174/bin/erb \
    --slave /usr/bin/testrb testrb /opt/ruby-1.8.7-p174/bin/testrb \
    --slave /usr/bin/gem gem /opt/ruby-1.8.7-p174/bin/gem \
    --slave /usr/bin/rake rake /opt/ruby-1.8.7-p174/bin/rake
    

    make sure current ruby is set to 1.8.7: /usr/sbin/alternatives –config ruby

    install rubygems:

    wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
    sudo ruby setup.rb
    

    install gems (No docs):

    gem install --no-rdoc --no-ri rails
    gem install --no-rdoc --no-ri passenger
    gem install --no-rdoc --no-ri mysql
    gem install --no-rdoc --no-ri rack -v=1.0.1
    

    Passenger said I needed to install curl-dev  (yum install curl-devel)

    install passenger apache module:

    	/opt/ruby-1.8.7-p174/lib/ruby/gems/1.8/gems/passenger-3.0.0/bin/passenger-install-apache2-module
    

    modify your httpd conf file

       LoadModule passenger_module /opt/ruby-1.8.7-p174/lib/ruby/gems/1.8/gems/passenger-3.0.0/ext/apache2/mod_passenger.so
       PassengerRoot /opt/ruby-1.8.7-p174/lib/ruby/gems/1.8/gems/passenger-3.0.0
       PassengerRuby /opt/ruby-1.8.7-p174/bin/ruby
    

    Install redmine according to Docs


  • My current WordPress Update Script

    Below is my current WordPress update script. First this script downloads the most recent version and determines which version it is:

    cd ~/src/
    rm -f ~/src/latest.tar.gz
    rm -rf ~/src/wordpress/
    wget -q http://wordpress.org/latest.tar.gz
    tar -xzf latest.tar.gz
    CURRENTVERSION=$(grep "wp_version =" wordpress/wp-includes/version.php | cut -f 3 -d " " | sed "s/;//" | sed "s/'//g")
    echo "Latest Version: $CURRENTVERSION"
    

    Next it looks for all wp-config.php files in all the websites to identify which sites have WordPress installed. Then and finds the version from the versions.php script. If the version is not equal to the most recent downloaded version (from the code above), it copies the updated source to the website:

    for installpath in $(find /webdir -name wp-config.php)
    	do
    	BASEDIR=$(dirname $installpath)
    	INSTALLEDVERSION=$(grep "wp_version =" $BASEDIR/wp-includes/version.php | cut -f 3 -d " " | sed "s/;//" | sed "s/'//g")
    	if [ ! $CURRENTVERSION == $INSTALLEDVERSION ]; then
    		echo "updating" $BASEDIR from $INSTALLEDVERSION "to" $CURRENTVERSION
    		cp -R  ~/src/wordpress/* $BASEDIR/
    	else
    		echo $BASEDIR "is already" $CURRENTVERSION
    	fi
    	done
    

  • Using ajax to query XML in SharePoint Doc Lib, for use in a form’s input autocomplete

    Long title, but I wanted to get across what I was trying to do. If I had and XML file in a document library (you could mail enable the doc lib, and send XML from a query in SQL server using the “FOR XML” statement!), could I use jquery to add Autocomplete values to an input field in a newform.aspx? Ended up being not that difficult.

    1. Once the ajax call sucessfully retrievs the xml file, the parseXml routine is called.
    2. Seems there is an issue that IE will not think the file is XML, but rather as txt, so there some quick code to load the file as XML
    3. Then I just look in the file and grab the values I want, and append them to an array
    4. Then just set the array to be used as the autocomplete source
    <script type="text/javascript">
    $(document).ready(function() {
    $.ajax({ 	
    	type: "GET",
    	url: "http://URL/To/xmlfile.xml",
    	dataType: ($.browser.msie) ? "text" : "xml",
    	success: parseXml
    });
    });
    function parseXml(data)
    {
        var xml;
         if (typeof data == "string") {
           xml = new ActiveXObject("Microsoft.XMLDOM");
           xml.async = false;
           xml.loadXML(data);
         } else {
           xml = data;
         };
     	var results = []; 
    	$(xml).find("ID").each(function(){  
    		var ClientName = $.trim($(this).find('Name').text());
    		var ClientCode = $.trim($(this).find('ZipCode').text());
    		results[results.length] = ClientName + "(" + ClientCode + ")"
    	});
    
    	$('input[title=Title]').autocomplete({
    	source: results,
    	delay:10,
    	minLength: 3
    	});
    };
    </script>
    

  • Apple to push virtualization of OSX?

    Seems that Apple is discontinuing their XServe product. I hope this means that Apple is moving towards virtualizion of OSX in the enterprise. VDI with OSX would be sweet!