Новый участник
Сообщения: 42
Благодарности: 0
|
Профиль
|
Отправить PM
| Цитировать
Здравствуйте! Мне понадобилось изменить исходный код плагина в Wordpress через админку. вот я так начал программу
Код: 
Dim myLogin As String = txtLogin.Text
Dim myPass As String = txtPass.Text
Dim myUrl As String = txtSite.Text
Dim myHttpWebRequest As HttpWebRequest
Dim myHttpWebResponse As HttpWebResponse
Dim sCookies As String = "wordpress_test_cookie=WP+Cookie+check"
myHttpWebRequest = HttpWebRequest.Create(myUrl & "/wp-login.php")
myHttpWebRequest.Method = "POST"
myHttpWebRequest.Referer = myUrl & "/wp-admin"
myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1"
myHttpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
myHttpWebRequest.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3")
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
If Not String.IsNullOrEmpty(sCookies) Then
myHttpWebRequest.Headers.Add(HttpRequestHeader.Cookie, sCookies)
End If
myHttpWebRequest.AllowAutoRedirect = False
Dim sQueryString As String = "log=" & myLogin & "&pwd=" & myPass
Dim ByteArr As Byte() = Encoding.GetEncoding(1251).GetBytes(sQueryString)
myHttpWebRequest.ContentLength = ByteArr.Length()
myHttpWebRequest.GetRequestStream().Write(ByteArr, 0, ByteArr.Length)
myHttpWebResponse = myHttpWebRequest.GetResponse()
Dim myStreamReader As New StreamReader(myHttpWebResponse.GetResponseStream, Encoding.GetEncoding(65001))
sCookies = ""
If Not String.IsNullOrEmpty(myHttpWebResponse.Headers("Set-Cookie")) Then
sCookies = myHttpWebResponse.Headers("Set-Cookie")
End If
Dim wtc As String = "" 'wordpress_test_cookie
Dim wp As String = "" 'wordpress_
Dim wli As String = "" 'wordpress_logged_in
For i = 1 To sCookies.Length
If Mid$(sCookies, i, 22) = "wordpress_test_cookie=" Then
For j = i + 22 To sCookies.Length
If Mid$(sCookies, j, 1) = ";" Or j = sCookies.Length Or Mid$(sCookies, j, 1) = "," Then
wtc = Mid$(sCookies, i, j - i) '& ";"
Exit For
End If
Next j
End If
If Mid$(sCookies, i, 10) = "wordpress_" And Mid$(sCookies, i, 11) <> "wordpress_l" Then
For j = i + 10 To sCookies.Length
If Mid$(sCookies, j, 1) = ";" Or j = sCookies.Length Or Mid$(sCookies, j, 1) = "," Then
wp = Mid$(sCookies, i, j - i) & "; "
Exit For
End If
Next j
End If
If Mid$(sCookies, i, 19) = "wordpress_logged_in" Then
For j = i + 19 To sCookies.Length
If Mid$(sCookies, j, 1) = ";" Or j = sCookies.Length Or Mid$(sCookies, j, 1) = "," Then
wli = Mid$(sCookies, i, j - i) & "; "
Exit For
End If
Next j
End If
Next i
sCookies = wp & wli & wtc
Dim wps As String = "" 'wp-settings-time-1
myHttpWebRequest = HttpWebRequest.Create(myUrl & "/wp-admin/")
myHttpWebRequest.Method = "GET"
myHttpWebRequest.Referer = myUrl & "/wp-login.php"
myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1"
myHttpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
myHttpWebRequest.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3")
If Not String.IsNullOrEmpty(sCookies) Then
myHttpWebRequest.Headers.Add(HttpRequestHeader.Cookie, sCookies)
End If
myHttpWebRequest.AllowAutoRedirect = False
myHttpWebResponse = myHttpWebRequest.GetResponse()
If Not String.IsNullOrEmpty(myHttpWebResponse.Headers("Set-Cookie")) Then
wps = myHttpWebResponse.Headers("Set-Cookie")
End If
Dim myStreamReader1 As New StreamReader(myHttpWebResponse.GetResponseStream, Encoding.GetEncoding(65001))
For i = 1 To wps.Length
If Mid$(wps, i, 19) = "wp-settings-time-1=" Then
For j = i + 19 To wps.Length
If Mid$(wps, j, 1) = ";" Or Mid$(wps, j, 1) = ";" Or j = wps.Length Then
wps = Mid$(wps, i, j - i)
Exit For
End If
Next j
End If
Next
sCookies = sCookies & "; " & wps
myHttpWebRequest = HttpWebRequest.Create(myUrl & "wp-admin/plugin-editor.php?file=hello-dolly/hello.php")
myHttpWebRequest.Method = "GET"
myHttpWebRequest.Referer = myUrl & "/wp-admin.php"
myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1"
myHttpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
myHttpWebRequest.Headers.Add("Accept-Language", "ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3")
If Not String.IsNullOrEmpty(sCookies) Then
myHttpWebRequest.Headers.Add(HttpRequestHeader.Cookie, sCookies)
End If
myHttpWebRequest.AllowAutoRedirect = False
myHttpWebResponse = myHttpWebRequest.GetResponse()
If Not String.IsNullOrEmpty(myHttpWebResponse.Headers("Set-Cookie")) Then
wps = myHttpWebResponse.Headers("Set-Cookie")
End If
myStreamReader1 = New StreamReader(myHttpWebResponse.GetResponseStream, Encoding.GetEncoding(65001))
вот, я перешел на страницу редактирования плагина. а как его отредактировать? и нужно ли переходить на страницу редактирования вообще или сразу посылать запрос на редактирование?
|