All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.throttling.trottle-policy-editor_ajaxprocessor.jsp Maven / Gradle / Ivy



<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.mediators.throttle.admin.stub.types.ThrottlePolicy" %>
<%@ page import="org.wso2.carbon.mediators.throttle.admin.stub.types.InternalData" %>
<%@ page import="org.wso2.carbon.mediator.throttle.client.ThrottleClient" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ page import="java.util.Map" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>

<%         
    // Set standard HTTP/1.1 no-cache headers.
    response.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
    // Set IE extended HTTP/1.1 no-cache headers.
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");

    boolean popup = false;
    if ("true".equals(request.getParameter("popup"))) {
        popup = true;
    }
    
    String policyID = request.getParameter("policyID");
    Map policyXMLMap = (Map) request.getSession().getAttribute("throttle_policy_map");
    String policyXML = "";
    if (policyXMLMap != null) {
        policyXML = (String) policyXMLMap.get(policyID);
        if (policyXML == null) {
            policyXML = "";
        }
    }

    String param = "policyID=" + policyID;
    if (popup) {
        param = param + "&popup=true";
    }

    if (request.getParameter("backURL") != null) {
        session.setAttribute("backURL", request.getParameter("backURL"));
    }

    String BUNDLE = "org.wso2.carbon.mediator.throttle.ui.i18n.Resources";
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE, request.getLocale());
    String header = bundle.getString("throttling.configuration.mediator");

    //Obtaining the client-side ConfigurationContext instance.
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    //Server URL which is defined in the server.xml
    String serverBackendURL = CarbonUIUtil.getServerURL(config.getServletContext(),
            session);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ThrottlePolicy policy;

    try {
        ThrottleClient client = new ThrottleClient(cookie,
                serverBackendURL, configContext, request.getLocale());
        policy = client.toThrottlePolicy(policyXML, request.getParameter("loadDefault"));

    } catch (Exception e) {
%>

<%
        return;
    }

    String maxAccesses = "";
    if (policy.getMaxConcurrentAccesses() != 0) {
        maxAccesses = String.valueOf(policy.getMaxConcurrentAccesses());
    }

    String htmlString = "";
    String disableFields;
    int newRows = 0;

    //If the incoming internal configs are not empty, load them
    if (policy.getMaxConcurrentAccesses() != 0 ||
            policy.getInternalConfigs() != null && policy.getInternalConfigs()[0] != null) {

        InternalData[] data = policy.getInternalConfigs();
        if (data != null) {
            newRows = data.length;

            String opt1, opt2, opt3, opt4, opt5;
            int f2, f3, f4;
            for (int i = 0; i < data.length; i++) {
                opt1 = "IP";
                opt2 = "DOMAIN";
                opt3 = "Control";
                opt4 = "Deny";
                opt5 = "Allow";
                disableFields = "";
                if (data[i] != null) {
                    if (data[i].getAccessLevel() == 1) {
                        opt3 = "Deny";
                        opt4 = "Control";
                        disableFields = "disabled=\'true\'";
                    } else if (data[i].getAccessLevel() == 2) {
                        opt3 = "Allow";
                        opt5 = "Control";
                        disableFields = "disabled=\'true\'";
                    }
                    if (data[i].getRangeType().equals("DOMAIN")) {
                        opt1 = "DOMAIN";
                        opt2 = "IP";
                    }
                    f2 = data[i].getMaxRequestCount();
                    f3 = data[i].getUnitTime();
                    f4 = data[i].getProhibitTimePeriod();
                    htmlString += "\n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            \n" +
                            "            " + bundle.getString("throttling.delete") + "\n" +
                            "        \n";
                } else {
                    newRows--;
                }
            }
        }
    }
%>


<%
    if (!popup) {
%>

<%
    }
%>



<%= header%>

 

<%= htmlString%>
" onclick="submitForm();" class="button"/> " onclick="resetForm();" class="button"/> " onclick="loadDefault();" class="button"/> " onclick="clearAll();" class="button"/> " class="button"/>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy