private Task <ProcessResult> FlushNetworkSequence(bool isEth0Changes, bool isWlan0Changes, NICProperties theEth0, NICProperties theWlan0)
        {
            return(Task.Run(async() =>
            {
                await DHCPCD.UpdateResultAsync(new NICProperties[] { theEth0, theWlan0 });
                await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "daemon-reload");
                await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "stop dhcpcd.service");
                if (isEth0Changes)
                {
                    await ProcessRunner.GetProcessResultAsync(c_IPCommand, "addr flush dev eth0");
                }
                if (isWlan0Changes)
                {
                    await ProcessRunner.GetProcessResultAsync(c_IPCommand, "addr flush dev wlan0");
                }
                await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "start dhcpcd.service");
                await ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "restart networking.service");

                if (isWlan0Changes)
                {
                    await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 reconfigure");
                }

                return new ProcessResult(0, string.Empty, string.Empty);
            }));
        }
        internal MemoryProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [2];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_DFCommand, "-h");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_FreeCommand, "-h -t");

            Task.WaitAll(Tasks);

            this.FreeDisk = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                            .Skip(1)
                            .Select(line => line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
                            .ToArray()
                : new string[0][];

            this.FreeRam = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                           .Skip(1)
                           .Select(line => line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
                           .ToArray()
                : new string[0][];

            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.DiskFreeSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.RAMFreeSettingGetError);

            return(this);
        }
        private Task <ProcessResult> SetWiFiSSIDPassphraseSequence(NetworkProperties theModel)
        {
            return(Task.Run(async() =>
            {
                Log?.Invoke(EventLogEntryCodes.SSIDChanging, new string[] { theModel.NewSSID });

                var AddNetworkTask = await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 add_network");

                var NewNetworkId = AddNetworkTask.GetOutput().Trim();

                ProcessResult SetSSID = await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 set_network " + NewNetworkId + " ssid '\"" + theModel.NewSSID + "\"'");

                ProcessResult SetPassphrase;

                if (string.IsNullOrEmpty(theModel.NewPassphrase))
                {
                    SetPassphrase = await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 set_network " + NewNetworkId + " key_mgmt NONE");
                }
                else
                {
                    SetPassphrase = await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 set_network " + NewNetworkId + " psk '\"" + theModel.NewPassphrase + "\"'");
                }

                await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 enable_network " + NewNetworkId);
                await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 save_config");
                await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 reconfigure");

                return new ProcessResult(0, string.Empty, string.Empty);
            }));
        }
        internal bool DeleteWiFi(string id)
        {
            // TODO All Results aren't being catched.

            Task <ProcessResult> ScanTask = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 list_networks");

            ScanTask.Wait();

            bool Result = ScanTask.Result.Okay();

            if (Result)
            {
                string[] SSIDS = ScanTask.Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                                 .Where(line => line.Contains(id))
                                 .Select(line => line.Substring(0, line.IndexOf("\t")))
                                 .ToArray();

                if (SSIDS.Any())
                {
                    Task <Task <ProcessResult> > RemoveWiFi = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 remove_network " + SSIDS[0])
                                                              .ContinueWith(async RemoveNetworkTask => await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 save_config"))
                                                              .ContinueWith(async SaveConfigTask => await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 reconfigure"));

                    RemoveWiFi.Wait();

                    Result = RemoveWiFi.Result.Result.Okay();
                }
                else
                {
                    Result = false;
                }
            }

            return(Result);
        }
示例#5
0
        internal void UpdateProperties(HomeProperties theProperties)
        {
            bool RestartHostAPd = false;

            IEnumerable <PropertyInfo> Properties = typeof(HomeProperties).GetProperties().Where(Property => Property.IsDefined(typeof(Models.Attributes.FileName), false));

            foreach (PropertyInfo Property in Properties)
            {
                Models.Attributes.FileName FileNameAttribute = Property.GetCustomAttribute <Models.Attributes.FileName>();
                if (FileNameAttribute != null)
                {
                    string Old = Property.GetValue(this) as string;
                    string New = Property.GetValue(theProperties) as string;

                    if ((Old == null && New != null) || (!Old.Equals(New, StringComparison.Ordinal)))
                    {
                        Property.SetValue(this, New);
                        RestartHostAPd = true;
                    }
                }
            }

            Save();

            if (m_RunningLinux && HostAPdEnabled != theProperties.HostAPdEnabled)
            {
                Task <ProcessResult> StartHostAPd   = null;
                Task <ProcessResult> DisableHostAPd = null;

                if (theProperties.HostAPdEnabled)
                {
                    Task <ProcessResult> EnableHostAPd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "enable " + c_HostAPdCommand);
                    EnableHostAPd.Wait();

                    if (EnableHostAPd.Result.Okay())
                    {
                        StartHostAPd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "start " + c_HostAPdCommand);
                        StartHostAPd.Wait();
                    }
                }
                else
                {
                    Task <ProcessResult> StopTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "stop " + c_HostAPdCommand);
                    StopTimesyncd.Wait();

                    if (StopTimesyncd.Result.Okay())
                    {
                        DisableHostAPd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "disable " + c_HostAPdCommand);
                        DisableHostAPd.Wait();
                    }
                }
            }
            else if (m_RunningLinux && HostAPdEnabled && RestartHostAPd)
            {
                Task <ProcessResult> Restart = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "restart " + c_HostAPdCommand);
                Restart.Wait();
            }
        }
        internal NetworkProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [4];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/hostname");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 get country");
            Tasks[2] = GetSSIDs();
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_IFConfigCommand);

            ReadResult ReadResult = DHCPCD.Read();

            var Eth0 = ReadResult.Properties.FirstOrDefault(nic => nic.Id == c_Eth0);

            Eth0IPAddress         = (Eth0 == null || Eth0.IPAddress == null) ? string.Empty : Eth0.IPAddress;
            Eth0IP6Address        = (Eth0 == null || Eth0.IP6Address == null) ? string.Empty : Eth0.IP6Address;
            Eth0Routers           = (Eth0 == null || Eth0.Routers == null) ? new string[0] : Eth0.Routers;
            Eth0DomainNameServers = (Eth0 == null || Eth0.DomainNameServers == null) ? new string[0] : Eth0.DomainNameServers;

            var Wlan0 = ReadResult.Properties.FirstOrDefault(nic => nic.Id == c_Wlan0);

            Wlan0IPAddress         = (Wlan0 == null || Wlan0.IPAddress == null) ? string.Empty : Wlan0.IPAddress;
            Wlan0IP6Address        = (Wlan0 == null || Wlan0.IP6Address == null) ? string.Empty : Wlan0.IP6Address;
            Wlan0Routers           = (Wlan0 == null || Wlan0.Routers == null) ? new string[0] : Wlan0.Routers;
            Wlan0DomainNameServers = (Wlan0 == null || Wlan0.DomainNameServers == null) ? new string[0] : Wlan0.DomainNameServers;

            ReadResult = null;

            Task.WaitAll(Tasks);

            var WiFiCountryResult = Tasks[1].Result.GetOutput().TrimEnd();

            WiFiCountrySet = WiFiCountryResult != c_WiFiCountryNotSet;

            HostName    = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd() : string.Empty;
            WiFiCountry = WiFiCountrySet ? WiFiCountryResult : string.Empty;
            SSIDs       = ProcessSSIDs(Tasks[2]);
            Interfaces  = Tasks[3].Result.Okay() ? IFCONFIG.Parse(Tasks[3].Result.GetOutput()) : new NICInterface[0];

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.HostNameSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.WiFiCountrySettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.SSIDSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.NICInterfacesGetError);
            return(this);
        }
示例#7
0
        private Task <ProcessResult> UnsetWiFiSequence()
        {
            return(Task.Run(async() =>
            {
                ProcessResult Result = await ProcessRunner.GetProcessResultAsync(c_SedCommand, "-i '/country=/d' /etc/wpa_supplicant/wpa_supplicant.conf");

                if (Result.Okay())
                {
                    Result = await ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 reconfigure");
                }

                return Result;
            }));
        }
        internal static void CheckRunningRaspberryPi()
        {
            if (Type.GetType("Mono.Runtime") != null)
            {
                isRunningMono = true;

                Task <ProcessResult> RaspberryPiModel = ProcessRunner.GetProcessResultAsync("cat", "/proc/device-tree/model");

                RaspberryPiModel.Wait();

                if (RaspberryPiModel.Result.Okay())
                {
                    isRunningRaspberryPi = true;
                }
            }
        }
        public Response Get()
        {
            Task <ProcessResult> ScanTask = ProcessRunner.GetProcessResultAsync("iwlist", "wlan0 scan");

            ScanTask.Wait();

            const string c_SSIDLine = "ESSID:\"";

            string[] SSIDS = ScanTask.Result.Okay() ? ScanTask.Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                             .Where(line => line.Contains(c_SSIDLine))
                             .Select(line => line.Substring(line.IndexOf(c_SSIDLine) + c_SSIDLine.Length).TrimEnd('"'))
                             .ToArray()
                : new string[0];

            return(new Response {
                MediaType = "application/json", Model = SSIDS
            });
        }
示例#10
0
        internal LocalisationProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [9];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/usr/share/zoneinfo/iso3166.tab");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 get country");
            Tasks[2] = ProcessRunner.GetProcessResultAsync(c_TimeDateControlCommand, "list-timezones");
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/timezone");
            Tasks[4] = ProcessRunner.GetProcessResultAsync(c_DateCommand, "+%d/%m/%Y");
            Tasks[5] = ProcessRunner.GetProcessResultAsync(c_DateCommand, "+%T");
            Tasks[6] = ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "is-active systemd-timesyncd");
            Tasks[7] = ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "is-active fake-hwclock");
            Tasks[8] = ProcessRunner.GetProcessResultAsync(c_HardwareClockCommand, "-r");

            Task.WaitAll(Tasks);

            WifiCountry        = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput() : string.Empty;
            WifiCountries      = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Skip(25).Select(line => new string[] { line, line.StartsWith(WifiCountry) ? "selected=\"selected\"" : "" }).ToArray() : new string[0][];
            TimeZone           = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput().TrimEnd() : string.Empty;
            TimeZones          = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Skip(25).Select(line => new string[] { line, line.StartsWith(TimeZone) ? "selected=\"selected\"" : "" }).ToArray() : new string[0][];
            Date               = Tasks[4].Result.Okay() ? Tasks[4].Result.GetOutput().TrimEnd() : string.Empty;
            Time               = Tasks[5].Result.Okay() ? Tasks[5].Result.GetOutput().TrimEnd() : string.Empty;
            TimeSyncdEnabled   = Tasks[6].Result.Okay() ? Tasks[6].Result.GetOutput().TrimEnd().Equals(c_Active) : false;
            FakeHWClockEnabled = Tasks[7].Result.Okay() ? Tasks[7].Result.GetOutput().TrimEnd().Equals(c_Active) : false;
            HWClockPresent     = Tasks[8].Result.Okay();

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.WiFiCountriesSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.WiFiCountrySettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.TimeZonesSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.TimeZoneSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.DateSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[5], EventLogEntryCodes.TimeSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[6], EventLogEntryCodes.TimeSyncdEnabledSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[7], EventLogEntryCodes.FakeHWClockEnabledSettingGetError);

            return(this);
        }
        internal HatProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            if (Directory.Exists("/proc/device-tree/hat/"))
            {
                Task <ProcessResult>[] Tasks = new Task <ProcessResult> [5];

                Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/product");
                Tasks[1] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/product_id");
                Tasks[2] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/product_ver");
                Tasks[3] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/uuid");
                Tasks[4] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/vendor");

                Task.WaitAll(Tasks);

                Product        = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput() : string.Empty;
                ProductId      = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput() : string.Empty;
                ProductVersion = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput() : string.Empty;
                UUID           = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput() : string.Empty;
                Vendor         = Tasks[4].Result.Okay() ? Tasks[4].Result.GetOutput() : string.Empty;

                // Log only if errors have occured
                LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.HATSettingsGetProductError);
                LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.HATSettingsGetProductIdError);
                LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.HATSettingsGetProductVersionError);
                LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.HATSettingsGetUUIDError);
                LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.HATSettingsGetVendorError);
            }
            else
            {
                Product        = string.Empty;
                ProductId      = string.Empty;
                ProductVersion = string.Empty;
                UUID           = string.Empty;
                Vendor         = string.Empty;
            }

            return(this);
        }
        internal InterfacingProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [8];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_camera");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_ssh");
            Tasks[2] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_vnc");
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_spi");
            Tasks[4] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_i2c");
            Tasks[5] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_serial");
            Tasks[6] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_onewire");
            Tasks[7] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_rgpio");

            Task.WaitAll(Tasks);

            this.Camera     = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.SSH        = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.VNC        = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.SPI        = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.I2C        = Tasks[4].Result.Okay() ? Tasks[4].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.Serial     = Tasks[5].Result.Okay() ? Tasks[5].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.OneWire    = Tasks[6].Result.Okay() ? Tasks[6].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.RemoteGPIO = Tasks[7].Result.Okay() ? Tasks[7].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.CameraSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.SSHSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.VNCSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.SPISettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.I2CSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[5], EventLogEntryCodes.SerialSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[6], EventLogEntryCodes.OneWireSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[7], EventLogEntryCodes.RemoteGPIOSettingGetError);

            return(this);
        }
