Exemple #1
0
        public void GetEmailsByRegexReturnsEmails()
        {
            var client            = new cPanelClient(_username, _hostname, password: _password, cpanel: true);
            var emailListResponse = client.Api2("Email", "listpops", param: new { regex = "pr" });

            Assert.IsTrue(emailListResponse.Length > 0);
        }
Exemple #2
0
        public void GetMonthlyBandwidthReturnsBandwidth()
        {
            var client            = new cPanelClient(_username, _hostname, password: _password, cpanel: true);
            var bandwidthResponse = client.Api2("Stats", "getmonthlybandwidth");

            Assert.IsTrue(bandwidthResponse.Length > 0);
        }
        public void UpdateDomain(String zone, String record, String address)
        {
            log.InfoFormat("Updating record {0} with address {1}", record, address);

            String lastRunFile = String.Format("Status/{0}_last_run.txt", record);

            if (!File.Exists(lastRunFile))
            {
                log.InfoFormat("Creating file {0}", lastRunFile);
                Directory.CreateDirectory(Path.GetDirectoryName(lastRunFile));
                using (FileStream fs = File.Create(lastRunFile))
                {
                    byte[] placeholderAddress = Encoding.UTF8.GetBytes("0.0.0.0");
                    fs.Write(placeholderAddress, 0, placeholderAddress.Length);
                }
            }

            String lastRunAddress = File.ReadAllText(lastRunFile);

            if (address.Equals(lastRunAddress))
            {
                log.InfoFormat("New address is identical to the address saved from the last run ({0}), not calling API", lastRunAddress);
                return;
            }

            // Hack to handle non-trusted SSL certificates
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            String recordName        = record;
            String recordNameWithDot = record += '.'; // Add a trailing dot

            String jsonResponse = client.Api2("ZoneEdit", "fetchzone", null, new { domain = zone });

            JObject jsonObject = JObject.Parse(jsonResponse);
            JToken  jsonData   = jsonObject["cpanelresult"]["data"][0];
            JArray  records    = jsonData["record"] as JArray;
            JToken  jsonRecord = JsonUtility.FindRecord(records, recordNameWithDot);

            if (jsonRecord != null)
            {
                String oldAddress = jsonRecord["address"].Value <String>();
                if (!address.Equals(oldAddress))
                {
                    // Line is "primary key" for the record
                    String line     = jsonRecord["line"].Value <String>();
                    String response = client.Api2("ZoneEdit", "edit_zone_record", null, new { domain = zone, line, address });

                    File.WriteAllText(lastRunFile, address);

                    log.InfoFormat("Updated address for record {0} to {1}", recordName, address);
                }
                else
                {
                    log.InfoFormat("Old and new addresses are identical ({0}), not updating", address);
                }
            }
            else
            {
                log.WarnFormat("Record {0} doesn't exist", record);
            }
        }
Exemple #4
0
        public void NoFunctionThrowsException()
        {
            var client = new cPanelClient(_username, _hostname, password: _password, cpanel: true);

            client.Api2("fooModule", "");
        }
Exemple #5
0
        public void NoModuleThrowsException()
        {
            var client = new cPanelClient(_username, _hostname, password: _password);

            client.Api2("", "fooFunc");
        }
Exemple #6
0
        public void WhmAndNoUserThrowsException()
        {
            var client = new cPanelClient(_username, _hostname, accessHash: "foo");

            client.Api2("fooModule", "fooFunc");
        }