Public
Authored by Dmitry Maydashev

Library brending

let brending_functions = {
    'default':function(){
        $("#logo").attr("src","https://hotspot.bitrace.ru/library-static/valoviy_5.jpg");
        document.body.style.backgroundColor = "#f5e4b8";
    },
    'valovaya':function(){
        $("#logo").attr("src","https://hotspot.bitrace.ru/library-static/valoviy_5.jpg");
        document.body.style.backgroundColor = "#f5e4b8";
    },
    'klementevka':function(){
        $("#logo").attr("src","https://hotspot.bitrace.ru/library-static/klementevka.jpg");
    },
    'uglich':function(){
        $("#logo").attr("src","https://hotspot.bitrace.ru/library-static/uglich.jpg");
    }
}
let LIBRARY_RESOLVER = {
    valovaya: '10.10.10.0/24',
    klementevka: '10.10.11.0/24',
    uglich: '10.10.12.0/24',
}
function IPnumber(IPaddress) {
    // let ip = IPaddress.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
    let ip = IPaddress.split('.')
    if(ip) {
        // return (+ip[1]<<24) + (+ip[2]<<16) + (+ip[3]<<8) + (+ip[4]);
        return (+ip[0]<<24) + (+ip[1]<<16) + (+ip[2]<<8) + (+ip[3]);
    }
    return null;
}
function IPmask(maskSize) {
    return -1<<(32-maskSize)
}
function check_library(ip){
    let is_draw_default = true;
    for (let library in LIBRARY_RESOLVER) {
        let subnet = LIBRARY_RESOLVER[library].split('/')[0]
        let mask = LIBRARY_RESOLVER[library].split('/')[1]
        let result = (IPnumber(ip) & IPmask(mask)) === IPnumber(subnet)
            if(result){
                brending_functions[library]();
                is_draw_default = false;
            }
    }
    if(is_draw_default){
        brending_functions['default']()
    }
}
$(document).ready(function () {
    if(window.location.href.indexOf("mikrotik") > -1) {
        const queryString = window.location.search;
        const urlParams = new URLSearchParams(queryString);
        const user_ip = urlParams.get('ip');
        localStorage.setItem('user_ip', user_ip);
    }
    if (localStorage.getItem("user_ip") != null) {
        check_library(localStorage.getItem("user_ip"))
    }
});
Edited
2.05 KB
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment