├── .gitignore ├── LICENSE ├── README.md ├── bash ├── example.sh └── plesk_api_client.sh ├── c-sharp ├── apirpcexample.csproj ├── apirpcexample.sln ├── app.config ├── program.cs └── properties │ └── assemblyinfo.cs ├── cpp ├── Makefile ├── example.cpp ├── plesk_api_client.cpp └── plesk_api_client.h ├── go ├── example.go └── plesk_api_client.go ├── java ├── Example.java └── PleskApiClient.java ├── nodejs ├── .jshintrc ├── example.js └── plesk_api_client.js ├── objective-c ├── PleskApiExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── PleskApiExample │ ├── PleskApiClient.h │ ├── PleskApiClient.m │ ├── PleskApiExample-Prefix.pch │ └── main.m ├── php ├── PleskApiClient.php └── example.php ├── plain ├── generate_docs.php └── template.php ├── python ├── example.py └── plesk_api_client.py ├── python3 ├── example.py └── plesk_api_client.py ├── ruby ├── example.rb └── plesk_api_client.rb └── vb ├── apirpcexample.sln ├── apirpcexample.vb ├── apirpcexample.vbproj ├── app.config └── my project ├── application.designer.vb ├── application.myapp ├── assemblyinfo.vb ├── resources.designer.vb ├── resources.resx ├── settings.designer.vb └── settings.settings /.gitignore: -------------------------------------------------------------------------------- 1 | python/*.pyc 2 | python3/__pycache__/ 3 | cpp/*.o 4 | cpp/example 5 | java/*.class 6 | c-sharp/bin 7 | c-sharp/obj 8 | c-sharp/*.suo 9 | vb/bin 10 | vb/obj 11 | vb/*.suo 12 | objective-c/**/xcuserdata/ 13 | objective-c/**/*.xccheckout 14 | plain/execution.log 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plesk API-RPC Usage Examples 2 | 3 | Repository contains the examples on how to use Plesk API-RPC using different programming languages. 4 | Here you can find useful helpers to execute API-RPC requests. 5 | 6 | ## Languages 7 | 8 | * Bash 9 | * C++ 10 | * C# 11 | * Go 12 | * Java 13 | * Node.js 14 | * Objective-C 15 | * PHP 16 | * Python 17 | * Ruby 18 | * Visual Basic 19 | 20 | ## How to Run 21 | 22 | To run the example use the following command: 23 | 24 | `REMOTE_HOST=your-plesk-host.dom REMOTE_LOGIN=admin REMOTE_PASSWORD=password ./example.py` 25 | 26 | ## Plain Text Examples 27 | 28 | Plain text examples of possible requests and responses: http://plesk.github.io/api-examples/ 29 | 30 | ## Documentation 31 | 32 | * [Official XML API documentation](https://docs.plesk.com/en-US/current/api-rpc/) 33 | * [Interactive schemas of XML-RPC packets structure](http://plesk.github.io/api-schemas/) 34 | -------------------------------------------------------------------------------- /bash/example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 3 | 4 | . ./plesk_api_client.sh 5 | 6 | request=' 7 | 8 | 9 | 10 | 11 | 12 | ' 13 | 14 | plesk_api "$request" 15 | -------------------------------------------------------------------------------- /bash/plesk_api_client.sh: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | function plesk_api() { 4 | local request="$1" 5 | 6 | /usr/bin/curl -s -k https://$REMOTE_HOST:8443/enterprise/control/agent.php \ 7 | -H "HTTP_AUTH_LOGIN: $REMOTE_LOGIN" -H "HTTP_AUTH_PASSWD: $REMOTE_PASSWORD" \ 8 | -H "HTTP_PRETTY_PRINT: true" -H "Content-Type: text/xml" -d "$request" 9 | 10 | } 11 | -------------------------------------------------------------------------------- /c-sharp/apirpcexample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {26C7E24E-CB9F-4670-B008-A3E3F04AA807} 8 | Exe 9 | Properties 10 | ApiRpcExample 11 | ApiRpcExample 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | -------------------------------------------------------------------------------- /c-sharp/apirpcexample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiRpcExample", "ApiRpcExample.csproj", "{26C7E24E-CB9F-4670-B008-A3E3F04AA807}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {26C7E24E-CB9F-4670-B008-A3E3F04AA807}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {26C7E24E-CB9F-4670-B008-A3E3F04AA807}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {26C7E24E-CB9F-4670-B008-A3E3F04AA807}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {26C7E24E-CB9F-4670-B008-A3E3F04AA807}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /c-sharp/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /c-sharp/program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | using System; 4 | using System.Net; 5 | using System.Text; 6 | using System.IO; 7 | using System.Xml; 8 | using System.Xml.Schema; 9 | using System.Security.Cryptography.X509Certificates; 10 | using System.Net.Security; 11 | 12 | namespace ApiRpcExample 13 | { 14 | public class Request 15 | { 16 | public string Hostname = "localhost"; 17 | public string Login = "admin"; 18 | public string Password = ""; 19 | 20 | public Request() 21 | { 22 | } 23 | 24 | public string AgentEntryPoint { get { return "https://" + Hostname + ":8443/enterprise/control/agent.php"; } } 25 | 26 | public XmlDocument Send(XmlDocument packet) 27 | { 28 | HttpWebRequest request = SendRequest(packet.OuterXml); 29 | XmlDocument result = GetResponse(request); 30 | return result; 31 | } 32 | 33 | public XmlDocument Send(Stream packet) 34 | { 35 | using (TextReader reader = new StreamReader(packet)) 36 | { 37 | return Send(Parse(reader)); 38 | } 39 | } 40 | 41 | public XmlDocument Send(string packetUri) 42 | { 43 | using (TextReader reader = new StreamReader(packetUri)) 44 | { 45 | return Send(Parse(reader)); 46 | } 47 | } 48 | 49 | private HttpWebRequest SendRequest(string message) 50 | { 51 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AgentEntryPoint); 52 | 53 | request.Method = "POST"; 54 | request.Headers.Add("HTTP_AUTH_LOGIN", Login); 55 | request.Headers.Add("HTTP_AUTH_PASSWD", Password); 56 | request.ContentType = "text/xml"; 57 | request.ContentLength = message.Length; 58 | 59 | ASCIIEncoding encoding = new ASCIIEncoding(); 60 | byte[] buffer = encoding.GetBytes(message); 61 | 62 | using (Stream stream = request.GetRequestStream()) 63 | { 64 | stream.Write(buffer, 0, message.Length); 65 | } 66 | 67 | return request; 68 | } 69 | 70 | private XmlDocument Parse(TextReader xml) 71 | { 72 | XmlDocument document = new XmlDocument(); 73 | 74 | using (XmlReader reader = XmlTextReader.Create(xml)) 75 | { 76 | document.Load(reader); 77 | } 78 | 79 | return document; 80 | } 81 | 82 | private XmlDocument GetResponse(HttpWebRequest request) 83 | { 84 | using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 85 | using (Stream stream = response.GetResponseStream()) 86 | using (TextReader reader = new StreamReader(stream)) 87 | { 88 | return Parse(reader); 89 | } 90 | } 91 | } 92 | 93 | class Program 94 | { 95 | static void Main(string[] args) 96 | { 97 | if (args.Length < 4) 98 | { 99 | Console.WriteLine("Usage: PanelApiRpcClient "); 100 | Console.WriteLine(" "); 101 | Console.WriteLine(" Hostname - Panel host name"); 102 | Console.WriteLine(" Login - Administrator's login"); 103 | Console.WriteLine(" Password - Administrator's password"); 104 | Console.WriteLine(" Request - Request file path (*.xml)"); 105 | return; 106 | } 107 | 108 | ServicePointManager.ServerCertificateValidationCallback = 109 | new RemoteCertificateValidationCallback(RemoteCertificateValidation); 110 | Request request = new Request(); 111 | request.Hostname = args[0]; 112 | request.Login = args[1]; 113 | request.Password = args[2]; 114 | string packet = args[3]; 115 | try 116 | { 117 | XmlDocument result = request.Send(packet); 118 | PrintResult(result); 119 | } 120 | catch (Exception e) 121 | { 122 | Console.WriteLine("Request error: {0}", e.Message); 123 | } 124 | } 125 | 126 | private static bool RemoteCertificateValidation(object sender, 127 | X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 128 | { 129 | if (sslPolicyErrors != SslPolicyErrors.RemoteCertificateNotAvailable) 130 | return true; 131 | 132 | Console.WriteLine("Certificate error: {0}", sslPolicyErrors); 133 | 134 | // Do not allow this client to communicate with unauthenticated servers. 135 | return false; 136 | } 137 | 138 | private static void XmlSchemaValidation(object sender, ValidationEventArgs e) 139 | { 140 | Console.WriteLine("Validation error: {0}", e.Message); 141 | } 142 | 143 | static void PrintResult(XmlDocument document) 144 | { 145 | XmlTextWriter writer = new XmlTextWriter(Console.Out); 146 | writer.Formatting = Formatting.Indented; 147 | 148 | document.WriteTo(writer); 149 | 150 | writer.Flush(); 151 | Console.WriteLine(); 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /c-sharp/properties/assemblyinfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ApiRpcExample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Organization")] 12 | [assembly: AssemblyProduct("ApiRpcExample")] 13 | [assembly: AssemblyCopyright("Copyright © Organization 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4792bfd3-1809-42b5-8ee9-24a8b308bbf0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /cpp/Makefile: -------------------------------------------------------------------------------- 1 | TARGET := example 2 | SRCS := example.cpp plesk_api_client.cpp 3 | OBJS := $(SRCS:.cpp=.o) 4 | 5 | CCFLAGS = -Wall -Werror 6 | LDFLAGS = 7 | LIBS = -lcurl 8 | 9 | .PHONY: all clean 10 | all:: $(TARGET) 11 | 12 | $(TARGET): $(OBJS) 13 | $(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) 14 | 15 | $(OBJS): %.o: %.cpp 16 | $(CXX) $(CCFLAGS) -o $@ -c $< 17 | 18 | clean:: 19 | $(RM) $(OBJS) $(TARGET) 20 | 21 | -------------------------------------------------------------------------------- /cpp/example.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | #include 4 | #include "plesk_api_client.h" 5 | 6 | using namespace std; 7 | 8 | int main(void) 9 | { 10 | string host = getenv("REMOTE_HOST"); 11 | string password = getenv("REMOTE_PASSWORD"); 12 | string login; 13 | 14 | char *envLogin = getenv("REMOTE_LOGIN"); 15 | 16 | if (NULL == envLogin) { 17 | login = "admin"; 18 | } else { 19 | login = string(envLogin); 20 | } 21 | 22 | PleskApiClient *client = new PleskApiClient(host); 23 | client->setCredentials(login, password); 24 | 25 | string request = "\ 26 | \ 27 | \ 28 | \ 29 | \ 30 | \ 31 | "; 32 | 33 | string response; 34 | client->request(request, response); 35 | cout << response; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /cpp/plesk_api_client.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | #include 4 | #include 5 | #include "plesk_api_client.h" 6 | 7 | PleskApiClient::PleskApiClient(const string& host) 8 | { 9 | m_host = host; 10 | } 11 | 12 | void PleskApiClient::setCredentials(const string& login, const string& password) 13 | { 14 | m_login = login; 15 | m_password = password; 16 | } 17 | 18 | size_t writeToString(void *ptr, size_t size, size_t count, void *stream) 19 | { 20 | ((string*)stream)->append((char*)ptr, 0, size*count); 21 | return size*count; 22 | } 23 | 24 | void PleskApiClient::request(const string& request, string& response) 25 | { 26 | CURL *curl; 27 | CURLcode res; 28 | struct curl_slist *headers = NULL; 29 | 30 | curl = curl_easy_init(); 31 | 32 | if (curl) { 33 | headers = curl_slist_append(headers, "Content-type: text/xml"); 34 | headers = curl_slist_append(headers, "HTTP_PRETTY_PRINT: TRUE"); 35 | headers = curl_slist_append(headers, ("HTTP_AUTH_LOGIN: " + m_login).c_str()); 36 | headers = curl_slist_append(headers, ("HTTP_AUTH_PASSWD: " + m_password).c_str()); 37 | 38 | curl_easy_setopt(curl, CURLOPT_URL, string(string("https://") + m_host + string(":8443/enterprise/control/agent.php")).c_str()); 39 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); 40 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); 41 | curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str()); 42 | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); 43 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeToString); 44 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); 45 | 46 | res = curl_easy_perform(curl); 47 | if (res != CURLE_OK) { 48 | fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); 49 | } 50 | curl_easy_cleanup(curl); 51 | curl_slist_free_all(headers); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /cpp/plesk_api_client.h: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | #ifndef PLESK_API_CLIENT_H 4 | #define PLESK_API_CLIENT_H 5 | 6 | #include 7 | 8 | using namespace std; 9 | 10 | class PleskApiClient 11 | { 12 | 13 | private: 14 | string m_host; 15 | string m_login; 16 | string m_password; 17 | 18 | PleskApiClient() {} 19 | 20 | public: 21 | PleskApiClient(const string& host); 22 | void setCredentials(const string& login, const string& password); 23 | void request(const string& request, string& response); 24 | 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /go/example.go: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | package main 3 | 4 | import ( 5 | "fmt" 6 | "log" 7 | "os" 8 | ) 9 | 10 | const request = ` 11 | 12 | 13 | 14 | 15 | 16 | ` 17 | 18 | func main() { 19 | host := os.Getenv("REMOTE_HOST") 20 | login := os.Getenv("REMOTE_LOGIN") 21 | if login == "" { login = "admin" } 22 | password := os.Getenv("REMOTE_PASSWORD") 23 | 24 | cli := NewPleskApiClient(host) 25 | cli.SetCredentials(login, password) 26 | 27 | // remove the line below in case of valid SSL certificate for 8443 port 28 | cli.InsecureSkipVerify = true 29 | 30 | responseData, err := cli.Request(request) 31 | if err != nil { 32 | log.Fatal(err) 33 | } 34 | fmt.Print(responseData) 35 | } 36 | -------------------------------------------------------------------------------- /go/plesk_api_client.go: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | package main 3 | 4 | import ( 5 | "net/http" 6 | "crypto/tls" 7 | "fmt" 8 | "strings" 9 | "io/ioutil" 10 | ) 11 | 12 | type PleskApiClient struct { 13 | host string 14 | port uint 15 | protocol string 16 | login string 17 | password string 18 | secretKey string 19 | InsecureSkipVerify bool 20 | } 21 | 22 | func NewPleskApiClient(host string) *PleskApiClient { 23 | c := new(PleskApiClient) 24 | c.host = host 25 | c.port = 8443 26 | c.protocol = "https" 27 | return c 28 | } 29 | 30 | func (c *PleskApiClient) SetPort(port uint) { 31 | c.port = port 32 | } 33 | 34 | func (c *PleskApiClient) SetProtocol(protocol string) { 35 | c.protocol = protocol 36 | } 37 | 38 | func (c *PleskApiClient) SetCredentials(login, password string) { 39 | c.login, c.password = login, password 40 | } 41 | 42 | func (c *PleskApiClient) SetSecretKey(secret_key string) { 43 | c.secretKey = secret_key 44 | } 45 | 46 | func (c *PleskApiClient) Request(request string) (response string, err error) { 47 | url := fmt.Sprintf("%s://%s:%d/enterprise/control/agent.php", c.protocol, c.host, c.port) 48 | 49 | req, err := http.NewRequest("POST", url, strings.NewReader(request)) 50 | if err != nil { return } 51 | req.Header.Add("Content-type", "text/xml") 52 | req.Header.Add("HTTP_PRETTY_PRINT", "TRUE") 53 | if c.secretKey != "" { 54 | req.Header.Add("KEY", c.secretKey) 55 | } else { 56 | req.Header.Add("HTTP_AUTH_LOGIN", c.login) 57 | req.Header.Add("HTTP_AUTH_PASSWD", c.password) 58 | } 59 | 60 | client := http.Client{} 61 | if c.InsecureSkipVerify { 62 | tr := &http.Transport { 63 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 64 | } 65 | client.Transport = tr 66 | } 67 | 68 | resp, err := client.Do(req) 69 | if err != nil { return } 70 | defer resp.Body.Close() 71 | bytes, err := ioutil.ReadAll(resp.Body) 72 | response = string(bytes) 73 | return 74 | } 75 | 76 | -------------------------------------------------------------------------------- /java/Example.java: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | class Example { 4 | 5 | public static void main(String[] args) throws Exception { 6 | String login = System.getenv("REMOTE_LOGIN"); 7 | String password = System.getenv("REMOTE_PASSWORD"); 8 | String host = System.getenv("REMOTE_HOST"); 9 | 10 | if (null == login) { 11 | login = "admin"; 12 | } 13 | 14 | PleskApiClient client = new PleskApiClient(host); 15 | client.setCredentials(login, password); 16 | 17 | String request = 18 | "" + 19 | "" + 20 | "" + 21 | "" + 22 | ""; 23 | 24 | String response = client.request(request); 25 | System.out.println(response); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /java/PleskApiClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | import java.net.*; 4 | import java.io.*; 5 | import javax.net.ssl.*; 6 | import java.security.cert.X509Certificate; 7 | 8 | class PleskApiClient { 9 | 10 | private String host; 11 | private String login; 12 | private String password; 13 | private String secretKey; 14 | 15 | public PleskApiClient(String host) { 16 | this.host = host; 17 | } 18 | 19 | public void setCredentials(String login, String password) { 20 | this.login = login; 21 | this.password = password; 22 | } 23 | 24 | public void setSecretKey(String secretKey) { 25 | this.secretKey = secretKey; 26 | } 27 | 28 | public String request(String request) throws Exception { 29 | this.setTrustAllSslCertificates(); 30 | 31 | URL url = new URL("https://" + this.host + ":8443/enterprise/control/agent.php"); 32 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 33 | 34 | connection.setRequestMethod("POST"); 35 | connection.setRequestProperty("Content-Type", "text/xml"); 36 | connection.setRequestProperty("HTTP_PRETTY_PRINT", "TRUE"); 37 | 38 | if (null != this.secretKey) { 39 | connection.setRequestProperty("KEY", this.secretKey); 40 | } else { 41 | connection.setRequestProperty("HTTP_AUTH_LOGIN", this.login); 42 | connection.setRequestProperty("HTTP_AUTH_PASSWD", this.password); 43 | } 44 | 45 | connection.setDoOutput(true); 46 | 47 | DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); 48 | writer.writeBytes(request); 49 | writer.flush(); 50 | writer.close(); 51 | 52 | BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 53 | 54 | String response = ""; 55 | String inputLine; 56 | 57 | while ((inputLine = reader.readLine()) != null) { 58 | response += inputLine + "\n"; 59 | } 60 | 61 | reader.close(); 62 | 63 | return response; 64 | } 65 | 66 | private void setTrustAllSslCertificates() throws Exception { 67 | TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { 68 | public java.security.cert.X509Certificate[] getAcceptedIssuers() { 69 | return null; 70 | } 71 | public void checkClientTrusted(X509Certificate[] certs, String authType) { 72 | } 73 | public void checkServerTrusted(X509Certificate[] certs, String authType) { 74 | } 75 | } 76 | }; 77 | 78 | SSLContext sc = SSLContext.getInstance("SSL"); 79 | sc.init(null, trustAllCerts, new java.security.SecureRandom()); 80 | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 81 | 82 | HostnameVerifier allHostsValid = new HostnameVerifier() { 83 | public boolean verify(String hostname, SSLSession session) { 84 | return true; 85 | } 86 | }; 87 | 88 | HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /nodejs/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esversion": 6, 3 | "node": true 4 | } 5 | -------------------------------------------------------------------------------- /nodejs/example.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 3 | "use strict"; 4 | 5 | const pleskApi = require('./plesk_api_client.js'); 6 | 7 | let host = process.env.REMOTE_HOST; 8 | let login = process.env.REMOTE_LOGIN || 'admin'; 9 | let password = process.env.REMOTE_PASSWORD; 10 | 11 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 12 | 13 | let client = new pleskApi.Client(host); 14 | client.setCredentials(login, password); 15 | 16 | let request = ` 17 | 18 | 19 | 20 | 21 | 22 | `; 23 | 24 | client.request(request, (response) =>console.log(response)); 25 | -------------------------------------------------------------------------------- /nodejs/plesk_api_client.js: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | /* jshint -W069 */ 3 | "use strict"; 4 | 5 | const http = require('http'); 6 | const https = require('https'); 7 | 8 | class Client { 9 | 10 | constructor(host, port, protocol) { 11 | this._host = host; 12 | this._port = port || 8443; 13 | this._protocol = protocol || 'https'; 14 | } 15 | 16 | setCredentials(login, password) { 17 | this._login = login; 18 | this._password = password; 19 | } 20 | 21 | setSecretKey(secretKey) { 22 | this._secretKey = secretKey; 23 | } 24 | 25 | request(body, callback) { 26 | let headers = { 27 | 'Content-type': 'text/xml', 28 | 'HTTP_PRETTY_PRINT': 'TRUE' 29 | }; 30 | 31 | if (this._secretKey) { 32 | headers['KEY'] = this._secretKey; 33 | } else { 34 | headers['HTTP_AUTH_LOGIN'] = this._login; 35 | headers['HTTP_AUTH_PASSWD'] = this._password; 36 | } 37 | 38 | let options = { 39 | host: this._host, 40 | port: this._port, 41 | path: '/enterprise/control/agent.php', 42 | method: 'POST', 43 | headers: headers 44 | }; 45 | 46 | let handler = (response) => { 47 | let result = ''; 48 | response.on('data', (chunk) => result += chunk); 49 | response.on('end', () => callback(result)); 50 | }; 51 | 52 | let client = 'https' == this._protocol ? https : http; 53 | let request = client.request(options, handler); 54 | request.write(body); 55 | request.end(); 56 | } 57 | 58 | } 59 | 60 | exports.Client = Client; 61 | -------------------------------------------------------------------------------- /objective-c/PleskApiExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F38CE86A18D9DFA1003E12D6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F38CE86918D9DFA1003E12D6 /* Foundation.framework */; }; 11 | F38CE86D18D9DFA1003E12D6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F38CE86C18D9DFA1003E12D6 /* main.m */; }; 12 | F3A2488D18D9E6080075B647 /* PleskApiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F3A2488C18D9E6080075B647 /* PleskApiClient.m */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXCopyFilesBuildPhase section */ 16 | F38CE86418D9DFA1003E12D6 /* CopyFiles */ = { 17 | isa = PBXCopyFilesBuildPhase; 18 | buildActionMask = 2147483647; 19 | dstPath = /usr/share/man/man1/; 20 | dstSubfolderSpec = 0; 21 | files = ( 22 | ); 23 | runOnlyForDeploymentPostprocessing = 1; 24 | }; 25 | /* End PBXCopyFilesBuildPhase section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | F38CE86618D9DFA1003E12D6 /* PleskApiExample */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = PleskApiExample; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | F38CE86918D9DFA1003E12D6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 30 | F38CE86C18D9DFA1003E12D6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | F38CE86F18D9DFA1003E12D6 /* PleskApiExample-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PleskApiExample-Prefix.pch"; sourceTree = ""; }; 32 | F3A2488B18D9E6080075B647 /* PleskApiClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PleskApiClient.h; sourceTree = ""; }; 33 | F3A2488C18D9E6080075B647 /* PleskApiClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PleskApiClient.m; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | F38CE86318D9DFA1003E12D6 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | F38CE86A18D9DFA1003E12D6 /* Foundation.framework in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | F38CE85D18D9DFA1003E12D6 = { 49 | isa = PBXGroup; 50 | children = ( 51 | F38CE86B18D9DFA1003E12D6 /* PleskApiExample */, 52 | F38CE86818D9DFA1003E12D6 /* Frameworks */, 53 | F38CE86718D9DFA1003E12D6 /* Products */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | F38CE86718D9DFA1003E12D6 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | F38CE86618D9DFA1003E12D6 /* PleskApiExample */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | F38CE86818D9DFA1003E12D6 /* Frameworks */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | F38CE86918D9DFA1003E12D6 /* Foundation.framework */, 69 | ); 70 | name = Frameworks; 71 | sourceTree = ""; 72 | }; 73 | F38CE86B18D9DFA1003E12D6 /* PleskApiExample */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | F38CE86C18D9DFA1003E12D6 /* main.m */, 77 | F3A2488B18D9E6080075B647 /* PleskApiClient.h */, 78 | F3A2488C18D9E6080075B647 /* PleskApiClient.m */, 79 | F38CE86E18D9DFA1003E12D6 /* Supporting Files */, 80 | ); 81 | path = PleskApiExample; 82 | sourceTree = ""; 83 | }; 84 | F38CE86E18D9DFA1003E12D6 /* Supporting Files */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | F38CE86F18D9DFA1003E12D6 /* PleskApiExample-Prefix.pch */, 88 | ); 89 | name = "Supporting Files"; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXNativeTarget section */ 95 | F38CE86518D9DFA1003E12D6 /* PleskApiExample */ = { 96 | isa = PBXNativeTarget; 97 | buildConfigurationList = F38CE87418D9DFA1003E12D6 /* Build configuration list for PBXNativeTarget "PleskApiExample" */; 98 | buildPhases = ( 99 | F38CE86218D9DFA1003E12D6 /* Sources */, 100 | F38CE86318D9DFA1003E12D6 /* Frameworks */, 101 | F38CE86418D9DFA1003E12D6 /* CopyFiles */, 102 | ); 103 | buildRules = ( 104 | ); 105 | dependencies = ( 106 | ); 107 | name = PleskApiExample; 108 | productName = PleskApiExample; 109 | productReference = F38CE86618D9DFA1003E12D6 /* PleskApiExample */; 110 | productType = "com.apple.product-type.tool"; 111 | }; 112 | /* End PBXNativeTarget section */ 113 | 114 | /* Begin PBXProject section */ 115 | F38CE85E18D9DFA1003E12D6 /* Project object */ = { 116 | isa = PBXProject; 117 | attributes = { 118 | LastUpgradeCheck = 0510; 119 | ORGANIZATIONNAME = "Alexei Yuzhakov"; 120 | }; 121 | buildConfigurationList = F38CE86118D9DFA1003E12D6 /* Build configuration list for PBXProject "PleskApiExample" */; 122 | compatibilityVersion = "Xcode 3.2"; 123 | developmentRegion = English; 124 | hasScannedForEncodings = 0; 125 | knownRegions = ( 126 | en, 127 | ); 128 | mainGroup = F38CE85D18D9DFA1003E12D6; 129 | productRefGroup = F38CE86718D9DFA1003E12D6 /* Products */; 130 | projectDirPath = ""; 131 | projectRoot = ""; 132 | targets = ( 133 | F38CE86518D9DFA1003E12D6 /* PleskApiExample */, 134 | ); 135 | }; 136 | /* End PBXProject section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | F38CE86218D9DFA1003E12D6 /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | F38CE86D18D9DFA1003E12D6 /* main.m in Sources */, 144 | F3A2488D18D9E6080075B647 /* PleskApiClient.m in Sources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXSourcesBuildPhase section */ 149 | 150 | /* Begin XCBuildConfiguration section */ 151 | F38CE87218D9DFA1003E12D6 /* Debug */ = { 152 | isa = XCBuildConfiguration; 153 | buildSettings = { 154 | ALWAYS_SEARCH_USER_PATHS = NO; 155 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 156 | CLANG_CXX_LIBRARY = "libc++"; 157 | CLANG_ENABLE_MODULES = YES; 158 | CLANG_ENABLE_OBJC_ARC = YES; 159 | CLANG_WARN_BOOL_CONVERSION = YES; 160 | CLANG_WARN_CONSTANT_CONVERSION = YES; 161 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 162 | CLANG_WARN_EMPTY_BODY = YES; 163 | CLANG_WARN_ENUM_CONVERSION = YES; 164 | CLANG_WARN_INT_CONVERSION = YES; 165 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 166 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 167 | COPY_PHASE_STRIP = NO; 168 | GCC_C_LANGUAGE_STANDARD = gnu99; 169 | GCC_DYNAMIC_NO_PIC = NO; 170 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 171 | GCC_OPTIMIZATION_LEVEL = 0; 172 | GCC_PREPROCESSOR_DEFINITIONS = ( 173 | "DEBUG=1", 174 | "$(inherited)", 175 | ); 176 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 177 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 178 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 179 | GCC_WARN_UNDECLARED_SELECTOR = YES; 180 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 181 | GCC_WARN_UNUSED_FUNCTION = YES; 182 | GCC_WARN_UNUSED_VARIABLE = YES; 183 | MACOSX_DEPLOYMENT_TARGET = 10.9; 184 | ONLY_ACTIVE_ARCH = YES; 185 | SDKROOT = macosx; 186 | }; 187 | name = Debug; 188 | }; 189 | F38CE87318D9DFA1003E12D6 /* Release */ = { 190 | isa = XCBuildConfiguration; 191 | buildSettings = { 192 | ALWAYS_SEARCH_USER_PATHS = NO; 193 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 194 | CLANG_CXX_LIBRARY = "libc++"; 195 | CLANG_ENABLE_MODULES = YES; 196 | CLANG_ENABLE_OBJC_ARC = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_CONSTANT_CONVERSION = YES; 199 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 200 | CLANG_WARN_EMPTY_BODY = YES; 201 | CLANG_WARN_ENUM_CONVERSION = YES; 202 | CLANG_WARN_INT_CONVERSION = YES; 203 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | COPY_PHASE_STRIP = YES; 206 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 207 | ENABLE_NS_ASSERTIONS = NO; 208 | GCC_C_LANGUAGE_STANDARD = gnu99; 209 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 210 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 211 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 212 | GCC_WARN_UNDECLARED_SELECTOR = YES; 213 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 214 | GCC_WARN_UNUSED_FUNCTION = YES; 215 | GCC_WARN_UNUSED_VARIABLE = YES; 216 | MACOSX_DEPLOYMENT_TARGET = 10.9; 217 | SDKROOT = macosx; 218 | }; 219 | name = Release; 220 | }; 221 | F38CE87518D9DFA1003E12D6 /* Debug */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 225 | GCC_PREFIX_HEADER = "PleskApiExample/PleskApiExample-Prefix.pch"; 226 | PRODUCT_NAME = "$(TARGET_NAME)"; 227 | }; 228 | name = Debug; 229 | }; 230 | F38CE87618D9DFA1003E12D6 /* Release */ = { 231 | isa = XCBuildConfiguration; 232 | buildSettings = { 233 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 234 | GCC_PREFIX_HEADER = "PleskApiExample/PleskApiExample-Prefix.pch"; 235 | PRODUCT_NAME = "$(TARGET_NAME)"; 236 | }; 237 | name = Release; 238 | }; 239 | /* End XCBuildConfiguration section */ 240 | 241 | /* Begin XCConfigurationList section */ 242 | F38CE86118D9DFA1003E12D6 /* Build configuration list for PBXProject "PleskApiExample" */ = { 243 | isa = XCConfigurationList; 244 | buildConfigurations = ( 245 | F38CE87218D9DFA1003E12D6 /* Debug */, 246 | F38CE87318D9DFA1003E12D6 /* Release */, 247 | ); 248 | defaultConfigurationIsVisible = 0; 249 | defaultConfigurationName = Release; 250 | }; 251 | F38CE87418D9DFA1003E12D6 /* Build configuration list for PBXNativeTarget "PleskApiExample" */ = { 252 | isa = XCConfigurationList; 253 | buildConfigurations = ( 254 | F38CE87518D9DFA1003E12D6 /* Debug */, 255 | F38CE87618D9DFA1003E12D6 /* Release */, 256 | ); 257 | defaultConfigurationIsVisible = 0; 258 | defaultConfigurationName = Release; 259 | }; 260 | /* End XCConfigurationList section */ 261 | }; 262 | rootObject = F38CE85E18D9DFA1003E12D6 /* Project object */; 263 | } 264 | -------------------------------------------------------------------------------- /objective-c/PleskApiExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /objective-c/PleskApiExample/PleskApiClient.h: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | #import 4 | 5 | @interface PleskApiClient : NSObject 6 | { 7 | NSString *remoteLogin; 8 | NSString *remotePassword; 9 | NSString *remoteHost; 10 | } 11 | 12 | - (id)initWithHost:(NSString *)host; 13 | - (void)setCredentials:(NSString *)login password:(NSString *)password; 14 | - (NSString *)request:(NSString *)requestText; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /objective-c/PleskApiExample/PleskApiClient.m: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | #import "PleskApiClient.h" 4 | 5 | @implementation NSURLRequest(DataController) 6 | 7 | + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host 8 | { 9 | return YES; 10 | } 11 | 12 | @end 13 | 14 | @implementation PleskApiClient 15 | 16 | - (id)initWithHost:(NSString *)host 17 | { 18 | self = [super init]; 19 | remoteHost = host; 20 | return self; 21 | } 22 | 23 | - (void)setCredentials:(NSString *)login password:(NSString *)password 24 | { 25 | remoteLogin = login; 26 | remotePassword = password; 27 | } 28 | 29 | - (NSString *)request:(NSString *)requestText 30 | { 31 | NSString *url = [NSString stringWithFormat:@"%@://%@:%@/enterprise/control/agent.php", @"https", remoteHost, @"8443"]; 32 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 33 | [request setURL:[NSURL URLWithString:url]]; 34 | [request setHTTPMethod:@"POST"]; 35 | 36 | [request addValue:@"text/xml" forHTTPHeaderField: @"Content-Type"]; 37 | [request addValue:@"TRUE" forHTTPHeaderField: @"HTTP_PRETTY_PRINT"]; 38 | [request addValue:remoteLogin forHTTPHeaderField: @"HTTP_AUTH_LOGIN"]; 39 | [request addValue:remotePassword forHTTPHeaderField: @"HTTP_AUTH_PASSWD"]; 40 | 41 | NSMutableData *postBody = [NSMutableData data]; 42 | [postBody appendData:[requestText dataUsingEncoding:NSUTF8StringEncoding]]; 43 | [request setHTTPBody:postBody]; 44 | 45 | NSHTTPURLResponse* urlResponse = nil; 46 | NSError *error = [[NSError alloc] init]; 47 | NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; 48 | NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 49 | 50 | if ([urlResponse statusCode] < 200 || [urlResponse statusCode] >= 300) { 51 | NSLog(@"Response code: %ld", (long)[urlResponse statusCode]); 52 | } 53 | 54 | return response; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /objective-c/PleskApiExample/PleskApiExample-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /objective-c/PleskApiExample/main.m: -------------------------------------------------------------------------------- 1 | // Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | #import 4 | #import "PleskApiClient.h" 5 | 6 | int main(int argc, const char * argv[]) 7 | { 8 | @autoreleasepool { 9 | NSString *login = [[[NSProcessInfo processInfo] environment] objectForKey:@"REMOTE_LOGIN"]; 10 | NSString *password = [[[NSProcessInfo processInfo] environment] objectForKey:@"REMOTE_PASSWORD"]; 11 | NSString *host = [[[NSProcessInfo processInfo] environment] objectForKey:@"REMOTE_HOST"]; 12 | 13 | PleskApiClient *client = [[PleskApiClient alloc] initWithHost:host]; 14 | [client setCredentials:login password:password]; 15 | 16 | NSString *request = @"" 17 | "" 18 | "" 19 | "" 20 | "" 21 | ""; 22 | 23 | NSString *response = [client request:request]; 24 | 25 | NSLog(@"Response: %@", response); 26 | } 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /php/PleskApiClient.php: -------------------------------------------------------------------------------- 1 | _host = $host; 26 | $this->_port = $port; 27 | $this->_protocol = $protocol; 28 | } 29 | 30 | /** 31 | * Setup credentials for authentication 32 | * 33 | * @param string $login 34 | * @param string $password 35 | */ 36 | public function setCredentials($login, $password) 37 | { 38 | $this->_login = $login; 39 | $this->_password = $password; 40 | } 41 | 42 | /** 43 | * Define secret key for alternative authentication 44 | * 45 | * @param string $secretKey 46 | */ 47 | public function setSecretKey($secretKey) 48 | { 49 | $this->_secretKey = $secretKey; 50 | } 51 | 52 | /** 53 | * Perform API request 54 | * 55 | * @param string $request 56 | * @return string 57 | */ 58 | public function request($request) 59 | { 60 | $curl = curl_init(); 61 | 62 | curl_setopt($curl, CURLOPT_URL, "$this->_protocol://$this->_host:$this->_port/enterprise/control/agent.php"); 63 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 64 | curl_setopt($curl, CURLOPT_POST, true); 65 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 66 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 67 | curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_getHeaders()); 68 | curl_setopt($curl, CURLOPT_POSTFIELDS, $request); 69 | 70 | $result = curl_exec($curl); 71 | 72 | curl_close($curl); 73 | 74 | return $result; 75 | } 76 | 77 | /** 78 | * Retrieve list of headers needed for request 79 | * 80 | * @return array 81 | */ 82 | private function _getHeaders() 83 | { 84 | $headers = array( 85 | "Content-Type: text/xml", 86 | "HTTP_PRETTY_PRINT: TRUE", 87 | ); 88 | 89 | if ($this->_secretKey) { 90 | $headers[] = "KEY: $this->_secretKey"; 91 | } else { 92 | $headers[] = "HTTP_AUTH_LOGIN: $this->_login"; 93 | $headers[] = "HTTP_AUTH_PASSWD: $this->_password"; 94 | } 95 | 96 | return $headers; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /php/example.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | setCredentials($login, $password); 13 | 14 | $request = << 16 | 17 | 18 | 19 | 20 | EOF; 21 | 22 | $response = $client->request($request); 23 | echo $response; 24 | -------------------------------------------------------------------------------- /plain/generate_docs.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | EOF; 20 | 21 | $xsl = new DOMDocument(); 22 | $xsl->loadXML($xslTemplate); 23 | 24 | $proc = new XSLTProcessor(); 25 | $proc->importStyleSheet($xsl); 26 | 27 | $xml = new DOMDocument(); 28 | if (!@$xml->loadXML($content)) { 29 | return $content; 30 | } 31 | 32 | return $proc->transformToXML($xml); 33 | } 34 | 35 | /** 36 | * @param string $content 37 | * @return string 38 | */ 39 | function prepareXmlContent($content) 40 | { 41 | $content = getPrettyXml(filterContent($content)); 42 | $content = preg_replace('/^<\?xml.*\n/', '', $content); 43 | return $content; 44 | } 45 | 46 | function filterContent($content) 47 | { 48 | $contentXml = simplexml_load_string($content); 49 | 50 | if ($foundNode = $contentXml->xpath('//result/key/content')) { 51 | $foundNode[0][0] = 'PD94bWwgdmVyc...encoded license content here...'; 52 | } 53 | 54 | return $contentXml->saveXML(); 55 | } 56 | 57 | /** 58 | * @param SimpleXmlElement $node 59 | * @return string 60 | */ 61 | function getNodeTitle($node) 62 | { 63 | if ($node->children()) { 64 | $nodeName = $node->children()[0]->getName(); 65 | $subNodeName = getNodeTitle($node->children()[0]); 66 | return $nodeName . ($subNodeName ? (' > ' . $subNodeName) : ''); 67 | } 68 | 69 | return ''; 70 | } 71 | 72 | /** 73 | * @param string $request 74 | * @return string 75 | */ 76 | function getRequestTitle($request) 77 | { 78 | $requestXml = simplexml_load_string($request); 79 | $nodeTitle = getNodeTitle($requestXml); 80 | 81 | $parts = explode(' > ', $nodeTitle); 82 | $partsLimit = 2; 83 | 84 | if (preg_match('/^server > /', $nodeTitle)) { 85 | $partsLimit = 3; 86 | } 87 | 88 | $nodeTitle = join(' > ', array_slice($parts, 0, $partsLimit)); 89 | 90 | return $nodeTitle; 91 | } 92 | 93 | if ($argc < 2) { 94 | echo "Usage: generate_docs.php \n"; 95 | exit(1); 96 | } 97 | 98 | $indexHtmlFile = $argv[1]; 99 | 100 | $log = json_decode(file_get_contents('execution.log'), true); 101 | $examples = []; 102 | $menu = []; 103 | $contentHashes = []; 104 | 105 | foreach ($log as $record) { 106 | $trace = join(';', array_column($record['trace'], 'file')); 107 | if (preg_match('/ApiClientTest\.php/', $trace)) { 108 | continue; 109 | } 110 | 111 | $origTitle = $title = getRequestTitle($record['request']); 112 | $origName = $name = str_replace(' > ', '-', $title); 113 | 114 | $index = 2; 115 | while (array_key_exists($name, $examples)) { 116 | $title = $origTitle . " ($index)"; 117 | $name = $origName . '-' . $index++; 118 | } 119 | 120 | $contentHash = md5(preg_replace('/>([^<]+?)<', $record['request'])); 121 | if (array_key_exists($contentHash, $contentHashes)) { 122 | continue; 123 | } else { 124 | $contentHashes[$contentHash] = true; 125 | } 126 | 127 | $examples[$name] = [ 128 | 'title' => $title, 129 | 'request' => $record['request'], 130 | 'response' => $record['response'], 131 | ]; 132 | } 133 | 134 | ksort($examples); 135 | 136 | foreach ($examples as $name => $example) { 137 | $titleParts = explode(' > ', $example['title']); 138 | $operator = $titleParts[0]; 139 | $menuItem = [ 140 | 'subTitle' => join(' > ', array_slice($titleParts, 1)), 141 | 'name' => $name, 142 | ]; 143 | 144 | if (!isset($menu[$operator])) { 145 | $menu[$operator] = [$menuItem]; 146 | } else { 147 | $menu[$operator][] = $menuItem; 148 | } 149 | } 150 | 151 | $title = 'Plesk XML-RPC Examples'; 152 | 153 | ob_start(); 154 | require_once('template.php'); 155 | $content = ob_get_contents(); 156 | ob_end_clean(); 157 | 158 | file_put_contents($indexHtmlFile, $content); 159 | -------------------------------------------------------------------------------- /plain/template.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <?php echo $title; ?> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Fork me on GitHub 19 |
20 | 23 | 24 |

Table of Contents

25 | 26 |
    27 | $items): ?> 28 |
  • 29 | 30 |
      31 | 32 |
    • 33 | 34 |
    35 |
  • 36 | 37 |
38 | 39 |

Examples

40 | 41 | $example): ?> 42 | 43 |

44 |

Request:

45 |
46 |

Response:

47 |
48 | 49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /python/example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 3 | 4 | import os 5 | from plesk_api_client import PleskApiClient 6 | 7 | host = os.getenv('REMOTE_HOST') 8 | login = os.getenv('REMOTE_LOGIN', 'admin') 9 | password = os.getenv('REMOTE_PASSWORD') 10 | 11 | client = PleskApiClient(host) 12 | client.set_credentials(login, password) 13 | 14 | request = """ 15 | 16 | 17 | 18 | 19 | 20 | """ 21 | 22 | response = client.request(request) 23 | print response 24 | -------------------------------------------------------------------------------- /python/plesk_api_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | import httplib 4 | import ssl 5 | 6 | class PleskApiClient: 7 | 8 | def __init__(self, host, port = 8443, protocol = 'https', ssl_unverified = False): 9 | self.host = host 10 | self.port = port 11 | self.protocol = protocol 12 | self.secret_key = None 13 | self.ssl_unverified = ssl_unverified 14 | 15 | def set_credentials(self, login, password): 16 | self.login = login 17 | self.password = password 18 | 19 | def set_secret_key(self, secret_key): 20 | self.secret_key = secret_key 21 | 22 | def request(self, request): 23 | headers = {} 24 | headers["Content-type"] = "text/xml" 25 | headers["HTTP_PRETTY_PRINT"] = "TRUE" 26 | 27 | if self.secret_key: 28 | headers["KEY"] = self.secret_key 29 | else: 30 | headers["HTTP_AUTH_LOGIN"] = self.login 31 | headers["HTTP_AUTH_PASSWD"] = self.password 32 | 33 | if 'https' == self.protocol: 34 | if self.ssl_unverified == True: 35 | conn = httplib.HTTPSConnection(self.host, self.port, context=ssl._create_unverified_context()) 36 | else: 37 | conn = httplib.HTTPSConnection(self.host, self.port) 38 | else: 39 | conn = httplib.HTTPConnection(self.host, self.port) 40 | 41 | conn.request("POST", "/enterprise/control/agent.php", request, headers) 42 | response = conn.getresponse() 43 | data = response.read() 44 | return data 45 | -------------------------------------------------------------------------------- /python3/example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 3 | 4 | import os 5 | from plesk_api_client import PleskApiClient 6 | 7 | host = os.getenv('REMOTE_HOST') 8 | login = os.getenv('REMOTE_LOGIN', 'admin') 9 | password = os.getenv('REMOTE_PASSWORD') 10 | 11 | client = PleskApiClient(host) 12 | client.set_credentials(login, password) 13 | 14 | request = """ 15 | 16 | 17 | 18 | 19 | 20 | """ 21 | 22 | response = client.request(request) 23 | print(response) 24 | -------------------------------------------------------------------------------- /python3/plesk_api_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | import http.client 4 | import ssl 5 | 6 | class PleskApiClient: 7 | 8 | def __init__(self, host, port = 8443, protocol = 'https', ssl_unverified = False): 9 | self.host = host 10 | self.port = port 11 | self.protocol = protocol 12 | self.secret_key = None 13 | self.ssl_unverified = ssl_unverified 14 | 15 | def set_credentials(self, login, password): 16 | self.login = login 17 | self.password = password 18 | 19 | def set_secret_key(self, secret_key): 20 | self.secret_key = secret_key 21 | 22 | def request(self, request): 23 | headers = {} 24 | headers["Content-type"] = "text/xml" 25 | headers["HTTP_PRETTY_PRINT"] = "TRUE" 26 | 27 | if self.secret_key: 28 | headers["KEY"] = self.secret_key 29 | else: 30 | headers["HTTP_AUTH_LOGIN"] = self.login 31 | headers["HTTP_AUTH_PASSWD"] = self.password 32 | 33 | if 'https' == self.protocol: 34 | if self.ssl_unverified: 35 | conn = http.client.HTTPSConnection(self.host, self.port, context=ssl._create_unverified_context()) 36 | else: 37 | conn = http.client.HTTPSConnection(self.host, self.port) 38 | else: 39 | conn = http.client.HTTPConnection(self.host, self.port) 40 | 41 | conn.request("POST", "/enterprise/control/agent.php", request, headers) 42 | response = conn.getresponse() 43 | data = response.read() 44 | return data.decode("utf-8") 45 | -------------------------------------------------------------------------------- /ruby/example.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 3 | 4 | require './plesk_api_client' 5 | 6 | host = ENV['REMOTE_HOST'] 7 | login = ENV['REMOTE_LOGIN'] || 'admin' 8 | password = ENV['REMOTE_PASSWORD'] 9 | 10 | client = PleskApiClient.new(host) 11 | client.set_credentials(login, password) 12 | 13 | request = < 15 | 16 | 17 | 18 | 19 | eof 20 | 21 | response = client.request(request) 22 | puts response.body 23 | 24 | -------------------------------------------------------------------------------- /ruby/plesk_api_client.rb: -------------------------------------------------------------------------------- 1 | # Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | require 'net/http' 4 | require 'net/https' 5 | 6 | class PleskApiClient 7 | 8 | def initialize(host, port = 8443, protocol = 'https') 9 | @host = host 10 | @port = port 11 | @protocol = protocol 12 | end 13 | 14 | def set_credentials(login, password) 15 | @login = login 16 | @password = password 17 | end 18 | 19 | def set_secret_key(secret_key) 20 | @secret_key = secret_key 21 | end 22 | 23 | def request(body) 24 | http_request = Net::HTTP::Post.new('/enterprise/control/agent.php') 25 | http_request.body = body 26 | http_request.content_type = 'text/xml' 27 | http_request.add_field 'HTTP_PRETTY_PRINT', 'TRUE' 28 | 29 | if @secret_key 30 | http_request.add_field 'KEY', @secret_key 31 | else 32 | http_request.add_field 'HTTP_AUTH_LOGIN', @login 33 | http_request.add_field 'HTTP_AUTH_PASSWD', @password 34 | end 35 | 36 | http = Net::HTTP.new(@host, @port) 37 | if 'https' == @protocol 38 | http.use_ssl = true 39 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE 40 | end 41 | 42 | response = http.start{ |http| http.request(http_request) } 43 | end 44 | 45 | end 46 | -------------------------------------------------------------------------------- /vb/apirpcexample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ApiRpcExample", "ApiRpcExample.vbproj", "{BFBEE2B0-D990-4781-B2BA-321FF2D9B238}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {BFBEE2B0-D990-4781-B2BA-321FF2D9B238}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {BFBEE2B0-D990-4781-B2BA-321FF2D9B238}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {BFBEE2B0-D990-4781-B2BA-321FF2D9B238}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {BFBEE2B0-D990-4781-B2BA-321FF2D9B238}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /vb/apirpcexample.vb: -------------------------------------------------------------------------------- 1 | ' Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved. 2 | 3 | Imports System 4 | Imports System.Net 5 | Imports System.Text 6 | Imports System.IO 7 | Imports System.Xml 8 | Imports System.Xml.Schema 9 | Imports System.Security.Cryptography.X509Certificates 10 | Imports System.Net.Security 11 | 12 | Namespace ApiRpcExample 13 | Public Class Request 14 | Public Hostname As String = "localhost" 15 | Public Login As String = "" 16 | Public Password As String = "" 17 | 18 | Public ReadOnly Property AgentEntryPoint As String 19 | Get 20 | Return ("https://" & Me.Hostname & ":8443/enterprise/control/agent.php") 21 | End Get 22 | End Property 23 | 24 | Public Function Send(ByVal packet As XmlDocument) As XmlDocument 25 | Dim request As HttpWebRequest = Me.SendRequest(packet.OuterXml) 26 | Return Me.GetResponse(request) 27 | End Function 28 | 29 | Public Function Send(ByVal packet As Stream) As XmlDocument 30 | Using reader As TextReader = New StreamReader(packet) 31 | Return Me.Send(Me.Parse(reader)) 32 | End Using 33 | End Function 34 | 35 | Public Function Send(ByVal packetUri As String) As XmlDocument 36 | Using reader As TextReader = New StreamReader(packetUri) 37 | Return Me.Send(Me.Parse(reader)) 38 | End Using 39 | End Function 40 | 41 | Private Function SendRequest(ByVal message As String) As HttpWebRequest 42 | Dim request As HttpWebRequest = DirectCast(WebRequest.Create(Me.AgentEntryPoint), HttpWebRequest) 43 | request.Method = "POST" 44 | request.Headers.Add("HTTP_AUTH_LOGIN", Me.Login) 45 | request.Headers.Add("HTTP_AUTH_PASSWD", Me.Password) 46 | request.ContentType = "text/xml" 47 | request.ContentLength = message.Length 48 | Dim bytes As Byte() = New ASCIIEncoding().GetBytes(message) 49 | Using stream As Stream = request.GetRequestStream 50 | stream.Write(bytes, 0, message.Length) 51 | End Using 52 | Return request 53 | End Function 54 | 55 | Private Function Parse(ByVal xml As TextReader) As XmlDocument 56 | Dim document As New XmlDocument 57 | Using reader As XmlReader = XmlReader.Create(xml) 58 | document.Load(reader) 59 | End Using 60 | Return document 61 | End Function 62 | 63 | Private Function GetResponse(ByVal request As HttpWebRequest) As XmlDocument 64 | Using response As HttpWebResponse = DirectCast(request.GetResponse, HttpWebResponse) 65 | Using stream As Stream = response.GetResponseStream 66 | Using reader As TextReader = New StreamReader(stream) 67 | Return Me.Parse(reader) 68 | End Using 69 | End Using 70 | End Using 71 | End Function 72 | End Class 73 | 74 | Friend Class Program 75 | 76 | Shared Sub Main(ByVal args As String()) 77 | If (args.Length < 4) Then 78 | Console.WriteLine("Usage: apirpcexample ") 79 | Console.WriteLine(" ") 80 | Console.WriteLine(" Host name - The Panel's host name") 81 | Console.WriteLine(" Login - Administrator's login") 82 | Console.WriteLine(" Password - Administrator's password") 83 | Console.WriteLine(" Request - Request file path (*.xml)") 84 | Else 85 | ' Verifies the remote Secure Sockets Layer (SSL) certificate 86 | ' used for authentication. 87 | ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf Program.RemoteCertificateValidation) 88 | Dim request As New Request 89 | request.Hostname = args(0) 90 | request.Login = args(1) 91 | request.Password = args(2) 92 | Dim packetUri As String = args(3) 93 | Try 94 | Program.PrintResult(request.Send(packetUri)) 95 | Catch exception As Exception 96 | Console.WriteLine("Request error: {0}", exception.Message) 97 | End Try 98 | End If 99 | End Sub 100 | 101 | ' The following method is invoked by the RemoteCertificateValidationDelegate. 102 | Private Shared Function RemoteCertificateValidation(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean 103 | If (sslPolicyErrors <> sslPolicyErrors.RemoteCertificateNotAvailable) Then 104 | Return True 105 | End If 106 | Console.WriteLine("Certificate error: {0}", sslPolicyErrors) 107 | ' Do not allow this client to communicate with unauthenticated servers. 108 | Return False 109 | End Function 110 | 111 | Private Shared Sub PrintResult(ByVal document As XmlDocument) 112 | Dim w As New XmlTextWriter(Console.Out) 113 | w.Formatting = Formatting.Indented 114 | document.WriteTo(w) 115 | w.Flush() 116 | Console.WriteLine() 117 | End Sub 118 | 119 | End Class 120 | 121 | End Namespace 122 | -------------------------------------------------------------------------------- /vb/apirpcexample.vbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {BFBEE2B0-D990-4781-B2BA-321FF2D9B238} 8 | Exe 9 | ApiRpcExample.ApiRpcExample.Program 10 | ApiRpcExample 11 | ApiRpcExample 12 | 512 13 | Console 14 | v4.5 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | true 21 | true 22 | bin\Debug\ 23 | ApiRpcExample.xml 24 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | false 30 | true 31 | true 32 | bin\Release\ 33 | ApiRpcExample.xml 34 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 35 | 36 | 37 | On 38 | 39 | 40 | Binary 41 | 42 | 43 | Off 44 | 45 | 46 | On 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | True 73 | Application.myapp 74 | 75 | 76 | True 77 | True 78 | Resources.resx 79 | 80 | 81 | True 82 | Settings.settings 83 | True 84 | 85 | 86 | 87 | 88 | VbMyResourcesResXFileCodeGenerator 89 | Resources.Designer.vb 90 | My.Resources 91 | Designer 92 | 93 | 94 | 95 | 96 | MyApplicationCodeGenerator 97 | Application.Designer.vb 98 | 99 | 100 | SettingsSingleFileGenerator 101 | My 102 | Settings.Designer.vb 103 | 104 | 105 | 106 | 107 | 114 | -------------------------------------------------------------------------------- /vb/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /vb/my project/application.designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.17929 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | -------------------------------------------------------------------------------- /vb/my project/application.myapp: -------------------------------------------------------------------------------- 1 |  2 | 3 | false 4 | false 5 | 0 6 | true 7 | 0 8 | 2 9 | true 10 | 11 | -------------------------------------------------------------------------------- /vb/my project/assemblyinfo.vb: -------------------------------------------------------------------------------- 1 | Imports System 2 | Imports System.Reflection 3 | Imports System.Runtime.InteropServices 4 | 5 | ' General Information about an assembly is controlled through the following 6 | ' set of attributes. Change these attribute values to modify the information 7 | ' associated with an assembly. 8 | 9 | ' Review the values of the assembly attributes 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM 21 | 22 | 23 | ' Version information for an assembly consists of the following four values: 24 | ' 25 | ' Major Version 26 | ' Minor Version 27 | ' Build Number 28 | ' Revision 29 | ' 30 | ' You can specify all the values or you can default the Build and Revision Numbers 31 | ' by using the '*' as shown below: 32 | ' 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /vb/my project/resources.designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.17929 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My.Resources 16 | 17 | 'This class was auto-generated by the StronglyTypedResourceBuilder 18 | 'class via a tool like ResGen or Visual Studio. 19 | 'To add or remove a member, edit your .ResX file then rerun ResGen 20 | 'with the /str option, or rebuild your VS project. 21 | ''' 22 | ''' A strongly-typed resource class, for looking up localized strings, etc. 23 | ''' 24 | _ 28 | Friend Module Resources 29 | 30 | Private resourceMan As Global.System.Resources.ResourceManager 31 | 32 | Private resourceCulture As Global.System.Globalization.CultureInfo 33 | 34 | ''' 35 | ''' Returns the cached ResourceManager instance used by this class. 36 | ''' 37 | _ 38 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager 39 | Get 40 | If Object.ReferenceEquals(resourceMan, Nothing) Then 41 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("ApiRpcExample.Resources", GetType(Resources).Assembly) 42 | resourceMan = temp 43 | End If 44 | Return resourceMan 45 | End Get 46 | End Property 47 | 48 | ''' 49 | ''' Overrides the current thread's CurrentUICulture property for all 50 | ''' resource lookups using this strongly typed resource class. 51 | ''' 52 | _ 53 | Friend Property Culture() As Global.System.Globalization.CultureInfo 54 | Get 55 | Return resourceCulture 56 | End Get 57 | Set(ByVal value As Global.System.Globalization.CultureInfo) 58 | resourceCulture = value 59 | End Set 60 | End Property 61 | End Module 62 | End Namespace 63 | -------------------------------------------------------------------------------- /vb/my project/resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /vb/my project/settings.designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.17929 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | _ 20 | Partial Friend NotInheritable Class MySettings 21 | Inherits Global.System.Configuration.ApplicationSettingsBase 22 | 23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) 24 | 25 | #Region "My.Settings Auto-Save Functionality" 26 | #If _MyType = "WindowsForms" Then 27 | Private Shared addedHandler As Boolean 28 | 29 | Private Shared addedHandlerLockObject As New Object 30 | 31 | _ 32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) 33 | If My.Application.SaveMySettingsOnExit Then 34 | My.Settings.Save() 35 | End If 36 | End Sub 37 | #End If 38 | #End Region 39 | 40 | Public Shared ReadOnly Property [Default]() As MySettings 41 | Get 42 | 43 | #If _MyType = "WindowsForms" Then 44 | If Not addedHandler Then 45 | SyncLock addedHandlerLockObject 46 | If Not addedHandler Then 47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings 48 | addedHandler = True 49 | End If 50 | End SyncLock 51 | End If 52 | #End If 53 | Return defaultInstance 54 | End Get 55 | End Property 56 | End Class 57 | End Namespace 58 | 59 | Namespace My 60 | 61 | _ 64 | Friend Module MySettingsProperty 65 | 66 | _ 67 | Friend ReadOnly Property Settings() As Global.ApiRpcExample.My.MySettings 68 | Get 69 | Return Global.ApiRpcExample.My.MySettings.Default 70 | End Get 71 | End Property 72 | End Module 73 | End Namespace 74 | -------------------------------------------------------------------------------- /vb/my project/settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | --------------------------------------------------------------------------------