Exemple #1
0
        /// <summary>
        /// Powinno dawać to samo co Call_AddonDomain_List
        /// Full description: http://docs.cpanel.net
        /// </summary>
        /// <returns></returns>
        public AddonDomain[] Call_Park_listaddondomains()
        {
            CpanelApiResult x  = Call2("Park::listaddondomains");
            var             cc = x.GetResult(AddonDomain.FromXElement);

            return(cc);
        }
Exemple #2
0
        internal static string getString(CpanelApiResult x, string name)
        {
            var d = x.XData.Where(q => q.Element("name").Value == name).FirstOrDefault();

            if (d != null)
            {
                return(d.Element("value").Value);
            }
            return("");
        }
Exemple #3
0
        private static ResourceD getResourceD(CpanelApiResult x, string name)
        {
            XElement d = x.XData.Where(q => q.Element("name").Value == name).FirstOrDefault();

            if (d == null)
            {
                return(null);
            }
            var maxElement   = d.Element("_max");
            var countElement = d.Element("_count");

            if (maxElement != null && maxElement.Value.Trim().ToLower() == "unlimited")
            {
                return(ResourceD.GetUnlimited(getDouble(countElement)));
            }
            return(new ResourceD(getDouble(countElement), getDouble(maxElement)));
        }
Exemple #4
0
        // Public Methods 

        public static Statistics FromResult(CpanelApiResult x)
        {
            Statistics s = new Statistics();

            s.FtpAccounts     = getResource(x, "ftpaccounts");
            s.PerlVersion     = getString(x, "perlversion");
            s.Hostname        = getString(x, "hostname");
            s.OperatingSystem = getString(x, "operatingsystem");
            s.SendmailPath    = getString(x, "sendmailpath");
            s.Autoresponders  = getResource(x, "autoresponders");
            s.PerlPath        = getString(x, "perlpath");
            s.EmailForwarders = getResource(x, "emailforwarders");
            s.BandwidthUsage  = getResourceD(x, "bandwidthusage");
            s.EmailFilters    = getResource(x, "emailfilters");

            s.DiskUsage    = getResourceD(x, "diskusage");
            s.PhpVersion   = getString(x, "phpversion");
            s.SqlDatabases = getResource(x, "sqldatabases");

            s.ApacheVersion = getString(x, "apacheversion");
            s.KernelVersion = getString(x, "kernelversion");

            s.ParkedDomains  = getResource(x, "parkeddomains");
            s.AddonDomains   = getResource(x, "addondomains");
            s.SubDomains     = getResource(x, "subdomains");
            s.MachineType    = getString(x, "machinetype");
            s.Theme          = getString(x, "theme");
            s.CPanelVersion  = getString(x, "cpanelversion");
            s.MysqlDiskUsage = getResourceD(x, "mysqldiskusage") / (1024 * 1024);
            s.MysqlVersion   = getString(x, "mysqlversion");
            s.SharedIP       = getString(x, "sharedip");
            s.HostingPackage = getString(x, "hostingpackage");
            s.EmailAccounts  = getResource(x, "emailaccounts");

            return(s);
        }
Exemple #5
0
        // Protected Methods 

        protected CpanelApiResult Call(string module, string function, int apiVersion, params string[] parameters)
        {
            if (string.IsNullOrEmpty(URL))
            {
                throw new CPanelException(WellKownCpanelProblems.EmptyOrInvalidCPanelURL, "");
            }
            if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))
            {
                throw new CPanelException(WellKownCpanelProblems.EmptyUsernameOrPassword, "");
            }

            Uri u;

            try
            {
                u = new Uri(URL);
            }
            catch (UriFormatException)
            {
                throw new CPanelException(WellKownCpanelProblems.EmptyOrInvalidCPanelURL, "");
            }
            if (u.Scheme.ToLower() != "http" && u.Scheme.ToLower() != "https")
            {
                throw new CPanelException(WellKownCpanelProblems.EmptyOrInvalidCPanelURL, "");
            }
            URL = u.AbsoluteUri;


            TransmissionMessage msg = new TransmissionMessage();

            msg.CallFunction = module + "::" + function;

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict["user"] = string.IsNullOrEmpty(ActionUsername) ? Username : ActionUsername;
            dict["cpanel_xmlapi_module"]     = module;
            dict["cpanel_xmlapi_func"]       = function;
            dict["cpanel_xmlapi_apiversion"] = apiVersion.ToString();
            string encodedParams = EncodeHttpParameters(parameters, dict);


            string cPanelRequestURL = string.Format("{0}xml-api/cpanel?{1}", URL, encodedParams);
            var    aaa = new NetworkCredential(Username, Password);

            if (MyCredential == null)
            {
                MyCredential = new CredentialCache();
                MyCredential.Add(new Uri(URL), "Basic", aaa);
            }


            WebRequest wRequest = WebRequest.Create(cPanelRequestURL);

            wRequest.PreAuthenticate = true;
            wRequest.Credentials     = aaa;

            wRequest.Timeout = 1000 * 30;
            wRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(aaa.UserName + ":" + aaa.Password)));

            msg.Progress = TransmissionMessageType.RequestSending;
            oh_CpanelMessage.PushOnNext(msg);
            CpanelApiResult result = null;

            try
            {
                using (HttpWebResponse httpResponse = (HttpWebResponse)wRequest.GetResponse())
                {
                    msg.Progress = TransmissionMessageType.ResponseReading;
                    oh_CpanelMessage.PushOnNext(msg);
                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        MemoryStream tmpMemoreStream = new MemoryStream(Math.Max(1024, (int)httpResponse.ContentLength));
                        byte[]       copyBuffer      = new byte[1024 * 8];
                        using (var stream = httpResponse.GetResponseStream())
                        {
                            while (true)
                            {
                                int bytesReaded = stream.Read(copyBuffer, 0, copyBuffer.Length);
                                if (bytesReaded == 0)
                                {
                                    break;
                                }
                                tmpMemoreStream.Write(copyBuffer, 0, bytesReaded);
                            }
                        }
                        copyBuffer = null;
                        string response = Encoding.UTF8.GetString(tmpMemoreStream.ToArray());
                        result = new CpanelApiResult(XDocument.Parse(response));
                    }
                }
            }
            catch (WebException e)
            {
                switch (e.Status)
                {
                case WebExceptionStatus.ProtocolError:
                    var r = e.Response as HttpWebResponse;
                    if (r != null)
                    {
                        if (r.StatusCode == HttpStatusCode.Forbidden)
                        {
                            throw new CPanelException(WellKownCpanelProblems.LoginError, "");
                        }
                    }
                    break;

                case WebExceptionStatus.NameResolutionFailure:
                    throw new CPanelException(WellKownCpanelProblems.NameResolutionFailure, "");
                }
                throw;
            }
            msg.Progress = TransmissionMessageType.Finished;
            oh_CpanelMessage.PushOnNext(msg);
            return(result);
        }