示例#13
0
        private bool isRunningLinux()
        {
            if (Type.GetType("Mono.Runtime") != null)
            {
                try
                {
                    Task <ProcessResult> RaspberryPiModel = ProcessRunner.GetProcessResultAsync("cat", "/proc/device-tree/model");

                    RaspberryPiModel.Wait();

                    return(RaspberryPiModel.Result.Okay());
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        internal HomeProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [7];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/model");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/debian_version");
            Tasks[2] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/hostname");
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_DateCommand);
            Tasks[4] = GetGPUTemperature();
            Tasks[5] = GetCPUTemperature();
            Tasks[6] = GetDiskSpacePercentage();

            Task.WaitAll(Tasks);

            RaspberryPiModel   = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd() : string.Empty;
            OSVersion          = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().TrimEnd() : string.Empty;
            HostName           = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput().TrimEnd() : string.Empty;
            Date               = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput().TrimEnd() : string.Empty;
            GPUTemperature     = ProcessGPUTemperature(Tasks[4]);
            CPUTemperature     = ProcessCPUTemperature(Tasks[5]);
            FreeDiskPercentage = ProcessDiskSpacePercentage(Tasks[6]);

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.RaspberryPiModelSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.DebianVersionSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.HostNameSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.DateTimeSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.GPUTemperatureSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[5], EventLogEntryCodes.CPUTemperatureSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[6], EventLogEntryCodes.DiskFreeSettingGetError);

            return(this);
        }
示例#15
0
        internal BootProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [2];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_boot_wait");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_boot_splash");

            Task.WaitAll(Tasks);

            NetworkWait  = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd().Equals("0") : false;
            SplashScreen = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().TrimEnd().Equals("0") : false;

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.NetworkWaitSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.SplashScreenSettingsGetError);

            return(this);
        }
        /// <summary>
        /// Restarts the Pi. Must be running as SU.
        /// </summary>
        /// <returns>The process result.</returns>
        public async Task <ProcessResultModel> Restart()
        {
            var piResult = await ProcessRunner.GetProcessResultAsync("reboot", null, null);

            return(this._mapper.Map <ProcessResultModel>(piResult));
        }
 internal static Task <ProcessResult> GetDiskSpacePercentage()
 {
     return(ProcessRunner.GetProcessResultAsync(c_DFCommand, "-h"));
 }
 internal static Task <ProcessResult> GetCPUTemperature()
 {
     return(ProcessRunner.GetProcessResultAsync(c_CatCommand, "/sys/class/thermal/thermal_zone0/temp"));
 }
 internal static Task <ProcessResult> GetGPUTemperature()
 {
     return(ProcessRunner.GetProcessResultAsync(c_VCGenCommand, "measure_temp"));
 }
示例#20
0
 /// <summary>
 /// Restarts the Pi. Must be running as SU
 /// </summary>
 /// <returns>The process result</returns>
 public static async Task <ProcessResult> RestartAsync() => await ProcessRunner.GetProcessResultAsync("reboot");
示例#21
0
        internal HomeProperties RepopulateAndGetProperties()
        {
            List <PropertyInfo> Properties = GetType().GetProperties().Where(prop => prop.IsDefined(typeof(Models.Attributes.FileName), false)).ToList();

            SetDefaults(Properties);

            if (m_RunningLinux)
            {
                Task <ProcessResult>[] Tasks = new Task <ProcessResult> [1];

                Tasks[0] = ProcessRunner.GetProcessResultAsync("systemctl", "is-active hostapd");

                Task.WaitAll(Tasks);

                HostAPdEnabled = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd().Equals("active") : false;
            }

            if (!File.Exists(Location))
            {
                return(this);
            }

            List <string> OrphanLinesList = new List <string>();



            using (System.IO.StreamReader file = new System.IO.StreamReader(Location))
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    string[] KeyValue = line.Split('=');

                    PropertyInfo LinkedProperty = null;

                    if (KeyValue.Length == 2 && (!KeyValue[0].Contains("#")))
                    {
                        string Key = KeyValue[0].Trim();

                        foreach (PropertyInfo Property in Properties)
                        {
                            Models.Attributes.FileName FileNameAttribute = Property.GetCustomAttribute <Models.Attributes.FileName>();

                            if (FileNameAttribute != null && Key.Equals(FileNameAttribute.Name, StringComparison.OrdinalIgnoreCase))
                            {
                                Property.SetValue(this, KeyValue[1]);
                                LinkedProperty = Property;
                                break;
                            }
                        }

                        if (LinkedProperty != null)
                        {
                            Properties.Remove(LinkedProperty);
                        }
                        else
                        {
                            OrphanLinesList.Add(line);
                        }
                    }
                    else
                    {
                        OrphanLinesList.Add(line);
                    }
                }
            }

            OrphanLines = OrphanLinesList.ToArray();

            return(this);
        }
