login to website in script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

login to website in script

#1 Post by Matt Williamson » 13 Jan 2021 07:52

Since search is broken, I wonder if anyone can help me with this. I have an internal website on my corporate network that I want to automate logging into and searching a specific field, extracting something from it and writing to an excel spreadsheet. It has to be in IE11. The site has a lot of Javascript behind it and I can run the debugger in it and see the code but I can't figure out the form name. I've tried it in excel VBA and powershell so far with no luck because they both need the form name to be able to post. Here is the code from the website.

Code: Select all

!--Login.XSL begin--><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Support Center</title>
<link rel="stylesheet" href="Views\Default\Brand.css" type="text/css"><!--FormEncode.xsl begin--><script type="text/javascript">
			function Encode(Form)
			{
				i=0;
				j=0;
				urlstr="";
				Form.EncodedUrl.value="";
				Time = new Date();
				if (Form.eventtime)
				{

					Form.eventtime.value = Time.getTime();
				}
				else
				{
					TimeStamp = document.createElement("input");
					with(TimeStamp){
						name = "eventtime";
						id = "eventtime";
						type = "hidden";
						value =  Time.getTime();
					}
					Form.appendChild(TimeStamp);
				}
				nSubmitButtonCount = 0;
				strSubmitButtonName = "";
				nSubmitButtonValue = 0;
				for(i=0; i < Form.length; i++)
				{
					str="";
					if(Form.elements[i].type=="text" ||
						Form.elements[i].type=="textarea" ||
						Form.elements[i].type=="password" ||
						Form.elements[i].type=="hidden")
					{
						urlstr = urlstr + Form.elements[i].name + "=";
						str = EncodeString(Form.elements[i].value);
						urlstr = urlstr + str + "&";
						
						if (IsBlankable(Form.elements[i].name))
						{
							Form.elements[i].value = "";
							
						}
					}
					else if (Form.elements[i].type=="submit") {
						nSubmitButtonCount = nSubmitButtonCount + 1;
						nSubmitButtonValue = Form.elements[i].value;
						strSubmitButtonName = Form.elements[i].name;
					}
				}
				
	
				if (nSubmitButtonCount == 1){
					urlstr =  urlstr + strSubmitButtonName + "=" + nSubmitButtonValue  + "&";
				}
				Form.EncodedUrl.value = urlstr;
				
				return true;
			}

			function EncodeString(Value)
			{
				str = "";
				var i = 0;
				var j = 0;
				for(j=0; j <Value.length; j++)
				{

					code =  Value.charCodeAt(j);
					if (code > 128)
					{
						val = code.toString(16);
						for (i=4-val.length; i > 0; i--)
						{
							val = "0" + val;
						}
						str = str + "%u" + val;
					}
					else {
						val = Value.charAt(j);
						str = str + escape(val);
					}
				}

				return str;

			}

			function IsBlankable(name)
			{
				

				if ((name == "type") || (name == "menuchoice") || (name == "community"))
				{
					return false;
				}
				return true;
			}

			
			function PostEncode(Form)
			{
				if (Encode(Form))
				{
					var strEncodedUrl = escape(Form.EncodedUrl.value);
					Form.EncodedUrl.value = strEncodedUrl;
					
					//Set the limit for field size.
					var FormFieldLimit = 102399;
										
										
					  //If the length of the object is greater than the limit, break it
					  //into multiple objects.
					  if (strEncodedUrl.length > FormFieldLimit)
					  {
					   	 Form.EncodedUrl.value = strEncodedUrl.substr(0, FormFieldLimit)
					   	 strEncodedUrl = strEncodedUrl.substr(FormFieldLimit );
					   	 var nIndex = 1;
					   	 while (strEncodedUrl.length > 0)
					   	 {
						      var objTEXTAREA = document.createElement("TEXTAREA");
							var objEncodedUrl = document.createElement("input");
							with(objEncodedUrl ){
								name = "EncodedUrl" + nIndex;
								id = "EncodedUrl" + nIndex;
								type = "hidden";
								value =  strEncodedUrl.substr(0, FormFieldLimit);
							}
							Form.appendChild(objEncodedUrl);					      
					     		strEncodedUrl = strEncodedUrl.substr(FormFieldLimit);
							nIndex = nIndex + 1;
					   	 }
					  }	
				}
				return true;
			}

		</script><!--FormEncode.xsl end--><script type="text/javascript">//Global variable with id of Technician form field.
						var g_Technician = 'technician';

					
						function SetCookie(Name, Value) 
						{
						    var cookieString = Name + "=" + escape(Value)  + ";";
                            if (document.location.protocol == "https:") {											     
							    cookieString += "secure;";
							}				   
							document.cookie = cookieString;
						}											    

					
						function GetCookieByName(Name) 
						{   
							var Name = Name + "=";
							var nIndex = document.cookie.indexOf(Name);
					   
							if (nIndex != -1) {
					
							     	nIndex += Name.length;
							      	end = document.cookie.indexOf(";", nIndex);  
							      	if (end == -1)  {
					
									end = document.cookie.length;
								 }
								return unescape(document.cookie.substring(nIndex, end)) ;        
							}
							return "";
						}

					
						function  EncodeAndSetCookie(Form)
						{
							var Today = new Date();
							SetCookie(g_Technician, Form.technician.value);	
							return PostEncode(Form);				
						}

					
						function SetFocusOnForm()
						{
							var TechnicianCookie = GetCookieByName(g_Technician);
							var TechId = document.getElementById(g_Technician);
							if (TechnicianCookie && TechnicianCookie != "") {
					
								TechId.value = TechnicianCookie;
								document.getElementById('password').focus();
								return;
							}
							TechId.focus();
						}
						
						function GetPartnerId()
						{
							var name = prompt("To sign in with an SSO root-level technician, leave blank. \n Otherwise enter your Technician SSO Provider ID.","");
							if (name!=null && name!="") {
								document.getElementById('fedLoginLink').href += "&partnerId=" + name;
								return true;
							} else {
								var linkValue = document.getElementById('fedLoginLink').href;
							    document.getElementById('fedLoginLink').href = linkValue.replace('community=&','community=-1&');
								return true;
							}
							return false;
						}
						</script></head>
<body class="WebText" onload="SetFocusOnForm();">
<form method="post" autocomplete="off" action="login.aspx" onsubmit="return EncodeAndSetCookie(this);" target="_self"><input type="hidden" name="EncodedUrl"><input type="hidden" name="type" value="12"><input type="hidden" id="community" name=""><input type="hidden" name="value" value=""><input type="hidden" name="menuchoice" value=""><center>

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: login to website in script

#2 Post by Squashman » 13 Jan 2021 12:43

Matt Williamson wrote:
13 Jan 2021 07:52
Since search is broken,
I don't have an answer for your question but you do know you can use Google to search the site. Most of the time that is what I use because it is better at indexing the site then using the site search. Just append this to the end of your Google Search: site:dostips.com

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: login to website in script

#3 Post by Matt Williamson » 13 Jan 2021 13:36

Yes, that is what I figured out earlier. There were only a couple of hits and they just said use telnet which you said was really stupid and I agree.

Post Reply