Beispiel #1
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);
            }
        }
Beispiel #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);
            }
        }