示例#22
0
        internal void UpdateProperties(LocalisationProperties theModel)
        {
            List <Task <ProcessResult> > Tasks = new List <Task <ProcessResult> >();

            RepopulateAndGetProperties();

            bool AskToRestart = false;

            Task <ProcessResult> StartTimesyncd   = null;
            Task <ProcessResult> DisableTimesyncd = null;

            if (TimeSyncdEnabled != theModel.TimeSyncdEnabled)
            {
                LoggingActions.LogTaskAction(Log, theModel.TimeSyncdEnabled, EventLogEntryCodes.TimesyncdEnabling, EventLogEntryCodes.TimesyncdStopping);

                if (theModel.TimeSyncdEnabled)
                {
                    Task <ProcessResult> EnableTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "enable systemd-timesyncd");
                    EnableTimesyncd.Wait();
                    LoggingActions.LogTaskResult(Log, EnableTimesyncd, EventLogEntryCodes.TimesyncdEnabled, EventLogEntryCodes.TimesyncdEnablingError);

                    if (EnableTimesyncd.Result.Okay())
                    {
                        Log?.Invoke(EventLogEntryCodes.TimesyncdStarting, null);
                        StartTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "start systemd-timesyncd");
                        Tasks.Add(StartTimesyncd);
                    }
                }
                else
                {
                    Task <ProcessResult> StopTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "stop systemd-timesyncd");
                    StopTimesyncd.Wait();
                    LoggingActions.LogTaskResult(Log, StopTimesyncd, EventLogEntryCodes.TimesyncdStopped, EventLogEntryCodes.TimesyncdStoppingError);

                    if (StopTimesyncd.Result.Okay())
                    {
                        Log?.Invoke(EventLogEntryCodes.TimesyncdDisabling, null);
                        DisableTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "disable systemd-timesyncd");
                        Tasks.Add(DisableTimesyncd);
                    }
                }
            }

            Task <ProcessResult> StartFakeHWClock   = null;
            Task <ProcessResult> DisableFakeHWClock = null;

            if (FakeHWClockEnabled != theModel.FakeHWClockEnabled)
            {
                LoggingActions.LogTaskAction(Log, theModel.FakeHWClockEnabled, EventLogEntryCodes.FakeHwClockEnabling, EventLogEntryCodes.FakeHwClockStopping);

                if (theModel.FakeHWClockEnabled)
                {
                    Task <ProcessResult> EnableFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "enable fake-hwclock");
                    EnableFakeHWClock.Wait();
                    LoggingActions.LogTaskResult(Log, EnableFakeHWClock, EventLogEntryCodes.FakeHwClockEnabled, EventLogEntryCodes.FakeHwClockEnablingError);

                    if (EnableFakeHWClock.Result.Okay())
                    {
                        Log?.Invoke(EventLogEntryCodes.TimesyncdEnabling, null);
                        StartFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "start fake-hwclock");
                        Tasks.Add(StartFakeHWClock);
                    }
                }
                else
                {
                    Task <ProcessResult> StopFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "stop fake-hwclock");
                    StopFakeHWClock.Wait();
                    LoggingActions.LogTaskResult(Log, StopFakeHWClock, EventLogEntryCodes.FakeHwClockStopped, EventLogEntryCodes.FakeHwClockStoppingError);

                    if (StopFakeHWClock.Result.Okay())
                    {
                        Log?.Invoke(EventLogEntryCodes.FakeHwClockDisabling, null);
                        DisableFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "disable fake-hwclock");
                        Tasks.Add(DisableFakeHWClock);
                    }
                }
            }

            Task <ProcessResult> SetTimeZone = null;

            if (TimeZone != theModel.TimeZone)
            {
                Log?.Invoke(EventLogEntryCodes.TimeZoneSetting, new string[] { theModel.TimeZone });
                SetTimeZone = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_change_timezone " + theModel.TimeZone);
                Tasks.Add(SetTimeZone);
            }

            Task <ProcessResult> SetWifiCountry = null;

            if (WifiCountry != theModel.WifiCountry)
            {
                if (theModel.WifiCountry == string.Empty)
                {
                    AskToRestart = true;
                    Log?.Invoke(EventLogEntryCodes.WifiCountrySetting, new string[] { "None" });
                    SetWifiCountry = UnsetWiFiSequence();
                    Tasks.Add(SetWifiCountry);
                }
                else
                {
                    AskToRestart = true;
                    Log?.Invoke(EventLogEntryCodes.WifiCountrySetting, new string[] { theModel.WifiCountry });
                    SetWifiCountry = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_wifi_country " + theModel.WifiCountry);
                    Tasks.Add(SetWifiCountry);
                }
            }

            Task <ProcessResult> SetDate = null;

            if (theModel.SetDate)
            {
                DateTime DateConvert = DateTime.ParseExact(theModel.Date.Replace("/", ""), "ddMMyyyy", CultureInfo.InvariantCulture);
                string   DateCommand = "+%Y%m%d -s \"" + DateConvert.ToString("yyyyMMdd") + "\"";
                Log?.Invoke(EventLogEntryCodes.DateSetting, new string[] { "date " + DateCommand });
                SetDate = ProcessRunner.GetProcessResultAsync(c_DateCommand, DateCommand);
                Tasks.Add(SetDate);
            }

            Task <ProcessResult> SetTime = null;

            if (theModel.SetTime)
            {
                string TimeCommand = "+%T -s \"" + theModel.Time + "\"";
                Log?.Invoke(EventLogEntryCodes.TimeSetting, new string[] { "date " + TimeCommand });
                SetTime = ProcessRunner.GetProcessResultAsync(c_DateCommand, TimeCommand);
                Tasks.Add(SetTime);
            }

            if (AskToRestart)
            {
                RestartDue?.Invoke();
            }

            Task.WaitAll(Tasks.ToArray());

            Task <ProcessResult> SyncRTC = null;

            if (HWClockPresent && (theModel.SetTime || theModel.SetDate || (theModel.TimeSyncdEnabled && !TimeSyncdEnabled)) && theModel.HWClockPresent)
            {
                Log?.Invoke(EventLogEntryCodes.RTCSyncing, null);
                SyncRTC = ProcessRunner.GetProcessResultAsync(c_HardwareClockCommand, "-w");
                SyncRTC.Wait();
            }

            // Check if Tasks have completed Okay and Log result
            LoggingActions.LogTaskResult(Log, StartTimesyncd, EventLogEntryCodes.TimesyncdStarted, EventLogEntryCodes.TimesyncdStartingError);
            LoggingActions.LogTaskResult(Log, DisableTimesyncd, EventLogEntryCodes.TimesyncdDisabled, EventLogEntryCodes.TimesyncdDisablingError);
            LoggingActions.LogTaskResult(Log, StartFakeHWClock, EventLogEntryCodes.FakeHwClockStarted, EventLogEntryCodes.FakeHwClockStartingError);
            LoggingActions.LogTaskResult(Log, DisableFakeHWClock, EventLogEntryCodes.FakeHwClockDisabled, EventLogEntryCodes.FakeHwClockDisablingError);
            LoggingActions.LogTaskResult(Log, SetTimeZone, EventLogEntryCodes.TimeZoneSet, EventLogEntryCodes.TimeZoneSettingError);
            LoggingActions.LogTaskResult(Log, SetWifiCountry, EventLogEntryCodes.WifiCountrySet, EventLogEntryCodes.WifiCountrySettingError);
            LoggingActions.LogTaskResult(Log, SetDate, EventLogEntryCodes.DateSet, EventLogEntryCodes.DateSettingError);
            LoggingActions.LogTaskResult(Log, SetTime, EventLogEntryCodes.TimeSet, EventLogEntryCodes.TimeSettingError);
            LoggingActions.LogTaskResult(Log, SyncRTC, EventLogEntryCodes.RTCSynced, EventLogEntryCodes.RTCSyncError);
        }
