Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74455

[micro-focus-performance-center-integration] Extract inline script blocks and event handlers in com/microfocus/performancecenter/integration/pctestrun/PcTestRunBuilder/config.jelly

XMLWordPrintable

      Problems

      == Inline Script Block
      Line: 93
      ----
      <script>
      
      
          function assignhostPath(){
              setTimeout(function(){
                  var href = window.location.href;
                  var splitter = href.split("/job");
                  var baseurl = splitter[0];
                  var p = document.getElementById('serverAndPort');
                  if(p){
                      p.value = baseurl;
                  }
              },50)
      
          }
      
      
      
      		function isAddRunToTrendReportEnabled(sender) {
      			var x = sender.selectedIndex;
      			var y = sender.options;
      			var addRunToTrendReport = document.getElementById('trendReportTable');
      			//alert(y[x].value);
      			if (y[x].value === 'COLLATE_AND_ANALYZE'){
      				addRunToTrendReport.classList.remove("disabledLine");
      			}
      			else{
      				addRunToTrendReport.classList.add("disabledLine");
      			}
      						
      		}
      		
      		function onPostRunActionLoad(){
      			var postRunAction = document.getElementById('postRunAction');
      			if(postRunAction != null){
      			    isAddRunToTrendReportEnabled(postRunAction);
      			}
      
      		}
      
      		function verifyURLAvailable(){
      
                  var pcServerAndTenant = getLreServer(document.getElementsByName("pc.pcServerName")[0].value);
                  var scheme = "http";
                  if(document.getElementsByName("pc.HTTPSProtocol")[0].checked){
                      scheme = "https"
                  }
                  if (pcServerAndTenant.length == 2 &amp;&amp; pcServerAndTenant[0]) {
                      var popup = window.open(scheme + "://" + pcServerAndTenant[0] + "/loadtest/"  + pcServerAndTenant[1]);
                      popup.opener = null;
                  } else {
                      alert("LoadRunner Enterprise Server name is missing.");
                  }
                  return false;
                  }
      
                  function getLreServer(lreServer){
                      var delimiterSlash = "/";
                      var delimiterQuestionMark = "?";
                      var useDelimiter = delimiterSlash;
                      var strServerAndTenant = [lreServer, ""];
                      var theLreServer = lreServer;
                      if (lreServer != null &amp;&amp; !(lreServer.length === 0)) {
                          theLreServer = /* replace */ lreServer.toLowerCase().split("http://").join("");
                          theLreServer = /* replace */ theLreServer.split("https://").join("");
                          theLreServer = /* replace */ theLreServer.split("/lre").join("");
                          theLreServer = /* replace */ theLreServer.split("/site").join("");
                          theLreServer = /* replace */ theLreServer.split("/loadtest").join("");
                          theLreServer = /* replace */ theLreServer.split("/pcx").join("");
                          theLreServer = /* replace */ theLreServer.split("/adminx").join("");
                          theLreServer = /* replace */ theLreServer.split("/admin").join("");
                          theLreServer = /* replace */ theLreServer.split("/login").join("");
                      }
                      if (theLreServer != null &amp;&amp; !(theLreServer.length === 0)) {
                          if ( /* contains */(theLreServer.indexOf("/") != -1)) {
                              useDelimiter = delimiterSlash;
                          }
                          else if ( /* contains */(theLreServer.indexOf("?") != -1)) {
                              useDelimiter = delimiterQuestionMark;
                          }
                          var severTenantArray = theLreServer.split(useDelimiter);
                          if (severTenantArray.length &gt; 0) {
                              strServerAndTenant[0] = severTenantArray[0];
                              if (severTenantArray.length &gt; 1) {
                                  if (useDelimiter === delimiterQuestionMark) {
                                      strServerAndTenant[1] = delimiterQuestionMark + severTenantArray[1];
                                  }
                                  else {
                                      strServerAndTenant[1] = severTenantArray[1];
                                  }
                              }
                          }
                      }
                      return strServerAndTenant;
                  }
      		</script>
      ----
      
      == Inline Script Block
      Line: 227
      ----
      <script>assignhostPath();</script>
      ----
      
      == Inline Script Block
      Line: 311
      ----
      <script>onPostRunActionLoad();</script>
      ----
      
      == Inline Event Handler
      Line: 223
      ----
      <f:textbox id="serverAndPort" name="pc.serverAndPort" value="" onchange="assignhostPath()" />
      ----
      
      == Inline Event Handler
      Line: 247
      ----
      <a id="pcServerURL" href="#" onclick="verifyURLAvailable();return false;">
      ----
      
      == Inline Event Handler
      Line: 284
      ----
      <select id="postRunAction" name="pc.postRunAction" onchange="isAddRunToTrendReportEnabled(this)">
      ----
      
      == Inline Event Handler
      Line: 327
      ----
      <f:textbox name="timeslotDurationHours" id="${h_id}"
      						value="${instance.pcTestRunModel.timeslotDurationHours}" default="0"
      						style="width:40px;height:24px;text-align:center"
      						onchange="if (!value.Startwith('&#x24;&#x24;')) {
      										var hours = parseInt(value);
      										value = (isNaN(hours) || (hours &lt; 0)) ? 0 : ((hours &gt; 480) ? 480 : hours);
      										var minutes = document.getElementById('${m_id}');
      										if (value == 0 &amp;&amp; minutes.value &lt; 30) minutes.value = 30;
      										else if (value == 480) minutes.value = 0; }" />
      ----
      
      == Inline Event Handler
      Line: 338
      ----
      <input type="button" value=" /\ "
      						style="font-size:4px;margin:0;padding:0;width:20px;height:15px;vertical-align:top"
      						onclick="var hours = document.getElementById('${h_id}');
      										var v = parseInt(hours.value);
      										v = (isNaN(v) || v &lt; 0) ? 0 : v + 1;
      										hours.value = (v &gt; 480) ? 480 : v;" />
      ----
      
      == Inline Event Handler
      Line: 350
      ----
      <f:textbox name="timeslotDurationMinutes" id="${m_id}"
      						value="${instance.pcTestRunModel.timeslotDurationMinutes}" default="30"
      						style="width:40px;height:24px;text-align:center"
      						onchange="if (!value.Startwith('&#x24;&#x24;')) {
      										var v = parseInt(value);
      										v = isNaN(v) || (v &lt; 0) || (v &gt; 59) ? 0 : v ;
      										value = (v &lt; 30 &amp;&amp; document.getElementById('${h_id}').value == 0) ? 30 : v; }" />
      ----
      
      == Inline Event Handler
      Line: 359
      ----
      <input type="button" value=" /\ "
      						style="font-size:4px;margin:0;padding:0;width:20px;height:15px;vertical-align:top"
      						onclick="var minutes = document.getElementById('${m_id}');
      										var v = parseInt(minutes.value);
      										v = (v + 15) % 60; minutes.value = v - v % 15;
      										var hours = document.getElementById('${h_id}');
      										if (hours.value == 0 &amp;&amp; minutes.value &lt; 30)
      											minutes.value = 30;" />
      ----
      
      == Inline Event Handler
      Line: 374
      ----
      <input type="button" value=" \/ "
      						style="font-size:4px;margin:0;padding:0;width:20px;height:14px;vertical-align:middle"
      						onclick="var hours = document.getElementById('${h_id}');
      										var v = parseInt(hours.value);
      										v = isNaN(v) || v &lt; 1 ? 1 : hours.value = v - 1;
      										var minutes = document.getElementById('${m_id}');
      										if (hours.value == 0 &amp;&amp; minutes.value &lt; 30)
      											minutes.value = 30;" />
      ----
      
      == Inline Event Handler
      Line: 384
      ----
      <input type="button" value=" \/ "
      						style="font-size:4px;margin:0;padding:0;width:20px;height:14px;vertical-align:middle"
      						onclick="var minutes = document.getElementById('${m_id}');
      										var v = parseInt(minutes.value);
      										v = (v + 45) % 60;
      										if (v % 15 != 0)
      											v = v + 15 - v % 15;
      										if (document.getElementById('${h_id}').value == 0 &amp;&amp; v &lt; 30)
      											v = 45;
      										minutes.value= v" />
      ----
      

      Solutions

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks
      https://www.jenkins.io/doc/developer/security/csp/#inline-event-handlers

            Unassigned Unassigned
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: