at path:ROOT / clients / assets / js / whmcs / utils.js
run:R W Run
2.97 KB
2026-04-08 19:29:25
R W Run
9 KB
2026-04-08 19:29:26
R W Run
1.49 KB
2026-04-08 19:29:25
R W Run
2.44 KB
2026-04-08 19:29:28
R W Run
5.28 KB
2026-04-08 19:29:28
R W Run
45 By
2026-04-08 19:29:27
R W Run
5.71 KB
2026-04-08 19:29:26
R W Run
4.91 KB
2026-04-08 19:29:25
R W Run
3.24 KB
2026-04-08 19:29:27
R W Run
24.58 KB
2026-04-08 19:29:26
R W Run
13.16 KB
2026-04-08 19:29:26
R W Run
5.46 KB
2026-04-08 19:29:27
R W Run
error_log
📄utils.js
1/**
2 * General utilities module
3 *
4 * @copyright Copyright (c) WHMCS Limited 2005-2017
5 * @license http://www.whmcs.com/license/ WHMCS Eula
6 */
7(function(module) {
8 if (!WHMCS.hasModule('utils')) {
9 WHMCS.loadModule('utils', module);
10 }
11})(
12function () {
13 /**
14 * Not crypto strong; server-side must discard for
15 * something with more entropy; the value is sufficient
16 * for strong client-side validation check
17 */
18 this.simpleRNG = function () {
19 var chars = './$_-#!,^*()|';
20 var r = 0;
21 for (var i = 0; r < 3; i++) {
22 r += Math.floor((Math.random() * 10) / 2);
23 }
24 r = Math.floor(r);
25 var s = '';
26 for (var x = 0; x < r; x++) {
27 v = (Math.random() + 1).toString(24).split('.')[1];
28 if ((Math.random()) > 0.5) {
29 s += btoa(v).substr(0,4)
30 } else {
31 s += v
32 }
33
34 if ((Math.random()) > 0.5) {
35 s += chars.substr(
36 Math.floor(Math.random() * 13),
37 1
38 );
39 }
40 }
41
42 return s;
43 };
44
45 this.getRouteUrl = function (path) {
46 return whmcsBaseUrl + "/index.php?rp=" + path;
47 };
48
49 this.validateBaseUrl = function() {
50 if (typeof window.whmcsBaseUrl === 'undefined') {
51 console.log('Warning: The WHMCS Base URL definition is missing '
52 + 'from your active template. Please refer to '
53 + 'https://docs.whmcs.com/WHMCS_Base_URL_Template_Variable '
54 + 'for more information and details of how to resolve this '
55 + 'warning.');
56 window.whmcsBaseUrl = this.autoDetermineBaseUrl();
57 window.whmcsBaseUrlAutoSet = true;
58 } else if (window.whmcsBaseUrl === ''
59 && typeof window.whmcsBaseUrlAutoSet !== 'undefined'
60 && window.whmcsBaseUrlAutoSet === true
61 ) {
62 window.whmcsBaseUrl = this.autoDetermineBaseUrl();
63 }
64 };
65
66 this.autoDetermineBaseUrl = function() {
67 var windowLocation = window.location.href;
68 var phpExtensionLocation = -1;
69
70 if (typeof windowLocation !== 'undefined') {
71 phpExtensionLocation = windowLocation.indexOf('.php');
72 }
73
74 if (phpExtensionLocation === -1) {
75 windowLocation = jQuery('#Primary_Navbar-Home a').attr('href');
76 if (typeof windowLocation !== 'undefined') {
77 phpExtensionLocation = windowLocation.indexOf('.php');
78 }
79 }
80
81 if (phpExtensionLocation !== -1) {
82 windowLocation = windowLocation.substring(0, phpExtensionLocation);
83 var lastTrailingSlash = windowLocation.lastIndexOf('/');
84 if (lastTrailingSlash !== false) {
85 return windowLocation.substring(0, lastTrailingSlash);
86 }
87 }
88
89 return '';
90 };
91
92 this.normaliseStringValue = function(status) {
93 return status ? status.toLowerCase().replace(/\s/g, '-') : '';
94 };
95
96 this.generatePassword = function(len) {
97 var charset = this.getPasswordCharacterSet();
98 var result = "";
99 for (var i = 0; len > i; i++)
100 result += charset[this.randomInt(charset.length)];
101 return result;
102 };
103 this.getPasswordCharacterSet = function() {
104 var rawCharset = '0123456789'
105 + 'abcdefghijklmnopqrstuvwxyz'
106 + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
107 + '!#$%()*+,-.:;=@_|{ldelim}{rdelim}~';
108
109 // Parse UTF-16, remove duplicates, convert to array of strings
110 var charset = [];
111 for (var i = 0; rawCharset.length > i; i++) {
112 var c = rawCharset.charCodeAt(i);
113 if (0xD800 > c || c >= 0xE000) { // Regular UTF-16 character
114 var s = rawCharset.charAt(i);
115 if (charset.indexOf(s) == -1)
116 charset.push(s);
117 continue;
118 }
119 if (0xDC00 > c ? rawCharset.length > i + 1 : false) { // High surrogate
120 var d = rawCharset.charCodeAt(i + 1);
121 if (d >= 0xDC00 ? 0xE000 > d : false) { // Low surrogate
122 var s = rawCharset.substring(i, i + 2);
123 i++;
124 if (charset.indexOf(s) == -1)
125 charset.push(s);
126 continue;
127 }
128 }
129 throw "Invalid UTF-16";
130 }
131 return charset;
132 };
133 this.randomInt = function(n) {
134 var x = this.randomIntMathRandom(n);
135 x = (x + this.randomIntBrowserCrypto(n)) % n;
136 return x;
137 };
138 this.randomIntMathRandom = function(n) {
139 var x = Math.floor(Math.random() * n);
140 if (0 > x || x >= n)
141 throw "Arithmetic exception";
142 return x;
143 };
144 this.randomIntBrowserCrypto = function(n) {
145 var cryptoObject = null;
146
147 if ("crypto" in window)
148 cryptoObject = crypto;
149 else if ("msCrypto" in window)
150 cryptoObject = msCrypto;
151 else
152 return 0;
153
154 if (!("getRandomValues" in cryptoObject) || !("Uint32Array" in window) || typeof Uint32Array != "function")
155 cryptoObject = null;
156
157 if (cryptoObject == null)
158 return 0;
159
160 // Generate an unbiased sample
161 var x = new Uint32Array(1);
162 do cryptoObject.getRandomValues(x);
163 while (x[0] - x[0] % n > 4294967296 - n);
164 return x[0] % n;
165 };
166
167 return this;
168});
169
170WHMCS.utils.validateBaseUrl();
171