I am trying to use sub_filter to replace pieces of this code in a .js file.
SYNO.SDS.AzureSSOUtils = function() {
var a = 600
, c = 500
, e = (screen.width / 2) - c / 2
, d = (screen.height / 2) - a / 2
, b = String.format("height={0},width={1},left={2},top={3}", a, c, e, d);
return {
login: function(l, i) {
var f = (function(m) {
l(i, m)
}
).createDelegate(this);
var g = _S("dsm_https_port");
var k = Ext.urlEncode({
action: "signin",
method: "azure_oidc",
origin: location.origin
});
var j = location.hostname;
var h = "https://" + j + ":" + g + "/webman/index.cgi?" + k;
window.addEventListener("message", f);
window.open(h, "OIDC", b)
},
logout: function() {
var g = Ext.urlEncode({
asso: "true"
});
var f = "webman/logout.cgi?" + g;
window.open(f, "OIDC", b)
}
}
I have managed to use sub_filter to replace simple fragments
For example all of these examples work just fine and replace what i expect:
sub_filter 'dsm_https_port' '443';
sub_filter "dsm_https_port" "443";
sub_filter 'SYNO.SDS.AzureSSOUtils' 'PleaseWorkDamnYou'
What I really want to do is one of these two replacements:
sub_filter 'var g = _S("dsm_https_port");' 'var g = 443;';
or
sub filter 'var h = "https://" + j + ":" + g + "/webman/index.cgi?" + k;' 'var h = "https://" + j + + "/webman/index.cgi?" + k;';
However neither of these seem to do anything. I have tried escaping every space, quote and semi colon by placing \ in front of them - while that didn't error it didn't make a difference.
What am I doing wrong? I assume this is because the text to be replaced has ambiguous characters in it but i am not sure.
for reference, yes i have made sure the following is enabled in my location section (which is what most articles advise, first all of this was need to be able to edit the small fragments that are working:
gzip off;
proxy_set_header Accept-Encoding "";
sub_filter_once off;
sub_filter_types *;
sub_filter
when you actually need to define variables outside the scope of JavaScript file.sub_filter 'var g = _S("dsm_https_port")' 'var g = 443'
also one example i saw only escaped the find string and not the replacement string. Do i need to escape both sides of the sub_filter parameters?