2015-10-16 15:09:01 +02:00

9 lines
40 KiB
JavaScript

/*! pimpmylog - 1.7.9 - 10b502eaf17be208850be61febb044c2fdb86207*/
/*
* pimpmylog
* http://pimpmylog.com
*
* Copyright (c) 2015 Potsky, contributors
* Licensed under the GPLv3 license.
*/function s(a,b){"use strict";sort=a,sorto=b,reload_page(!0),get_logs(!1,!0)}function get_top_offset(){return parseInt($("#logsbody").find("tr:last-child").data("offset"),10)}function log_selector_init(){$(".logs-selector-yes").click(function(){$(this).parent().find("label.logs-selector-no").removeClass("btn-danger").addClass("btn-default"),$(this).parent().find("label.logs-selector-yes").addClass("btn-success")}),$(".logs-selector-no").click(function(){$(this).parent().find("label.logs-selector-yes").removeClass("btn-success").addClass("btn-default"),$(this).parent().find("label.logs-selector-no").addClass("btn-danger")}),$(".logs-selector-toggler").click(function(){var a=$(this).parents(".logs-selector").find("label.logs-selector-yes:first").hasClass("active");a===!0?$(this).parents(".logs-selector").find("label.logs-selector-no").click():$(this).parents(".logs-selector").find("label.logs-selector-yes").click()})}function get_alert(a,b,c){var d='<div class="alert alert-'+a+'" role="alert">';return c===!0&&(d+='<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>'),d+=b,d+="</div>"}$(function(){"use strict";$("#changeLogModal").on("show.bs.modal",function(){$.ajax({url:"version.js?local=true&callback=?",type:"GET",dataType:"jsonp",jsonp:"pml_version_cb"}).done(function(){}).fail(function(){}).always(function(){})})});var pml_version_cb=function(a){"use strict";var b={fixed:{name:"Fixed","class":"success"},"new":{name:"New","class":"warning"},changed:{name:"Changed","class":"info"}},c='<div class="alert alert-info"><a href="https://github.com/potsky/PimpMyLog" class="alert-link" target="_blank">Star me</a> on Github if you <span class="glyphicon glyphicon-heart"></span> me!</div>';for(var d in a.changelog){c+='<div class="panel panel-default">',c+=' <div class="panel-heading">',c+=' <h3 class="panel-title">',c+=" <strong>Version "+d+"</strong>",c+=void 0!==a.changelog[d].released?" - released on "+a.changelog[d].released:"",c+=" </h3>",c+=" </div>",c+=' <div class="panel-body">',void 0!==a.changelog[d].notice&&(c+='<div class="alert alert-warning">'+a.changelog[d].notice+"</div><br/>");for(var e in b)if(void 0!==a.changelog[d][e])for(var f in a.changelog[d][e]){var g=a.changelog[d][e][f].replace(/#([0-9]+)/g,'<a href="https://github.com/potsky/PimpMyLog/issues/$1" target="ghissue">#$1</a>');c+='<div class="row" style="margin-bottom:2px;"><div class="col-sm-2" ><span class="label label-'+b[e].class+'">'+b[e].name+'</span></div><div class="col-sm-10">'+g+"</div></div>"}c+=" </div>",c+="</div>",c+="<br/>"}c+='Congrats, you have read the full change log. <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" target="_blank">Here is a <span class="glyphicon glyphicon-gift"></span></a> for you!',$("#changeLogModal .modal-body").html(c)},type_parser=function(a){"use strict";var b="txt",c="",d=0;if(void 0!==a){var e=a.split("/");void 0!==e[1]?(d=parseInt(a.split("/").slice(-1),10),b=a.split("/").slice(0,-1).join("/")):b=a,e=b.split(":"),void 0!==e[1]&&(c=b.split(":").slice(1).join(":"),b=e[0])}return{parser:b,param:c,cut:d}},val_cut=function(a,b){"use strict";return void 0===b?a:0===b?a:a.length<=Math.abs(b)?a:b>0?a.substr(0,b)+"&hellip;":"&hellip;"+a.substr(b)},get_logs=function(load_default_values,load_full_file,load_from_get,load_more){"use strict";var wanted_lines;if($(".loadmore").button("loading"),null!==auto_refresh_timer&&(clearTimeout(auto_refresh_timer),auto_refresh_timer=null),load_default_values===!0){if(load_from_get===!0){var found;set_notification("true"===query_parameters.n?!0:"false"===query_parameters.n?!1:files[file].notify),found=files[file].max,void 0!==typeof query_parameters.m&&$("#max option").each(function(){this.value===query_parameters.m&&(found=query_parameters.m)}),set_max(found),found=files[file].refresh,void 0!==typeof query_parameters.r&&$("#autorefresh option").each(function(){this.value===query_parameters.r&&(found=query_parameters.r)}),set_auto_refresh(found),set_columns(void 0!==query_parameters.t?query_parameters.t.split(","):files[file].thinit),sort=void 0!==query_parameters.o?query_parameters.o:files[file].sort,sorto=void 0!==query_parameters.p?query_parameters.p:files[file].order}else set_max(files[file].max),set_auto_refresh(files[file].refresh),set_notification(files[file].notify),set_columns(files[file].thinit),sort=files[file].sort;files[file].export===!1?($("#export").hide(),$("#noexport").show()):export_default!==!1||files[file].export?($("#noexport").hide(),$("#export").show()):($("#export").hide(),$("#noexport").show()),load_full_file=!0}else load_default_values=!1;reload_page(!0),load_full_file===!0?(reset=1,file_size=0,load_more=!1,last_line="",has_loaded_more=!1):(reset=0,load_full_file=!1),$(".loader").toggle(),loading=!0,wanted_lines=$("#max").val();var post_values={ldv:load_default_values,file:file,filesize:file_size,max:wanted_lines,search:$("#search").val(),csrf_token:csrf_token,lastline:last_line,reset:reset};load_more===!0&&(post_values.sp=get_top_offset(),has_loaded_more=!0),$.ajax({url:"inc/getlog.pml.php?"+(new Date).getTime()+"&"+querystring,data:post_values,type:"POST",dataType:"json"}).fail(function(a){return $(".loader").toggle(),loading=!1,a.responseText.indexOf("Pimp My Log Login Match")>-1?(notify("Pimp my Logs ["+files[file].display+"]",lemma.youhavebeendisconnected),void document.location.reload()):a.error?($(".result").hide(),$("#error").show(),$("#errortxt").html(a.responseText),void notify("Pimp my Logs ["+files[file].display+"]",lemma.error)):void 0}).done(function(logs){if($(".loader").toggle(),loading=!1,logs.lastline&&(last_line=logs.lastline,file_size=logs.newfilesize),logs.error)return $(".result").hide(),$("#error").show(),$("#errortxt").html(logs.error),void notify(notification_title.replace("%i",file).replace("%f",files[file].display),lemma.error);if(logs.warning&&pml_alert(logs.warning,"warning"),logs.notice&&pml_alert(logs.notice,"info"),logs.singlewarning&&pml_singlealert(logs.singlewarning,"warning"),logs.singlenotice&&pml_singlealert(logs.singlenotice,"info"),$("#error").hide(),$(".result").show(),logs.full)if(logs.found===!1){var nolog=lemma.no_log;""!==logs.search&&(nolog=logs.regsearch?lemma.search_no_regex.replace("%s","<code>"+logs.search+"</code>"):lemma.search_no_regular.replace("%s","<code>"+logs.search+"</code>")),$("#nolog").html(nolog).show(),$("#logshead").hide()}else $("#nolog").text("").hide(),$("#logshead").show();else logs.logs&&($("#nolog").text("").hide(),$("#logshead").show());if(logs.regsearch?($("#searchctn").addClass("has-success"),$("#searchctn").prop("title",lemma.regex_valid)):($("#searchctn").removeClass("has-success"),$("#searchctn").prop("title",lemma.regex_invalid)),logs.headers){$("#logshead").text(""),$(".thmenucol").remove();var thtr=$("<tr>").addClass(file);sorto=1===parseInt(sorto,10)?1:-1;var sortn=-1;for(var h in logs.headers){$(".thmenuicon").removeClass("text-danger");var ic="";if(sort===h){sortn=-1*sorto;var q=1===sorto?"up":"down";ic='&nbsp;<span class="glyphicon glyphicon-chevron-'+q+'"></span>'}var a=$('<th style="white-space:nowrap;"><a href=\'javascript:s("'+h+'",'+sortn+")'>"+logs.headers[h]+ic+"</a></th>").addClass(h).appendTo(thtr),f;is_column_displayed(h)?f="on":($(a).hide(),f="off"),$('<li class="thmenucol"><a href="#" class="btn btn-default thmenuitem thmenu'+f+'" data-h="'+h+'" title="'+lemma.toggle_column.replace("%s",logs.headers[h])+'">'+logs.headers[h]+"</a></li>").appendTo(".thmenu")}thtr.appendTo("#logshead"),set_column_icon(),$(".thmenuitem").click(function(a){a.stopPropagation(),$(this).hasClass("thmenuon")?remove_column($(this).attr("data-h")):add_column($(this).attr("data-h"))})}logs.full&&$("#logsbody").text(""),void 0!==logs.logs&&$("#logsbody tr").removeClass("newlog");var uaparser=new UAParser,rowidx=0,rows=[];for(var log in logs.logs){var tr=$("<tr>").addClass(file).data("log",logs.logs[log].pml).data("offset",logs.logs[log].pmlo);for(var c in logs.logs[log])if("pml"!==c&&"pmlo"!==c&&"pmld"!==c){var type=type_parser(files[file].format.types[c]),val=logs.logs[log][c],title=val,output_html=!0;if("-"===val&&(val=""),"uaw3c"===type.parser&&(type.parser="ua",val=val.replace(/\+/g," ")),"badge"===type.parser){var clas;"http"===type.param?clas=badges[type.param][logs.logs[log][c].substr(0,1)]:"severity"===type.param&&(clas=badges[type.param][logs.logs[log][c].toLowerCase()],void 0===clas&&(clas=badges[type.param][logs.logs[log][c]])),void 0===clas&&(clas="default"),val='<span class="label label-'+clas+'">'+val_cut(val,type.cut)+"</span>"}else if("date"===type.parser)title=logs.logs[log].pml,val=val_cut(val,type.cut);else if("numeral"===type.parser)""!==val&&""!==type.param&&(val=numeral(val).format(type.param));else if("ip"===type.parser)val="geo"===type.param?'<a href="'+geoip_url.replace("%p",val)+'" target="linkout">'+val_cut(val,type.cut)+"</a>":'<a href="'+type.param+"://"+val+'" target="linkout">'+val_cut(val,type.cut)+"</a>";else if("link"===type.parser)val='<a href="'+val+'" target="linkout">'+val_cut(val,type.cut)+"</a>";else if("ua"===type.parser){var ua=uaparser.setUA(val).getResult(),uas=type.param.match(/\{[a-zA-Z.]*\}/g),uaf=!1;for(var k in uas){var d;try{d=eval("ua."+uas[k].replace("{","").replace("}","")),void 0===d&&(d="")}catch(e){d=""}""!==d&&(uaf=!0,type.param=type.param.replace(uas[k],d))}uaf===!0&&(val=$.trim(type.param))}else"preformatted"===type.parser?(val=val_cut(val.replace(/(?:\\r\\n|\\r|\\n)/g,"\n").replace(/\\t/g," "),type.cut),output_html=!1):"prefake"===type.parser?val=val_cut(val.replace(/(?:\r\n|\r|\n)/g,"<br/>"),type.cut):(val=val_cut(val,type.cut),output_html=!1);output_html===!1&&(val=val.replace(/&hellip;/g,"..."));var b=output_html===!0?$("<td></td>").html(val):$("<td></td>").text(val);b=b.prop("title",title).addClass("pml-"+c+" pml-"+type.parser).appendTo(tr),is_column_displayed(c)||$(b).hide()}logs.full||(tr.addClass("newlog"),rowidx++),rows.push(tr)}if(logs.full||load_more===!0)$("#logsbody").append(rows);else if($("#logsbody").prepend(rows),has_loaded_more!==!0){var rowd=$("#logsbody tr").length;rowd>wanted_lines&&(rowd-=wanted_lines,$("#logsbody").find("tr:nth-last-child(-n+"+rowd+")").remove())}var older_line_offset=get_top_offset();if(1>=older_line_offset||""!==logs.search&&parseInt(logs.lpo,10)<=1?$(".loadmore").text($(".loadmore").data("nomore-text")).addClass("disabled").prop("disabled","disabled").attr("title",""):$(".loadmore").button("reset").attr("title",sprintf(lemma.loadmore,numeral(older_line_offset).format("0 b"))),void 0!==sort){var i=0,col=-1;if($("#logshead tr th").each(function(){$(this).hasClass(sort)&&(col=i),i++}),col>=0){var tbody=document.getElementById("logsbody"),trs=Array.prototype.slice.call(tbody.rows,0);for(trs=trs.sort(function(a,b){return a=a.cells[col].getAttribute("title"),b=b.cells[col].getAttribute("title"),$.isNumeric(a)&&$.isNumeric(b)?sorto*(parseFloat(a)-parseFloat(b)):sorto*a.toLowerCase().localeCompare(b.toLowerCase())}),i=0;i<trs.length;++i)tbody.appendChild(trs[i])}}var rowct="",rowc=$("#logsbody tr").length;1===rowc?rowct=lemma.display_log+" ":rowc>1&&(rowct=lemma.display_nlogs.replace("%s",rowc)+" "),$("#footer").html(rowct+logs.footer),first_launch===!1&&(logs.full?logs.fingerprint!==fingerprint&&(notify(notification_title.replace("%i",file).replace("%f",files[file].display),lemma.new_logs),fingerprint=logs.fingerprint):1===rowidx?notify(notification_title.replace("%i",file).replace("%f",files[file].display),lemma.new_log):rowidx>1&&notify(notification_title.replace("%i",file).replace("%f",files[file].display),lemma.new_nlogs.replace("%s",rowidx))),first_launch=!1;var p=Math.max(0,parseInt($("#autorefresh").val(),10));p>0&&(auto_refresh_timer=setTimeout(function(){get_logs()},1e3*p))}).always(function(){})},notification_class="warning",set_notification=function(a){"use strict";void 0===a&&(a=notification),a===!0?($("#notification").removeClass("btn-warning btn-success btn-danger btn-default").addClass("active btn-"+notification_class),notification=!0):($("#notification").removeClass("btn-warning btn-success btn-danger active").addClass("btn-default"),notification=!1)},is_notification=function(){"use strict";return $("#notification").hasClass("active")},notify=function(a,b){"use strict";if("webkitNotifications"in window){var c=window.webkitNotifications.checkPermission();if(0===c){if(notification_class="success",set_notification(),notification===!0&&void 0!==a&&notification_displayed===!1){notification_displayed=!0;var d=window.webkitNotifications.createNotification("img/icon72.png",a,b);d.onclick=function(){window.focus(),d.close()},d.onclose=function(){notification_displayed=!1},d.show(),setTimeout(function(){try{d.close()}catch(a){}},5e3)}}else 2===c?(notification_class="danger",set_notification()):(notification_class="warning",set_notification(),window.webkitNotifications.requestPermission(function(){notify(a,b)}))}else if("Notification"in window)if("default"===window.Notification.permission)notification_class="warning",set_notification(),window.Notification.requestPermission(function(){notify(a,b)});else if("granted"===window.Notification.permission){if(notification_class="success",set_notification(),notification===!0&&void 0!==a&&notification_displayed===!1){notification_displayed=!0;var e=new window.Notification(a,{body:b,tag:"Pimp My Log"});e.onclick=function(){this.close()},e.onclose=function(){notification_displayed=!1}}}else if("denied"===window.Notification.permission)return notification_class="danger",void set_notification()},refresh_rss=function(){$("#exModalRefresh").button("loading"),$.ajax({url:$("#exModalUrl").text(),dataType:"text",success:function(a){$("#exModalRefresh").button("reset"),$("#exModalCtn").text(a)}})},get_rss=function(a){return $("#exModalResultLoading").show(),$("#exModalResult").hide(),$("#exModalRefresh").button("loading"),$.ajax({url:"inc/rss.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"get_rss_link",file:file,search:$("#search").val(),format:a}}).always(function(){}).fail(function(a){$("#prBody").html(get_alert("danger",c.message+"<hr/>"+a.responseText,!1))}).done(function(b){b.singlewarning?pml_singlealert(b.singlewarning,"warning"):b.singlenotice?pml_singlealert(b.singlenotice,"info"):b.error?pml_singlealert(b.error,"danger"):"if"===b.met?document.body.innerHTML+="<iframe src='"+b.url+"' style='display: none;' ></iframe>":("nd"===b.met?($("#exModalResultLoading").hide(),$("#exModalResult").hide(),$("#exModalRefresh").button("reset")):$.ajax({url:b.url,dataType:"text",success:function(a){$("#exModalCtn").text(a),$("#exModalResultLoading").hide(),$("#exModalResult").show(),$("#exModalRefresh").button("reset")}}),$("#exModalFormat").text(a),$("#exModalUrl").text(b.url),b.war===!1?$("#exModalWar").hide():$("#exModalWar").show(),$("#exModalOpen").attr("href",b.url),$("#exModal").modal("show"))}),!1};$(function(){"use strict";$("#prModal").on("show.bs.modal",function(){a()});var a=function(a,b,c){return $("#prAlert").html(void 0!==a?get_alert(a,b,c):""),$("#prBody").html('<img src="img/loader.gif"/>'),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"profile_get"}}).always(function(){}).fail(function(a){$("#prBody").html(get_alert("danger",a.responseText,!1))}).done(function(a){$("#prBody").html(a.singlewarning?get_alert("warning",a.singlewarning,!1):a.singlenotice?get_alert("info",a.singlenotice,!1):a.error?get_alert("danger",a.error,!1):a.b)}),!1};$("#prForm").on("submit",function(a){return b(),a.preventDefault(),!1});var b=function(){$("#prSave").button("loading");var b={csrf_token:csrf_token,action:"profile_save"};return $.each($("#prForm").serializeArray(),function(a,c){b[c.name]=c.value}),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:b}).always(function(){$("#prSave").button("reset")}).fail(function(a){$("#prAlert").html(get_alert("danger",a.responseText,!1))}).done(function(b){return b.singlewarning?($("#prBody").html(get_alert("warning",b.singlewarning,!1)),!1):b.singlenotice?($("#prBody").html(get_alert("info",b.singlenotice,!1)),!1):b.error?($("#prBody").html(get_alert("danger",b.error,!1)),!1):(a("success",lemma.profile_ok,!0),!1)}),!1};$("#cpModal").on("show.bs.modal",function(){$("#cpErr").hide(),$("#password1group").removeClass("has-error"),$("#password2group").removeClass("has-error"),$("#password3group").removeClass("has-error"),$("#cpSave").button("reset"),$("#password1").val(""),$("#password2").val(""),$("#password3").val("")}),$("#changepassword").on("submit",function(a){return $("#password1group").removeClass("has-error"),$("#password2group").removeClass("has-error"),$("#password3group").removeClass("has-error"),$("#cpErr").hide(),$("#cpSave").button("loading"),$("#cpErr").hide(),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{password1:$("#password1").val(),password2:$("#password2").val(),password3:$("#password3").val(),csrf_token:csrf_token,action:"change_password"}}).always(function(){$("#cpSave").button("reset")}).fail(function(a){$("#cpErrM").html(a.responseText).show(),$("#cpErr").show()}).done(function(a){if(a.singlewarning)$("#cpErr").html(get_alert("warning",a.singlewarning,!1)).show();else if(a.singlenotice)$("#cpErr").html(get_alert("info",a.singlenotice,!1)).show();else if(a.error)$("#cpErr").html(get_alert("danger",a.error,!1)).show();else if(a.ok)$("#notice").html(get_alert("success",a.ok,!0)),$("#cpModal").modal("hide");else if(a.errors){$("#cpErrUl").html("");for(var b in a.errors)$("#cpErrUl").append("<li>"+a.errors[b]+"</li>");for(var b in a.fields)$("#"+a.fields[b]+"group").addClass("has-error");$("#cpErr").show()}}),a.preventDefault(),!1}),$("#umModal").on("show.bs.modal",function(){users_load($("#usermanagement div.tab-pane.active").attr("id"))}),$('#usermanagement a[data-toggle="pill"]').on("shown.bs.tab",function(a){users_load($(a.target).attr("href"))}),$(".roles-user").click(function(){$(this).parent().find("label.roles-admin").removeClass("btn-danger").addClass("btn-default"),$(this).parent().find("label.roles-user").addClass("btn-primary"),$(this).parent().parent().parent().parent().find(".logs-selector").show()}),$(".roles-admin").click(function(){$(this).parent().find("label.roles-user").removeClass("btn-primary").addClass("btn-default"),$(this).parent().find("label.roles-admin").addClass("btn-danger"),$(this).parent().parent().parent().parent().find(".logs-selector").hide()}),$("#umUsersAddForm").on("submit",function(a){return a.preventDefault(),users_add_save(this)}),log_selector_init(),$("#umAnonymousForm").on("submit",function(a){return a.preventDefault(),anonymous_save(this)})});var users_load=function(a){switch(a.replace(/#/g,"")){case"umUsers":users_list();break;case"umAnonymous":anonymous_list();break;case"umAuthLog":users_authlog();break;default:console.log("Oups ! User action "+a+" is unknown !")}},users_list=function(a,b,c){return $("#umUsersListAlert").html(void 0!==a?get_alert(a,b,c):""),$("#umUsersListBody").html('<img src="img/loader.gif"/>'),$("#umUsersList").show(),$("#umUsersView").hide(),$("#umUsersEdit").hide(),$("#umUsersAdd").hide(),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"users_list"}}).always(function(){}).fail(function(a){$("#umUsersListBody").html(get_alert("danger",a.responseText,!1))}).done(function(a){if(a.singlewarning)$("#umUsersListBody").html(get_alert("warning",a.singlewarning,!1));else if(a.singlenotice)$("#umUsersListBody").html(get_alert("info",a.singlenotice,!1));else if(a.error)$("#umUsersListBody").html(get_alert("danger",a.error,!1));else{var b="",c=a.b.length;b+='<div class="row">',b+='<div class="col-sm-6"><p class="lead">'+c+" ",b+=c>1?lemma.users:lemma.user,b+="</p></div>",b+='<div class="col-sm-6 text-right">',b+='<a href="#" onclick="users_add()" class="btn btn-xs btn-primary">'+lemma.adduser+"</a>",b+="</div>",b+="</div>",b+='<div class="table-responsive">',b+='<table class="table table-striped table-hover" data-sort-name="username" data-sort-order="asc" id="userlisttable">',b+="<thead>",b+="<tr>",b+='<th data-field="username" data-sortable="true">'+lemma.username+"</th>",b+='<th data-field="roles" data-sortable="true">'+lemma.roles+"</th>",b+='<th data-field="creationdate" data-sortable="true">'+lemma.creationdate+"</th>",b+='<th data-field="lastlogin" data-sortable="true">'+lemma.lastlogin+"</th>",b+="</tr>",b+="</thead>",b+="<tbody>";for(var d in a.b){var e=a.b[d],f=e.u,g=e.roles,h=e.cd,i=(e.logs,e.lastlogin),j="";for(var k in g)switch(g[k]){case"admin":j+='<span class="label label-danger">'+g[k]+"</span>";break;case"user":j+='<span class="label label-primary">'+g[k]+"</span>";break;default:j+='<span class="label label-default">'+g[k]+"</span>"}i=void 0!==i?i.ts:"",b+="<tr>",b+='<td><a href="#" onclick="users_view(this)">'+f+"</a></td>",b+="<td>"+j+"</td>",b+="<td>"+h+"</td>",b+="<td>"+i+"</td>",b+="</tr>"}b+="</tbody>",b+="</table>",b+="</div>",$("#umUsersListBody").html(b),$("#userlisttable").bootstrapTable().bootstrapTable("hideLoading")}}),!1},users_view=function(a){$("#umUsersViewBody").html('<img src="img/loader.gif"/>'),$("#umUsersViewAlert").html(""),$("#umUsersList").hide(),$("#umUsersView").show(),$("#umUsersEdit").hide(),$("#umUsersAdd").hide();var b=$(a).data("user")?$(a).data("user"):$(a).text();return $("#umUserEditBtn").data("user",b).show(),currentuser===b?$("#umUserEditBtn").attr("disabled","disabled"):$("#umUserEditBtn").removeAttr("disabled"),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"users_view",u:b}}).always(function(){}).fail(function(a){$("#umUsersViewBody").html(get_alert("danger",a.responseText,!1))}).done(function(a){if(a.singlewarning)return $("#umUsersViewBody").html(get_alert("warning",a.singlewarning,!1)),!1;if(a.singlenotice)return $("#umUsersViewBody").html(get_alert("info",a.singlenotice,!1)),!1;if(a.error)return $("#umUsersViewBody").html(get_alert("danger",a.error,!1)),!1;if(a.e)return $("#umUsersViewBody").html(get_alert("danger",a.e,!1)),!1;var c="",d=new UAParser,e=$.inArray("admin",a.b.roles)>-1;c+='<div class="row del_base">',c+='<div class="col-sm-6"><p class="lead">'+a.b.u+"</p></div>",c+='<div class="col-sm-6 text-right">',currentuser!==b&&(c+='<div class="btn-group">',c+=' <button type="button" class="btn btn-xs btn-danger dropdown-toggle" data-toggle="dropdown">'+lemma.deleteuser+"...</button>",c+=' <ul class="dropdown-menu" role="menu">',c+=' <li><a href="#" onclick="users_delete(this);">'+lemma.reallydeleteuser+"</a></li>",c+=" </ul>",c+="</div>",c+="&nbsp;",c+='<div class="btn-group">',c+=' <button type="button" class="btn btn-xs btn-primary dropdown-toggle" data-toggle="dropdown">'+lemma.signinuser+"...</button>",c+=' <ul class="dropdown-menu" role="menu">',c+=' <li><a href="#" onclick="users_signinas(this);">'+lemma.reallysigninuser+"</a></li>",c+=" </ul>",c+="</div>"),c+="</div>",c+="</div>",c+='<table class="table table-striped table-hover">',c+="<tbody>";for(var f in a.b){var g=a.b[f];if("api_lastlogin"===f){var h=d.setUA(g.ua).getResult();g='<a href="'+$("<div/>").text(g.ur).html()+'" target="_blank" class="hyphen">'+g.ur+"</a><br/>"+g.ts+"<br/>"+g.ip+"<br/>"+h.browser.name+" "+h.browser.version+" - "+h.os.name+" "+h.os.version}else if("lastlogin"===f){var h=d.setUA(g.ua).getResult();g=g.ts+"<br/>"+g.ip+"<br/>"+h.browser.name+" "+h.browser.version+" - "+h.os.name+" "+h.os.version}else if("cb"===f)g||(g='<span class="label label-default">'+lemma.system+"</span>");else{if("u"===f)continue;if("at"===f)continue;if("hp"===f)continue;if("logs"===f)if(e===!0)g=lemma.all_access;else{var i="";for(var j in g)files[j]&&(i+=g[j].r===!0?'<span style="display:block;float:left;margin:2px;" class="label label-success" data-toggle="tooltip" data-placement="bottom" data-html="true" title="<div class=\'hyphen\'>'+$("<div/>").text(files[j].path).html()+'</div>">'+files[j].display+"</span> ":'<span style="display:block;float:left;margin:2px;" class="label label-danger" data-toggle="tooltip" data-placement="bottom" data-html="true" title="<div class=\'hyphen\'>'+$("<div/>").text(files[j].path).html()+'</div>">'+files[j].display+"</span> ");g=i}else if("roles"===f){var k="";for(var j in g)switch(g[j]){case"admin":k+='<span class="label label-danger">'+g[j]+"</span>";break;case"user":k+='<span class="label label-primary">'+g[j]+"</span>";break;default:k+='<span class="label label-default">'+g[j]+"</span>"}g=k}}c+="<tr>",c+="<th>"+lemma["user_"+f]+"</th>",c+="<td>"+g+"</td>",c+="</tr>"}c+="</tbody>",c+="</table>",$("#umUsersViewBody").html(c),$(function(){$('[data-toggle="tooltip"]').tooltip()})}),!1},users_add=function(){return $("#umUsersList").hide(),$("#umUsersView").hide(),$("#umUsersEdit").hide(),$("#umUsersAdd").show(),$("#umUsersAddLoader").hide(),$("#umUsersAddBody").show(),$("#umUsersAddPwdHelp").hide(),$("#umUsersAdd").find("label.logs-selector-yes").click(),$("#add-roles-user").click(),$("#add-username").val("").removeAttr("readonly"),$("#add-password").val(""),$("#add-password2").val(""),$("#umUsersAddAlert").html(""),$.each($("#umUsersAddForm").serializeArray(),function(a,b){$("#add-"+b.name+"-group").removeClass("has-error")}),$("#add-type").val("add"),$("#umUsersAddBtn").show(),$("#umUsersViewBtn").hide(),!1},users_add_save=function(){$("#umUsersAddSave").button("loading");var a={csrf_token:csrf_token,action:"users_add"};return $.each($("#umUsersAddForm").serializeArray(),function(b,c){$("#add-"+c.name+"-group").removeClass("has-error"),a[c.name]=c.value}),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:a}).always(function(){$("#umUsersAddSave").button("reset")}).fail(function(a){$("#umUsersAddAlert").html(get_alert("danger",a.responseText,!1))}).done(function(a){if(a.singlewarning)return $("#umUsersAddAlert").html(get_alert("warning",a.singlewarning,!1)),!1;if(a.singlenotice)return $("#umUsersAddAlert").html(get_alert("info",a.singlenotice,!1)),!1;if(a.error)return $("#umUsersAddAlert").html(get_alert("danger",a.error,!1)),!1;if(a.c>0){var b="<strong>"+lemma.form_invalid+"</strong><ul>";for(var c in a.e)b+="<li>"+a.e[c]+"</li>",$("#add-"+c+"-group").addClass("has-error");return b+="</ul>",$("#umUsersAddAlert").html(get_alert("danger",b,!1)),!1}users_list("success",lemma.user_add_ok,!0)}),!1},users_edit=function(a){var b=$(a).data("user");return $("#umUsersList").hide(),$("#umUsersView").hide(),$("#umUsersEdit").hide(),$("#umUsersAdd").show(),$("#umUsersAddLoader").show(),$("#umUsersAddBody").hide(),$("#umUsersAddPwdHelp").show(),$("#umUsersAdd").find("label.logs-selector-no").click(),$("#add-roles-user").click(),$("#add-username").val(b).attr("readonly","readonly"),$("#add-password").val(""),$("#add-password2").val(""),$("#umUsersAddAlert").html(""),$.each($("#umUsersAddForm").serializeArray(),function(a,b){$("#add-"+b.name+"-group").removeClass("has-error")}),$("#add-type").val("edit"),$("#umUsersAddBtn").hide(),$("#umUsersViewBtn").show().data("user",b),$("#umUsersAddSave").button("loading"),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"users_edit",u:b}}).always(function(){$("#umUsersAddSave").button("reset"),$("#umUsersAddLoader").hide(),$("#umUsersAddBody").show()}).fail(function(a){$("#umUsersAddBody").html(get_alert("danger",a.responseText,!1))}).done(function(a){if(a.b.roles)for(var b in a.b.roles)$("#add-roles-"+a.b.roles[b]).click();if(a.b.logs)for(var b in a.b.logs)$("#add-logs-f-"+b+"-"+a.b.logs[b].r).click()}),!1},users_delete=function(a){var b=$(a).parents(".del_base").find("p.lead").text();return $.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"users_delete",u:b}}).always(function(){}).fail(function(a){$("#umUsersViewAlert").html(get_alert("danger",a.responseText,!1))}).done(function(a){return a.singlewarning?($("#umUsersViewAlert").html(get_alert("warning",a.singlewarning,!1)),!1):a.singlenotice?($("#umUsersViewAlert").html(get_alert("info",a.singlenotice,!1)),!1):a.error?($("#umUsersViewAlert").html(get_alert("danger",a.error,!1)),!1):(users_list("success",lemma.user_delete_ok,!0),!1)}),!1},users_signinas=function(a){var b=$(a).parents(".del_base").find("p.lead").text();return $.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"users_signinas",u:b}}).always(function(){}).fail(function(a){$("#umUsersViewAlert").html(get_alert("danger",a.responseText,!1))}).done(function(a){return a.singlewarning?($("#umUsersViewAlert").html(get_alert("warning",a.singlewarning,!1)),!1):a.singlenotice?($("#umUsersViewAlert").html(get_alert("info",a.singlenotice,!1)),!1):a.error?($("#umUsersViewAlert").html(get_alert("danger",a.error,!1)),!1):(document.location.reload(),!1)}),!1},users_logfiles=function(){},users_authlog=function(){return $("#umAuthLogBody").html('<img src="img/loader.gif"/>'),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"authlog"}}).always(function(){}).fail(function(a){$("#umAuthLogBody").html(get_alert("danger",a.responseText,!1))}).done(function(a){if(a.singlewarning)return $("#umAuthLogBody").html(get_alert("warning",a.singlewarning,!1)),!1;if(a.singlenotice)return $("#umAuthLogBody").html(get_alert("info",a.singlenotice,!1)),!1;if(a.error)return $("#umAuthLogBody").html(get_alert("danger",a.error,!1)),!1;var b=a.b.length,c="";if(b>0){var d=new UAParser;c+='<div class="table-responsive">',c+='<table class="table table-striped table-hover" data-sort-name="date" data-sort-order="desc" id="authlogtable">',c+="<thead>",c+="<tr>",c+='<th data-field="date" data-sortable="true">'+lemma.date+"</th>",c+='<th data-field="username" data-sortable="true">'+lemma.username+"</th>",c+='<th data-field="action" data-sortable="true">'+lemma.action+"</th>",c+='<th data-field="ip" data-sortable="true">'+lemma.ip+"</th>",c+='<th data-field="useragent" data-sortable="true">'+lemma.useragent+"</th>",c+="</tr>",c+="</thead>",c+="<tbody>";for(var e=0;b>e;e++){var f=a.b[e][2],g=a.b[e][0],h=a.b[e][1],i=a.b[e][3],j=d.setUA(a.b[e][4]).getResult();switch(j=j.browser.name+" "+j.browser.version+" - "+j.os.name+" "+j.os.version,g){case"signin":g='<span class="label label-success">'+lemma.signin+"</span>";break;case"signinerr":g='<span class="label label-danger">'+lemma.signinerr+"</span>";break;case"signout":g='<span class="label label-warning">'+lemma.signout+"</span>";break;case"changepwd":g='<span class="label label-info">'+lemma.changepwd+"</span>"}g=g.replace(/^addadmin/,'<span class="label label-info">'+lemma.addadmin+"</span>"),g=g.replace(/^adduser/,'<span class="label label-info">'+lemma.adduser+"</span>"),g=g.replace(/^signinas/,'<span class="label label-success">'+lemma.signinas+"</span>"),g=g.replace(/^deleteuser/,'<span class="label label-info">'+lemma.deleteuser+"</span>"),c+="<tr>",c+="<td>"+f+"</td>",c+="<td>"+h+"</td>",c+="<td>"+g+"</td>",c+="<td>"+i+"</td>",c+='<td title="'+$("<div/>").text(a.b[e][4]).html()+'">'+j+"</td>",c+="</tr>"}c+="</tbody>",c+="</table>",c+="</div>"}else c=get_alert("info",lemma.authlogerror,!1);$("#umAuthLogBody").html(c),$("#authlogtable").bootstrapTable().bootstrapTable("hideLoading")}),!1},anonymous_save=function(){$("#umAnonymousSave").button("loading");var a={csrf_token:csrf_token,action:"anonymous_save"};return $.each($("#umAnonymousForm").serializeArray(),function(b,c){a[c.name]=c.value}),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:a}).always(function(){$("#umAnonymousSave").button("reset")
}).fail(function(a){$("#umAnonymousAlert").html(get_alert("danger",a.responseText,!1))}).done(function(a){return a.singlewarning?($("#umAnonymousBody").html(get_alert("warning",a.singlewarning,!1)),!1):a.singlenotice?($("#umAnonymousBody").html(get_alert("info",a.singlenotice,!1)),!1):a.error?($("#umAnonymousBody").html(get_alert("danger",a.error,!1)),!1):(anonymous_list("success",lemma.anonymous_ok,!0),!1)}),!1},anonymous_list=function(a,b,c){return $("#umAnonymousAlert").html(void 0!==a?get_alert(a,b,c):""),$("#umAnonymousBody").html('<img src="img/loader.gif"/>'),$.ajax({url:"inc/users.pml.php?"+(new Date).getTime()+"&"+querystring,type:"POST",dataType:"json",data:{csrf_token:csrf_token,action:"anonymous_list"}}).always(function(){}).fail(function(a){$("#umAnonymousBody").html(get_alert("danger",a.responseText,!1))}).done(function(a){a.singlewarning?$("#umAnonymousBody").html(get_alert("warning",a.singlewarning,!1)):a.singlenotice?$("#umAnonymousBody").html(get_alert("info",a.singlenotice,!1)):a.error?$("#umAnonymousBody").html(get_alert("danger",a.error,!1)):($("#umAnonymousBody").html(a.b),log_selector_init())}),!1},file,notification,displayed_th,auto_refresh_timer,fingerprint,first_launch,file_size,last_line,loading,reset,sort,sorto,has_loaded_more=!1,notification_displayed=!1,query_parameters=function(){for(var a,b=[],c=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),d=0;d<c.length;d++)a=c[d].split("="),b.push(a[0]),b[a[0]]=decodeURIComponent(a[1]);return b}(),clipboard_enable=function(a,b,c,d){$(a).on("mouseover",function(){$(a).off("mouseover"),$(a).zclip({path:"js/ZeroClipboard.swf",copy:function(){return $(b).val()?$(b).val():$(b).text()},afterCopy:function(){$(a).popover({html:!0,animation:!0,placement:c,delay:{show:100,hide:5e3},content:d}).popover("show"),setTimeout(function(){$(a).popover("hide")},2e3),$(a).on("hidden.bs.popover",function(){$(a).show()})}})})},reload_page=function(a){"use strict";a="undefined"!=typeof a?a:!1;var b={tz:$("select#cog-tz").val(),l:$("select#cog-lang").val(),w:$("#cog-wide").data("value"),o:sort,p:sorto,i:file,m:$("#max").val(),r:$("#autorefresh").val(),s:$("#search").val(),n:notification};custom_columns()===!0&&(b.t=get_columns());var c=window.location.href.split("?")[0]+"?"+$.param(b);a===!1?document.location.href=c:window.history.pushState({pageTitle:document.title},"",c)},set_auto_refresh=function(a){"use strict";$("#autorefresh").val(a)},set_max=function(a){"use strict";$("#max").val(a)},get_columns=function(){"use strict";return $.isArray(displayed_th)===!0?displayed_th.join(","):!1},set_columns=function(a){"use strict";displayed_th=$.isArray(a)===!0?0===a.length?!1:a:!1},set_column_icon=function(){$(".thmenuoff").length>0?$(".thmenuicon").addClass("text-danger"):$(".thmenuicon").removeClass("text-danger")},parse_columns=function(){var a=[];$(".thmenuon").each(function(){a.push($(this).data("h"))}),set_columns(a),set_column_icon(),reload_page(!0)},custom_columns=function(){"use strict";return $.isArray(displayed_th)},is_column_displayed=function(a){"use strict";return $.isArray(displayed_th)===!0?$.inArray(a,displayed_th)>-1:!0},remove_column=function(a){"use strict";$('.thmenuitem[data-h="'+a+'"]').removeClass("thmenuon"),$('.thmenuitem[data-h="'+a+'"]').addClass("thmenuoff"),$("."+a).hide(),$(".pml-"+a).hide(),parse_columns()},add_column=function(a){"use strict";$('.thmenuitem[data-h="'+a+'"]').removeClass("thmenuoff"),$('.thmenuitem[data-h="'+a+'"]').addClass("thmenuon"),$("."+a).show(),$(".pml-"+a).show(),parse_columns()},set_title=function(){"use strict";document.title=title_file.replace("%i",file).replace("%f",files[file].display)},pml_alert=function(a,b){"use strict";$('<div class="alert alert-'+b+' alert-dismissable fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+a+"</div>").appendTo("#notice")},pml_singlealert=function(a,b){"use strict";$("#singlenotice").html('<div class="alert alert-'+b+' alert-dismissable fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+a+"</div>")};$(function(){"use strict";function a(a){return a?"addClass":"removeClass"}$("#singlelog").length?(file=$("#singlelog").data("file"),set_title(),get_logs(!0)):"bs"===file_selector?($(".file_menup.active").length||$(".file_menup:first").addClass("active"),$("#file_selector").text($(".file_menup.active:first a").text()),file=$(".file_menup.active").data("file"),set_title(),$(".file_menu").click(function(){$("#file_selector").text($(this).text()),$(".file_menup").removeClass("active"),$(this).parent().addClass("active"),file=$(this).parent().data("file"),set_title(),get_logs(!0)})):(file=$("#file_selector_big").val(),set_title(),$("#file_selector_big").change(function(){file=$("#file_selector_big").val(),set_title(),get_logs(!0)})),$(".logo").click(function(){document.location.href="?"}),$("#refresh").click(function(){notify(),get_logs()}),$(".cog").click(function(){switch($(this).data("cog")){case"wideview":"on"===$(this).data("value")?($(this).data("value","off"),$(this).find(".cogon").hide(),$(this).find(".cogoff").show(),$(".tableresult").removeClass("containerwide").addClass("container")):($(this).data("value","on"),$(this).find(".cogoff").hide(),$(this).find(".cogon").show(),$(".tableresult").addClass("containerwide").removeClass("container"))}reload_page(!0)}),$(".cog").each(function(){"on"===$(this).data("value")?($(this).find(".cogon").show(),$(this).find(".cogoff").hide(),$(".tableresult").addClass("containerwide").removeClass("container")):($(this).find(".cogon").hide(),$(this).find(".cogoff").show(),$(".tableresult").addClass("container").removeClass("containerwide"))}),$("#cog-lang").change(function(){reload_page()}),$("#cog-tz").change(function(){reload_page()}),$(document).keypress(function(a){$(a.target).is("input, textarea")||(114===a.which?(notify(),get_logs()):(102===a.which||47===a.which)&&(a.preventDefault(),$("#search").focus()))}),$(document).on("input",".clearable",function(){$(this)[a(this.value)]("x")}).on("mousemove",".x",function(b){$(this)[a(this.offsetWidth-18<b.clientX-this.getBoundingClientRect().left)]("onX")}).on("click",".onX",function(){$(this).removeClass("x onX").val("")}),""!==$("#search.clearable").val()&&$("#search.clearable")[a($("#search.clearable").val())]("x"),$("#search").blur(function(){get_logs(!1,!0)}),$(document).keydown(function(a){13===a.keyCode&&$("#search").is(":focus")&&($("#search").blur(),get_logs(!1,!0))}),set_auto_refresh(logs_refresh_default),$("#autorefresh").change(function(){get_logs()}),set_max(logs_max_default),$("#max").change(function(){get_logs(!1,!0)}),("Notification"in window||"webkitNotifications"in window)&&($("#notification").show(),set_notification(notification_default)),$("#notification").click(function(){$(this).hasClass("btn-warning")?notify():$(this).hasClass("btn-danger")?pml_alert(lemma.notification_deny,"danger"):set_notification(!is_notification()),reload_page(!0)}),notify(),$("#logsbody").click(function(a){var b=$(a.target);$(b).hasClass("pml-date")&&($(b).siblings().toggleClass("marker"),$(b).toggleClass("marker"))}),$("#clear-markers").click(function(){$(".marker").removeClass("marker")}),pull_to_refresh===!0&&$("#hook").hook({dynamic:!1,reloadPage:!1,reloadEl:function(){notify(),get_logs()}}),$(".loadmore").click(function(){get_logs(!1,!1,!1,!0)}),clipboard_enable("a.clipboardex","#exModalUrl","right",lemma.urlcopied),clipboard_enable("a.clipboardexr","#exModalCtn","right",lemma.resultcopied),$('[data-toggle="tooltip"]').tooltip(),get_logs(!0,!0,!0),$.ajax({url:"inc/upgrade.pml.php?"+(new Date).getTime()+"&"+querystring,dataType:"json",data:{csrf_token:csrf_token},type:"POST"}).done(function(a){$("#upgradefooter").html(" - "+a.footer);var b=$.cookie("upgradehide");if(b!==a.to&&($("#upgrademessage").html(a.alert),$("#upgradestop").click(function(){$.cookie("upgradehide",$(this).data("version")),$("#upgradealert").alert("close")})),a.messagesto){{$.cookie("messageshide")}$("#upgrademessages").html(a.messages),$("#messagesstop").click(function(){$.cookie("messageshide",$(this).data("version")),$("#messagesalert").alert("close")})}$("#upgradegitpull").unbind().on("click",function(){$("#upgradegitpull").button("loading"),$.ajax({url:"inc/upgrade.pml.php?"+(new Date).getTime()+"&"+querystring,dataType:"json",data:{csrf_token:csrf_token,action:"upgradegitpull"},type:"POST"}).fail(function(a,b,c){$("#upgradegitpull").button("reset"),$("#upgradeerror").html(c).show(),$("#upgradeerrorctn").show(),$("#upgradealert").hide()}).done(function(a){a.logs?document.location.reload():($("#upgradeerror").html(a.error),$("#upgradeerrorctn").show(),$("#upgradealert").hide())})})})});