var transcoder_params = {"Formats":["mpegts"],"VideoCodecs":["copy","libx264","hevc","h264_vaapi","h264_nvenc","hevc_nvenc","mpeg2video","mpeg4","amv","libvpx","libvpx-vp9","wmv2","zlib","rawvideo"],"VideoDecoders":["auto","h264","h264_cuvid","hevc","hevc_cuvid","mpeg2video","mpeg2_cuvid","mpeg4","mpeg4_cuvid","mpeg1_cuvid","vp8_cuvid","vp9_cuvid"],"VideoSizes":["Keep original","640x360","704x528","720x480","720x576","736x414","800x600","848x480","1024x576","1080x720","1280x720","1280x1080","1440x1080","1600x1080","1645x1080","1728x1080","1888x1056","1904x1088","1920x1080"],"VideoPresets":{"default":[],"libx264":{"ultrafast":"Ultra Fast","superfast":"Super Fast","veryfast":"Very Fast","faster":"Faster","fast":"Fast","medium":"Medium","slow":"Slow","slower":"Slower","veryslow":"Very Slow","placebo":"Placebo"},"h264_nvenc":{"slow":"Slow","medium":"Medium","fast":"Fast","hp":"High Performance","hq":"High Quality","bd":"Blu-Ray","ll":"Low Latency","llhq":"Low Latency High Quality","llhp":"Low Latency High Performance","lossless":"Lossless","losslesshp":"Lossless High Performance"},"hevc_nvenc":{"slow":"Slow","medium":"Medium","fast":"Fast","hp":"High Performance","hq":"High Quality","bd":"Blu-Ray","ll":"Low Latency","llhq":"Low Latency High Quality","llhp":"Low Latency High Performance","lossless":"Lossless","losslesshp":"Lossless High Performance"}},"AudioCodecs":["copy","libfdk_aac","aac","ac3","ac3_fixed","g726","alac","eac3","flac","libmp3lame","opus","libopus","tta","vorbis","libvorbis","wavpack","wmav2"]};var dimmer,loader; var sid,aid,uid,pid,scan_id=false; var scan_data = []; var graphs = []; window.addEventListener("load",function(){ dimmer = document.getElementById('dimmer'); loader = document.getElementById('loader'); }); function loadColor(load){ if(typeof(load)=='string')load=parseFloat(load); return "rgb("+(load<50 ? Math.round(5*load) : 255)+','+(load<50 ? 255 : Math.round(255-5*(load-50)))+",0)"; } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i 1024){b/=1024;s='k'} if(b > 1024){b/=1024;s='M'} if(b > 1024){b/=1024;s='G'} if(b > 1024){b/=1024;s='T'} return Math.round(b*100)/100+s; } function show_loader(txt){ dimmer.style.visibility='visible'; dimmer.style.opacity=.5; dimmer.style.zIndex=99; loader.style.visibility='visible'; loader.style.opacity=1; loader.style.top='50%'; loader.innerHTML=txt; } function hide_loader(){ dimmer.style=''; loader.style=''; } function generate_loading_screen(){ var id = '_loader_'+Math.random()*1e18; while(document.getElementById(id)) id = '_loader_'+Math.random()*1e18; var obj = ''; return [obj,id]; } function generate_radial_loader(id){ return '
-
'; } function set_radial_loader(obj,value,min,max,units){ var value = parseFloat(value); var i = Math.ceil((value-min)/max*100); if(Math.abs(value)>=1)value=Math.round(value); else value=Math.round(value*100)/100; if(i<0)i=0; else if(i>100)i=100; obj.setAttribute('data-progress',i); obj.children[1].children[0].innerHTML=value+units; } function GET(url,outputElement,loaderElement){ var xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ outputElement.style.opacity=0; if(loaderElement.parentNode != outputElement) loaderElement.style.opacity=0; setTimeout( function(){ loaderElement.parentNode.removeChild(loaderElement); outputElement.innerHTML = xmlhttp.responseText; outputElement.style.opacity=1; },500 ); } }; xmlhttp.open("GET", url); xmlhttp.send(); } function POST(url,data,onOK,onERR){ var xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200) onOK(xmlhttp.responseText); else onERR(xmlhttp.status); } }; xmlhttp.open("POST", url); xmlhttp.send(data); } function new_transcoder_open(){ dimmer.setAttribute('onclick','new_transcoder_cancel()'); dimmer.style.visibility='visible'; dimmer.style.opacity=.5; var obj = document.getElementById('new_transcoder_form'); obj.style.visibility='visible'; obj.style.opacity=1; obj.style.top='50%'; } function new_transcoder_cancel(){ dimmer.style=''; document.getElementById('new_transcoder_form').style=''; } function new_astra_open(){ dimmer.style.visibility='visible'; dimmer.style.opacity=.5; dimmer.setAttribute('onclick','new_astra_cancel()'); var obj = document.getElementById('new_astra_form'); obj.style.visibility='visible'; obj.style.opacity=1; obj.style.top='50%'; } function new_astra_cancel(){ dimmer.style=''; document.getElementById('new_astra_form').style=''; } function new_astra_add(){ var name = document.getElementById('new_server_name').value; var ip = document.getElementById('new_server_ip').value; var usr = document.getElementById('new_server_usr').value; var pwd = document.getElementById('new_server_pwd').value; if(name == '') name=ip; if(ip.length < 7) alert('Incorrect IP address!'); else{ var data=new FormData(); data.append('ip',ip); data.append('usr',usr); data.append('pwd',pwd); data.append('name',name); show_loader('Connecting to server...'); POST('servers.php?add',data,function(resp){ resp = JSON.parse(resp); if(resp['error']) show_loader(resp['error']+"
"); else{ show_loader("Server added: Astra "+resp['version']+"
"); } }, function(status){show_loader('Error '+status+"
");} ); } } function stream_edit(id){ sid=id; dimmer.style.visibility='visible'; dimmer.style.opacity=.5; dimmer.setAttribute('onclick','edit_stream_cancel()'); var obj = document.getElementById('stream_edit'); var loader = generate_loading_screen(); var div = document.getElementById('stream_edit_content'); div.innerHTML = loader[0]; obj.style.visibility='visible'; obj.style.opacity=1; obj.style.top='50%'; if(sid == 'new') GET('stream_edit.php?new',div,document.getElementById(loader[1])); else POST('stream_edit.php?sid='+sid,false,function(resp){ outputElement = div; loaderElement = document.getElementById(loader[1]); outputElement.style.opacity=0; if(loaderElement.parentNode != outputElement) loaderElement.style.opacity=0; setTimeout( function(){ loaderElement.parentNode.removeChild(loaderElement); outputElement.innerHTML = resp; outputElement.style.opacity=1; if(document.getElementById('on_stream_edit_loaded')) eval(document.getElementById('on_stream_edit_loaded').getAttribute('do')); },500 ); },function(err){ alert("Error "+err); }); } function stream_edit_change_vcodec(codec){ if(document.getElementById('stream_edit_vpres')){ var vpres = document.getElementById('stream_edit_vpres'); var ih = ''; if(transcoder_params.VideoPresets[codec]){ for(var i in transcoder_params.VideoPresets[codec]) ih += ""; } else{ for(var i in transcoder_params.VideoPresets.default) ih += ""; } vpres.innerHTML = ih; } var obs = document.getElementsByClassName('if_VideoCodec'); if(codec == 'copy') for(var i=0;i 0)val+="\n"; val = val+param+"\n"; document.getElementById('stream_edit_addpr').value=val; } document.getElementById('stream_edit_addpr').focus(); } } function edit_stream_change_transcoder(transcoder){ var d = document.getElementsByClassName('if_transcoder'); for(var i in d){ if(transcoder == 'none') d[i].hidden = true; else d[i].hidden = false; } } function edit_stream_update(butt){ if(sid && document.getElementById('stream_edit_name')){ var name = document.getElementById('stream_edit_name').value, trans = document.getElementById('stream_edit_transcoder').value, inputs = [], tinputs = [], outs = [], outsa = document.getElementsByClassName('stream_edit_outputs'); if(document.getElementById('stream_edit_inputs')){ objs = document.getElementById('stream_edit_inputs').children; for(var i=0;i 0)profiles[0]['Input'] = tinputs; var data=new FormData(); data.append('name',name); data.append('trans',trans); data.append('transcoding',JSON.stringify(profiles)); data.append('inputs',JSON.stringify(inputs)); if(outs.length > 0) data.append('outputs',JSON.stringify(outs)); if(sid == 'new') if(document.getElementById('stream_edit_server')){ var server = document.getElementById('stream_edit_server').value; if(!server){ alert("Select server!"); return 0; } else data.append('server',server); } else{ alert("Select server!"); return 0; } POST("stream_edit.php?update="+sid,data,function(resp){ butt.value='Update'; butt.disabled=false; if(resp == '{"ok":true}' || resp == 'null'){ edit_stream_cancel(); if(sid == 'new') location.reload(); } else if(resp.length > 0) alert(resp); else{ edit_stream_cancel(); if(sid == 'new') location.reload(); } }, function(err){alert("Error #"+err);butt.value='Update';butt.disabled=false;} ); } } } function edit_stream_cancel(){ dimmer.style=''; document.getElementById('stream_edit').style=''; jts_player2.destroy(); dimmer.setAttribute('onclick',''); } function streams_update_status(){ POST('streams.php?streams_data',0,function(resp){ resp = JSON.parse(resp); for(var i in resp){ if(document.getElementById('stream_'+i)){ var tr = document.getElementById('stream_'+i); tr.children[1].innerHTML = resp[i].name; var v = 'Unknown'; if(resp[i].state <= 0) v = "Disabled"; else{ if(resp[i].telemetry){ if(resp[i].telemetry.onair){ c = '#f00'; if(resp[i].telemetry.bitrate > 0) c = '#ff0'; if(resp[i].telemetry.bitrate > 1000){ c = '#0f0'; resp[i].telemetry.bitrate = Math.floor(resp[i].telemetry.bitrate/1000)+"'"+(resp[i].telemetry.bitrate-Math.floor(resp[i].telemetry.bitrate/1000)*1000); } v = resp[i].telemetry.bitrate+" kbps"; if(resp[i].telemetry.cc_error > 0) v+= "
CC: "+resp[i].telemetry.cc_error+""; if(resp[i].telemetry.pes_error > 0) v+= "
PES: "+resp[i].telemetry.pes_error+""; if(resp[i].telemetry.scrambled) v+= "
Scrambled"; } else v = "Offline"; } else v = "No data"; } tr.children[2].innerHTML = v; } } setTimeout(streams_update_status,5000); }, function(status){console.log('Error #'+status+' while fetching streams status');} ); } function stream_stat(id,output){ var data=new FormData(); data.append('id',id); data.append('sess',getCookie('PHPSESSID')); POST('/streams.php?stream_stat',data,function(resp){ var tmout = 10000; resp = JSON.parse(resp); if(resp['error']) output.innerHTML=resp['error']; else{ if(resp.name) output.children[1].innerHTML = resp.name; if(resp.orderID) output.children[0].value = resp.orderID; if(resp.state <= 0){ output.children[2].innerHTML = "Disabled"; output.classList.add('disabled'); } else{ output.classList.remove('disabled'); if(resp.telemetry){ var v = ""; if(resp.telemetry.transcoded){ output.classList.remove('error'); v+= "
"; if(resp.telemetry.transcoded.uptime){ if(resp.telemetry.transcoded.outputs){ if(resp.telemetry.transcoded.outputs.length > 0){ output.classList.add('active'); for(var i=0;i 1000) bitrate = bitrate.substr(0,bitrate.length-3)+"'"+bitrate.substr(-3); v+= bitrate+" kbps
"; } if(resp.telemetry.transcoded.started) v+= ""+secondsReadable(resp.telemetry.transcoded.uptime)+""; else v+= ""+secondsReadable((resp.telemetry.transcoded.playlist_segments+resp.telemetry.transcoded.playlist_sequence)*resp.telemetry.transcoded.playlist_target_duration)+""; } else{ v+= "Offline"; output.classList.add('error'); output.classList.remove('active'); } } else{ resp.telemetry.transcoded.bitrate = Math.round(resp.telemetry.transcoded.bitrate/1024).toString(); if(resp.telemetry.transcoded.bitrate > 1000) resp.telemetry.transcoded.bitrate = resp.telemetry.transcoded.bitrate.substr(0,resp.telemetry.transcoded.bitrate.length-3)+"'"+resp.telemetry.transcoded.bitrate.substr(-3); v+= resp.telemetry.transcoded.bitrate+" kbps
"; if(resp.telemetry.transcoded.started) v+= secondsReadable(resp.telemetry.transcoded.uptime)+"
"; else v+= secondsReadable((resp.telemetry.transcoded.playlist_segments+resp.telemetry.transcoded.playlist_sequence)*resp.telemetry.transcoded.playlist_target_duration)+""; } } else{ output.classList.add('error'); output.classList.remove('active'); if(resp.telemetry.transcoded.error) if(resp.telemetry.transcoded.error.length > 3) v+= "Error
"; else v+= "Offline"; else v+= "Offline"; } v+= "
"; if(resp.telemetry.transcoded.hwuse) v+= "
CPU: "+resp.telemetry.transcoded.hwuse.CPU+"%
RAM: "+resp.telemetry.transcoded.hwuse.RAM+"%

"; w = 'Unknown'; if(resp.telemetry.transcoded.clients){ if(Array.isArray(resp.telemetry.transcoded.clients)){ w = '---'; if(resp.telemetry.transcoded.clients.length > 0){ w = "
"; for(var j=0;j 3) w+= "
"+resp.telemetry.transcoded.clients[j].IP+" - "+secondsReadable(t)+"
"; else w+= "
"+resp.telemetry.transcoded.clients[j].IP+" - "+secondsReadable(t)+"
"; } w+= "
"; } } } if(output.children[3].innerHTML != w) output.children[3].innerHTML = w; } else{ v+= "Offline"; output.classList.add('error'); output.classList.remove('active'); } output.children[2].innerHTML = v; } else output.children[2].innerHTML = "No data"; } } setTimeout(function(){stream_stat(id,output)},tmout); }, function(status){ output.innerHTML='Error '+status; setTimeout(function(){stream_stat(id,output)},10000); } ); /* var data=new FormData(); data.append('id',id); POST('streams.php?stream_stat',data,function(resp){ var tmout = 10000; resp = JSON.parse(resp); if(resp['error']) output.innerHTML=resp['error']; else{ if(resp.name) output.children[1].innerHTML = resp.name; if(resp.orderID) output.children[0].children[0].value = resp.orderID; if(resp.state <= 0){ output.children[1].style.opacity = output.children[2].style.opacity = .5; output.children[2].innerHTML = "Disabled"; } else{ if(resp.telemetry){ var v = "
"; if(resp.telemetry.origin){ if(resp.telemetry.origin.onair){ c = '#f00'; if(resp.telemetry.origin.bitrate > 0) c = '#ff0'; if(resp.telemetry.origin.bitrate > 1000){ c = '#000'; resp.telemetry.origin.bitrate = resp.telemetry.origin.bitrate.toString(); resp.telemetry.origin.bitrate = resp.telemetry.origin.bitrate.substr(0,resp.telemetry.origin.bitrate.length-3)+"'"+resp.telemetry.origin.bitrate.substr(-3); } v+= ""+resp.telemetry.origin.bitrate+" kbps"; if(resp.telemetry.origin.cc_error > 0) v+= "
CC: "+resp.telemetry.origin.cc_error+""; if(resp.telemetry.origin.pes_error > 0) v+= "
PES: "+resp.telemetry.origin.pes_error+""; if(resp.telemetry.origin.scrambled) v+= "
Scrambled"; } else{ v+= "Offline"; tmout = 30000; } } v+= "
"; if(resp.telemetry.transcoded){ v+= " >
"; if(resp.telemetry.transcoded.uptime){ if(resp.telemetry.transcoded.outputs){ if(resp.telemetry.transcoded.outputs.length > 0){ for(var i=0;i 1000) bitrate = bitrate.substr(0,bitrate.length-3)+"'"+bitrate.substr(-3); v+= bitrate+" kbps
"; } if(resp.telemetry.transcoded.started) v+= ""+secondsReadable(resp.telemetry.transcoded.uptime)+""; else v+= ""+secondsReadable((resp.telemetry.transcoded.playlist_segments+resp.telemetry.transcoded.playlist_sequence)*resp.telemetry.transcoded.playlist_target_duration)+""; } else v+= "Offline"; } else{ resp.telemetry.transcoded.bitrate = Math.round(resp.telemetry.transcoded.bitrate/1024).toString(); if(resp.telemetry.transcoded.bitrate > 1000) resp.telemetry.transcoded.bitrate = resp.telemetry.transcoded.bitrate.substr(0,resp.telemetry.transcoded.bitrate.length-3)+"'"+resp.telemetry.transcoded.bitrate.substr(-3); v+= resp.telemetry.transcoded.bitrate+" kbps
"; if(resp.telemetry.transcoded.started) v+= secondsReadable(resp.telemetry.transcoded.uptime)+"
"; else v+= secondsReadable((resp.telemetry.transcoded.playlist_segments+resp.telemetry.transcoded.playlist_sequence)*resp.telemetry.transcoded.playlist_target_duration)+""; } } else{ if(resp.telemetry.transcoded.error) if(resp.telemetry.transcoded.error.length > 3) v+= "Error
"; else v+= "Offline"; else v+= "Offline"; } v+= "
"; if(resp.telemetry.transcoded.hwuse) v+= "
CPU: "+resp.telemetry.transcoded.hwuse.CPU+"%
RAM: "+resp.telemetry.transcoded.hwuse.RAM+"%

"; w = 'Unknown'; if(resp.telemetry.transcoded.clients){ if(Array.isArray(resp.telemetry.transcoded.clients)){ w = '---'; if(resp.telemetry.transcoded.clients.length > 0){ w = "
"; for(var j=0;j 3) w+= "
"+resp.telemetry.transcoded.clients[j].IP+" - "+secondsReadable(t)+"
"; else w+= "
"+resp.telemetry.transcoded.clients[j].IP+" - "+secondsReadable(t)+"
"; } w+= "
"; } } } if(output.children[3].innerHTML != w) output.children[3].innerHTML = w; } output.children[2].innerHTML = v; } else output.children[2].innerHTML = "No data"; } } setTimeout(function(){stream_stat(id,output)},tmout); }, function(status){ output.innerHTML='Error '+status; setTimeout(function(){stream_stat(id,output)},10000); } ); */ } function servers_streams(servers){ for(var i in servers)if(servers[i]){ server_streams(i); } } function server_streams(id){ var data=new FormData(); data.append('id',id); data.append('sess',getCookie('PHPSESSID')); POST('/streams.php?server_streams',data,function(resp){ resp = JSON.parse(resp); if(resp['error']) output.innerHTML=resp['error']; else{ for(var i in resp){ var output = document.getElementById('stream_'+resp[i].ID); if(output){ if(resp[i].name) output.children[1].innerHTML = resp[i].name; if(resp[i].orderID) output.children[0].value = resp[i].orderID; if(resp[i].state <= 0){ output.children[2].innerHTML = "Disabled"; output.classList.add('disabled'); } else{ output.classList.remove('disabled'); if(resp[i].telemetry){ var v = ""; if(resp[i].telemetry.transcoded){ output.classList.remove('error'); v+= "
"; if(resp[i].telemetry.transcoded.uptime){ if(resp[i].telemetry.transcoded.outputs){ if(resp[i].telemetry.transcoded.outputs.length > 0){ output.classList.add('active'); for(j in resp[i].telemetry.transcoded.outputs)if(resp[i].telemetry.transcoded.outputs[j]){ bitrate = Math.round(resp[i].telemetry.transcoded.outputs[j].bitrate/1024).toString(); if(bitrate > 1000) bitrate = bitrate.substr(0,bitrate.length-3)+"'"+bitrate.substr(-3); v+= bitrate+" kbps
"; } if(resp[i].telemetry.transcoded.started) v+= ""+secondsReadable(resp[i].telemetry.transcoded.uptime)+""; else v+= ""+secondsReadable((resp[i].telemetry.transcoded.playlist_segments+resp[i].telemetry.transcoded.playlist_sequence)*resp[i].telemetry.transcoded.playlist_target_duration)+""; } else{ v+= "Offline"; output.classList.add('error'); output.classList.remove('active'); } } else{ resp[i].telemetry.transcoded.bitrate = Math.round(resp[i].telemetry.transcoded.bitrate/1024).toString(); if(resp[i].telemetry.transcoded.bitrate > 1000) resp[i].telemetry.transcoded.bitrate = resp[i].telemetry.transcoded.bitrate.substr(0,resp[i].telemetry.transcoded.bitrate.length-3)+"'"+resp[i].telemetry.transcoded.bitrate.substr(-3); v+= resp[i].telemetry.transcoded.bitrate+" kbps
"; if(resp[i].telemetry.transcoded.started) v+= secondsReadable(resp[i].telemetry.transcoded.uptime)+"
"; else v+= secondsReadable((resp[i].telemetry.transcoded.playlist_segments+resp[i].telemetry.transcoded.playlist_sequence)*resp[i].telemetry.transcoded.playlist_target_duration)+""; } } else{ output.classList.add('error'); output.classList.remove('active'); if(resp[i].telemetry.transcoded.error) if(resp[i].telemetry.transcoded.error.length > 3) v+= "Error
"; else v+= "Offline"; else v+= "Offline"; } v+= "
"; if(resp[i].telemetry.transcoded.hwuse) v+= "
CPU: "+resp[i].telemetry.transcoded.hwuse.CPU+"%
RAM: "+resp[i].telemetry.transcoded.hwuse.RAM+"%

"; w = 'Unknown'; if(resp[i].telemetry.transcoded.clients){ if(Array.isArray(resp[i].telemetry.transcoded.clients)){ w = '---'; if(resp[i].telemetry.transcoded.clients.length > 0){ w = "
"; for(var j=0;j 3) w+= "
"+resp[i].telemetry.transcoded.clients[j].IP+" - "+secondsReadable(t)+"
"; else w+= "
"+resp[i].telemetry.transcoded.clients[j].IP+" - "+secondsReadable(t)+"
"; } w+= "
"; } } } if(output.children[3].innerHTML != w) output.children[3].innerHTML = w; } else{ v+= "Offline"; output.classList.add('error'); output.classList.remove('active'); } output.children[2].innerHTML = v; } else output.children[2].innerHTML = "No data"; } } } } setTimeout(function(){server_streams(id)},10000); }, function(status){ output.innerHTML='Error '+status; setTimeout(function(){server_streams(id)},10000); } ); } function server_stat(id,output){ var data=new FormData(); data.append('id',id); POST('servers.php?stat',data,function(resp){ resp = JSON.parse(resp); if(resp['error']){ output.innerHTML=resp['error']; output.classList.remove('active'); output.classList.add('error'); } else{ output.innerHTML="Astra "+resp['version']+''; output.classList.add('active'); output.classList.remove('error'); } setTimeout(function(){server_stat(id,output)},10000); }, function(status){ output.innerHTML='Error '+status; setTimeout(function(){server_stat(id,output)},5000); } ); } function transcoder_stat(id,output){ POST('servers.php?server_stat='+id,0,function(resp){ resp = JSON.parse(resp); if(resp['error']){ output.innerHTML=""+resp['error']+""; output.classList.remove('active'); output.classList.add('error'); } else{ if(resp.RAM['%'] < 0) resp.RAM['%'] = Math.round(resp.RAM.used/resp.RAM.free*100)/100; if(!document.getElementById('server_'+id+'_ram')){ var o="
Uptime:
"+ "
Active Streams:
"+ "
RAM usage:"+generate_radial_loader('server_'+id+'_ram')+'
'+ "
CPU usage:"+generate_radial_loader('server_'+id+'_cpu')+"
"; if(typeof(resp.GPUS) == 'object'){ if(resp.GPUS.gpu.uuid)resp.GPUS.gpu=[resp.GPUS.gpu]; for(var i in resp.GPUS.gpu){ o+="
"+ ""+resp.GPUS.gpu[i].product_name+":"+ (resp.GPUS.gpu.length>1?"
gpu "+i+"
":'')+ "
Memory:"+generate_radial_loader('GPU_'+resp.GPUS.gpu[i].uuid+'_mem')+'
'+ "
Encoder:"+generate_radial_loader('GPU_'+resp.GPUS.gpu[i].uuid+'_enc')+'
'+ "
"; } } for(var i in resp.NET)if(resp.NET[i].state) if(resp.NET[i].state == 'up') o+="
Net "+i+":
"; output.innerHTML=o; } set_radial_loader(document.getElementById('server_'+id+'_ram'),resp.RAM['%'],0,100,'%'); set_radial_loader(document.getElementById('server_'+id+'_cpu'),resp.CPU,0,100,'%'); document.getElementById('server_'+id+'_ram').title=bitsReadable(resp.RAM['total']*resp.RAM['%']*10.24)+'B / '+bitsReadable(resp.RAM['total']*1024)+'B'; document.getElementById('server_'+id+'_uptime').innerHTML=secondsReadable(resp.runtime); document.getElementById('server_'+id+'_proc').innerHTML=resp.FFmpeg_processes; for(var i in resp.NET)if(resp.NET[i].state) if(resp.NET[i].state == 'up') document.getElementById("server_"+id+"_net_"+i+"_info").innerHTML="In: "+bitsReadable(resp.NET[i].rs)+'
Out: '+bitsReadable(resp.NET[i].ts); if(document.getElementById('server_'+id+'_cpu_loadbar')){ var bar = document.getElementById('server_'+id+'_cpu_loadbar').children; var col = loadColor(resp.CPU-50); bar[0].style = "width:"+resp.CPU+"%;background:"+col+";box-shadow:0 0 5px "+col+";"; bar[1].innerHTML = resp.CPU+"%"; } if(document.getElementById('server_'+id+'_ram_loadbar')){ var bar = document.getElementById('server_'+id+'_ram_loadbar').children; var col = loadColor(resp.RAM['%']); bar[0].style = "width:"+resp.RAM['%']+"%;background:"+col+";box-shadow:0 0 5px "+col+";"; bar[1].innerHTML = resp.RAM['%']+"%"; } for(var dev in resp.NET){ if(graphs['server_'+id+'_net_'+dev]){ graphs['server_'+id+'_net_'+dev].data.labels.push(''); graphs['server_'+id+'_net_'+dev].data.datasets[0].data.push(Math.round(resp.NET[dev].rs/1024/10.24)/100); graphs['server_'+id+'_net_'+dev].data.datasets[1].data.push(Math.round(resp.NET[dev].ts/1024/10.24)/100); if(graphs['server_'+id+'_net_'+dev].data.labels.length > 15){ graphs['server_'+id+'_net_'+dev].data.labels.shift(); graphs['server_'+id+'_net_'+dev].data.datasets[0].data.shift(); graphs['server_'+id+'_net_'+dev].data.datasets[1].data.shift(); } if(document.getElementById('server_'+id+'_net_'+dev)) graphs['server_'+id+'_net_'+dev].update(); } else{ graphs['server_'+id+'_net_'+dev] = { data: { labels: [''], datasets: [ { label: "RX", backgroundColor: "#03f", borderColor: "#03f", data: [Math.round(resp.NET[dev].rs/1024)/1024], fill: false }, { label: "TX", fill: false, backgroundColor: "#0f3", borderColor: "#0f3", data: [Math.round(resp.NET[dev].ts/1024)/1024] } ] } }; } } if(typeof(resp.GPUS) == 'object'){ if(resp.GPUS.gpu.uuid) resp.GPUS.gpu=[resp.GPUS.gpu]; for(var i in resp.GPUS.gpu){ if(document.getElementById('GPU_'+resp.GPUS.gpu[i].uuid+'_mem')){ var p = 100*parseInt(resp.GPUS.gpu[i].fb_memory_usage.used)/parseInt(resp.GPUS.gpu[i].fb_memory_usage.total); set_radial_loader(document.getElementById('GPU_'+resp.GPUS.gpu[i].uuid+'_mem'),p,0,100,'%'); document.getElementById('GPU_'+resp.GPUS.gpu[i].uuid+'_mem').title=resp.GPUS.gpu[i].fb_memory_usage.used+" / "+resp.GPUS.gpu[i].fb_memory_usage.total; } if(document.getElementById('GPU_'+resp.GPUS.gpu[i].uuid+'_enc')) set_radial_loader(document.getElementById('GPU_'+resp.GPUS.gpu[i].uuid+'_enc'),parseInt(resp.GPUS.gpu[i].utilization.encoder_util),0,100,'%'); } } } setTimeout(function(){transcoder_stat(id,output)},5000); }, function(status){ console.log('Error #'+status+' while updating transcoder stats'); setTimeout(function(){transcoder_stat(id,output)},5000); } ); } function server_edit(id){ sid=id; dimmer.style.visibility='visible'; dimmer.style.opacity=.5; var obj = document.getElementById('server_edit'); var loader = generate_loading_screen(); var div = document.getElementById('server_edit_content'); div.innerHTML = loader[0]; obj.style.visibility='visible'; obj.style.opacity=1; obj.style.top='50%'; loader = document.getElementById(loader[1]); POST('servers.php?edit='+sid,0, function(resp){ div.style.opacity=0; if(loader.parentNode != div) loader.style.opacity=0; setTimeout( function(){ loader.parentNode.removeChild(loader); div.innerHTML = resp; div.style.opacity=1; var g = document.getElementsByClassName('graph'); for(var i=0;i"); },function(e){alert("Error #"+e);}); dimmer.style=''; document.getElementById('server_edit').style=''; } } function user_edit(id){ uid=id; dimmer.style.visibility='visible'; dimmer.style.opacity=.5; var obj = document.getElementById('user_edit'); var loader = generate_loading_screen(); var div = document.getElementById('user_edit_content'); div.innerHTML = loader[0]; obj.style.visibility='visible'; obj.style.opacity=1; obj.style.top='50%'; if(uid == 'new') GET('user_edit.php?new',div,document.getElementById(loader[1])); else GET('user_edit.php?uid='+uid,div,document.getElementById(loader[1])); } function edit_user_cancel(){ dimmer.style=''; document.getElementById('user_edit').style=''; } function edit_user_update(butt){ if(document.getElementById('user_edit_name') && document.getElementById('user_edit_pwd')){ var name = document.getElementById('user_edit_name').value, pwd = document.getElementById('user_edit_pwd').value; if(name.length < 3 || name.length > 64) return alert("User name must be more than 3 and less than 64 characters long"); if(pwd.length < 3 || pwd.length > 64) return alert("User password must be more than 3 and less than 64 characters long"); butt.value='Updating...'; butt.disabled=true; var data=new FormData(); data.append('name',name); data.append('pwd',pwd); data.append('iplist',document.getElementById('user_edit_content_iplist').value); POST("user_edit.php?update="+uid,data,function(resp){ butt.value='Update'; butt.disabled=false; if(resp == '{"ok":true}'){ edit_user_cancel(); location.reload(); } else alert(resp); }, function(err){alert("Error #"+err);butt.value='Update';butt.disabled=false;} ); } } function edit_user_input_iplist(input){ input.value=input.value.replace(/[^\d\.\n]/g, ""); } function user_disable(id){ POST('user_edit.php?disable='+id,0,function(e){location.reload();},function(e){alert("Error #"+e);}); } function user_enable(id){ POST('user_edit.php?enable='+id,0,function(e){location.reload();},function(e){alert("Error #"+e);}); } function user_delete(id){ if(confirm("Are you sure you want to delete this user?")) POST('user_edit.php?delete='+id,0,function(e){location.reload();},function(e){alert("Error #"+e);}); } function show_adapter(serverID,adapterID){ sid=serverID; aid=adapterID; dimmer.style.visibility='visible'; dimmer.style.opacity=.5; var obj = document.getElementById('adapter_edit'); var loader = generate_loading_screen(); var div = document.getElementById('adapter_edit_content'); div.innerHTML = loader[0]; obj.style.visibility='visible'; obj.style.opacity=1; obj.style.top='50%'; GET('servers.php?adapter='+aid+'&server='+sid,div,document.getElementById(loader[1])); } function adapter_close(){ dimmer.style=''; document.getElementById('adapter_edit').style=''; } function adapter_scan(serverID,adapterID,button){ sid=serverID; aid=adapterID; var loader = generate_loading_screen(); var div = document.getElementById('adapter_scan_results'); div.innerHTML = loader[0]; button.value='Scanning...'; button.setAttribute('onclick',''); POST('servers.php?adapter='+aid+'&scan&server='+sid,'', function(response){ resp=JSON.parse(response); if(resp.error){ div.innerHTML=resp.error; button.value='Scan'; button.setAttribute('onclick',"adapter_scan('"+sid+"','"+aid+"',this)"); } else if(resp.id){ scan_id = resp.id; div.innerHTML='Scanning...'; scan_data = []; setTimeout(function(){adapter_scan_check(sid,scan_id,button,div,10)},1000); button.value='Stop scan'; button.setAttribute('onclick',"adapter_scan_stop('"+sid+"','"+scan_id+"',this)"); } else{ div.innerHTML='Scanning failed.'; button.value='Scan'; button.setAttribute('onclick',"adapter_scan('"+sid+"','"+aid+"',this)"); } }, function(error){ div.innerHTML=error; button.value='Scan'; button.setAttribute('onclick',"adapter_scan('"+sid+"','"+aid+"',this)"); } ); } function adapter_scan_stop(serverID,scan,button){ sid=serverID; button.value='Stopping scan...'; button.setAttribute('onclick',''); POST('servers.php?stop_scan='+scan+'&server='+sid,'', function(response){ resp=JSON.parse(response); if(resp.error){ alert("Scan stop failed:\n"+resp.error); button.value='Stop scan'; button.setAttribute('onclick',"adapter_scan_stop('"+sid+"','"+scan+"',this)"); } else if(resp.ok){ if(scan_id == scan) scan_id = false; button.value='Scan'; button.setAttribute('onclick',"adapter_scan('"+sid+"','"+aid+"',this)"); } else{ alert('Scan stop failed.'); button.value='Stop scan'; button.setAttribute('onclick',"adapter_scan_stop('"+sid+"','"+scan+"',this)"); } }, function(error){ alert("Scan stop failed:\n"+error); button.value='Stop scan'; button.setAttribute('onclick',"adapter_scan_stop('"+sid+"','"+scan+"',this)"); } ); } function adapter_scan_check(serverID,scan,button,div,count){ if(scan_id == scan && count >= 0){ button.value='Scanning... ('+count+')'; POST('servers.php?scan_check='+scan+'&server='+serverID,'', function(response){ resp=JSON.parse(response); if(resp.scan){ var sdl = JSON.stringify(scan_data); data = resp.scan; for(var i = 0, l = data.length; i < l; ++i) { var p = data[i]; switch(p.psi) { case "pat": scan_check_pat(p); break; case "pmt": scan_check_pmt(p); break; case "sdt": scan_check_sdt(p); break; default: break; } } if(sdl != JSON.stringify(scan_data) && scan_data.length){ div.innerHTML=''; for(var i=0;i"+scan_data[i].name+"
Provider: "+scan_data[i].provider+"
PNR: "+scan_data[i].pnr+" "; if(scan_data[i].type) ht+=scan_data[i].type; if(scan_data[i].drm) ht+=" DRM"; else ht+=" FTA"; ht+=""; div.innerHTML += ht; } div.innerHTML+="
"; } } count--; if(count >= 0){ setTimeout(function(){adapter_scan_check(serverID,scan,button,div,count)},1000); } else adapter_scan_stop(serverID,scan,button); }, function(error){ div.innerHTML=error; adapter_scan_stop(serverID,scan,button); } ); } else{ adapter_scan_stop(serverID,scan,button); } } function scan_check_pnr(pnr){ for(var i = 0, l = scan_data.length; i < l; ++i) { var s = scan_data[i]; if(s.pnr === pnr) return s; } return undefined; }; function scan_check_pat(pat){ for(var i = 0, l = pat.programs.length; i < l; ++i) { var p = pat.programs[i]; if(p.pnr !== 0) { var ss = scan_check_pnr(p.pnr); if(!ss) { scan_data.push({ pnr: p.pnr }); } } } }; function scan_check_pmt(pmt){ var check_cas = function(arr) { if(arr) { for(var i = 0, l = arr.length; i < l; ++i) { if(arr[i].type_id == 9) return true; } } return false; }; var drm = false, video = false; if(check_cas(pmt.descriptors)) drm = true; for(var i = 0, l = pmt.streams.length; i < l; ++i) { var s = pmt.streams[i]; if(s.type_name === "VIDEO") { video = true; if(check_cas(s.descriptors)) drm = true; } } var ss = scan_check_pnr(pmt.pnr); if(!ss) { ss = { pnr: pmt.pnr }; scan_data.push(ss); } ss.type = (video) ? "TV" : "Radio"; ss.drm = drm; }; function scan_check_sdt(sdt){ var check_sdt_desc = function(arr, ss) { if(!arr) return; for(var i = 0, l = arr.length; i < l; ++i) { var desc = arr[i]; if(desc.service_name) ss.name = desc.service_name; if(desc.service_provider) ss.provider = desc.service_provider; } }; for(var i = 0, l = sdt.services.length; i < l; ++i) { var s = sdt.services[i]; var ss = scan_check_pnr(s.sid); if(!ss) { ss = { pnr: s.sid }; scan_data.push(ss); } check_sdt_desc(s.descriptors, ss); } }; function adapter_add_selected(){ var doms = document.getElementsByClassName('stream_selected'); var adapter_id = document.getElementById('adapter_'+aid+'_settings').getAttribute('aid'); var streams = []; for(var i=0;i 0){ show_loader("Saving streams..."); var data=new FormData(); data.append('streams',JSON.stringify(streams)); POST('servers.php?push_streams&server='+sid,data,function(resp){ resp = JSON.parse(resp); if(resp.ok) show_loader("Streams Added!

"); else show_loader(resp.error+"
"); }, function(status){show_loader('Error '+status+"
");} ); } } function user_content_select(obj){ if(obj.parentNode.id == 'user_edit_content_avail') document.getElementById('user_edit_content_allow').appendChild(obj); else document.getElementById('user_edit_content_avail').appendChild(obj); } function graph_init(obj,id,config){ if(graphs[id]) config.data = graphs[id].data; graphs[id] = new Chart(obj.getContext("2d"), config); obj.setAttribute('graph_id',id); } function edit_profile(id){ pid = id; dimmer.style.visibility='visible'; dimmer.style.opacity=.5; dimmer.style.zIndex=99; dimmer.setAttribute('onclick','edit_profile_close()'); loader.style.visibility='visible'; loader.style.opacity=1; loader.style.top='50%'; var ldr = generate_loading_screen()[0]; loader.style.minWidth='100px'; loader.style.minHeight='100px'; loader.innerHTML=ldr; POST('stream_edit.php?profile='+pid+'&stream='+sid,0, function(resp){ loader.innerHTML=resp+""; var pres = document.getElementById('stream_edit_vpres').value; stream_edit_change_vcodec(document.getElementById('stream_edit_vcdec').value); stream_edit_change_vpreset(pres); }, function(status){ console.log('Error #'+status+' while opening transcoding profile'); edit_profile_close(); } ); } function edit_profile_close(){ dimmer.style.zIndex=10; dimmer.setAttribute('onclick','edit_stream_cancel()'); loader.innerHTML=""; loader.style=''; } function edit_profile_save(){ var holder = document.getElementById('transcoding_profiles'), vrate = parseInt(document.getElementById('stream_edit_vrate').value), vrate_min = parseInt(document.getElementById('stream_edit_vrate_min').value), vrate_max = parseInt(document.getElementById('stream_edit_vrate_max').value); if(!vrate) vrate = 1800; if(!vrate_min || vrate_min > vrate_max || vrate_min > vrate || vrate_min <= 0) vrate_min = vrate; if(!vrate_max || vrate_max < vrate_max || vrate_max < vrate) vrate_max = vrate; var data = { 'VideoCodec':document.getElementById('stream_edit_vcdec').value, 'VideoDecoder':document.getElementById('stream_edit_vdcdr').value, 'PreOptions':document.getElementById('stream_edit_decopts').value, 'VideoSize':document.getElementById('stream_edit_vsize').value, 'VideoFrameRate':parseInt(document.getElementById('stream_edit_frate').value), 'VideoBufferSize':parseInt(document.getElementById('stream_edit_vbuff').value), 'VideoBitRate':vrate, 'VideoBitRateRange':vrate_min+'-'+vrate_max, 'VideoPreset':document.getElementById('stream_edit_vpres').value, 'AVOptionVideo':document.getElementById('stream_edit_vopts').value, 'AudioCodec':document.getElementById('stream_edit_acdec').value, 'AudioBitRate':parseInt(document.getElementById('stream_edit_arate').value), 'AudioChannels':parseInt(document.getElementById('stream_edit_achns').value), 'AVOptionAudio':document.getElementById('stream_edit_aopts').value, 'Additional':document.getElementById('stream_edit_addpr').value }; if(!data.VideoCodec) data.VideoCodec = 'copy'; if(!data.VideoDecoder) data.VideoDecoder = 'auto'; if(!data.AudioCodec) data.AudioCodec = 'copy'; if(data.AudioChannels < 1) data.AudioChannels = 1; if(document.getElementById('transcoding_profile_'+pid)){ var div = document.getElementById('transcoding_profile_'+pid); div.setAttribute('data',JSON.stringify(data)); div.innerHTML = data.VideoCodec if(data.VideoCodec != 'copy') div.innerHTML+="
"+' | '+data.VideoSize+' | '+data.VideoBitRate+'kbps'; div.innerHTML+='
'+data.AudioCodec; if(data.AudioCodec != 'copy') div.innerHTML+=' | '+data.AudioBitRate+'kbps'; div.style.background='#fd8'; } else{ if(pid == 'new')pid = holder.children.length; var div = document.createElement("div"); div.style='position:relative;background:#fd8;color:#000;text-align:center;'; div.setAttribute('data',JSON.stringify(data)); div.className="div_button transition_fast transcoding_profile"; div.setAttribute('onclick','edit_profile('+pid+')'); div.id='transcoding_profile_'+pid; div.innerHTML = "
"+data.VideoCodec if(data.VideoCodec != 'copy') div.innerHTML+=' | '+data.VideoSize+' | '+data.VideoBitRate+'kbps'; div.innerHTML+='
'+data.AudioCodec; if(data.AudioCodec != 'copy') div.innerHTML+=' | '+data.AudioBitRate+'kbps'; holder.insertBefore(div,holder.children[holder.children.length-1]); } edit_profile_close(); } function profile_edit(id){ pid = id; dimmer.style.visibility='visible'; dimmer.style.opacity=.5; dimmer.style.zIndex=99; dimmer.setAttribute('onclick','profile_edit_close()'); loader.style.visibility='visible'; loader.style.opacity=1; loader.style.top='50%'; var ldr = generate_loading_screen()[0]; loader.style.minWidth='100px'; loader.style.minHeight='100px'; loader.innerHTML=ldr; POST('profile_edit.php?profile='+id,0, function(resp){ loader.innerHTML=resp+""; var pres = document.getElementById('stream_edit_vpres').value; stream_edit_change_vcodec(document.getElementById('stream_edit_vcdec').value); stream_edit_change_vpreset(pres); }, function(status){ console.log('Error #'+status+' while opening transcoding profile'); profile_edit_close(); } ); } function profile_edit_close(){ loader.innerHTML=""; loader.style=''; dimmer.style=''; dimmer.setAttribute('onclick',''); } function profile_edit_save(button){ button.value='Saving...'; var vrate = parseInt(document.getElementById('stream_edit_vrate').value), vrate_min = parseInt(document.getElementById('stream_edit_vrate_min').value), vrate_max = parseInt(document.getElementById('stream_edit_vrate_max').value), name = document.getElementById('stream_edit_profname').value; if(!vrate) vrate = 1800; if(!vrate_min || vrate_min > vrate_max || vrate_min > vrate || vrate_min <= 0) vrate_min = vrate; if(!vrate_max || vrate_max < vrate_max || vrate_max < vrate) vrate_max = vrate; var data = { 'VideoCodec':document.getElementById('stream_edit_vcdec').value, 'VideoDecoder':document.getElementById('stream_edit_vdcdr').value, 'PreOptions':document.getElementById('stream_edit_decopts').value, 'VideoSize':document.getElementById('stream_edit_vsize').value, 'VideoFrameRate':parseInt(document.getElementById('stream_edit_frate').value), 'VideoBufferSize':parseInt(document.getElementById('stream_edit_vbuff').value), 'VideoBitRate':vrate, 'VideoBitRateRange':[vrate_min,vrate_max], 'VideoPreset':document.getElementById('stream_edit_vpres').value, 'AVOptionVideo':document.getElementById('stream_edit_vopts').value, 'AudioCodec':document.getElementById('stream_edit_acdec').value, 'AudioBitRate':parseInt(document.getElementById('stream_edit_arate').value), 'AudioChannels':parseInt(document.getElementById('stream_edit_achns').value), 'AVOptionAudio':document.getElementById('stream_edit_aopts').value, 'Additional':document.getElementById('stream_edit_addpr').value }; if(!data.VideoCodec) data.VideoCodec = 'copy'; if(!data.VideoDecoder) data.VideoDecoder = 'auto'; if(!data.AudioCodec) data.AudioCodec = 'copy'; if(data.AudioChannels < 1) data.AudioChannels = 1; var json = JSON.stringify(data); var dt=new FormData(); dt.append('data',json); dt.append('name',name); POST('profile_edit.php?profile='+pid,dt, function(resp){ profile_edit_close(); var divs; if(pid == 'new'){ divs = document.createElement("tr"); divs.className='table_list stream_stat'; divs.id='profile_'+resp; divs.setAttribute('pid',resp); divs.innerHTML=""+name+"
"; document.getElementById('profiles_table').appendChild(divs); pid = resp; } divs = document.getElementById('profile_'+pid).children; divs[0].innerHTML = name; divs[1].innerHTML = "Video: "+data.VideoCodec; if(data.VideoCodec != 'copy') divs[1].innerHTML += ' '+data.VideoSize+'x'+data.VideoFrameRate+'fps @ '+data.VideoBitRate+'kbps'; divs[1].innerHTML += '
Audio: '+data.AudioCodec; if(data.AudioCodec != 'copy') divs[1].innerHTML += ' x'+data.AudioChannels+' @ '+data.AudioBitRate+'kbps'; divs[1].innerHTML += '
'+data.Additional; }, function(status){alert('Error #'+status+' while saving transcoding profile');console.log('Error #'+status+' while saving transcoding profile');} ); } function stream_edit_change_profpreset(val){ val = JSON.parse(val); document.getElementById('stream_edit_vcdec').value = val.VideoCodec; stream_edit_change_vcodec(val.VideoCodec); document.getElementById('stream_edit_vdcdr').value = val.VideoDecoder; document.getElementById('stream_edit_decopts').value = val.PreOptions; document.getElementById('stream_edit_vsize').value = val.VideoSize; document.getElementById('stream_edit_frate').value = val.VideoFrameRate; document.getElementById('stream_edit_vbuff').value = val.VideoBufferSize; document.getElementById('stream_edit_vrate').value = val.VideoBitRate; document.getElementById('stream_edit_vrate_min').value = val.VideoBitRateRange[0]; document.getElementById('stream_edit_vrate_max').value = val.VideoBitRateRange[1]; document.getElementById('stream_edit_vpres').value = val.VideoPreset; stream_edit_change_vpreset(val.VideoPreset); document.getElementById('stream_edit_vopts').value = val.AVOptionVideo; document.getElementById('stream_edit_acdec').value = val.AudioCodec; stream_edit_change_acodec(val.AudioCodec); document.getElementById('stream_edit_arate').value = val.AudioBitRate; document.getElementById('stream_edit_achns').value = val.AudioChannels; document.getElementById('stream_edit_aopts').value = val.AVOptionAudio; document.getElementById('stream_edit_addpr').value = val.Additional; }