MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/imenso.co/mps/StClairSurvey/Default.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail

Partial Class _Default
    Inherits System.Web.UI.Page


#Region "Initial_Settings"

    Private ConnStringName As String = "SQL_Cnct_MadisCnctDB"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'        Dim ipAddress as String = Get_IPAddress()
'        If ipAddress = "40.143.42.116" OrElse ipAddress = "70.60.102.90" Then
'            Me.Btn_Submit_Survey.Enabled = False
'            Response.Write("<font color='red' style='text-size:2.4em;'><b><center>MPS Employees NEED NOT FILL OUT - GO AWAY</center></b></font><br />")
'        End If
    End Sub

#End Region



#Region "Local_Standard_Utility"

    Protected Function Get_IPAddress() As String
        'The X-Forwarded-For (XFF) HTTP header field Is a de facto standard for identifying the originating IP address of a 
        'client connecting to a web server through an HTTP proxy Or load balancer
        Dim IP_Address As String = HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR")

        If IP_Address = "" Or IP_Address Is Nothing Then
            IP_Address = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
        End If

        Return IP_Address
    End Function


    Protected Function InsertSurvey(ByVal Q1 As String, ByVal Q2 As String, ByVal Q3 As String, ByVal Q4 As String, ByVal Q5 As String,
                                              ByVal Q6 As String, ByVal Q7 As String, ByVal Q8 As String, ByVal Q9 As String, ByVal IP_Address As String,
                                              ByVal User_Agent As String, ByVal User_Platform As String, ByVal User_Browser As String) As Boolean
        '**********************************************************************************************************************************************************'
        ' ****DETAIL: This function adds a new record in selected table
        '**********************************************************************************************************************************************************'
        Dim SqlConnection As New SqlConnection("Server=192.168.0.52;Database=StClairSurvey;uid=StClairSurveyAdmin;pwd=password")

        Using SqlCommand As SqlCommand = New SqlCommand("[dbo].[usp_InsertSurvey]", SqlConnection)
            SqlCommand.CommandType = CommandType.StoredProcedure
            SqlCommand.Parameters.AddWithValue("@Answer01", Q1)
            SqlCommand.Parameters.AddWithValue("@Answer02", Q2)
            SqlCommand.Parameters.AddWithValue("@Answer03", Q3)
            SqlCommand.Parameters.AddWithValue("@Answer04", Q4)
            SqlCommand.Parameters.AddWithValue("@Answer05", Q5)
            SqlCommand.Parameters.AddWithValue("@Answer06", Q6)
            SqlCommand.Parameters.AddWithValue("@Answer07", Q7)
            SqlCommand.Parameters.AddWithValue("@Answer08", Q8)
            SqlCommand.Parameters.AddWithValue("@Answer09", Q9)
            SqlCommand.Parameters.AddWithValue("@IPAddress", IP_Address)
            SqlCommand.Parameters.AddWithValue("@UserAgent", User_Agent)
            SqlCommand.Parameters.AddWithValue("@UserPlatform", User_Platform)
            SqlCommand.Parameters.AddWithValue("@UserBrowser", User_Browser)

            Try
                SqlConnection.Open()
                If Convert.ToInt32(SqlCommand.ExecuteNonQuery()) = 0 Then
                    Return False
                    Exit Function
                End If

		Dim mailMessage As MailMessage = New MailMessage()
		mailMessage.IsBodyHtml = True
		mailMessage.From = New MailAddress("johnb@mpsonlineservices.com", "John Bossaller")
		mailMessage.To.Add("johnb@mpsonlineservices.com")
		'mailMessage.CC.Add(ccAddress)
		'mailMessage.Bcc.Add(bccAddresses)
		mailMessage.SubjectEncoding = Encoding.UTF8
		mailMessage.Subject = "[StClairSurvey] - Results saved to database."
		mailMessage.BodyEncoding = Encoding.UTF8
		mailMessage.Body = "Someone submitted a St. Clair Survey.<br /><br />"

Dim emailBody As New StringBuilder()
emailBody.AppendLine("Somone submitted a St. Clair Survey.<br /><br />")
emailBody.AppendLine("<table width='100%' cellpadding='1' cellspacing='3' border='1'>")
emailBody.AppendLine(String.Format("<tr><td>Answer01</td><td>{0}</td></tr>", Q1))
emailBody.AppendLine(String.Format("<tr><td>Answer02</td><td>{0}</td></tr>", Q2))
emailBody.AppendLine(String.Format("<tr><td>Answer03</td><td>{0}</td></tr>", Q3))
emailBody.AppendLine(String.Format("<tr><td>Answer04</td><td>{0}</td></tr>", Q4))
emailBody.AppendLine(String.Format("<tr><td>Answer05</td><td>{0}</td></tr>", Q5))
emailBody.AppendLine(String.Format("<tr><td>Answer06</td><td>{0}</td></tr>", Q6))
emailBody.AppendLine(String.Format("<tr><td>Answer07</td><td>{0}</td></tr>", Q7))
emailBody.AppendLine(String.Format("<tr><td>Answer08</td><td>{0}</td></tr>", Q8))
emailBody.AppendLine(String.Format("<tr><td>Answer09</td><td>{0}</td></tr>", Q9))
emailBody.AppendLine(String.Format("<tr><td>IPAddress</td><td>{0}</td></tr>", IP_Address))
emailBody.AppendLine(String.Format("<tr><td>UserAgent</td><td>{0}</td></tr>", User_Agent))
emailBody.AppendLine(String.Format("<tr><td>UserPlatform</td><td>{0}</td></tr>", User_Platform))
emailBody.AppendLine(String.Format("<tr><td>UserBrowser</td><td>{0}</td></tr>", User_Browser))
emailBody.AppendLine("</table>")
mailMessage.Body = emailBody.ToString()

		Dim smtpClient As SmtpClient = New SmtpClient("192.168.0.14")
		smtpClient.Port = 25
		smtpClient.EnableSsl = False
		smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network

		' If you set the network credentials before the following line, it will fail.  Every time, for NO reason.  :)
		smtpClient.UseDefaultCredentials = False

		'If smtpRequiresAuthentication Then
		'	smtpClient.Credentials = New NetworkCredential(smtpUsername, smtpPassword)
		'End If

		'Try
			smtpClient.Send(mailMessage)
		'	sentSuccessfully = True
		'Catch ex As Exception
		'	sentSuccessfully = False
		'End Try

            Catch ex As Exception
                'If DebugMode = True Then
                'MsgBox("Error Message: " + ex.Message)
                'End If
		'Response.Write("Error: " & ex.Message)

		Dim mailMessage As MailMessage = New MailMessage()
		mailMessage.IsBodyHtml = True
		mailMessage.From = New MailAddress("johnb@mpsonlineservices.com", "John Bossaller")
		mailMessage.To.Add("johnb@mpsonlineservices.com")
		'mailMessage.CC.Add(ccAddress)
		'mailMessage.Bcc.Add(bccAddresses)
		mailMessage.SubjectEncoding = Encoding.UTF8
		mailMessage.Subject = "[StClairSurvey] - Failed to save results to database."
		mailMessage.BodyEncoding = Encoding.UTF8
'		mailMessage.Body = "There was an issue saving the results to the database.<br /><br />Error: " & ex.Message & "<br /><br />" & ex.ToString()
		mailMessage.Body = "There was an issue saving the results to the database.<br /><br />Error: " & FlattenException(ex) & "<br /><br />"

