Last active
July 31, 2018 16:37
-
-
Save dobesv/fd70974421b891b3f277 to your computer and use it in GitHub Desktop.
Revisions
-
dobesv revised this gist
Jun 5, 2015 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ You must provide the following configuration variables: 1. `WP_XMLRPC_URL` = `https://www.yourdomain.com/xmlrpc.php` (replace with your domain and use http:// if you don't have SSL support) 2. `WP_ADMIN_USER` = `admin` (use your own admin username) 3. `WP_ADMIN_PASSWORD` = `somepassword` (use your own admin password) -
dobesv revised this gist
Jun 4, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function getByEmail (name, callback) { }}); request.post({ url: configuration.WP_XMLRPC_URL, body: reqXml, encoding: 'utf8', method: 'POST', -
dobesv revised this gist
Jun 4, 2015 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,21 +14,22 @@ function login (email, password, callback) { }}); request.post({ url: configuration.WP_XMLRPC_URL, body: reqXml, encoding: 'utf8', method: 'POST', headers: { 'Content-Type' : 'application/xml', 'Accept' : 'application/xml' } }, function (err, response, body) { if (err) return callback(err); var parser = new xml2js.Parser(); return parser.parseString(body, function(err, doc) { if(err) return callback(err); var mr = doc.methodResponse; if(typeof(mr) === 'undefined') { throw new Error(JSON.stringify(mr)+" <-- "+body); } if('fault' in mr) { if(mr.fault[0].value[0].struct[0].member[0].value[0].int[0] === '403') { return callback(new WrongUsernameOrPasswordError(email, mr.fault[0].value[0].struct[0].member[1].value[0].string[0])); } else { -
dobesv revised this gist
Jun 4, 2015 . 1 changed file with 70 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ function getByEmail (name, callback) { var xpath = require('xpath') , xmldom = require('xmldom') , xml2js = require('xml2js'); var dom = xmldom.DOMParser; var builder = new xml2js.Builder(); var reqXml = builder.buildObject({'methodCall':{ 'methodName':'wp.getUsers', 'params':[ {'param':{'value':{'i4':0}}}, {'param':{'value':configuration.WP_ADMIN_USER}}, {'param':{'value':configuration.WP_ADMIN_PASSWORD}} ] }}); request.post({ url: 'https://www.menoraway.com/xmlrpc.php', body: reqXml, encoding: 'utf8', method: 'POST', headers: { 'Content-Type' : 'application/xml' } }, function (err, response, body) { if (err) return callback(err); var parser = new xml2js.Parser(); return parser.parseString(body, function(err, doc) { if(err) return callback(err); var mr = doc.methodResponse; if('fault' in mr) { if(mr.fault[0].value[0].struct[0].member[0].value[0].int[0] === '403') { return callback(new WrongUsernameOrPasswordError(configuration.WP_ADMIN_USER, mr.fault[0].value[0].struct[0].member[1].value[0].string[0])); } else { return callback(new Error(mr.fault[0].value[0].struct[0].member[1].value[0].string[0])); } } else { var userdatas = mr.params[0].param[0].value[0].array[0].data[0].value; var userlist = userdatas.map(function(userdata) { var result = { user_id: null, username: null, nickname: null, email: null, display_name: null, nicename: null, first_name: null, last_name: null }; userdata.struct[0].member.forEach(function(prop) { if(prop.name[0] in result) { result[prop.name[0]] = prop.value[0].string[0]; } }); result.given_name = result.first_name; result.family_name = result.last_name; return result; }); var matches = userlist.filter(function(u) { return u.email === name || u.username === name; }); if(matches.length > 0) { return callback(null, matches[0]); } return callback(new ValidationError("not-found", "No matching user found")); } }); }); } -
dobesv revised this gist
Jun 4, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ function login (email, password, callback) { result.username === null || result.nickname === null || result.email === null) { return callback(new Error("Failed to parse login response: "+JSON.stringify(doc))); } return callback(null, result); } -
dobesv renamed this gist
Jun 4, 2015 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,13 +25,14 @@ function login (email, password, callback) { var parser = new xml2js.Parser(); return parser.parseString(body, function(err, doc) { if(err) return callback(err); var mr = doc.methodResponse; if('fault' in mr) { if(mr.fault[0].value[0].struct[0].member[0].value[0].int[0] === '403') { return callback(new WrongUsernameOrPasswordError(email, mr.fault[0].value[0].struct[0].member[1].value[0].string[0])); } else { return callback(new Error(mr.fault[0].value[0].struct[0].member[1].value[0].string[0])); } } else { var result = { -
dobesv revised this gist
Jun 4, 2015 . 1 changed file with 48 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,46 +1,60 @@ function login (email, password, callback) { var xpath = require('xpath') , xmldom = require('xmldom') , xml2js = require('xml2js'); var dom = xmldom.DOMParser; var builder = new xml2js.Builder(); var reqXml = builder.buildObject({'methodCall':{ 'methodName':'wp.getProfile', 'params':[ {'param':{'value':{'i4':0}}}, {'param':{'value':email}}, {'param':{'value':password}} ] }}); request.post({ url: 'https://www.menoraway.com/xmlrpc.php', body: reqXml, encoding: 'utf8', method: 'POST', headers: { 'Content-Type' : 'application/xml' } }, function (err, response, body) { if (err) return callback(err); var parser = new xml2js.Parser(); return parser.parseString(body, function(err, doc) { if(err) return callback(err); //throw new Error(JSON.stringify(doc)); var mr = doc.methodResponse; if('fault' in mr) { if(mr.fault[0].value[0].struct[0].member[0].value[0].int[0] === '403') { return callback(new WrongUsernameOrPasswordError(email, mr.fault[0].value[0].struct[0].member[1].value[0])); } else { return callback(new Error(mr.fault[0].value[0].struct[0].member[1].value[0])); } } else { var result = { user_id: null, username: null, nickname: null, email: null, email_verified: true }; mr.params[0].param[0].value[0].struct[0].member.forEach(function(prop) { if(prop.name[0] in result) { result[prop.name[0]] = prop.value[0].string[0]; } }); if(result.user_id === null || result.username === null || result.nickname === null || result.email === null) { return callback(new Error("Faield to parse login response: "+JSON.stringify(doc))); } return callback(null, result); } }); }); } -
dobesv revised this gist
May 27, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,8 @@ function login (email, password, callback) { callback(null, { user_id: user_id, nickname: nickname, email: email, email_verified: true }); }); -
dobesv created this gist
May 27, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ function login (email, password, callback) { var escapeXml = function escapeXml(unsafe) { return unsafe.replace(/[<>&'"]/g, function (c) { switch (c) { case '<': return '<'; case '>': return '>'; case '&': return '&'; case '\'': return '''; case '"': return '"'; } }); }; request.post({ url: 'https://yourdomain.com/xmlrpc.php', body: '<?xml version="1.0"?><methodCall>' + '<methodName>wp.getProfile</methodName>' + '<params>'+ '<param><value><i4>0</i4></value></param>' + '<param><value>'+escapeXml(email)+'</value></param>' + '<param><value>'+escapeXml(password)+'</value></param>' + '</params></methodCall>', encoding: 'utf8', method: 'POST', headers: { 'Content-Type' : 'application/xml' } //for more options check: //https://github.com/mikeal/request#requestoptions-callback }, function (err, response, body) { if (err) return callback(err); if (response.statusCode !== 200) return callback(); var user_id = body.match('<member><name>user_id</name><value><string>([^<]*)')[1]; var nickname = body.match('<member><name>nickname</name><value><string>([^<]*)')[1]; var email = body.match('<member><name>email</name><value><string>([^<]*)')[1]; callback(null, { user_id: user_id, nickname: nickname, email: email }); }); }