Ejemplo n.º 1
0
    private bool doGET()
    {
        UserDAO user = (UserDAO)Session["userDAO"];
        String pluginName = Request.QueryString["pluginname"];
        if (pluginName == null)
        {
            // Redirect them back
            SendErrorMessage("Please specify a plugin");
            return false;
        }
        IDBController controller = new SqlController();
        PluginDAO plugin = null;
        try
        {
            plugin = controller.RetrievePlugin(pluginName);
            PluginDescriptionEditor.InnerText = plugin.Description;

            if (!plugin.OwnerID.Equals(user.UserID))
            {
                //SendErrorMessage("That is not a plugin you have written");
                //return false;
                extraJavascript = @"editor.setReadOnly(true);";
            }

            String luacodeFileLoc = LUADefinitions.getLuaScriptLocation(plugin.Name);

            // See if it's there
            if (File.Exists(luacodeFileLoc))
            {
                String luacode = "";
                try
                {
                    luacode = File.ReadAllText(luacodeFileLoc);
                }
                catch (Exception)
                {
                    SendErrorMessage("Could not find plugin " + pluginName);
                    return false;
                }

                editorText.InnerText = luacode;
            }
            else
            {
                SendErrorMessage("Could not find plugin " + pluginName);
                return false;
            }
        }
        catch (CouldNotFindException)
        {
            SendErrorMessage("That is not a valid plugin");
            return false;
        }

        return true;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Splits up the user names in the given TextBox input, finds them in the database and adds them to a HashSet.
    /// </summary>
    /// <param name="textarea"></param>
    /// <returns></returns>
    private HashSet<PluginDAO> ParseFromTextArea(TextBox textarea)
    {
        string[] pluginsSplit;
        if (textarea.Text.IndexOf(',') < 0)
        {
            pluginsSplit = new string[] { textarea.Text.Trim() };
        }
        else
        {
            pluginsSplit = textarea.Text.Split(',');
        }

        HashSet<PluginDAO> plugins = new HashSet<PluginDAO>();

        try
        {
            IDBController controller = new SqlController();
            foreach (string plug in pluginsSplit)
            {
                try
                {
                    plugins.Add(controller.RetrievePlugin(plug.Trim()));
                }
                catch (CouldNotFindException)
                {
                    Response.Redirect(string.Format("ManagePlugins.aspx?grouptag={0}&error={1}{2}{3}",
                    HttpUtility.UrlEncode(_currentGroup.GroupTag),
                    HttpUtility.UrlEncode("Could not find plugin '"),
                    HttpUtility.UrlEncode(plug),
                    HttpUtility.UrlEncode("'")));
                    return null;
                }
            }
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugins.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManagePlugins.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return null;
        }

        return plugins;
    }
Ejemplo n.º 3
0
    private void GetPagePlugin()
    {
        if (null == Request["pluginname"])
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An error occurred retrieving the plugin information")));
            return;
        }

        try
        {
            IDBController controller = new SqlController();
            _currentPlugin = controller.RetrievePlugin(Request["pluginname"]);
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An unknown error occurred loading plugin data. Please try again soon.")));
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugin: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An unknown error occurred loading plugin data. Please try again soon.")));
        }
    }
Ejemplo n.º 4
0
    private bool doPOST()
    {
        UserDAO user = (UserDAO)Session["userDAO"];
        String pluginName = Request.Form["pluginName"];

        String successMessage = "";

        if (pluginName == null)
        {
            // Redirect them back
            SendErrorMessage("Please specify a plugin");
            return false;
        }

        IDBController controller = new SqlController();
        PluginDAO plugin = null;
        try
        {
            plugin = controller.RetrievePlugin(pluginName);

            if (!plugin.OwnerID.Equals(user.UserID))
            {
                SendErrorMessage("That is not a plugin you have written.");
                return false;
            }
            else
            {
                // Go ahead and save it
                String luacodeFileLoc = LUADefinitions.getLuaScriptLocation(plugin.Name);

                // See if it's there
                if (File.Exists(luacodeFileLoc))
                {
                    String luacode = Request.Form["editorText"];
                    try
                    {
                        File.WriteAllText(luacodeFileLoc, luacode);
                        controller.ResetPluginFailedAttemptCount(plugin.PluginID);
                        if (controller.GetPluginFailedAttemptCount(plugin.PluginID) == 0)
                        {
                            // Reenable the plugin
                            controller.EnableGlobalPlugin(plugin.PluginID);
                        }
                        successMessage = "Plugin has been updated.";
                    }
                    catch (Exception)
                    {
                        SendErrorMessage("Could not save plugin.");
                        return false;
                    }
                }
                else
                {
                    SendErrorMessage("Could not save plugin.");
                    return false;
                }
            }
        }
        catch (CouldNotFindException)
        {
            SendErrorMessage("That is not a valid plugin");
            return false;
        }

        // Always redirect on POST
        Response.Redirect(string.Format("EditPlugin.aspx?pluginname={0}&success={1}", HttpUtility.UrlEncode(pluginName), HttpUtility.UrlEncode(successMessage)));

        return false;
    }