Dim emailBody As New StringBuilder()
emailBody.AppendLine(String.Format("There was an issue saving the results to the database.<br /><br />Error: {0}<br /><br />", FlattenException(ex)))
emailBody.AppendLine("<table width='100%' cellpadding='1' cellspacing='3' border='1'>")
emailBody.AppendLine(String.Format("<tr><td>Answer01</td><td>{0}</td></tr>", Q1))
emailBody.AppendLine(String.Format("<tr><td>Answer02</td><td>{0}</td></tr>", Q2))
emailBody.AppendLine(String.Format("<tr><td>Answer03</td><td>{0}</td></tr>", Q3))
emailBody.AppendLine(String.Format("<tr><td>Answer04</td><td>{0}</td></tr>", Q4))
emailBody.AppendLine(String.Format("<tr><td>Answer05</td><td>{0}</td></tr>", Q5))
emailBody.AppendLine(String.Format("<tr><td>Answer06</td><td>{0}</td></tr>", Q6))
emailBody.AppendLine(String.Format("<tr><td>Answer07</td><td>{0}</td></tr>", Q7))
emailBody.AppendLine(String.Format("<tr><td>Answer08</td><td>{0}</td></tr>", Q8))
emailBody.AppendLine(String.Format("<tr><td>Answer09</td><td>{0}</td></tr>", Q9))
emailBody.AppendLine(String.Format("<tr><td>IPAddress</td><td>{0}</td></tr>", IP_Address))
emailBody.AppendLine(String.Format("<tr><td>UserAgent</td><td>{0}</td></tr>", User_Agent))
emailBody.AppendLine(String.Format("<tr><td>UserPlatform</td><td>{0}</td></tr>", User_Platform))
emailBody.AppendLine(String.Format("<tr><td>UserBrowser</td><td>{0}</td></tr>", User_Browser))
emailBody.AppendLine("</table>")
mailMessage.Body = emailBody.ToString()

		Dim smtpClient As SmtpClient = New SmtpClient("192.168.0.14")
		smtpClient.Port = 25
		smtpClient.EnableSsl = False
		smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network

		' If you set the network credentials before the following line, it will fail.  Every time, for NO reason.  :)
		smtpClient.UseDefaultCredentials = False

		'If smtpRequiresAuthentication Then
		'	smtpClient.Credentials = New NetworkCredential(smtpUsername, smtpPassword)
		'End If

		'Try
			smtpClient.Send(mailMessage)
		'	sentSuccessfully = True
		'Catch ex As Exception
		'	sentSuccessfully = False
		'End Try

                Return False
                Exit Function
            End Try
        End Using


        ' If there is no error or issue, then return true
        Return True
    End Function

#End Region



#Region "Survey_Submit_Process"

    Protected Sub Btn_Submit_Survey_Click(sender As Object, e As EventArgs) Handles btn_Submit_Survey.Click

        ' --------------------------------------------------------------------------------------------------------'
        ' -- Get the user's submitted values
        ' --------------------------------------------------------------------------------------------------------'

        Dim Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9 As String
        Dim vIPAddress, vUserAgent, vUserPlatform, vUserBrowser As String
        Q1 = Question_1.SelectedValue.ToString()
        Q2 = Question_2.SelectedValue.ToString()
        Q3 = Question_3.SelectedValue.ToString()
        Q4 = Question_4.SelectedValue.ToString()
        Q5 = Question_5.SelectedValue.ToString()
        Q6 = Question_6.SelectedValue.ToString()
        Q7 = Question_7.SelectedValue.ToString()
        Q8 = Question_8.SelectedValue.ToString()
        Q9 = Question_9.SelectedValue.ToString()

        vIPAddress = Get_IPAddress()
        vUserAgent = Request.UserAgent
        vUserPlatform = Request.Browser.Platform
        vUserBrowser = Request.Browser.Type
        ' --------------------------------------------------------------------------------------------------------'



        ' -- Submit the values from the user and save to new record in DB.  Redirect user to 'finished' page -- '
        Try
            ' Submit the values to DB
            If InsertSurvey(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, vIPAddress, vUserAgent, vUserPlatform, vUserBrowser) Then
                ' Hide the survey controls and display the completed message.
                fieldset_Survey.Visible = False
                fieldset_completed.Visible = True
                fieldset_error.Visible = False
            Else
                fieldset_Survey.Visible = False
                fieldset_completed.Visible = False
                fieldset_error.Visible = True
            End If
        Catch ex As Exception
            'MsgBox("Error: " + ex.Message)
            fieldset_Survey.Visible = False
            fieldset_completed.Visible = False
            fieldset_error.Visible = True
        End Try
        ' --------------------------------------------------------------------------------------------------------'


    End Sub

#End Region

    Function FlattenException(ex As Exception) As String
        Dim sb As StringBuilder = New StringBuilder()

        While ex IsNot Nothing
	    sb.AppendLine(ex.Message)
            sb.AppendLine(ex.StackTrace.Replace(VbCrLf, "<br />"))

            ex = ex.InnerException
        End While

        Return sb.ToString()
    End Function

End Class