private static string FixFtpFolderPrefix(string server, string username, string password, string location)
        {
            if (FtpFolderPrefix != "/" + Settings.Default.FTPSubFolder + "/")
            {
                HardwareDetails det = HardwareDetailsFactory.CreateDetails((HardwareTypeEnum)Enum.Parse(typeof(HardwareTypeEnum), Settings.Default.HardwareType));

                if (Settings.Default.FTPSubFolder.Length > 0)
                {
                    FtpFolderPrefix = "/" + Settings.Default.FTPSubFolder + "/";
                }
                else
                {
                    FtpFolderPrefix = "/";
                }
            }
            if (Settings.Default.FTPSubFolder != "")
            {
                GuessFolder = IsFtpCorrect(server, username, password);
                if (GuessFolder == FtpFolderPrefix)
                {
                    return(FtpFolderPrefix + ((location[0] == '/') ? location.Substring(1) : location));
                }
                else
                {
                    return(GuessFolder + ((location[0] == '/') ? location.Substring(1) : location));
                }
            }
            else
            {
                return(FtpFolderPrefix + ((location[0] == '/') ? location.Substring(1) : location));
            }
        }
Exemple #2
0
        public static string StartScript(string server, string script)
        {
            FtpCommands.SetExecutePermissions(Settings.Default.Server, Settings.Default.Username, Settings.Default.Password, script.Split('?')[0], false);

            HardwareDetails det      = HardwareDetailsFactory.CreateDetails((HardwareTypeEnum)Enum.Parse(typeof(HardwareTypeEnum), Settings.Default.HardwareType));
            string          resquest = string.Empty;
            var             port     = 0;

            if (det.RepositoryType == "z")
            {
                script    = "/share/" + script;
                script    = Regex.Replace(script, @"\?", " ");
                resquest  = Regex.Replace(script, @"\&", " ");
                resquest += "\n";
                port      = 23;
            }
            else
            {
                resquest += "GET " + ((Settings.Default.WebserverSubFolder.Length > 0) ? "/" + Settings.Default.WebserverSubFolder + "/" : "/") + script + " HTTP/1.1" + "\r\n";
                resquest += "Host: localhost.drives:8883" + "\r\n";
                resquest += "\r\n";
                port      = 8883;
            }


            TcpClient clnt = new TcpClient();

            clnt.Connect(server, port);

            ASCIIEncoding ascend = new ASCIIEncoding();

            byte[] send = ascend.GetBytes(resquest);
            clnt.GetStream().Write(send, 0, send.Length);
            clnt.GetStream().Flush();

            string response = string.Empty;

            byte[] readbuffer = new byte[1024];
            int    readbytes  = 0;

            //clnt.GetStream().ReadTimeout = 30000;
            do
            {
                readbytes = 0;
                try
                {
                    readbytes = clnt.GetStream().Read(readbuffer, 0, readbuffer.Length);
                    response += ascend.GetString(readbuffer, 0, readbytes);
                }
                catch (IOException)
                {
                }


                Thread.Sleep(100);
            }while ((readbytes != 0) && (!response.ToLower().Contains("</html>") && (!response.ToLower().Contains(new string(new char[] { (char)4 })))));
            return(response);
        }
        private void FillMetaInfo()
        {
            HardwareDetails det = HardwareDetailsFactory.CreateDetails((HardwareTypeEnum)Enum.Parse(typeof(HardwareTypeEnum), Settings.Default.HardwareType));

            if ((Directory.GetFiles(LocalFolder).Length == 0) && (Directory.GetDirectories(LocalFolder).Length == 1))
            {
                LocalFolder = Directory.GetDirectories(LocalFolder)[0] + Path.DirectorySeparatorChar;
            }

            if (InstallItem is RepositoryApplicationInfo)
            {
                RepositoryApplicationInfo app = (RepositoryApplicationInfo)InstallItem;
                UploadLocation      = "/";
                CleanupAfterInstall = (app.Name != string.Empty);

                //executing commands (firmare, clean etc) will not have an appname
                //and will not require a appinit or installprepare
                if (app.Name != string.Empty)
                {
                    ExecuteScriptSequence.Add(Settings.Default.AppInitScriptURL.Substring(Settings.Default.AppInitScriptURL.LastIndexOf("/") + 1));
                    if (!app.InstallScript.StartsWith("Apps/"))
                    {
                        ExecuteScriptSequence.Add(string.Format(Settings.Default.InstallPrepareScriptURL.Substring(Settings.Default.InstallPrepareScriptURL.LastIndexOf("/") + 1) + "?autostart_add={0}&webservice_name={1}&webservice_url={2}", "", HttpCommands.UrlEncode(app.Name), HttpCommands.UrlEncode(app.GayaInterfaceURL)));
                    }
                    else
                    {
                        ExecuteScriptSequence.Add(string.Format(Settings.Default.InstallPrepareScriptURL.Substring(Settings.Default.InstallPrepareScriptURL.LastIndexOf("/") + 1) + "?autostart_add={0}&webservice_name={1}&webservice_url={2}", "", string.Empty, string.Empty));
                    }
                }
                ExecuteScriptSequence.Add(app.InstallScript);

                DeleteFoldersBeforeInstall.Clear();
                DeleteFilesBeforeInstall.Clear();
            }

            if (InstallItem is RepositoryThemeInfo)
            {
                RepositoryThemeInfo theme = (RepositoryThemeInfo)InstallItem;
                UploadLocation      = "/Photo/_theme_/";
                CleanupAfterInstall = false;

                ExecuteScriptSequence.Clear();

                DeleteFoldersBeforeInstall.Add(UploadLocation);
                DeleteFilesBeforeInstall.Add("/Photo/_theme_/.config");
            }

            if (InstallItem is RepositoryCustomMenuInfo)
            {
                if (det.RepositoryType == "AB")
                {
                    RepositoryCustomMenuInfo customMenu = (RepositoryCustomMenuInfo)InstallItem;

                    if (Directory.GetDirectories(LocalFolder, "Photo").Length > 0)
                    {
                        UploadLocation = "/";
                    }
                    else
                    {
                        UploadLocation = "/Photo/_index_/";
                    }

                    CleanupAfterInstall = false;

                    ExecuteScriptSequence.Clear();

                    DeleteFoldersBeforeInstall.Add("/Photo/_index_/");
                    DeleteFilesBeforeInstall.Add("/index.htm");
                }

                if (det.RepositoryType == "A4")
                {
                    RepositoryCustomMenuInfo customMenu = (RepositoryCustomMenuInfo)InstallItem;

                    UploadLocation      = "/.home/";
                    CleanupAfterInstall = false;

                    ExecuteScriptSequence.Clear();

                    DeleteFoldersBeforeInstall.Add("/.home/firmwareupdate/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/images/widgets/sevenDaysForecast/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/images/widgets/weatherbug/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/images/menu/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/images/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/xml/.profile/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/xml/data/");
                    DeleteFoldersBeforeInstall.Add("/.home/source/");
                    DeleteFoldersBeforeInstall.Add("/.home/components/popMsg/xml/key/");
                    DeleteFoldersBeforeInstall.Add("/.home/components/popMsg/");
                    DeleteFoldersBeforeInstall.Add("/.home/");
                }

                if (InstallItem is RepositoryWaitImagesInfo)
                {
                    RepositoryWaitImagesInfo waitImages = (RepositoryWaitImagesInfo)InstallItem;
                    UploadLocation      = "/Photo/_waitimages_/";
                    CleanupAfterInstall = false;

                    ExecuteScriptSequence.Add(Settings.Default.InstallPrepareScriptURL.Substring(Settings.Default.InstallPrepareScriptURL.LastIndexOf("/") + 1));

                    DeleteFoldersBeforeInstall.Add("/Photo/_waitimages_/");
                    DeleteFilesBeforeInstall.Clear();
                }

                if (InstallItem is RepositoryWebserviceInfo)
                {
                    RepositoryWebserviceInfo webservice = (RepositoryWebserviceInfo)InstallItem;
                    UploadLocation      = "/";
                    CleanupAfterInstall = true;

                    ExecuteScriptSequence.Add(string.Format(Settings.Default.InstallPrepareScriptURL.Substring(Settings.Default.InstallPrepareScriptURL.LastIndexOf("/") + 1) + "?autostart_add={0}&webservice_name={1}&webservice_url={2}", "", HttpCommands.UrlEncode(webservice.Name), HttpCommands.UrlEncode(webservice.WebserviceUrl)));

                    DeleteFoldersBeforeInstall.Clear();
                    DeleteFilesBeforeInstall.Clear();
                }
            }
        }
Exemple #4
0
        private static void SelectMainRepository()
        {
            RepositoryLocations _repositoryLocations = new RepositoryLocations();

            string Language = Settings.Default.UILanguage;

            if (!Enum.IsDefined(typeof(HardwareTypeEnum), Settings.Default.HardwareType))
            {
                return;
            }

            HardwareDetails det = HardwareDetailsFactory.CreateDetails((HardwareTypeEnum)Enum.Parse(typeof(HardwareTypeEnum), Settings.Default.HardwareType));

            bool found = false;
            int  i     = 0;

            while ((i < _repositoryLocations.MainRepositories.Count) && (!found))
            {
                if (_repositoryLocations.MainRepositories[i].Name.Equals("Main_Type" + det.RepositoryType + "_" + Language, StringComparison.CurrentCultureIgnoreCase))
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }



            if (found)
            {
                bool changed = false;
                foreach (RepositoryLocationInfo info in _repositoryLocations.MainRepositories)
                {
                    if (info.Name.StartsWith("Main_Type" + det.RepositoryType + "_" + Language, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (!info.Enabled)
                        {
                            info.Enabled = true;
                            changed      = true;
                        }
                    }
                    else
                    if (info.Name.StartsWith("Main_", StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (info.Enabled)
                        {
                            info.Enabled = false;
                            changed      = true;
                        }
                    }
                }

                if (changed)
                {
                    _repositoryLocations.SaveRepository();
                }
            }
            else
            {
                foreach (RepositoryLocationInfo info in _repositoryLocations.MainRepositories)
                {
                    if (info.Name.StartsWith("Main_Type" + det.RepositoryType + "_English", StringComparison.CurrentCultureIgnoreCase))
                    {
                        info.Enabled = true;
                    }
                    else
                    if (info.Name.StartsWith("Main_", StringComparison.CurrentCultureIgnoreCase))
                    {
                        info.Enabled = false;
                    }
                }

                _repositoryLocations.SaveRepository();
            }
        }