示例#23
0
 /// <summary>
 /// Restarts the Pi. Must be running as SU
 /// </summary>
 /// <returns>The process result</returns>
 public static async Task <ProcessResult> RestartAsync()
 {
     return(await ProcessRunner.GetProcessResultAsync("reboot"));
 }
        internal void UpdateProperties(InterfacingProperties theModel)
        {
            List <Task <ProcessResult> > Tasks = new List <Task <ProcessResult> >();

            bool AskToRestart = false;

            RepopulateAndGetProperties();

            Task <ProcessResult> SetCamera = null;

            if (Camera != theModel.Camera)
            {
                AskToRestart = true;
                LoggingActions.LogTaskAction(Log, theModel.Camera, EventLogEntryCodes.CameraSettingEnabling, EventLogEntryCodes.CameraSettingDisabling);
                SetCamera = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_camera " + (theModel.Camera ? c_Enabled : c_Disabled));
                Tasks.Add(SetCamera);
            }

            Task <ProcessResult> SetSSH = null;

            if (SSH != theModel.SSH)
            {
                LoggingActions.LogTaskAction(Log, theModel.SSH, EventLogEntryCodes.SSHSettingEnabling, EventLogEntryCodes.SSHSettingDisabling);
                SetSSH = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_ssh " + (theModel.SSH ? c_Enabled : c_Disabled));
                Tasks.Add(SetSSH);
            }

            Task <ProcessResult> SetVNC = null;

            if (VNC != theModel.VNC)
            {
                LoggingActions.LogTaskAction(Log, theModel.VNC, EventLogEntryCodes.VNCSettingEnabling, EventLogEntryCodes.VNCSettingDisabling);
                SetVNC = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_vnc " + (theModel.VNC ? c_Enabled : c_Disabled));
                Tasks.Add(SetVNC);
            }

            Task <ProcessResult> SetSPI = null;

            if (SPI != theModel.SPI)
            {
                LoggingActions.LogTaskAction(Log, theModel.SPI, EventLogEntryCodes.SPISettingEnabling, EventLogEntryCodes.SPISettingDisabling);
                SetSPI = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_spi " + (theModel.SPI ? c_Enabled : c_Disabled));
                Tasks.Add(SetSPI);
            }

            Task <ProcessResult> SetI2C = null;

            if (I2C != theModel.I2C)
            {
                LoggingActions.LogTaskAction(Log, theModel.I2C, EventLogEntryCodes.I2CSettingEnabling, EventLogEntryCodes.I2CSettingDisabling);
                SetI2C = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_i2c " + (theModel.I2C ? c_Enabled : c_Disabled));
                Tasks.Add(SetI2C);
            }

            Task <ProcessResult> SetSerial = null;

            if (Serial != theModel.Serial)
            {
                AskToRestart = true;
                LoggingActions.LogTaskAction(Log, theModel.Serial, EventLogEntryCodes.SerialSettingEnabling, EventLogEntryCodes.SerialSettingDisabling);
                SetSerial = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_serial " + (theModel.Serial ? c_Enabled : c_Disabled));
                Tasks.Add(SetSerial);
            }

            Task <ProcessResult> SetOneWire = null;

            if (OneWire != theModel.OneWire)
            {
                AskToRestart = true;
                LoggingActions.LogTaskAction(Log, theModel.OneWire, EventLogEntryCodes.OneWireSettingEnabling, EventLogEntryCodes.OneWireSettingDisabling);
                SetOneWire = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_onewire " + (theModel.OneWire ? c_Enabled : c_Disabled));
                Tasks.Add(SetOneWire);
            }

            Task <ProcessResult> SetRemoteGPIO = null;

            if (RemoteGPIO != theModel.RemoteGPIO)
            {
                LoggingActions.LogTaskAction(Log, theModel.RemoteGPIO, EventLogEntryCodes.RemoteGPIOSettingEnabling, EventLogEntryCodes.RemoteGPIOSettingDisabling);
                SetRemoteGPIO = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_rgpio " + (theModel.RemoteGPIO ? c_Enabled : c_Disabled));
                Tasks.Add(SetRemoteGPIO);
            }

            Task.WaitAll(Tasks.ToArray());

            if (AskToRestart)
            {
                RestartDue?.Invoke();
            }

            // Check if Tasks have completed Okay and Log result
            LoggingActions.LogTaskResult(Log, SetCamera, theModel.Camera, EventLogEntryCodes.CameraSettingEnabled, EventLogEntryCodes.CameraSettingDisabled, EventLogEntryCodes.CameraSettingError);
            LoggingActions.LogTaskResult(Log, SetSSH, theModel.SSH, EventLogEntryCodes.SSHSettingEnabled, EventLogEntryCodes.SSHSettingDisabled, EventLogEntryCodes.SSHSettingError);
            LoggingActions.LogTaskResult(Log, SetVNC, theModel.VNC, EventLogEntryCodes.VNCSettingEnabled, EventLogEntryCodes.VNCSettingDisabled, EventLogEntryCodes.VNCSettingError);
            LoggingActions.LogTaskResult(Log, SetSPI, theModel.SPI, EventLogEntryCodes.SPISettingEnabled, EventLogEntryCodes.SPISettingDisabled, EventLogEntryCodes.SPISettingError);
            LoggingActions.LogTaskResult(Log, SetI2C, theModel.I2C, EventLogEntryCodes.I2CSettingEnabled, EventLogEntryCodes.I2CSettingDisabled, EventLogEntryCodes.I2CSettingError);
            LoggingActions.LogTaskResult(Log, SetSerial, theModel.Serial, EventLogEntryCodes.SerialSettingEnabled, EventLogEntryCodes.SerialSettingDisabled, EventLogEntryCodes.SerialSettingError);
            LoggingActions.LogTaskResult(Log, SetOneWire, theModel.OneWire, EventLogEntryCodes.OneWireSettingEnabled, EventLogEntryCodes.OneWireSettingDisabled, EventLogEntryCodes.OneWireSettingError);
            LoggingActions.LogTaskResult(Log, SetRemoteGPIO, theModel.RemoteGPIO, EventLogEntryCodes.RemoteGPIOSettingEnabled, EventLogEntryCodes.RemoteGPIOSettingDisabled, EventLogEntryCodes.RemoteGPIOSettingError);
        }
示例#25
0
 /// <summary>
 /// Halts the Pi. Must be running as SU
 /// </summary>
 /// <returns>The process result</returns>
 public static async Task <ProcessResult> ShutdownAsync() => await ProcessRunner.GetProcessResultAsync("halt");
示例#26
0
 /// <summary>
 /// Restarts the Pi. Must be running as SU.
 /// </summary>
 /// <returns>The process result.</returns>
 public static Task <ProcessResult> RestartAsync() => ProcessRunner.GetProcessResultAsync("reboot", null, null);
示例#27
0
 /// <summary>
 /// Halts the Pi. Must be running as SU.
 /// </summary>
 /// <returns>The process result.</returns>
 public static Task <ProcessResult> ShutdownAsync() => ProcessRunner.GetProcessResultAsync("halt", null, null);
        /// <summary>
        /// Halts the Pi. Must be running as SU.
        /// </summary>
        /// <returns>The process result.</returns>
        public async Task <ProcessResultModel> Shutdown()
        {
            var piResult = await ProcessRunner.GetProcessResultAsync("halt", null, null);

            return(this._mapper.Map <ProcessResultModel>(piResult));
        }
示例#29
0
        public Response Post(UsersProperties theModel)
        {
            if (string.IsNullOrEmpty(theModel.Username))
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=1")
                });
            }

            if (string.IsNullOrEmpty(theModel.OldPassword))
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=2")
                });
            }

            if (theModel.NewPassword != theModel.NewPasswordCheck)
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=3")
                });
            }

            if (string.IsNullOrEmpty(theModel.NewPassword))
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=4")
                });
            }

            Task <ProcessResult> UserEntries = ProcessRunner.GetProcessResultAsync("grep", "^" + theModel.Username + " /etc/shadow");

            UserEntries.Wait();

            var CommandResultLines = UserEntries.Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(line => line.TrimEnd())
                                     .ToArray();

            if (CommandResultLines.Length == 0)
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=5")
                });
            }

            if (CommandResultLines.Length > 1)
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=6")
                });
            }

            // Format of Line is Username$AlgorithmType$Salt$HashedPassword:OtherMeta
            string UserEntry = CommandResultLines[0];

            const string Dollar = "$";
            const string Colon  = ":";

            int StartIndex = UserEntry.IndexOf(Dollar);
            int EndHashAlgorithmTypeIndex = UserEntry.IndexOf(Dollar, StartIndex + Dollar.Length);
            int EndSaltIndex = UserEntry.IndexOf(Dollar, EndHashAlgorithmTypeIndex + Dollar.Length);
            int EndHashIndex = UserEntry.IndexOf(Colon, StartIndex + Dollar.Length);

            string HashAlgorithmType = UserEntry.Substring(StartIndex, EndHashAlgorithmTypeIndex - StartIndex + Dollar.Length);

            // Existing Hash, including the Algorithm Type $6$, the Salt and the Hash
            string ExistingHash = UserEntry.Substring(StartIndex, EndHashIndex - StartIndex);
            string Salt         = UserEntry.Substring(EndHashAlgorithmTypeIndex + Dollar.Length, EndSaltIndex - EndHashAlgorithmTypeIndex - Dollar.Length);

            string NewHash = Linux.Crypt(theModel.OldPassword, HashAlgorithmType + Salt + Dollar);

            if (ExistingHash != NewHash)
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=7")
                });
            }

            Task <ProcessResult> ChangePassword = ProcessRunner.GetProcessResultAsync("bash", "-c \"echo '" + theModel.Username + ":" + theModel.NewPassword + "' | chpasswd\"");

            ChangePassword.Wait();

            if (ChangePassword.Result.Okay())
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=10")
                });
            }
            else
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Moved,
                    Location = new Uri(RemoveOldQueryString(Context.Request.AbsoluteUri) + "?msg=9")
                });
            }
        }
示例#30
0
 /// <summary>
 /// Halts the Pi. Must be running as SU
 /// </summary>
 /// <returns>The process result</returns>
 public static async Task <ProcessResult> ShutdownAsync()
 {
     return(await ProcessRunner.GetProcessResultAsync("halt"));
 }