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();
            }
        }
        public static HardwareDetails CreateDetails(HardwareTypeEnum HardwareIndex)
        {
            /*
             * Select hardware type
             *  Popcorn Hour A-100
             *  Popcorn Hour A-110
             *  Popcorn Hour A-200
             *  Popcorn Hour A-200 (USB)
             *  Popcorn Hour A-210
             *  Popcorn Hour A-210 (USB)
             *  Popcorn Hour S-210
             *                  Popcorn Hour S-210 (USB)
             *                  Popcorn Hour B-110
             *  Popcorn Hour C-200
             *  Popcorn Hour C-200 (USB)
             *  Popcorn Hour A-300
             *  Popcorn Hour A-300 (USB)
             *  Popcorn Hour C-300
             *  Popcorn Hour C-300 (USB)
             *  Popcorn Hour A-400
             *  Popcorn Hour A-400 (USB)
             *  Popcorn Hour A-400 (SD Card)
             *  Popcorn Hour A-410
             *  Popcorn Hour A-410 (USB)
             *  Popcorn Hour A-410 (SD Card)
             *  Popcorn Hour A-500
             *  Popcorn Hour A-500 (USB)
             *  Popcorn Hour A-500 (SD Card)
             *  Popcorn Hour A-500 (Esata)
             *  Popcorn Hour VTEN
             *  Popcorn Hour VTEN (USB)
             *  Popcorn Hour VTEN (SD Card)
             *  Popcorn Hour VTEN (Esata)
             *  eGreat
             *  Digitek HDX
             *  Kaiboer
             *  All others
             */

            HardwareDetails result;

            switch (HardwareIndex)
            {
            case HardwareTypeEnum.A100:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "", DefaultWebserverSubFolder = "HARD_DISK", RepositoryType = "AB", DefaultServerName = "PCH-A100", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A110:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "", DefaultWebserverSubFolder = "HARD_DISK", RepositoryType = "AB", DefaultServerName = "PCH-A110", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.B110:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "AB", DefaultServerName = "PCH-B110", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A200:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "C", DefaultServerName = "PCH-A200", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A210:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "C", DefaultServerName = "PCH-A210", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.S210:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "C", DefaultServerName = "PCH-S210", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.C200:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "C", DefaultServerName = "PCH-C200", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A300:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "C", DefaultServerName = "PCH-A300", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.C300:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "C", DefaultServerName = "PCH-C300", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A400:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "A4", DefaultServerName = "PCH-A400", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A410:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "A4", DefaultServerName = "PCH-A410", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A500:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "V", DefaultServerName = "PCH-A500", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.VTEN:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "SATA_DISK", DefaultWebserverSubFolder = "SATA_DISK", RepositoryType = "V", DefaultServerName = "PCH-VTEN", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A200_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "C", DefaultServerName = "PCH-A200", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A210_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "C", DefaultServerName = "PCH-A210", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.S210_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "C", DefaultServerName = "PCH-S210", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.C200_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "C", DefaultServerName = "PCH-C200", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A300_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "C", DefaultServerName = "PCH-A300", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.C300_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "C", DefaultServerName = "PCH-C300", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A400_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "A4", DefaultServerName = "PCH-A400", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A410_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "A4", DefaultServerName = "PCH-A410", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A500_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "V", DefaultServerName = "PCH-A500", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.VTEN_USB:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE", DefaultWebserverSubFolder = "USB_DRIVE", RepositoryType = "V", DefaultServerName = "PCH-VTEN", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A400_SDC:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE_SD_CARD", DefaultWebserverSubFolder = "USB_DRIVE_SD_CARD", RepositoryType = "A4", DefaultServerName = "PCH-A400", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A410_SDC:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE_SD_CARD", DefaultWebserverSubFolder = "USB_DRIVE_SD_CARD", RepositoryType = "A4", DefaultServerName = "PCH-A410", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A500_SDC:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE_SD_CARD", DefaultWebserverSubFolder = "USB_DRIVE_SD_CARD", RepositoryType = "V", DefaultServerName = "PCH-A500", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.A500_ESAT:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "ESATA_DRIVE", DefaultWebserverSubFolder = "ESATA_DRIVE", RepositoryType = "V", DefaultServerName = "PCH-A500", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.VTEN_SDC:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "USB_DRIVE_SD_CARD", DefaultWebserverSubFolder = "USB_DRIVE_SD_CARD", RepositoryType = "V", DefaultServerName = "PCH-VTEN", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.VTEN_ESAT:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "ESATA_DRIVE", DefaultWebserverSubFolder = "ESATA_DRIVE", RepositoryType = "V", DefaultServerName = "PCH-VTEN", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            case HardwareTypeEnum.EGREAT:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "", DefaultWebserverSubFolder = "HARD_DISK", RepositoryType = "AB", DefaultServerName = "HDEYESHOT", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;

            default:
                result = new HardwareDetails()
                {
                    DefaultFTPSubFolder = "", DefaultWebserverSubFolder = "HARD_DISK", RepositoryType = "AB", DefaultServerName = "(ip address)", DefaultFtpUsername = "******", DefaultFtpPassword = "******"
                };
                break;
            }

            return(result);
        }