k2hr3-api 1.0.42 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/k2hr3-init.sh.templ +2 -2
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -378
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
package/lib/k2hr3apiutil.js
DELETED
|
@@ -1,1494 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* K2HR3 REST API
|
|
3
|
-
*
|
|
4
|
-
* Copyright 2017 Yahoo Japan Corporation.
|
|
5
|
-
*
|
|
6
|
-
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
7
|
-
* common management information for the cloud.
|
|
8
|
-
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
9
|
-
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
10
|
-
* client system can dynamically read and modify these information.
|
|
11
|
-
*
|
|
12
|
-
* For the full copyright and license information, please view
|
|
13
|
-
* the license file that was distributed with this source code.
|
|
14
|
-
*
|
|
15
|
-
* AUTHOR: Takeshi Nakatani
|
|
16
|
-
* CREATE: Wed Jun 8 2017
|
|
17
|
-
* REVISION:
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
var dns = require('dns');
|
|
24
|
-
var url = require('url');
|
|
25
|
-
var fs = require('fs');
|
|
26
|
-
var crypto = require('crypto');
|
|
27
|
-
|
|
28
|
-
//---------------------------------------------------------
|
|
29
|
-
// Utilities for variables
|
|
30
|
-
//---------------------------------------------------------
|
|
31
|
-
function rawIsSafeString(str)
|
|
32
|
-
{
|
|
33
|
-
if(undefined === str || null === str || 'string' !== typeof str || '' === str){
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function rawIsSafeEntity(data)
|
|
40
|
-
{
|
|
41
|
-
return (undefined !== data && null !== data);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function rawCompareCaseString(str1, str2)
|
|
45
|
-
{
|
|
46
|
-
if(rawIsSafeString(str1) && rawIsSafeString(str2) && str1.toLowerCase() === str2.toLowerCase()){
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function rawHasPartString(strbase, sep, values, iscase)
|
|
53
|
-
{
|
|
54
|
-
if(!rawIsSafeString(strbase) || !rawIsSafeString(sep)){
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var valarray = values;
|
|
59
|
-
if(!rawIsArray(values)){
|
|
60
|
-
if(!rawIsSafeString(values)){
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
valarray = new Array();
|
|
64
|
-
valarray.push(values);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var basearray = strbase.split(sep);
|
|
68
|
-
for(var cnt1 = 0; cnt1 < basearray.length; ++cnt1){
|
|
69
|
-
var strtmp1 = basearray[cnt1].trim();
|
|
70
|
-
if(!rawIsSafeString(strtmp1)){
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
for(var cnt2 = 0; cnt2 < valarray.length; ++cnt2){
|
|
74
|
-
var strtmp2 = valarray[cnt2].trim();
|
|
75
|
-
if(!rawIsSafeString(strtmp2)){
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if(iscase){
|
|
79
|
-
if(rawCompareCaseString(strtmp1, strtmp2)){
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}else{
|
|
83
|
-
if(strtmp1 === strtmp2){
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function rawGetSafeString(str)
|
|
93
|
-
{
|
|
94
|
-
if(rawIsSafeString(str)){
|
|
95
|
-
return str;
|
|
96
|
-
}
|
|
97
|
-
return '';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function rawCheckSimpleJSON(str)
|
|
101
|
-
{
|
|
102
|
-
if(undefined === str || null === str || !isNaN(str) || 'string' !== typeof str){
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
try{
|
|
106
|
-
var tmp = JSON.parse(str); // eslint-disable-line no-unused-vars
|
|
107
|
-
}catch(exception){ // eslint-disable-line no-unused-vars
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function rawParseJSON(str)
|
|
114
|
-
{
|
|
115
|
-
if(undefined === str || null === str || !isNaN(str) || 'string' !== typeof str){
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
try{
|
|
119
|
-
return JSON.parse(str);
|
|
120
|
-
}catch(exception){ // eslint-disable-line no-unused-vars
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function rawIsArray(arr)
|
|
126
|
-
{
|
|
127
|
-
if(arr instanceof Array){
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function rawIsEmptyArray(arr)
|
|
134
|
-
{
|
|
135
|
-
if(!(arr instanceof Array) || 0 === arr.length){
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function rawGetSafeArray(arr)
|
|
142
|
-
{
|
|
143
|
-
var result_array;
|
|
144
|
-
if(!(arr instanceof Array)){
|
|
145
|
-
result_array = new Array(0);
|
|
146
|
-
}else{
|
|
147
|
-
result_array = arr;
|
|
148
|
-
}
|
|
149
|
-
return result_array;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function rawFindStringInArray(arr, str)
|
|
153
|
-
{
|
|
154
|
-
if(arr instanceof Array && undefined !== str && null !== str){
|
|
155
|
-
for(var cnt = 0; cnt < arr.length; ++cnt){
|
|
156
|
-
if(str == arr[cnt]){
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function rawAddStringToArray(arr, str)
|
|
165
|
-
{
|
|
166
|
-
var result_array;
|
|
167
|
-
if(!(arr instanceof Array)){
|
|
168
|
-
result_array = new Array(0);
|
|
169
|
-
}else{
|
|
170
|
-
result_array = arr;
|
|
171
|
-
}
|
|
172
|
-
result_array.push(str);
|
|
173
|
-
return result_array;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function rawTryAddStringToArray(arr, str)
|
|
177
|
-
{
|
|
178
|
-
if(!(arr instanceof Array)){
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
if(rawFindStringInArray(arr, str)){
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
// arr is array and it does not have str.
|
|
185
|
-
// so add str to arr.
|
|
186
|
-
arr.push(str);
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function rawRemoveStringFromArray(arr, str)
|
|
191
|
-
{
|
|
192
|
-
if(!(arr instanceof Array) || undefined === str || null === str){
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
for(var cnt = 0; cnt < arr.length; ++cnt){
|
|
196
|
-
if(str == arr[cnt]){
|
|
197
|
-
arr.splice(cnt, 1);
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function rawCompareArray(arr1, arr2, strict)
|
|
205
|
-
{
|
|
206
|
-
if(!(arr1 instanceof Array) || !(arr2 instanceof Array) || arr1.length !== arr2.length){
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
if(!rawIsSafeEntity(strict) || 'boolean' !== typeof strict || false === strict){
|
|
210
|
-
var is_found;
|
|
211
|
-
for(var cnt1 = 0; cnt1 < arr1.length; ++cnt1){
|
|
212
|
-
is_found = false;
|
|
213
|
-
for(var cnt2 = 0; cnt2 < arr2.length; ++cnt2){
|
|
214
|
-
if(arr1[cnt1] === arr2[cnt2]){
|
|
215
|
-
is_found = true;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if(!is_found){
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}else{
|
|
224
|
-
if(JSON.stringify(arr1) !== JSON.stringify(arr2)){
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function rawMergeArray(arr1, arr2)
|
|
232
|
-
{
|
|
233
|
-
if(!(arr1 instanceof Array) && !(arr2 instanceof Array)){
|
|
234
|
-
return [];
|
|
235
|
-
}
|
|
236
|
-
if(!(arr2 instanceof Array)){
|
|
237
|
-
return arr1;
|
|
238
|
-
}
|
|
239
|
-
if(!(arr1 instanceof Array)){
|
|
240
|
-
return arr2;
|
|
241
|
-
}
|
|
242
|
-
for(var cnt2 = 0; cnt2 < arr2.length; ++cnt2){
|
|
243
|
-
var is_found = false;
|
|
244
|
-
for(var cnt1 = 0; cnt1 < arr1.length; ++cnt1){
|
|
245
|
-
if(arr1[cnt1] === arr2[cnt2]){
|
|
246
|
-
is_found = true;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if(!is_found){
|
|
251
|
-
arr1.push(arr2[cnt2]);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return arr1;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
//
|
|
258
|
-
// Get difference from base to new array elements.
|
|
259
|
-
// If is_deleted_element is true, returns result difference elements for deleting from base.
|
|
260
|
-
// If is_deleted_element is false, returns result difference elements for adding from base.
|
|
261
|
-
//
|
|
262
|
-
function rawGetDiffArray(basearr, newarr, is_deleted_element)
|
|
263
|
-
{
|
|
264
|
-
if(!(basearr instanceof Array) && !(newarr instanceof Array)){
|
|
265
|
-
return [];
|
|
266
|
-
}else if(!(basearr instanceof Array) && (newarr instanceof Array)){
|
|
267
|
-
if(is_deleted_element){
|
|
268
|
-
return [];
|
|
269
|
-
}else{
|
|
270
|
-
return newarr;
|
|
271
|
-
}
|
|
272
|
-
}else if((basearr instanceof Array) && !(newarr instanceof Array)){
|
|
273
|
-
if(is_deleted_element){
|
|
274
|
-
return basearr;
|
|
275
|
-
}else{
|
|
276
|
-
return [];
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
var cnt;
|
|
281
|
-
var result = new Array(0);
|
|
282
|
-
if(is_deleted_element){
|
|
283
|
-
for(cnt = 0; cnt < basearr.length; ++cnt){
|
|
284
|
-
if(!rawFindStringInArray(newarr, basearr[cnt])){
|
|
285
|
-
result.push(basearr[cnt]);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}else{
|
|
289
|
-
for(cnt = 0; cnt < newarr.length; ++cnt){
|
|
290
|
-
if(!rawFindStringInArray(basearr, newarr[cnt])){
|
|
291
|
-
result.push(newarr[cnt]);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return result;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function rawMergeObjects(obj1, obj2)
|
|
299
|
-
{
|
|
300
|
-
if(!rawIsSafeEntity(obj1)){
|
|
301
|
-
obj1 = {};
|
|
302
|
-
}
|
|
303
|
-
if(!rawIsSafeEntity(obj2)){
|
|
304
|
-
obj2 = {};
|
|
305
|
-
}
|
|
306
|
-
var resobj = {};
|
|
307
|
-
for(var key1 in obj1){
|
|
308
|
-
resobj[key1] = obj1[key1];
|
|
309
|
-
}
|
|
310
|
-
for(var key2 in obj2){
|
|
311
|
-
resobj[key2] = obj2[key2];
|
|
312
|
-
}
|
|
313
|
-
return resobj;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
//---------------------------------------------------------
|
|
317
|
-
// Utilities for time
|
|
318
|
-
//---------------------------------------------------------
|
|
319
|
-
//
|
|
320
|
-
// base is UTC
|
|
321
|
-
//
|
|
322
|
-
function convertUnixtime(base)
|
|
323
|
-
{
|
|
324
|
-
var unixtime_ms;
|
|
325
|
-
if(undefined === base || null === base || '' === base){
|
|
326
|
-
var now = new Date();
|
|
327
|
-
unixtime_ms = now.getTime();
|
|
328
|
-
}else{
|
|
329
|
-
unixtime_ms = Date.parse(base);
|
|
330
|
-
}
|
|
331
|
-
return Math.floor(unixtime_ms / 1000);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function rawConvertISOStringToUnixtime(iso)
|
|
335
|
-
{
|
|
336
|
-
if(!rawIsSafeString(iso)){
|
|
337
|
-
return 0;
|
|
338
|
-
}
|
|
339
|
-
var isoTime = new Date(iso);
|
|
340
|
-
var utime = isoTime.getTime() / 1000;
|
|
341
|
-
return utime;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function rawGetExpireUnixtime(starttime, expiretime)
|
|
345
|
-
{
|
|
346
|
-
return (expiretime - starttime);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function rawGetExpireUnixtimeFromISOStrings(startiso, expireiso)
|
|
350
|
-
{
|
|
351
|
-
var starttime = rawConvertISOStringToUnixtime(startiso);
|
|
352
|
-
var expiretime = rawConvertISOStringToUnixtime(expireiso);
|
|
353
|
-
return rawGetExpireUnixtime(starttime, expiretime);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
//---------------------------------------------------------
|
|
357
|
-
// Utilities for Key and Hierarchy
|
|
358
|
-
//---------------------------------------------------------
|
|
359
|
-
//
|
|
360
|
-
// Convert string to Hierarchy Array by separator
|
|
361
|
-
// ex) "parent-", "a/b/c" => ["parent-", "parent-a", "parent-a/b", "parent-a/b/c"]
|
|
362
|
-
// null, "a/b/c" => ["a", "a/b", "a/b/c"]
|
|
363
|
-
//
|
|
364
|
-
function rawExpandHierarchyArray(parent, str, separator, allow_empty)
|
|
365
|
-
{
|
|
366
|
-
if(!rawIsSafeString(str)){
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
var sep = '/';
|
|
370
|
-
if(rawIsSafeString(separator)){
|
|
371
|
-
sep = separator;
|
|
372
|
-
}
|
|
373
|
-
if(!rawIsSafeEntity(allow_empty)){
|
|
374
|
-
allow_empty = false;
|
|
375
|
-
}else if('boolean' !== typeof allow_empty){
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
var result = new Array(0);
|
|
379
|
-
if(rawIsSafeString(parent)){
|
|
380
|
-
result.push(parent);
|
|
381
|
-
}else{
|
|
382
|
-
parent = '';
|
|
383
|
-
}
|
|
384
|
-
var parts = str.split(sep);
|
|
385
|
-
var tmp = parent;
|
|
386
|
-
for(var cnt = 0; cnt < parts.length; ++cnt){
|
|
387
|
-
if(0 !== cnt){
|
|
388
|
-
tmp += sep;
|
|
389
|
-
}
|
|
390
|
-
var tmpstr = rawGetSafeString(parts[cnt]);
|
|
391
|
-
tmp += tmpstr;
|
|
392
|
-
if(allow_empty || '' !== str){
|
|
393
|
-
result.push(tmp);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return result;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
//
|
|
400
|
-
// Convert parent and terminal children(string or array) to Hierarchy object
|
|
401
|
-
// The result is the object which is configured "key=parent", "value=parent's children".
|
|
402
|
-
//
|
|
403
|
-
// ex) parent = "parent-" ===> result = { "parent": ["parent-a"],
|
|
404
|
-
// children = "a/b/c" "parent-a": ["parent-a/b"],
|
|
405
|
-
// "parent-a/b": ["parent-a/b/c"],
|
|
406
|
-
// "parent-a/b/c": []
|
|
407
|
-
// };
|
|
408
|
-
//
|
|
409
|
-
// ex) parent = "parent-" ===> result = { "parent": ["parent-a", "parent-1"],
|
|
410
|
-
// children = [ "a/b/c", "parent-a": ["parent-a/b"],
|
|
411
|
-
// "1/2/3"] "parent-a/b": ["parent-a/b/c"],
|
|
412
|
-
// "parent-a/b/c": [],
|
|
413
|
-
// "parent-1": ["parent-1/2"],
|
|
414
|
-
// "parent-1/2": ["parent-1/2/3"],
|
|
415
|
-
// "parent-1/2/3": []
|
|
416
|
-
// };
|
|
417
|
-
//
|
|
418
|
-
// ex) parent = "" ===> result = { "a": ["a/b"],
|
|
419
|
-
// children = ["a/b/c"] "a/b": ["a/b/c"],
|
|
420
|
-
// "a/b/c": []
|
|
421
|
-
// };
|
|
422
|
-
//
|
|
423
|
-
// ex) parent = "" ===> result = null(because this case does not have hierarchy)
|
|
424
|
-
// children = "a"
|
|
425
|
-
//
|
|
426
|
-
function rawExpandHierarchy(parent, children, separator, allow_empty)
|
|
427
|
-
{
|
|
428
|
-
if(!rawIsSafeString(parent)){
|
|
429
|
-
parent = '';
|
|
430
|
-
}
|
|
431
|
-
if(!(children instanceof Array)){
|
|
432
|
-
if(!rawIsSafeString(children)){
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
var tmp = children;
|
|
436
|
-
children= [tmp];
|
|
437
|
-
}
|
|
438
|
-
var is_set = false;
|
|
439
|
-
var result = {};
|
|
440
|
-
var parent_in_array;
|
|
441
|
-
for(var cnt = 0; cnt < children.length; ++cnt){
|
|
442
|
-
// parent + children[x] ---> ["parent", "parent child1", "parent child1 sep child2", ...]
|
|
443
|
-
var child_hierarchy_arr = rawExpandHierarchyArray(parent, children[cnt], separator, allow_empty);
|
|
444
|
-
if(null === child_hierarchy_arr || !(child_hierarchy_arr instanceof Array) || 0 === child_hierarchy_arr.length){
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
parent_in_array = '';
|
|
448
|
-
for(var cnt2 = 0; cnt2 < child_hierarchy_arr.length; ++cnt2){
|
|
449
|
-
if('' !== parent_in_array){
|
|
450
|
-
// parent ---> [child, child, ...]
|
|
451
|
-
if(!rawFindStringInArray(result[parent_in_array], child_hierarchy_arr[cnt2])){
|
|
452
|
-
result[parent_in_array].push(child_hierarchy_arr[cnt2]);
|
|
453
|
-
is_set = true;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
parent_in_array = child_hierarchy_arr[cnt2];
|
|
457
|
-
if(!rawIsSafeEntity(result[parent_in_array]) || !(result[parent_in_array] instanceof Array)){
|
|
458
|
-
result[parent_in_array] = new Array(0);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
if(!is_set){
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
return result;
|
|
466
|
-
}
|
|
467
|
-
//
|
|
468
|
-
// Get direct parent path for key
|
|
469
|
-
// ex) parent: "parent", childkey: ":a/b/c" => parent:a/b
|
|
470
|
-
// parent: null, childkey: ":a/b/c" => :a/b
|
|
471
|
-
// parent: "parent", childkey: ":a" => parent
|
|
472
|
-
// parent: "parent", childkey: "" => null
|
|
473
|
-
//
|
|
474
|
-
function rawGetParentKey(parent, childkey, separator, allow_empty)
|
|
475
|
-
{
|
|
476
|
-
if(!rawIsSafeString(childkey)){
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
var child_hierarchy_arr = rawExpandHierarchyArray(parent, childkey, separator, allow_empty);
|
|
480
|
-
if(null === child_hierarchy_arr || !(child_hierarchy_arr instanceof Array) || 0 === child_hierarchy_arr.length){
|
|
481
|
-
return null;
|
|
482
|
-
}
|
|
483
|
-
if(1 === child_hierarchy_arr.length){
|
|
484
|
-
// there is no parent, the array is only childkey(or parent)
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
return child_hierarchy_arr[child_hierarchy_arr.length - 2];
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
//
|
|
491
|
-
// Get parent path from string
|
|
492
|
-
//
|
|
493
|
-
// ex) "a/b/c" => "a/b"
|
|
494
|
-
// "a" => null
|
|
495
|
-
// "a/b/c/" => "a/b" : if allow_empty is false
|
|
496
|
-
// "a/b/c/" => "a/b/c" : if allow_empty is true
|
|
497
|
-
// "a//b/c" => "a//b"
|
|
498
|
-
// "a/b/c//" => "a/b" : if allow_empty is false
|
|
499
|
-
// "a/b/c//" => "a/b/c/" : if allow_empty is true
|
|
500
|
-
// "a/" => null : if allow_empty is false
|
|
501
|
-
// "a/" => "a" : if allow_empty is true
|
|
502
|
-
// "/a/b" => "/a"
|
|
503
|
-
// "/a" => null
|
|
504
|
-
// "a//b" => "a" : if allow_empty is false
|
|
505
|
-
// "a//b" => "a/" : if allow_empty is true
|
|
506
|
-
// "a/b///" => "a" : if allow_empty is false
|
|
507
|
-
// "a/b///" => "a/b//" : if allow_empty is true
|
|
508
|
-
//
|
|
509
|
-
function rawGetParentPath(str, separator, allow_empty)
|
|
510
|
-
{
|
|
511
|
-
if(!rawIsSafeString(str)){
|
|
512
|
-
return '';
|
|
513
|
-
}
|
|
514
|
-
if(!rawIsSafeEntity(allow_empty)){
|
|
515
|
-
allow_empty = false;
|
|
516
|
-
}else if('boolean' !== typeof allow_empty){
|
|
517
|
-
return '';
|
|
518
|
-
}
|
|
519
|
-
if(!rawIsSafeString(separator)){
|
|
520
|
-
separator = '/';
|
|
521
|
-
}
|
|
522
|
-
var tmp;
|
|
523
|
-
var cnt;
|
|
524
|
-
|
|
525
|
-
// escape if allow empty
|
|
526
|
-
if(allow_empty){
|
|
527
|
-
// escape '\' --> '\\'
|
|
528
|
-
str = str.replace(/\\/g, '\\\\');
|
|
529
|
-
// last word is '/' --> add '\'
|
|
530
|
-
if('/' === str[str.length - 1]){
|
|
531
|
-
str += '\\';
|
|
532
|
-
}
|
|
533
|
-
// if '//' --> '/\/'
|
|
534
|
-
tmp = '';
|
|
535
|
-
for(cnt = 0; cnt < str.length; ++cnt){
|
|
536
|
-
tmp += str[cnt];
|
|
537
|
-
if('/' === str[cnt] && (cnt + 1) < str.length && '/' === str[cnt + 1]){
|
|
538
|
-
tmp += '\\';
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
str = tmp;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// parse by separator
|
|
545
|
-
var parts = str.split(separator);
|
|
546
|
-
|
|
547
|
-
// remove last elements until it is not empty
|
|
548
|
-
while(0 < parts.length && !rawIsSafeString(parts[parts.length - 1])){
|
|
549
|
-
parts.pop();
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// remove last element
|
|
553
|
-
if(0 < parts.length){
|
|
554
|
-
parts.pop();
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// remove last elements until it is not empty
|
|
558
|
-
while(0 < parts.length && !rawIsSafeString(parts[parts.length - 1])){
|
|
559
|
-
parts.pop();
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// join with separator
|
|
563
|
-
var parent = parts.join(separator);
|
|
564
|
-
|
|
565
|
-
// unescape if allow empty
|
|
566
|
-
if(allow_empty && rawIsSafeString(parent)){
|
|
567
|
-
// '\' --> '' or '\\' --> '\'
|
|
568
|
-
tmp = '';
|
|
569
|
-
for(cnt = 0; cnt < parent.length; ++cnt){
|
|
570
|
-
if('\\' === parent[cnt]){
|
|
571
|
-
++cnt;
|
|
572
|
-
if(cnt < parent.length && '\\' === parent[cnt]){
|
|
573
|
-
tmp += parent[cnt]; // = '\'
|
|
574
|
-
}
|
|
575
|
-
}else{
|
|
576
|
-
tmp += parent[cnt];
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
parent = tmp;
|
|
580
|
-
}
|
|
581
|
-
return parent;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
//
|
|
585
|
-
// Compare string by regex or string patterns(array)
|
|
586
|
-
//
|
|
587
|
-
function rawCompareStringByFormats(str, regex_ptn, pattern_array)
|
|
588
|
-
{
|
|
589
|
-
if(!rawIsSafeString(str)){
|
|
590
|
-
return null;
|
|
591
|
-
}
|
|
592
|
-
var tmpstr = str.toLowerCase();
|
|
593
|
-
|
|
594
|
-
if(rawIsSafeEntity(regex_ptn)){
|
|
595
|
-
var matches = tmpstr.match(regex_ptn);
|
|
596
|
-
if(!rawIsEmptyArray(matches) && 2 <= matches.length){
|
|
597
|
-
return tmpstr;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
if(!rawIsArray(pattern_array) && rawIsSafeString(pattern_array)){
|
|
602
|
-
var tmpptn = pattern_array;
|
|
603
|
-
pattern_array = [tmpptn];
|
|
604
|
-
}
|
|
605
|
-
if(rawIsArray(pattern_array)){
|
|
606
|
-
for(var cnt = 0; cnt < pattern_array.length; ++cnt){
|
|
607
|
-
if(rawCompareCaseString(tmpstr, pattern_array[cnt])){
|
|
608
|
-
return tmpstr;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
return null;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
//---------------------------------------------------------
|
|
616
|
-
// Utilities for regex
|
|
617
|
-
//---------------------------------------------------------
|
|
618
|
-
//
|
|
619
|
-
// return object = {
|
|
620
|
-
// result: true/false
|
|
621
|
-
// parameter: object(array) or null or '' or undefined
|
|
622
|
-
// }
|
|
623
|
-
//
|
|
624
|
-
function rawGetNormalizeParameter(parameter, regex_ptn, pattern)
|
|
625
|
-
{
|
|
626
|
-
var resobj = { result: false };
|
|
627
|
-
var resstr;
|
|
628
|
-
var cnt;
|
|
629
|
-
|
|
630
|
-
if(rawIsSafeEntity(parameter) && rawCheckSimpleJSON(parameter)){
|
|
631
|
-
parameter = JSON.parse(parameter);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if(!rawIsSafeEntity(parameter)){
|
|
635
|
-
resobj.result = true;
|
|
636
|
-
resobj.parameter= null; // = not update type
|
|
637
|
-
|
|
638
|
-
}else if(rawIsArray(parameter)){
|
|
639
|
-
if(rawIsEmptyArray(parameter)){
|
|
640
|
-
resobj.result = true;
|
|
641
|
-
resobj.parameter= ''; // = clean up type
|
|
642
|
-
}else{
|
|
643
|
-
resobj.result = true;
|
|
644
|
-
resobj.parameter= new Array(0);
|
|
645
|
-
for(cnt = 0; cnt < parameter.length; ++cnt){
|
|
646
|
-
resstr = rawCompareStringByFormats(parameter[cnt], regex_ptn, pattern);
|
|
647
|
-
if(null === resstr){
|
|
648
|
-
resobj.result = false;
|
|
649
|
-
resobj.parameter= null;
|
|
650
|
-
break;
|
|
651
|
-
}
|
|
652
|
-
resobj.parameter.push(resstr);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
}else if('' === parameter){
|
|
657
|
-
resobj.result = true;
|
|
658
|
-
resobj.parameter= ''; // = clean up type
|
|
659
|
-
|
|
660
|
-
}else if(rawIsSafeString(parameter)){
|
|
661
|
-
var tmparr = parameter.split(',');
|
|
662
|
-
if(rawIsArray(tmparr) && !rawIsEmptyArray(tmparr)){
|
|
663
|
-
resobj.result = true;
|
|
664
|
-
resobj.parameter= new Array(0);
|
|
665
|
-
for(cnt = 0; cnt < tmparr.length; ++cnt){
|
|
666
|
-
resstr = rawCompareStringByFormats(tmparr[cnt], regex_ptn, pattern);
|
|
667
|
-
if(null === resstr){
|
|
668
|
-
resobj.result = false;
|
|
669
|
-
resobj.parameter= null;
|
|
670
|
-
break;
|
|
671
|
-
}
|
|
672
|
-
resobj.parameter.push(resstr);
|
|
673
|
-
}
|
|
674
|
-
}else{
|
|
675
|
-
resobj.result = true;
|
|
676
|
-
resobj.parameter= ''; // = clean up type
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
}else{
|
|
680
|
-
resobj.result = false;
|
|
681
|
-
}
|
|
682
|
-
return resobj;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
//---------------------------------------------------------
|
|
686
|
-
// Utilities for UUID4
|
|
687
|
-
//---------------------------------------------------------
|
|
688
|
-
// RFC4122
|
|
689
|
-
// https://www.ietf.org/rfc/rfc4122.txt
|
|
690
|
-
//
|
|
691
|
-
// UUID4 = xxxxxxxx-xxxx-Nxxx-Mxxx-xxxxxxxxxxxx
|
|
692
|
-
// N: 0x4X
|
|
693
|
-
// M: 0x{8,9,A,B}X
|
|
694
|
-
//
|
|
695
|
-
function rawGetBinUuid4()
|
|
696
|
-
{
|
|
697
|
-
var binUuid4= crypto.randomBytes(16);
|
|
698
|
-
binUuid4[6] = (binUuid4[6] & 0x0f) | 0x40; // UUID4 must be 0x4X for pos 6 in buffer
|
|
699
|
-
binUuid4[8] = (binUuid4[8] & 0x3f) | 0x80; // UUID4 must be 0x{8,9,A,B}X for pos 8 in buffer
|
|
700
|
-
|
|
701
|
-
return binUuid4;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// [NOTE]
|
|
705
|
-
// If binary data is given, this is only a conversion to UUID format,
|
|
706
|
-
// not a method that enforces UUID4 format.
|
|
707
|
-
//
|
|
708
|
-
function rawGetStrUuid4(binUuid4)
|
|
709
|
-
{
|
|
710
|
-
if(!rawIsSafeEntity(binUuid4) || !(binUuid4 instanceof Buffer)){
|
|
711
|
-
binUuid4 = rawGetBinUuid4();
|
|
712
|
-
}
|
|
713
|
-
var parsed = binUuid4.toString('hex').match(/(.{8})(.{4})(.{4})(.{4})(.{12})/);
|
|
714
|
-
parsed.shift(); // first element is all, then skip it.
|
|
715
|
-
var strUuid = parsed.join('-');
|
|
716
|
-
return strUuid;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
function rawIsSafeStrUuid4(strUuid4)
|
|
720
|
-
{
|
|
721
|
-
if(!rawIsSafeString(strUuid4)){
|
|
722
|
-
return false;
|
|
723
|
-
}
|
|
724
|
-
// split '-' separator
|
|
725
|
-
var strArray = strUuid4.split('-');
|
|
726
|
-
if(5 != strArray.length){
|
|
727
|
-
return false;
|
|
728
|
-
}
|
|
729
|
-
// check length
|
|
730
|
-
if( 0 == strArray[0].length || 8 < strArray[0].length ||
|
|
731
|
-
0 == strArray[1].length || 4 < strArray[1].length ||
|
|
732
|
-
0 == strArray[2].length || 4 < strArray[2].length ||
|
|
733
|
-
0 == strArray[3].length || 4 < strArray[3].length ||
|
|
734
|
-
0 == strArray[4].length || 12 < strArray[4].length )
|
|
735
|
-
{
|
|
736
|
-
return false;
|
|
737
|
-
}
|
|
738
|
-
return true;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
function rawCvtStrToBinUuid4(strUuid4)
|
|
742
|
-
{
|
|
743
|
-
if(!rawIsSafeString(strUuid4)){
|
|
744
|
-
return null;
|
|
745
|
-
}
|
|
746
|
-
// split '-' separator
|
|
747
|
-
var strArray = strUuid4.split('-');
|
|
748
|
-
if(5 != strArray.length){
|
|
749
|
-
return null;
|
|
750
|
-
}
|
|
751
|
-
// check length and fill '0' for short part
|
|
752
|
-
strArray[0] = rawFillZeroString(strArray[0], 8);
|
|
753
|
-
strArray[1] = rawFillZeroString(strArray[1], 4);
|
|
754
|
-
strArray[2] = rawFillZeroString(strArray[2], 4);
|
|
755
|
-
strArray[3] = rawFillZeroString(strArray[3], 4);
|
|
756
|
-
strArray[4] = rawFillZeroString(strArray[4], 12);
|
|
757
|
-
if(null == strArray[0] || null == strArray[1] || null == strArray[2] || null == strArray[3] || null == strArray[4]){
|
|
758
|
-
return null;
|
|
759
|
-
}
|
|
760
|
-
// uuid full hex string
|
|
761
|
-
var fullString = strArray.join('');
|
|
762
|
-
|
|
763
|
-
// convert to binary array
|
|
764
|
-
var binUuid4 = new Uint8Array(fullString.match(/.{1,2}/g).map(function(val){ return parseInt(val, 16); }));
|
|
765
|
-
return Buffer.from(binUuid4);
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
function rawFillZeroString(str, size)
|
|
769
|
-
{
|
|
770
|
-
if(!rawIsSafeString(str)){
|
|
771
|
-
return null;
|
|
772
|
-
}
|
|
773
|
-
if(size < str.length){
|
|
774
|
-
return null;
|
|
775
|
-
}else if(str.length < size){
|
|
776
|
-
var fillstr = '';
|
|
777
|
-
for(var fillcnt = size - str.length; 0 < fillcnt; --fillcnt){
|
|
778
|
-
fillstr += '0';
|
|
779
|
-
}
|
|
780
|
-
str = fillstr + str;
|
|
781
|
-
}
|
|
782
|
-
return str;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
//
|
|
786
|
-
// Return result
|
|
787
|
-
// {
|
|
788
|
-
// hi_id: Buffer[16] for hi uuid
|
|
789
|
-
// low_id: Buffer[16] for low uuid
|
|
790
|
-
// base: Buffer[32] for base
|
|
791
|
-
// str_token: hex[32] string for token
|
|
792
|
-
// token: Buffer[32] for token
|
|
793
|
-
// }
|
|
794
|
-
//
|
|
795
|
-
function rawMakeToken256(hiUuid4, lowUuid4, base)
|
|
796
|
-
{
|
|
797
|
-
// hiUuid4[128] / lowUuid4[128]
|
|
798
|
-
if( !rawIsSafeEntity(hiUuid4) || !(hiUuid4 instanceof Buffer) || 16 != hiUuid4.length ||
|
|
799
|
-
!rawIsSafeEntity(lowUuid4) || !(lowUuid4 instanceof Buffer) || 16 != lowUuid4.length ||
|
|
800
|
-
!rawIsSafeEntity(base) || !(base instanceof Buffer) || 32 != base.length )
|
|
801
|
-
{
|
|
802
|
-
return null;
|
|
803
|
-
}
|
|
804
|
-
var result = {};
|
|
805
|
-
result.hi_id = hiUuid4;
|
|
806
|
-
result.low_id = lowUuid4;
|
|
807
|
-
result.base = base;
|
|
808
|
-
|
|
809
|
-
// raw not crypted token[256]
|
|
810
|
-
var token = Buffer.alloc(32);
|
|
811
|
-
for(var cnt = 0; cnt < 32; ++cnt){
|
|
812
|
-
if(cnt < 16){
|
|
813
|
-
token[cnt] = result.base[cnt] ^ hiUuid4[cnt];
|
|
814
|
-
}else{
|
|
815
|
-
token[cnt] = result.base[cnt] ^ lowUuid4[cnt - 16];
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
// sha256 token[256]
|
|
820
|
-
var cryptSha256 = crypto.createHash('sha256');
|
|
821
|
-
cryptSha256.update(token);
|
|
822
|
-
result.str_token = cryptSha256.digest('hex');
|
|
823
|
-
|
|
824
|
-
// sha256 binary token[256]
|
|
825
|
-
result.token = rawCvtNumberStringToBinBuffer(result.str_token, 16, 32);
|
|
826
|
-
|
|
827
|
-
return result;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
//
|
|
831
|
-
// Return result
|
|
832
|
-
// {
|
|
833
|
-
// str_hi_id: hi uuid string
|
|
834
|
-
// hi_id: Buffer[16] for hi uuid
|
|
835
|
-
// str_low_id: low uuid string
|
|
836
|
-
// low_id: Buffer[16] for low uuid
|
|
837
|
-
// str_base: base string
|
|
838
|
-
// base: Buffer[32] for base
|
|
839
|
-
// str_token: hex[32] string for token
|
|
840
|
-
// token: Buffer[32] for token
|
|
841
|
-
// }
|
|
842
|
-
//
|
|
843
|
-
function rawMakeStringToken256(strHiUuid4, strLowUuid4, strBase)
|
|
844
|
-
{
|
|
845
|
-
var hiUuid4 = rawCvtStrToBinUuid4(strHiUuid4);
|
|
846
|
-
var lowUuid4 = rawCvtStrToBinUuid4(strLowUuid4);
|
|
847
|
-
|
|
848
|
-
var base;
|
|
849
|
-
if(rawIsSafeString(strBase)){
|
|
850
|
-
// string base is specified, then convert to buffer[32]
|
|
851
|
-
base = rawCvtNumberStringToBinBuffer(strBase, 16, 32);
|
|
852
|
-
}else{
|
|
853
|
-
// base is not specified, then it is made at here.
|
|
854
|
-
base = crypto.randomBytes(32); // base data is random value in buffer[32]
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
var result = rawMakeToken256(hiUuid4, lowUuid4, base);
|
|
858
|
-
if(null == result){
|
|
859
|
-
return null;
|
|
860
|
-
}
|
|
861
|
-
result.str_hi_id = strHiUuid4;
|
|
862
|
-
result.str_low_id = strLowUuid4;
|
|
863
|
-
result.str_base = base.toString('hex');
|
|
864
|
-
|
|
865
|
-
return result;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
//
|
|
869
|
-
// Converts a decimal or hexadecimal character string into a Buffer array(hexadecimal)
|
|
870
|
-
// with a specified number of bytes.
|
|
871
|
-
//
|
|
872
|
-
// strNumber: string for decimal or hexadecimal number
|
|
873
|
-
// base: radix(10 or 16)
|
|
874
|
-
// size: output Buffer array size
|
|
875
|
-
//
|
|
876
|
-
// result: Buffer array
|
|
877
|
-
//
|
|
878
|
-
function rawCvtNumberStringToBinBuffer(strNumber, base, size)
|
|
879
|
-
{
|
|
880
|
-
if(!rawIsSafeString(strNumber)){
|
|
881
|
-
return null;
|
|
882
|
-
}
|
|
883
|
-
if(16 != base && 10 != base){
|
|
884
|
-
return null;
|
|
885
|
-
}
|
|
886
|
-
if(10 == base){
|
|
887
|
-
// convert dec string to hex string
|
|
888
|
-
var tmpNumber = parseInt(strNumber, 10);
|
|
889
|
-
strNumber = tmpNumber.toString(16);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
var uintarr = new Uint8Array(strNumber.match(/.{1,2}/g).map(function(val){ return parseInt(val, 16); }));
|
|
893
|
-
var binbuff = Buffer.alloc(size);
|
|
894
|
-
binbuff.fill(0);
|
|
895
|
-
|
|
896
|
-
var diff_length;
|
|
897
|
-
var cnt;
|
|
898
|
-
if(size < uintarr.length){
|
|
899
|
-
// If input number array length is larger than required length, fill bottom.
|
|
900
|
-
diff_length = uintarr.length - size;
|
|
901
|
-
for(cnt = uintarr.length; diff_length < cnt; --cnt){
|
|
902
|
-
binbuff[cnt - 1 - diff_length] = uintarr[cnt - 1];
|
|
903
|
-
}
|
|
904
|
-
}else{
|
|
905
|
-
// If required length is larger than input length, fill zero to top.
|
|
906
|
-
diff_length = size - uintarr.length;
|
|
907
|
-
for(cnt = size; 0 < cnt; --cnt){
|
|
908
|
-
if((cnt -1) < diff_length){
|
|
909
|
-
break;
|
|
910
|
-
}
|
|
911
|
-
binbuff[cnt - 1] = uintarr[cnt - 1 - diff_length];
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
return binbuff;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
function rawCvtNumberStringToUuid4(strNumber, base)
|
|
918
|
-
{
|
|
919
|
-
var bin_uuid4 = rawCvtNumberStringToBinBuffer(strNumber, base, 16); // UUID4 is 16bytes
|
|
920
|
-
if(null == bin_uuid4){
|
|
921
|
-
return null;
|
|
922
|
-
}
|
|
923
|
-
return rawGetStrUuid4(bin_uuid4);
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
//---------------------------------------------------------
|
|
927
|
-
// Utilities for Host/IP address
|
|
928
|
-
//---------------------------------------------------------
|
|
929
|
-
//
|
|
930
|
-
// Get client ip address
|
|
931
|
-
//
|
|
932
|
-
// [NOTE]
|
|
933
|
-
// If the server is behind of proxy, you have to set "trust proxy" to express app.
|
|
934
|
-
// Then we get client ip address in X-Forwarded-for header from req.ip.
|
|
935
|
-
//
|
|
936
|
-
// If you do not use "trust proxy", you can get client ip by following:
|
|
937
|
-
//
|
|
938
|
-
// ip = (rawIsSafeEntity(req.headers) && rawIsSafeEntity(req.headers['x-forwarded-for'])) ? req.headers['x-forwarded-for'].split(',')[0] :
|
|
939
|
-
// (rawIsSafeEntity(req.connection) && rawIsSafeString(req.connection.remoteAddress)) ? req.connection.remoteAddress :
|
|
940
|
-
// (rawIsSafeEntity(req.connection) && rawIsSafeEntity(req.connection.socket) && rawIsSafeString(req.connection.socket.remoteAddress)) ? req.connection.socket.remoteAddress :
|
|
941
|
-
// (rawIsSafeEntity(req.socket) && rawIsSafeString(req.socket.remoteAddress)) ? req.socket.remoteAddress :
|
|
942
|
-
// '0.0.0.0';
|
|
943
|
-
// ip = ip.split(':').slice(-1); //in case the ip returned in a format: "::ffff:xxx.xxx.xxx.xxx"
|
|
944
|
-
//
|
|
945
|
-
function rawGetClientIpAddress(req)
|
|
946
|
-
{
|
|
947
|
-
// If "trust proxy" is set, set client ip address to req.ip.
|
|
948
|
-
var ip = (rawIsSafeEntity(req) && rawIsSafeString(req.ip)) ? req.ip : null;
|
|
949
|
-
|
|
950
|
-
if(!rawIsSafeString(ip)){
|
|
951
|
-
ip = null;
|
|
952
|
-
}else{
|
|
953
|
-
// check format "::ffff:" for ipv4 on ipv6
|
|
954
|
-
if('::ffff:' === ip.substr(0,7)) {
|
|
955
|
-
ip = ip.substr(7);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
return ip;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
function rawCompareRequestIpAddress(req, ip)
|
|
962
|
-
{
|
|
963
|
-
var req_ip = rawGetClientIpAddress(req);
|
|
964
|
-
return (req_ip === ip);
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
//
|
|
968
|
-
// Get hostname from ip address
|
|
969
|
-
//
|
|
970
|
-
// ip : ip address
|
|
971
|
-
// callback : function(err message, result<string[]>)
|
|
972
|
-
//
|
|
973
|
-
function rawGetHostnameFromIpAddress(ip, callback)
|
|
974
|
-
{
|
|
975
|
-
if(!rawIsSafeString(ip)){
|
|
976
|
-
callback('ip address parameter is wrong', null);
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
var _ip = ip;
|
|
980
|
-
dns.reverse(_ip, function(err, hosts)
|
|
981
|
-
{
|
|
982
|
-
if(rawIsSafeEntity(err)){
|
|
983
|
-
callback('ip address(' + _ip + ') is not convert hostname: ' + err.message, null);
|
|
984
|
-
return;
|
|
985
|
-
}
|
|
986
|
-
if(rawIsEmptyArray(hosts)){
|
|
987
|
-
callback('ip address(' + _ip + ') is not convert hostname', null);
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
callback(null, hosts);
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
//
|
|
995
|
-
// Get ip address from hostname
|
|
996
|
-
//
|
|
997
|
-
// hostname : host name
|
|
998
|
-
// callback : function(err message, result<string[]>)
|
|
999
|
-
//
|
|
1000
|
-
function rawGetIpAddressFromHostname(hostname, callback)
|
|
1001
|
-
{
|
|
1002
|
-
if(!rawIsSafeString(hostname)){
|
|
1003
|
-
callback('hostname parameter is wrong', null);
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
// try ipv4
|
|
1007
|
-
var _hostname4 = hostname;
|
|
1008
|
-
dns.resolve4(_hostname4, function(err, ip4)
|
|
1009
|
-
{
|
|
1010
|
-
if(rawIsSafeEntity(err) || rawIsEmptyArray(ip4)){
|
|
1011
|
-
// try ipv6
|
|
1012
|
-
var _hostname6 = _hostname4;
|
|
1013
|
-
dns.resolve6(_hostname6, function(err, ip6)
|
|
1014
|
-
{
|
|
1015
|
-
if(rawIsSafeEntity(err) || rawIsEmptyArray(ip6)){
|
|
1016
|
-
callback('hostname(' + _hostname4 + ') is not convert ipv6 address' + ((rawIsSafeEntity(err) && rawIsSafeString(err.message)) ? err.message : ''), null);
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
callback(null, ip6);
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
callback(null, ip4);
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
//
|
|
1027
|
-
// Complement ip address and hostname
|
|
1028
|
-
//
|
|
1029
|
-
// hostname : host name
|
|
1030
|
-
// ip : ip address
|
|
1031
|
-
// callback : function(err message, ip array[ip,...], hostname array[name,...])
|
|
1032
|
-
//
|
|
1033
|
-
function rawComplementHostnameIpAddress(hostname, ip, callback)
|
|
1034
|
-
{
|
|
1035
|
-
if(!rawIsSafeString(hostname) && !rawIsSafeString(ip)){
|
|
1036
|
-
callback('hostname and ip parameter is wrong', null, null);
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
if(rawIsSafeString(hostname) && rawIsSafeString(ip)){
|
|
1040
|
-
var ips = [ip];
|
|
1041
|
-
var hosts = [hostname];
|
|
1042
|
-
callback('hostname and ip parameter is wrong', ips, hosts);
|
|
1043
|
-
return;
|
|
1044
|
-
}
|
|
1045
|
-
if(rawIsSafeString(hostname)){
|
|
1046
|
-
var _hostname = [hostname];
|
|
1047
|
-
rawGetIpAddressFromHostname(ip, function(err, result)
|
|
1048
|
-
{
|
|
1049
|
-
if(rawIsSafeEntity(err)){
|
|
1050
|
-
callback(err, null, null);
|
|
1051
|
-
return;
|
|
1052
|
-
}
|
|
1053
|
-
callback(null, result, _hostname);
|
|
1054
|
-
});
|
|
1055
|
-
}else{ // rawIsSafeString(ip)
|
|
1056
|
-
var _ips = [ip];
|
|
1057
|
-
rawGetHostnameFromIpAddress(ip, function(err, result)
|
|
1058
|
-
{
|
|
1059
|
-
if(rawIsSafeEntity(err)){
|
|
1060
|
-
callback(err, null, null);
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
callback(null, _ips, result);
|
|
1064
|
-
});
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
//
|
|
1069
|
-
// url parser with default port
|
|
1070
|
-
//
|
|
1071
|
-
function rawUrlParse(strurl)
|
|
1072
|
-
{
|
|
1073
|
-
var ep = url.parse(strurl);
|
|
1074
|
-
if(rawIsSafeEntity(ep) && (null === ep.port || !rawIsSafeEntity(ep.port) || isNaN(ep.port))){
|
|
1075
|
-
// set default port
|
|
1076
|
-
if(rawIsSafeString(ep.protocol) && 'https:' === ep.protocol){
|
|
1077
|
-
ep.port = 443;
|
|
1078
|
-
}else{
|
|
1079
|
-
ep.port = 80;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
return ep;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
//
|
|
1086
|
-
// Check hostname/ip address
|
|
1087
|
-
//
|
|
1088
|
-
// host : hostname or ip address string
|
|
1089
|
-
//
|
|
1090
|
-
const simple_reg_ipv4 = /^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
|
|
1091
|
-
const simple_reg_ipv6 = /^(([0-9]|[a-f]|[A-F])*:)*([0-9]|[a-f]|[A-F])$/;
|
|
1092
|
-
|
|
1093
|
-
function rawIsIpAddressString(host)
|
|
1094
|
-
{
|
|
1095
|
-
if(!rawIsSafeString(host)){
|
|
1096
|
-
return false;
|
|
1097
|
-
}
|
|
1098
|
-
if(host.match(simple_reg_ipv4) || host.match(simple_reg_ipv6)){
|
|
1099
|
-
return true;
|
|
1100
|
-
}
|
|
1101
|
-
return false;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
//
|
|
1105
|
-
// Check URL
|
|
1106
|
-
//
|
|
1107
|
-
// Allow formatted as "http(s)://<host{:port}>{/{<path>}...}"
|
|
1108
|
-
//
|
|
1109
|
-
// Result matches by regex
|
|
1110
|
-
// matches.length 7
|
|
1111
|
-
// matches[0] input string(url)
|
|
1112
|
-
// matches[1] method string(http or https)
|
|
1113
|
-
// matches[2] FQDN string(domain name)
|
|
1114
|
-
// matches[3] port number starting with ':'(':xxxx'). if url does not have port, this value is ''(empty string)
|
|
1115
|
-
// matches[4] port number starting with ':'(':xxxx'). if url does not have port, this value is undefined
|
|
1116
|
-
// matches[5] url path and arguments string(string after port number). if url end of character is port number, this value is ''(empty string)
|
|
1117
|
-
// matches[6] url path and arguments string(string after port number). if url end of character is port number, this value is undefined
|
|
1118
|
-
//
|
|
1119
|
-
// Ex.)
|
|
1120
|
-
// Input url : 'https://abc.co.jp:8080/path?arg=value'
|
|
1121
|
-
// matches : [ 'https://abc.co.jp:8080/path?arg=value',
|
|
1122
|
-
// 'https',
|
|
1123
|
-
// 'abc.co.jp',
|
|
1124
|
-
// ':8080',
|
|
1125
|
-
// ':8080',
|
|
1126
|
-
// '/path?arg=value',
|
|
1127
|
-
// '/path?arg=value',
|
|
1128
|
-
// index: 0,
|
|
1129
|
-
// input: 'https://abc.co.jp:8080/path?arg=value'
|
|
1130
|
-
// ]
|
|
1131
|
-
//
|
|
1132
|
-
// Input url : 'https://abc.co.jp/'
|
|
1133
|
-
// matches : [ 'https://abc.co.jp/',
|
|
1134
|
-
// 'https',
|
|
1135
|
-
// 'abc.co.jp',
|
|
1136
|
-
// '',
|
|
1137
|
-
// undefined,
|
|
1138
|
-
// '',
|
|
1139
|
-
// undefined,
|
|
1140
|
-
// index: 0,
|
|
1141
|
-
// input: 'https://abc.co.jp/'
|
|
1142
|
-
// ]
|
|
1143
|
-
//
|
|
1144
|
-
const reg_url = /^(https?):\/\/([a-z|A-Z|0-9|$|%|&|(|)|-|=|~|^|||@|+|.|_]+)((:[1-9]\d*)?)((\/.*)*)$/;
|
|
1145
|
-
|
|
1146
|
-
function rawIsSafeUrl(strurl)
|
|
1147
|
-
{
|
|
1148
|
-
if(!rawIsSafeString(strurl)){
|
|
1149
|
-
return false;
|
|
1150
|
-
}
|
|
1151
|
-
if(null === strurl.match(reg_url)){
|
|
1152
|
-
return false;
|
|
1153
|
-
}
|
|
1154
|
-
return true;
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
function rawParseUrl(strurl)
|
|
1158
|
-
{
|
|
1159
|
-
if(!rawIsSafeString(strurl)){
|
|
1160
|
-
return null;
|
|
1161
|
-
}
|
|
1162
|
-
var matches = strurl.match(reg_url);
|
|
1163
|
-
if(null === matches || rawIsEmptyArray(matches) || matches < 7){
|
|
1164
|
-
return null;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
var resobj = {};
|
|
1168
|
-
resobj.https = rawCompareCaseString(matches[1], 'https');
|
|
1169
|
-
resobj.host = matches[2];
|
|
1170
|
-
resobj.path = matches[5];
|
|
1171
|
-
if(rawIsSafeString(matches[3]) && !isNaN(matches[3].substr(1))){
|
|
1172
|
-
resobj.port = parseInt(matches[3].substr(1));
|
|
1173
|
-
}else{
|
|
1174
|
-
resobj.port = resobj.https ? 443 : 80;
|
|
1175
|
-
}
|
|
1176
|
-
return resobj;
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
function rawCheckFileExist(file)
|
|
1180
|
-
{
|
|
1181
|
-
if(!rawIsSafeString(file)){
|
|
1182
|
-
return false;
|
|
1183
|
-
}
|
|
1184
|
-
try{
|
|
1185
|
-
fs.statSync(file);
|
|
1186
|
-
}catch(err){ // eslint-disable-line no-unused-vars
|
|
1187
|
-
return false;
|
|
1188
|
-
}
|
|
1189
|
-
return true;
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
function rawReadFileContents(file)
|
|
1193
|
-
{
|
|
1194
|
-
var contents = null;
|
|
1195
|
-
if(!rawCheckFileExist(file)){
|
|
1196
|
-
return contents;
|
|
1197
|
-
}
|
|
1198
|
-
try{
|
|
1199
|
-
contents = fs.readFileSync(file).toString();
|
|
1200
|
-
}catch(err){ // eslint-disable-line no-unused-vars
|
|
1201
|
-
return contents;
|
|
1202
|
-
}
|
|
1203
|
-
return contents;
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
function rawCheckDir(path)
|
|
1207
|
-
{
|
|
1208
|
-
if(!rawIsSafeString(path)){
|
|
1209
|
-
return false;
|
|
1210
|
-
}
|
|
1211
|
-
return fs.existsSync(path);
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
function rawCheckMakeDir(path)
|
|
1215
|
-
{
|
|
1216
|
-
if(rawCheckDir(path)){
|
|
1217
|
-
return true;
|
|
1218
|
-
}
|
|
1219
|
-
if(!rawIsSafeString(path)){
|
|
1220
|
-
return false;
|
|
1221
|
-
}
|
|
1222
|
-
try{
|
|
1223
|
-
fs.mkdirSync(path);
|
|
1224
|
-
}catch(err){ // eslint-disable-line no-unused-vars
|
|
1225
|
-
return false;
|
|
1226
|
-
}
|
|
1227
|
-
return true;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
//---------------------------------------------------------
|
|
1231
|
-
// Exports
|
|
1232
|
-
//---------------------------------------------------------
|
|
1233
|
-
exports.isSafeEntity = function(data)
|
|
1234
|
-
{
|
|
1235
|
-
return rawIsSafeEntity(data);
|
|
1236
|
-
};
|
|
1237
|
-
|
|
1238
|
-
exports.isSafeString = function(str)
|
|
1239
|
-
{
|
|
1240
|
-
return rawIsSafeString(str);
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
exports.isSafeStrings = function()
|
|
1244
|
-
{
|
|
1245
|
-
for(var cnt = 0; cnt < arguments.length; ++cnt){
|
|
1246
|
-
if(!rawIsSafeString(arguments[cnt])){
|
|
1247
|
-
return false;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
return true;
|
|
1251
|
-
};
|
|
1252
|
-
|
|
1253
|
-
exports.compareCaseString = function(str1, str2)
|
|
1254
|
-
{
|
|
1255
|
-
return rawCompareCaseString(str1, str2);
|
|
1256
|
-
};
|
|
1257
|
-
|
|
1258
|
-
exports.hasPartString = function(strbase, sep, values, iscase)
|
|
1259
|
-
{
|
|
1260
|
-
return rawHasPartString(strbase, sep, values, iscase);
|
|
1261
|
-
};
|
|
1262
|
-
|
|
1263
|
-
exports.getSafeString = function(str)
|
|
1264
|
-
{
|
|
1265
|
-
return rawGetSafeString(str);
|
|
1266
|
-
};
|
|
1267
|
-
|
|
1268
|
-
exports.checkSimpleJSON = function(str)
|
|
1269
|
-
{
|
|
1270
|
-
return rawCheckSimpleJSON(str);
|
|
1271
|
-
};
|
|
1272
|
-
|
|
1273
|
-
exports.parseJSON = function(str)
|
|
1274
|
-
{
|
|
1275
|
-
return rawParseJSON(str);
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
|
-
exports.isArray = function(arr)
|
|
1279
|
-
{
|
|
1280
|
-
return rawIsArray(arr);
|
|
1281
|
-
};
|
|
1282
|
-
|
|
1283
|
-
exports.isEmptyArray = function(arr)
|
|
1284
|
-
{
|
|
1285
|
-
return rawIsEmptyArray(arr);
|
|
1286
|
-
};
|
|
1287
|
-
|
|
1288
|
-
exports.getSafeArray = function(arr)
|
|
1289
|
-
{
|
|
1290
|
-
return rawGetSafeArray(arr);
|
|
1291
|
-
};
|
|
1292
|
-
|
|
1293
|
-
exports.findStringInArray = function(arr, str)
|
|
1294
|
-
{
|
|
1295
|
-
return rawFindStringInArray(arr, str);
|
|
1296
|
-
};
|
|
1297
|
-
|
|
1298
|
-
exports.addStringToArray = function(arr, str)
|
|
1299
|
-
{
|
|
1300
|
-
return rawAddStringToArray(arr, str);
|
|
1301
|
-
};
|
|
1302
|
-
|
|
1303
|
-
exports.tryAddStringToArray = function(arr, str)
|
|
1304
|
-
{
|
|
1305
|
-
return rawTryAddStringToArray(arr, str);
|
|
1306
|
-
};
|
|
1307
|
-
|
|
1308
|
-
exports.removeStringFromArray = function(arr, str)
|
|
1309
|
-
{
|
|
1310
|
-
return rawRemoveStringFromArray(arr, str);
|
|
1311
|
-
};
|
|
1312
|
-
|
|
1313
|
-
exports.compareArray = function(arr1, arr2, strict)
|
|
1314
|
-
{
|
|
1315
|
-
return rawCompareArray(arr1, arr2, strict);
|
|
1316
|
-
};
|
|
1317
|
-
|
|
1318
|
-
exports.mergeArray = function(arr1, arr2)
|
|
1319
|
-
{
|
|
1320
|
-
return rawMergeArray(arr1, arr2);
|
|
1321
|
-
};
|
|
1322
|
-
|
|
1323
|
-
exports.getDeletingDifferenceArray = function(basearr, newarr)
|
|
1324
|
-
{
|
|
1325
|
-
return rawGetDiffArray(basearr, newarr, true);
|
|
1326
|
-
};
|
|
1327
|
-
|
|
1328
|
-
exports.getAddingDifferenceArray = function(basearr, newarr)
|
|
1329
|
-
{
|
|
1330
|
-
return rawGetDiffArray(basearr, newarr, false);
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
|
-
exports.mergeObjects = function(obj1, obj2)
|
|
1334
|
-
{
|
|
1335
|
-
return rawMergeObjects(obj1, obj2);
|
|
1336
|
-
};
|
|
1337
|
-
|
|
1338
|
-
exports.getUnixtime = function(base)
|
|
1339
|
-
{
|
|
1340
|
-
return convertUnixtime(base);
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
exports.calcExpire = function(expiredate)
|
|
1344
|
-
{
|
|
1345
|
-
var expire = convertUnixtime(expiredate) - convertUnixtime();
|
|
1346
|
-
if(expire < 0){
|
|
1347
|
-
expire = 0;
|
|
1348
|
-
}
|
|
1349
|
-
return expire;
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
exports.isExpired = function(base)
|
|
1353
|
-
{
|
|
1354
|
-
return (convertUnixtime(base) < convertUnixtime()); // base(UTC ISO 8601) < now
|
|
1355
|
-
};
|
|
1356
|
-
|
|
1357
|
-
exports.convertISOStringToUnixtime = function(iso)
|
|
1358
|
-
{
|
|
1359
|
-
return rawConvertISOStringToUnixtime(iso);
|
|
1360
|
-
};
|
|
1361
|
-
|
|
1362
|
-
exports.getExpireUnixtime = function(starttime, expiretime)
|
|
1363
|
-
{
|
|
1364
|
-
return rawGetExpireUnixtime(starttime, expiretime);
|
|
1365
|
-
};
|
|
1366
|
-
|
|
1367
|
-
exports.getExpireUnixtimeFromISOStrings = function(startiso, expireiso)
|
|
1368
|
-
{
|
|
1369
|
-
return rawGetExpireUnixtimeFromISOStrings(startiso, expireiso);
|
|
1370
|
-
};
|
|
1371
|
-
|
|
1372
|
-
exports.expandHierarchy = function(parent, children, separator)
|
|
1373
|
-
{
|
|
1374
|
-
return rawExpandHierarchy(parent, children, separator);
|
|
1375
|
-
};
|
|
1376
|
-
|
|
1377
|
-
exports.getParentKey = function(parent, childkey, separator, allow_empty)
|
|
1378
|
-
{
|
|
1379
|
-
return rawGetParentKey(parent, childkey, separator, allow_empty);
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
|
-
exports.getParentPath = function(str, separator, allow_empty)
|
|
1383
|
-
{
|
|
1384
|
-
return rawGetParentPath(str, separator, allow_empty);
|
|
1385
|
-
};
|
|
1386
|
-
|
|
1387
|
-
exports.getNormalizeParameter = function(parameter, regex_ptn, pattern)
|
|
1388
|
-
{
|
|
1389
|
-
return rawGetNormalizeParameter(parameter, regex_ptn, pattern);
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
exports.getBinUuid4 = function()
|
|
1393
|
-
{
|
|
1394
|
-
return rawGetBinUuid4();
|
|
1395
|
-
};
|
|
1396
|
-
|
|
1397
|
-
exports.getStrUuid4 = function(binUuid4)
|
|
1398
|
-
{
|
|
1399
|
-
return rawGetStrUuid4(binUuid4);
|
|
1400
|
-
};
|
|
1401
|
-
|
|
1402
|
-
exports.isSafeStrUuid4 = function(strUuid4)
|
|
1403
|
-
{
|
|
1404
|
-
return rawIsSafeStrUuid4(strUuid4);
|
|
1405
|
-
};
|
|
1406
|
-
|
|
1407
|
-
exports.cvtStrToBinUuid4 = function(strUuid4)
|
|
1408
|
-
{
|
|
1409
|
-
return rawCvtStrToBinUuid4(strUuid4);
|
|
1410
|
-
};
|
|
1411
|
-
|
|
1412
|
-
exports.makeToken256 = function(hiUuid4, lowUuid4, base)
|
|
1413
|
-
{
|
|
1414
|
-
return rawMakeToken256(hiUuid4, lowUuid4, base);
|
|
1415
|
-
};
|
|
1416
|
-
|
|
1417
|
-
exports.makeStringToken256 = function(strHiUuid4, strLowUuid4, strBase)
|
|
1418
|
-
{
|
|
1419
|
-
return rawMakeStringToken256(strHiUuid4, strLowUuid4, strBase);
|
|
1420
|
-
};
|
|
1421
|
-
|
|
1422
|
-
exports.cvtNumberStringToBinBuffer = function(strNumber, base, size)
|
|
1423
|
-
{
|
|
1424
|
-
return rawCvtNumberStringToBinBuffer(strNumber, base, size);
|
|
1425
|
-
};
|
|
1426
|
-
|
|
1427
|
-
exports.cvtNumberStringToUuid4 = function(strNumber, base)
|
|
1428
|
-
{
|
|
1429
|
-
return rawCvtNumberStringToUuid4(strNumber, base);
|
|
1430
|
-
};
|
|
1431
|
-
|
|
1432
|
-
exports.getClientIpAddress = function(req)
|
|
1433
|
-
{
|
|
1434
|
-
return rawGetClientIpAddress(req);
|
|
1435
|
-
};
|
|
1436
|
-
|
|
1437
|
-
exports.compareRequestIpAddress = function(req, ip)
|
|
1438
|
-
{
|
|
1439
|
-
return rawCompareRequestIpAddress(req, ip);
|
|
1440
|
-
};
|
|
1441
|
-
|
|
1442
|
-
exports.complementHostnameIpAddress = function(hostname, ip, callback)
|
|
1443
|
-
{
|
|
1444
|
-
return rawComplementHostnameIpAddress(hostname, ip, callback);
|
|
1445
|
-
};
|
|
1446
|
-
|
|
1447
|
-
exports.isIpAddressString = function(host)
|
|
1448
|
-
{
|
|
1449
|
-
return rawIsIpAddressString(host);
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
|
-
exports.urlParse = function(strurl)
|
|
1453
|
-
{
|
|
1454
|
-
return rawUrlParse(strurl);
|
|
1455
|
-
};
|
|
1456
|
-
|
|
1457
|
-
exports.isSafeUrl = function(strurl)
|
|
1458
|
-
{
|
|
1459
|
-
return rawIsSafeUrl(strurl);
|
|
1460
|
-
};
|
|
1461
|
-
|
|
1462
|
-
exports.parseUrl = function(strurl)
|
|
1463
|
-
{
|
|
1464
|
-
return rawParseUrl(strurl);
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
exports.checkFileExist = function(file)
|
|
1468
|
-
{
|
|
1469
|
-
return rawCheckFileExist(file);
|
|
1470
|
-
};
|
|
1471
|
-
|
|
1472
|
-
exports.readFileContents = function(file)
|
|
1473
|
-
{
|
|
1474
|
-
return rawReadFileContents(file);
|
|
1475
|
-
};
|
|
1476
|
-
|
|
1477
|
-
exports.checkDir = function(path)
|
|
1478
|
-
{
|
|
1479
|
-
return rawCheckDir(path);
|
|
1480
|
-
};
|
|
1481
|
-
|
|
1482
|
-
exports.checkMakeDir = function(path)
|
|
1483
|
-
{
|
|
1484
|
-
return rawCheckMakeDir(path);
|
|
1485
|
-
};
|
|
1486
|
-
|
|
1487
|
-
/*
|
|
1488
|
-
* Local variables:
|
|
1489
|
-
* tab-width: 4
|
|
1490
|
-
* c-basic-offset: 4
|
|
1491
|
-
* End:
|
|
1492
|
-
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
1493
|
-
* vim<600: noexpandtab sw=4 ts=4
|
|
1494
|
-
*/
|