Last active
May 20, 2020 15:07
-
-
Save ahmedsadman/ccf01704acf6e21c4ad8331a89dae0bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import requests | |
import calendar | |
import json | |
from datetime import datetime | |
from pprint import pprint | |
class ApiTester: | |
def __init__(self, api_key): | |
self.api_key = api_key | |
# EDIT URL HERE. | |
self.url = "https://wp1.ide4.bid/" | |
self.plugin_list = None | |
def _make_request(self, command, optional_args=None): | |
try: | |
d = datetime.utcnow() | |
unixtime = calendar.timegm(d.utctimetuple()) | |
headers = {"content-type": "application/x-www-form-urlencoded"} | |
payload = { | |
"shift8_remote_verify_key": self.api_key, | |
"timestamp": unixtime, | |
"actions[0]": command, | |
} | |
# print(payload) | |
if optional_args is not None: | |
payload.update(optional_args) | |
response = requests.post(self.url, data=payload, headers=headers) | |
# print(response.status_code) | |
# print(response.text) | |
return response | |
except Exception as e: | |
print(f"Error while request: {e}") | |
def get_plugin_version(self): | |
response = self._make_request("get_plugin_version") | |
self.print_response("get_plugin_version", response) | |
def get_plugins_list(self): | |
response = self._make_request("get_plugins") | |
self.plugin_list = json.loads(response.text) | |
self.print_response("get_plugins", response) | |
def get_filesystem_method(self): | |
response = self._make_request("get_filesystem_method") | |
self.print_response("get_filesystem_method", response) | |
def get_wp_version(self): | |
response = self._make_request("get_wp_version") | |
self.print_response("get_wp_version", response) | |
def get_constants(self): | |
response = self._make_request("get_constants") | |
self.print_response("get_constants", response) | |
def get_site_info(self): | |
response = self._make_request("get_site_info") | |
self.print_response("get_site_info", response) | |
def update_plugin(self): | |
if not self.plugin_list: | |
self.get_plugins_list() | |
if len(self.plugin_list) == 0: | |
print("No plugins found") | |
return | |
first_plugin = list(self.plugin_list["get_plugins"].keys())[ | |
0 | |
] # get first plugin | |
print(f"Trying to update the plugin: {first_plugin}") | |
response = self._make_request("update_plugin", {"plugin": first_plugin}) | |
self.print_response("update_plugin", response) | |
def print_response(self, name, response): | |
print(f"Command: {name}") | |
print("Response: ") | |
response = json.loads(response.text) | |
pprint(response) | |
print("\n=============================================\n") | |
# ecda69f7b992ec846b2e256c62d1e49504571e92b526cba6d52042328429c242 | |
# ce847d4e2733ec115418a6ad2c1df1b317bf812005af375a4165ebf83476dcc4 | |
if __name__ == "__main__": | |
# api_key = input("Please enter API Key: ") | |
# tester = ApiTester(api_key) | |
# tester = ApiTester( | |
# "8863051684f1f1f3d05ada6730fbb4ae392b5198f45de3226b65089ea45518f1" | |
# ) | |
tester = ApiTester( | |
"93d564f2a022115a74550b5c4fbb1f61d960b0508cf5021c220ee547e9ee725d" | |
) | |
tester.get_plugin_version() | |
tester.get_wp_version() | |
tester.get_site_info() | |
tester.get_filesystem_method() | |
tester.get_constants() | |
tester.get_plugins_list() | |
tester.update_plugin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment