Esempio n. 1
0
 protected void Page_Load(object sender, System.EventArgs e)
 {
     sbmt.Text = ui.Text("create");
     if (!Page.IsPostBack) {
         foreach (MacroEngineLanguage lang in MacroEngineFactory.GetSupportedUILanguages()) {
             filetype.Items.Add(new ListItem(string.Format(".{0} ({1})", lang.Extension.ToLowerInvariant(), lang.EngineName), lang.Extension));
         }
         filetype.SelectedIndex = 0;
     }
     _loadTemplates(template, filetype.SelectedValue);
 }
Esempio n. 2
0
        private List <string> validScriptingExtensions()
        {
            if (allowedExtensions.Count == 0)
            {
                foreach (MacroEngineLanguage lang in MacroEngineFactory.GetSupportedUILanguages())
                {
                    if (!allowedExtensions.Contains(lang.Extension))
                    {
                        allowedExtensions.Add(lang.Extension);
                    }
                }
            }

            return(allowedExtensions);
        }
Esempio n. 3
0
        public string SaveDLRScript(string fileName, string oldName, string fileContents, bool ignoreDebugging)
        {
            if (AuthorizeRequest(DefaultApps.developer.ToString()))
            {
                if (string.IsNullOrEmpty(fileName))
                {
                    throw new ArgumentNullException("fileName");
                }

                var allowedExtensions = new List <string>();
                foreach (var lang in MacroEngineFactory.GetSupportedUILanguages())
                {
                    if (!allowedExtensions.Contains(lang.Extension))
                    {
                        allowedExtensions.Add(lang.Extension);
                    }
                }


                // validate file
                IOHelper.ValidateEditPath(IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + fileName),
                                          SystemDirectories.MacroScripts);
                // validate extension
                IOHelper.ValidateFileExtension(IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + fileName),
                                               allowedExtensions);


                //As Files Can Be Stored In Sub Directories, So We Need To Get The Exeuction Directory Correct
                var lastOccurance   = fileName.LastIndexOf('/') + 1;
                var directory       = fileName.Substring(0, lastOccurance);
                var fileNameWithExt = fileName.Substring(lastOccurance);
                var tempFileName    =
                    IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + directory + DateTime.Now.Ticks + "_" +
                                     fileNameWithExt);

                using (var sw = new StreamWriter(tempFileName, false, Encoding.UTF8))
                {
                    sw.Write(fileContents);
                    sw.Close();
                }

                var errorMessage = "";
                if (!ignoreDebugging)
                {
                    var root = Document.GetRootDocuments().FirstOrDefault();
                    if (root != null)
                    {
                        var args = new Hashtable();
                        var n    = new Node(root.Id);
                        args.Add("currentPage", n);

                        try
                        {
                            var engine           = MacroEngineFactory.GetByFilename(tempFileName);
                            var tempErrorMessage = "";
                            var xpath            = UmbracoSettings.UseLegacyXmlSchema ? "/root/node" : "/root/*";
                            if (
                                !engine.Validate(fileContents, tempFileName, Node.GetNodeByXpath(xpath),
                                                 out tempErrorMessage))
                            {
                                errorMessage = tempErrorMessage;
                            }
                        }
                        catch (Exception err)
                        {
                            errorMessage = err.ToString();
                        }
                    }
                }

                if (errorMessage == "")
                {
                    var savePath = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + fileName);

                    //deletes the file
                    if (fileName != oldName)
                    {
                        var p = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + oldName);
                        if (File.Exists(p))
                        {
                            File.Delete(p);
                        }
                    }

                    using (var sw = new StreamWriter(savePath, false, Encoding.UTF8))
                    {
                        sw.Write(fileContents);
                        sw.Close();
                    }
                    errorMessage = "true";
                }

                File.Delete(tempFileName);


                return(errorMessage.Replace("\n", "<br/>\n"));
            }

            return("false");
        }