#!/bin/sh

# 
# Wordpress Securify v1.0a 
# Author: David Kierznowski (david.kierznowski_at_gmail.com)
# http://michaeldaw.org
#
# Tested on: Linux 2.6/Wordpress 2.0.5
#
# DISCLAIMER:
# This is BETA software use it at your own risk.
# It is recommended that you backup your WordPress 
# directory before using this tool.
#
# Credits:
# Kafkaesqui 
#	- http://wordpress.org/support/topic/32764#post-185346
#
#


#
# User Preferences can be selected here.
#
# New name of your wp-admin directory and admin css.
# Note: The admin.css file must match the name of NEW_ADM_DIR.
# If you intend to alter these values, becareful to select
# unique names that will not conflict with code functions etc.
#

NEW_ADM_DIR="CHANGEME";
NEW_INC_DIR="CHANGEME2";
NEW_CON_DIR="CHANGEME3";

#
# End of User Preferences.
#

echo "WordPress Securify v1.0a";
echo "http://michaeldaw.org/wpsec/";
echo

if [ ! -d wp-admin ]; then
 echo "ERR: Check your path.";
 echo "WordPress Securify must run from the root of your WordPress directory.";
 echo "It is strongly recommended that you backup your entire directory before running this tool.";
 echo
 exit;
fi

if [ $NEW_ADM_DIR == "CHANGEME" ]; then
 echo "ERR: Default preferences used.";
 echo "It is recommended that you use your own directory names.";
 echo "NEW_ADM_DIR, NEW_INC_DIR and NEW_CON_DIR require unique names.";
 echo
 exit;
fi

# exit;


echo "[Step 1] Removing .txt/.html/import*.php/install*.php/upgrade*.php files...";
 rm -rf *.txt wp-admin/import*.php wp-admin/install*.php wp-admin/upgrade*.php readme.html;

find . -name '*.php' > files.txt;

echo "[Step 2] Renaming default directories...(This may take a minute)";
for I in `cat files.txt` ;
 do

  cat $I | sed s/wp-admin/$NEW_ADM_DIR/g > $I.old ;
  cp $I.old $I;

 done;
 mv wp-admin $NEW_ADM_DIR ;


find . -name '*.php' > files.txt;

for I in `cat files.txt` ;
 do

  cat $I | sed s/wp-includes/$NEW_INC_DIR/g > $I.old ;
  cp $I.old $I;

 done;
 mv wp-includes $NEW_INC_DIR ;


find . -name '*.php' > files.txt;

for I in `cat files.txt` ;
 do


  cat $I | sed s/wp-content/$NEW_CON_DIR/g > $I.old ;
  cp $I.old $I;


 done;
 mv wp-content $NEW_CON_DIR ;


 if [ -e $NEW_ADM_DIR/wp-admin.css ]; then 

  echo "[Step 3] Changing filename wp-admin.css to $NEW_ADM_DIR.css " ; 
  mv $NEW_ADM_DIR/wp-admin.css $NEW_ADM_DIR/$NEW_ADM_DIR.css ;
 else
  echo "There was a problem moving the wp-admin stylesheet (check manually)";
 
 fi


 echo "[Step 4] Remove WordPress Version";
 if [ -e $NEW_INC_DIR/version.php ]; then

  cat $NEW_INC_DIR/version.php | sed s/[0-9]\.[0-9]\.[0-9]/x.x/g > , ;
  mv , $NEW_INC_DIR/version.php ;
 else 
  echo "ERR: Failed to find/write to file: $NEW_INC_DIR/version.php";

 fi


rm -f files.txt;

echo
echo
echo "Changes complete.";
echo "It is recommended that you remove the old *.old files.";
echo "This can be done by: rm -r *.old";
echo

