var regxPass = new RegExp(/^[a-zA-Z\d]{6,32}$/); var regxUser = new RegExp(/^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]{3,32}$/); var regxPS1 = new RegExp(/^(0[bB]0)[0-9a-fA-F]{2}(0|2|4|6|8|[aA]|[cC]|[eE])$/); var regxPS2 = new RegExp(/^(0[bB]10)[0-9a-fA-F]{2}$/); var regIS = new RegExp(/^(0[bB]11)[0-9a-fA-F]{2}$/); var regI1 = new RegExp(/^(0[bB]2)[0-9a-fA-F]{3}$/); var regVier = new RegExp(/^(0[bB]80)[0-9a-fA-F]{2}$/); var regGoogleAnalytics = /(UA|YT|MO)-\d+-\d+/i; var validFolder = new RegExp(/^((?!\/)(?!\;)(?!\?)(?!\@)(?!\&)(?!\=)(?!\+)(?!\$).)*$/i); var regxUUID = new RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); var gridColors = new Array('#ee1c24', '#f8941d', '#00aef0', '#2e3192', '#39b54a', '#ed008c', '#92278f', '#000000'); var flot_dashboard_options = { series: { lines: { show: true }, points: { show: false } }, grid: { hoverable: true, //IMPORTANT! this is needed for tooltip to work borderWidth:0 }, yaxis: { min:0, minTickSize: 1, tickDecimals: 0 }, xaxis: { mode: "time", tickFormatter: function(val, axis) { var d = moment(val); return d.format("h:mm A"); }, ticks: 5 }, tooltip: true, tooltipOpts: { content: "%x.2 = %y.4", }, colors: gridColors }; var opts_dp_onlydate = { format: 'L' } var opts_dp_onlytime = { format: 'LT' } var uploadkeepalive; var keepaliveURL = 'keepalive.php'; function keepalive(upd){ //console.log("KEEPALIVE" + upd) clearInterval(uploadkeepalive); uploadkeepalive = 0; if (upd){ keepaliveURL = 'keepalive.php?1'; } else { keepaliveURL = 'keepalive.php'; } uploadkeepalive = setInterval(function(){ /*$.get(keepaliveURL, function( data ) { //console.log(data) if (data.status < 1){ window.location.replace("login.php"); } });*/ $.ajax({ url: "//sctv.viebit.com/" + keepaliveURL, success: function( data ) { //console.log(data) if (data.status < 1){ window.location.replace("/"); } }, //timeout: 1 }); }, 60000); } function hexToRgb(hex) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; hex = hex.replace(shorthandRegex, function(m, r, g, b) { return r + r + g + g + b + b; }); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; } function getContrastYIQ(hex){ var r = hexToRgb(hex).r; var g = hexToRgb(hex).g; var b = hexToRgb(hex).b; var yiq = ((r*299)+(g*587)+(b*114))/1000; return (yiq >= 128) ? 'black' : 'white'; } function showAlert(msg, field){ $( field ).parent().addClass( "has-error" ); $( "#status" ).empty().append( "
" + msg +"
" ); } function showAlert1(msg, field){ $( field ).parent().addClass( "has-error" ); $( "#auth_status" ).empty().append( "
" + msg +"
" ); } function showAlert2(msg, field){ $( field ).parent().addClass( "has-error" ); $( "#forgot_status" ).empty().append( "
" + msg +"
" ); } function showAlert3(msg, field){ $( field ).parent().addClass( "has-error" ); $( "#reset_status" ).empty().append( "
" + msg +"
" ); } function showAlert4(msg, field){ $( field ).parent().addClass( "has-error" ); $( "#auth_status_code" ).empty().append( "
" + msg +"
" ); } function showFormAlert(msg, field, status){ $( field ).parent().addClass( "has-error" ); $( status ).empty().append( "
" + msg +"
" ); } $('.vbNavTop .btnLogout').off('click').on('click', function() { //console.log("test"); logout_attempt = $.post('//sctv.viebit.com/include/logout.php'); logout_attempt.done(function(data) { console.log( data ); switch (data.responce) { case 1: //SUCCESS window.location.reload(); break; } }); }); var buttonClose = { label: '', cssClass: 'btn-danger btn-sm', action: function(dialog) { dialog.close(); } } var buttonNo = buttonClose; var buttonCancel = buttonClose; var buttonSubmitForgot = { label: ' Submit', cssClass: 'btn-success btn-sm', hotkey: 13, action: function(dialog) { $( "#forgot_form" ).submit(); } } var buttonForgot = { label: ' Forgot', cssClass: 'btn-info btn-sm dialog-button-left', action: function(dialog) { dialog.close(); BootstrapDialog.show(dialogForgot); } } var buttonLogin = { label: ' Login', cssClass: 'btn-success btn-sm', hotkey: 13, action: function(dialog) { $( "#login_form" ).submit(); } } var dialogForgotSucess = { title: 'WARNING', message: 'Please check your email for furthur instructions.', type: BootstrapDialog.TYPE_INFO, onshown: function (dialog){ setTimeout(function(){dialog.close()}, 5000); } } var buttonSave = { label: ' Save', cssClass: 'btn-success btn-sm', hotkey: 13, action: function(dialog) { dialog.getModalBody().find("form").submit(); } } var buttonChangePass = { label: ' Change Password', cssClass: 'btn-success btn-sm pull-left', hotkey: 13, action: function(dialog) { dialog.close() BootstrapDialog.show({ title: " Change Password ()", closable: false, message: "
" + "
" + "" + "
", size: BootstrapDialog.SIZE_NORMAL, type: BootstrapDialog.TYPE_PRIMARY, buttons: [buttonSave, buttonCancel], onshow: function(dialog){ $dialogHead = dialog.getModalHeader(); $dialogBody = dialog.getModalBody(); $dialogFooter = dialog.getModalFooter(); $.getJSON( "//sctv.viebit.com/admin/data_users.php", function( data ) { var id = data[0].user_id; //console.log(data) $dialogHead.find(".bootstrap-dialog-title .uid").text( data[0].username ); //$dialogBody.find(".uid").text( val.username ); $dialogBody.find("form").submit(function( event ) { //console.log(event); event.preventDefault(); //var postData = $(this).serializeArray(); //console.log(postData); if ($(this).find("input[name='txtNewPass']").val() == ""){ var output = "
"; output += "
"; output += ""; output += "
"; output += "
"; $( '#statusPassMod' ).empty().append(output); } else if (!regxPass.test($(this).find("input[name='txtNewPass']").val())){ var output = "
"; output += "
"; output += ""; output += "
"; output += "
"; $( '#statusPassMod' ).empty().append(output); } else if ($(this).find("input[name='txtNewPass']").val() != $(this).find("input[name='txtNewPassConfirm']").val()){ var output = "
"; output += "
"; output += ""; output += "
"; output += "
"; $( '#statusPassMod' ).empty().append(output); } else { $( '#statusPassMod' ).empty(); var postData = $(this).serializeArray(); postData.splice(0,10); postData.push({name: "user_id",value: id}); postData.push({name: "txtNewPass",value: Sha256.hash(data[0].username + ":" + $(this).find("input[name='txtNewPass']").val())}); console.log(postData); $.ajax({ url: '//sctv.viebit.com/include/edit_user_pass.php', //Server script to process data type: 'POST', //Ajax events //beforeSend: beforeSendHandler, success: function (e){ //console.log(e); dialog.close() BootstrapDialog.alert('Account password changed sucessfully.'); }, data: postData, }); } }); }); }, }); } } var buttonSaveProfileWithout2fx = { label: ' Yes', cssClass: 'btn-success btn-sm', hotkey: 13, action: function(dialog) { var formData = new FormData($dialogBody[0]); formData.append("user_id", dialog.getData('user_id') ) formData.append("mobile_phone", dialog.getData('mobile_phone') ) formData.append("2_factor", dialog.getData('2_factor') ) formData.append("email", dialog.getData('email') ) //var postData = $(this).serializeArray(); //console.log(formData) $.ajax({ url: '//sctv.viebit.com/include/edit_profile.php', //Server script to process data type: 'POST', //beforeSend: beforeSendHandler, success: function (e){ //console.log("RESPONSE = " + e) dialog.close(); }, //error: errorHandler, data: formData, mimeType:"multipart/form-data", cache: false, contentType: false, processData: false }); } } var dialogForgot = { title: ' Password Assistance', closable: false, message: "

Please enter the email address attached to your account below. An email will be dispatched with furthur instructions on how to reset your password.

", size: BootstrapDialog.SIZE_NORMAL, type: BootstrapDialog.TYPE_INFO, buttons: [buttonSubmitForgot, buttonClose], onshown: function(dialog){ $( "#email").focus(); $( "#forgot_form" ).submit(function( event ) { event.preventDefault(); $( "#status" ).empty(); if ($(this).find( "input[name='email']" ).val() == ""){ showAlert2("Please enter your email address","#email"); } else { var forgot_attempt = $.post( 'include/process_forgot_pass.php', { email: $( this ).find( "input[name='email']" ).val() } ); forgot_attempt.done(function( data ) { //console.log( data ); switch (data.responce){ case 1: //SUCCESS dialog.close(); BootstrapDialog.alert(dialogForgotSucess); break; case 2: //INVALID EMAIL showAlert2("The email address you entered is not valid.
Please try again.","#email"); break; case 3: //UNKNOWN CONNECTION ERROR showAlert2("An unknown error has occured.
Please try again.","#email"); break; case 4: //UNKNOWN EMAIL showAlert2("The email address you entered does not match any of the user accounts in our system.
Please try again.","#email"); break; } }); } }); } }; var dialogTwoFactor = { title: 'Two-Factor Authentication', closable: false, message: "

Please choose which destionation is used to send the unique, one time authentication code:

", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: ' Submit', cssClass: 'btn-success', action: function(dialog) { $( "#authsel_form" ).submit(); } }], onshown: function(dialog){ $( "#authsel_form" ).submit(function( event ) { event.preventDefault(); var postData = $(this).serializeArray(); var auth_attempt = $.post( 'include/send_auth_token.php', postData ); auth_attempt.done(function( data ) { if (data.responce == 1 || data.responce == 2){ var destSel = ""; switch (data.responce){ case 1: //SUCCESS destSel = "your mobile phone number ending in"; break; case 2: //BAD PASS destSel = "the email address"; break; } dialog.close(); BootstrapDialog.show({ title: 'Two-Factor Authentication', closable: true, message: "

A code was sent to " + destSel + " " + data.dest + ". Please enter the code below to continue:

", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: ' Authenticate', cssClass: 'btn-success', action: function(dialog) { $( "#auth_form" ).submit(); } }], onshown: function(dialog){ $( "#auth_form" ).submit(function( event ) { event.preventDefault(); $( "#auth_status" ).empty(); $( ".form-group").removeClass( "has-error" ); var $form = $( this ), token = $form.find( "input[name='token']" ).val(); if (token == ""){ showAlert4("Please enter the code you recieved","#token"); } else { var auth_attempt = $.post( 'include/process_auth.php', { token: token } ); } auth_attempt.done(function( data ) { switch (data.responce){ case 1: //SUCCESS window.location.href = "/"; break; case 2: //BAD PASS showAlert4("The code you entered does not match.
Please try again.","#token"); break; case 7: //FIRST LOGIN - REQUIRE PASS CHANGE dialog.close(); BootstrapDialog.show(dialogFirstVisit); break; } }); }); } }); } }); }); } } var dialogFirstVisit = { title: 'Welcome to VieBit!', closable: false, message: "

Since this is your first visit we'd like to offer you the opportunity to change your password from the default you were given. Please enter a new password and confirm it below:

", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: ' Change Password', cssClass: 'btn-success', action: function(dialog) { $( "#pass_reset" ).submit(); } }], onshown: function(dialog){ $( "#pass_reset" ).submit(function( event ) { event.preventDefault(); $( "#status" ).empty(); $( ".form-group").removeClass( "has-error" ); var $form = $( this ), password_val = $form.find( "input[name='new_password']" ).val(); passwordConf_val = $form.find( "input[name='confim_new_password']" ).val(); if (password_val == ""){ showAlert3("Please enter a new password","#new_password"); } else { if (!regxPass.test(password_val)){ showAlert3("You have entered an invalid password","#new_password"); } else { if (password_val != passwordConf_val){ showAlert3("The passwords you have entered do not match. Please try again.","#confim_new_password"); } else { var reset_attempt = $.post( 'include/process_pass_chg_at_login.php', { password: password_val } ); reset_attempt.done(function( data ) { switch (data.responce){ case 1: //SUCCESS dialog.close(); BootstrapDialog.show({ title: 'Password Reset', closable: true, message: "

Thank you for securing your account.

", size: BootstrapDialog.SIZE_SMALL, buttons: [{ label: 'Close', cssClass: 'btn-success', action: function(dialog) { window.location.href = "/"; } }], onshown: function(dialog){ setTimeout(function() { window.location.href = "/"; }, 3000); } }); break; } }); } } } }); } } $('.vbNavTop .btnLogin').off('click').on('click', function() { BootstrapDialog.show({ title: ' User Login', closable: false, message: "
", size: BootstrapDialog.SIZE_SMALL, type: BootstrapDialog.TYPE_INFO, buttons: [buttonForgot, buttonLogin, buttonClose], onshown: function(dialog){ $( "#username").focus(); $( "#login_form" ).submit(function( event ) { event.preventDefault(); $( "#status" ).empty(); //$( ".form-group").removeClass( "has-error" ); //var postData = $(this).serializeArray(); //console.log(postData) var form = $( "#login_form" ), username_val = form.find( "input[name='username']" ).val(); password_val = form.find( "input[name='password']" ).val(); if (username_val == ""){ showAlert("Please enter your username to login","#username"); } else { if (!regxUser.test(username_val)){ showAlert("You have entered an invalid username","#username"); } else { if (password_val == ""){ showAlert("Please enter your password to login","#password"); } else { if (!regxPass.test(password_val)){ showAlert("You have entered an invalid password","#password"); } else { var hashUserPass = Sha256.hash(username_val + ":" + password_val); hashAll = Sha256.hash(hashUserPass + ":"); var login_attempt = $.post( 'include/process_login.php', { username: username_val, hash: hashAll } ); } } } } login_attempt.done(function( data ) { //console.log(data); switch (data.responce){ case 1: //SUCCESS //window.location.href = "/"; window.location.reload(); break; case 2: //BAD PASS showAlert("Incorrect Password","#password"); break; case 3: //UNKNOWN USER showAlert("Unknown user account","#username"); break; case 4: //NO DATA showAlert("ERROR","#password"); break; case 5: //AUTHENTICATE //dialog.setTitle('Two-Factor Authentication'); //dialog.setMessage("

Please choose which destionation is used to send the unique, one time authentication code:

"); dialog.close(); BootstrapDialog.show(dialogTwoFactor); $('cell_phone').text(data.cell) $('email').text(data.email) break; case 7: //FIRST LOGIN - REQUIRE PASS CHANGE dialog.close(); BootstrapDialog.show(dialogFirstVisit); break; } }); }); } }); }); $('.vbNavTop .btnProfile').off('click').on('click', function() { BootstrapDialog.show({ title: ' User Profile', closable: false, message: "
" + "" + "
", size: BootstrapDialog.SIZE_NORMAL, type: BootstrapDialog.TYPE_INFO, buttons: [buttonChangePass, buttonSave, buttonClose], onshow: function(dialog){ $dialogHead = dialog.getModalHeader(); $dialogBody = dialog.getModalBody(); $dialogFooter = dialog.getModalFooter(); $dialogBody.find('input[name=chk2Factor]').bootstrapToggle('on'); $.getJSON( "//sctv.viebit.com/admin/data_users.php", function( data ) { //console.log(data) var id = data[0].user_id; //$dialogBody.find("input[name='user_id']").val(data[0].user_id); $dialogBody.find("input[name='txtUserName']").val(data[0].username); $dialogBody.find("input[name='txtUserMobilePhone']").val(data[0].mobile_phone).mask('(000) 000-0000').trigger('keyup'); $dialogBody.find("input[name='txtUserEmail']").val(data[0].email); if (data[0].bypass == 1){ $dialogBody.find("input[name='chk2Factor']").bootstrapToggle('on'); } else { $dialogBody.find("input[name='chk2Factor']").bootstrapToggle('off'); } //$dialogBody.find("#btnPasswordMod").attr("value", data[0].user_id); //$dialogBody.find("#btnPasswordMod").attr("data-name", data[0].username); var validator = $dialogBody.find("form").validate({ onkeyup: false, //errorContainer: "#profileErrors", rules: { txtUserMobilePhone: { required: true, phoneUS: true }, txtUserEmail: { required: true, email: true } }, messages: { txtUserMobilePhone: { required: "Please enter your mobile telephone number including the area code", phoneUS: "Please enter a valid US telephone number" } }, invalidHandler: function() { console.log(validator.numberOfInvalids() + " field(s) are invalid" ); }, submitHandler: function (){ if (!$dialogBody.find("input[name='chk2Factor']").prop('checked')){ BootstrapDialog.show({ type:BootstrapDialog.TYPE_WARNING, title: ' WARNING', message:'Two-Factor authentication has been enabled by default to protect your site. Disabling this feature is NOT recomended.
Are you sure?', closable: false, data: { 'user_id':id, 'mobile_phone':$dialogBody.find("input[name='txtUserMobilePhone']").cleanVal(), '2_factor':$dialogBody.find("input[name='chk2Factor']").prop('checked'), 'email':$dialogBody.find("input[name='txtUserEmail']").val() }, buttons: [buttonSaveProfileWithout2fx,buttonNo] }); dialog.close(); } else { //console.log($('#modalProfile')[0]) var formData = new FormData($dialogBody[0]); formData.append("user_id", id ) formData.append("mobile_phone", $dialogBody.find("input[name='txtUserMobilePhone']").cleanVal() ) formData.append("2_factor", $dialogBody.find("input[name='chk2Factor']").prop('checked') ) formData.append("email", $dialogBody.find("input[name='txtUserEmail']").val() ) //var postData = $(this).serializeArray(); //console.log(formData) //console.log($(this).find("input[name='txtAdGraphic']").files) $.ajax({ url: '//sctv.viebit.com/include/edit_profile.php', //Server script to process data type: 'POST', //beforeSend: beforeSendHandler, success: function (e){ //console.log(e) dialog.close(); }, //error: errorHandler, data: formData, mimeType:"multipart/form-data", cache: false, contentType: false, processData: false }); //event.unbind(); } } }); $('.btnDelete').off('click').on('click', function (e) { var id = $(this).data("uid"); }); }); } }); }); function secs2timecode(seconds){ var varHours = Math.floor(seconds/3600); var varMinutes = Math.floor((seconds%3600)/60); var varSeconds = Math.floor((seconds%3600)%60); if (varHours < 10){ varHours = "0" + varHours; } if (varMinutes < 10){ varMinutes = "0" + varMinutes; } if (varSeconds < 10){ varSeconds = "0" + varSeconds; } return varHours + ":" + varMinutes + ":" + varSeconds; } function timecode2secs(timecode){ var temp = timecode.split(":"); var varHours = (temp[0]*3600)*1; var varMinutes = (temp[1]*60)*1; var varSeconds = (temp[2])*1; return varHours + varMinutes + varSeconds; } function intToIP(int) { var part1 = int & 255; var part2 = ((int >> 8) & 255); var part3 = ((int >> 16) & 255); var part4 = ((int >> 24) & 255); return part4 + "." + part3 + "." + part2 + "." + part1; } function bytes2time(bytes) { var rate = 768 * 1000; //CONVERT Kbits to bits var bits = bytes * 8; //CONVERT BYTES TO BITS /*CALC BITS PER SECOND*/ var bps = bits / rate; /*CONVERT TO BITS PER MINUTE*/ var bpm = Math.floor(bps / 60); return bpm; //((plan_total*8) / 60 ) / 786432) } function getReadableFileSizeString(bytes) { var i = -1; var byteUnits = [' KB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; do { bytes = bytes / 1024; i++; } while (bytes > 1024); return Math.max(bytes, 0.1).toFixed(1) + byteUnits[i]; }; function ppReadableByteString(bytes, type) { type = type || 0; var i = 0; if (type < 1){ var byteUnits = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; } else { var byteUnits = ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Ebps', 'Zbps', 'Ybps']; } do { bytes = bytes / 1024; i++; } while (bytes > 1024); return Math.max(bytes, 0.1).toFixed(3) + byteUnits[i]; }; function bytesConvert(bytes,to){ if (to=="kb") { return Math.round((bytes/1024)*1)/1; } else if(to=="mb") { return Math.round((bytes/1024/1024)*1)/1; } else if(to=="gb") { return Math.round((bytes/1024/1024/1024)*1)/1; } } var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } };