Пример #1
0
 public cPanelZoneEditFunctions(cPanelAPI api)
     : base(api)
 {
 }
Пример #2
0
        public static void Main(string[] args)
        {
            string logPath = Path.GetTempPath();
            logPath = Path.Combine(logPath, "cPanel");
            logPath += DateTime.Now.ToString("yyyyMMdd-HHmmss");
            logPath += ".log";
            Logger.Setup(logPath);

            Logger.Instance.Write (Logger.Severity.Debug, "Starting up...");

            CmdOptions options = new CmdOptions ();
            if (CommandLine.Parser.Default.ParseArguments (args, options) == false)
            {
                Console.WriteLine ("Return codes: ");
                Console.WriteLine (BuildReturnString ());
                Environment.Exit ((int)DDNSReturnCodes.InvalidOptionsGiven);
            }

            // Check if we need to lookup our public IP on the internet
            if (string.IsNullOrEmpty (options.IP))
            {
                Logger.Instance.Write (Logger.Severity.Debug,
                                       "No IP given on the command line, looking up");
                options.IP = PublicIP.Lookup ();

                if (options.IP == string.Empty)
                {
                    Logger.Instance.Write (Logger.Severity.Error, "IP Address lookup failed");
                    Environment.Exit ((int)DDNSReturnCodes.IPLookupFailure);
                }

                Logger.Instance.Write (Logger.Severity.Debug,
                                       "Got IP: " + options.IP);
            }

            // Setup the cPanelAPI
            cPanelAPI api = new cPanelAPI (options.URL,
                                           options.Username,
                                           options.Password,
                                           options.Secure);

            // Update the domain A record only, point to our IP.
            DDNSResult result;
            result = UpdateDomainARecord (api,
                                          options.Domain,
                                          options.Zone,
                                          options.IP);

            if (result == DDNSResult.NotNeccessary)
            {
                Logger.Instance.Write (Logger.Severity.Debug,
                                       "IP address in record same as given IP, nothing to do");
                Environment.Exit ((int)DDNSReturnCodes.NoUpdateNeccessary);
            }
            else if (result == DDNSResult.UpdateSuccess)
            {
                Logger.Instance.Write (Logger.Severity.Debug,
                                       "Successfully updated zone " + options.Zone +
                                       " on domain " + options.Domain +
                                       " to point to IP " + options.IP);
                Environment.Exit ((int)DDNSReturnCodes.UpdateSuccess);
            }
            else
            {
                Logger.Instance.Write (Logger.Severity.Error, "Updating zone record has failed");
                Environment.Exit ((int)DDNSReturnCodes.GeneralError);
            }
        }
Пример #3
0
 public cPanelModuleBase(cPanelAPI api)
 {
     _api = api;
 }
Пример #4
0
        private static DDNSResult UpdateDomainARecord(cPanelAPI api,
			                                          string domain,
			                                          string zone,
			                                          string ip)
        {
            cPanelZoneEditFunctions funcs = new cPanelZoneEditFunctions (api);
            FetchZoneResponse zoneInfo;

            if (funcs.FetchZone (domain, zone, out zoneInfo) == true)
            {
                EditZoneResponse zoneResponse;
                int recordLine = -1;

                try
                {
                    // Convert to int to make sure its a valid value
                    recordLine = Convert.ToInt32 (zoneInfo.Zone.Line);
                }
                catch (Exception)
                {
                    Logger.Instance.Write (Logger.Severity.Error, "Received record line is not an integer");
                    return DDNSResult.Error;
                }

                Logger.Instance.Write (Logger.Severity.Debug, "Given IP: " + ip);
                Logger.Instance.Write (Logger.Severity.Debug, "Zone IP: " + zoneInfo.Zone.Address);
                if (ip == zoneInfo.Zone.Address)
                {
                    return DDNSResult.NotNeccessary;
                }

                if (funcs.EditZoneARecord (domain, ip, recordLine, out zoneResponse) == true)
                {
                    if (zoneResponse.Status == "1")
                    {
                        return DDNSResult.UpdateSuccess;
                    }
                    else
                    {
                        return DDNSResult.Error;
                    }
                }
            }

            return DDNSResult.Error;
        }