<commit_before><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <meta content="Bootstrap static html page for campaign administration."
    name="description">
    <meta content=
    "RTB,OpenRTB,JAVA,Advertising,real-time,campaign,administration" name=
    "keywords">
    <meta content="RTB4FREE" name="author">

    <title>RTB4FREE Monitor</title>
    <link rel="shortcut icon" href="images/alien.png">
    <link href=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
    rel="stylesheet">
    <link href=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"
    rel="stylesheet">
    <link href="bootstrap-dialog.css" rel="stylesheet">
    <script src=
    "https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script src="bootstrap-dialog.js"></script>
    <script src="js/rtb4free.js"></script>
    <style type="text/css">
.bs-example{
        margin: 20px;
    }
    
    .form-signin
{
    max-width: 330px;
    padding: 15px;
    margin: 0 auto;
}
.form-signin .form-signin-heading, .form-signin .checkbox
{
    margin-bottom: 10px;
}
.form-signin .checkbox
{
    font-weight: normal;
}
.form-signin .form-control
{
    position: relative;
    font-size: 16px;
    height: auto;
    padding: 10px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
.form-signin .form-control:focus
{
    z-index: 2;
}
.form-signin input[type="text"]
{
    margin-bottom: -1px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.form-signin input[type="password"]
{
    margin-bottom: 10px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
.account-wall
{
    margin-top: 20px;
    padding: 40px 0px 20px 0px;
    background-color: #f7f7f7;
    -moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
}
.login-title
{
    color: #555;
    font-size: 18px;
    font-weight: 400;
    display: block;
}
.profile-img
{
    width: 96px;
    height: 96px;
    margin: 0 auto 10px;
    display: block;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    border-radius: 50%;
}
.need-help
{
    margin-top: 10px;
}
.new-account
{
    display: block;
    margin-top: 10px;
}

    </style>
</head>

<body>


 <div class="container">
 
    <div class="row" id="login">
        <div class="col-sm-6 col-md-4 col-md-offset-4">
            <h1 class="text-center login-title">Sign in to Monitor RTB4FREE</h1>
            <div >
                <form class="form">
                <input type="text" class="form-control" placeholder="Email" required autofocus id="username" value='demo'>
                <input type="password" class="form-control" placeholder="Password" required id="password" value='<PASSWORD>'>
                <input type="button" class="btn btn-primary btnSeccion" onclick="doFormLogin();" value="Sign In"></button>
                </form>
            </div>
         </div>
    </div>
    </div>

<script type="text/javascript">

function toggle(elementId) {
	var ele = document.getElementById(elementId);
	if(ele.style.display == "block") {
    		ele.style.display = "none";
  	}
	else {
		ele.style.display = "block";
	}
} 

</script>

        </div>
    </div>
</div>

 <div class="bs-example" style="display:none" id="bs-example">
           
  <div class="panel panel-primary">
   <div class="panel-heading">
      <h3 class="panel-title">RTB4FREE System Administration Page
      <a id='savechanges' href="#" onclick="saveChanges(); return false;" class="btn btn-success btn-sm"><i class="icon-white icon-heart"></i>Save Changes</a>
      		<a href="#" onclick="revert()" class="btn btn-info btn-sm"><i class="icon-white icon-heart"></i>Revert</a>
      	<a href="admin" class="btn btn-danger btn-sm"><i class="icon-white icon-heart"></i>Logout</a></h3>
   </div>
   <div class="panel-body">

        
        <p>This page is used to manage the operational RTB4FREE Bidder Farm</p>

</div>


   
            


        <ul class="nav nav-tabs" id="myTab">

            <li >
                <a data-toggle="tab" href="#users" onclick="setPaneOptions('users');">Users</a>
            </li>
            <li>
                <a data-toggle="tab" href="#configuration" onclick="setPaneOptions('config');">Configuration</a>
            </li>

            <li class='active'>
                <a data-toggle="tab" href="#status" onclick="setPaneOptions('status');">System Status</a>
            </li>
             <li >
                <a data-toggle="tab" href="#campaigns" onclick="setPaneOptions('users');">Campaigns</a>
            </li>
        </ul>

        <div class="tab-content" id="myTabContent">
        
        
        
        
     <div class="tab-pane fade" id="campaigns">
            
            
            <div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Current Users</h3>
   </div>
   <div class="panel-body">
    <input type="button" class="btn btn-primary btnSeccion" onclick="doReloadStatus();" value="Refresh"></button>
        <table id="addstatus" rules='all'>
                    <tr>
                        <th>Campaign</th>

                        <th>Action</th>
                    </tr>

                    <tr id="row0">
                        <td></td>

                        <td></td>
                    </tr>
                </table>
   
 </div>
</div>

   
            </div>     
        
        
        
        
        
        
        
        
        
        
        
       
        
            <div class="tab-pane fade" id="users">
            
            
            <div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Current Users</h3>
   </div>
   <div class="panel-body">
   
   <table id="addusers">
   <tr>
   <th>Name</th>
   <th>Password</th>
   <th>Directory</id>
   <th>Phone</th>
   <th>E-Mail</th>
   <th>Credit Card</th>
     <tr id="row0">
                        <td><input id="p_new_forward_url" name="p_new_x"
                        placeholder="Name" size="30" type="text" value=
                        ""></td>

                        <td><input id="p_new_image_url" name="p_new"
                        placeholder="Password" size="20" type="text" value=
                        ""></td>

                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Id" size="20" type="text" value=""></td>
                        
                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Phone" size="20" type="text" value=""></td>   
                        
                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Email" size="20" type="text" value=""></td>      
                        
                                  
                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Credit Authorization" size="20" type="text" value=""></td>      
                        <td>
                            <a href="javascript:doDynoSeats();">Add</a>
                        </td>
                    </tr>
   </table>
   
 </div>
</div>

   
            </div>

            <div class="tab-pane fade" id="configuration">


<div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Seats</h3>
   </div>
   <div class="panel-body">
   
   <table id="addseats">
   <tr>
   <th>Name</th>
   <th>Id</id>
   <th>Bid Endpoint</th>
   </tr>
    <tr id="row0">
                        <td><input id="p_new_forward_url" name="p_new_x"
                        placeholder="Name" size="50" type="text" value=
                        ""></td>

                        <td><input id="p_new_image_url" name="p_new"
                        placeholder="Id" size="10" type="text" value=
                        ""></td>

                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Bid Endpoint" size="50" type="text" value=""></td>

                        <td>
                            <a href="javascript:doDynoSeats();">Add</a>
                        </td>
                    </tr>
   </table>
   
 </div>
</div>

<div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Forensiq</h3>
   </div>
   <div class="panel-body">
   
    
   <table>
   
   <tr>
   <td>Threshhold</td>
   <td><input id="forensiq_threshhold" name="p_new" placeholder=
                        "Threshhold for no-bid" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>CK</td>
   <td><input id="forensiq_ck" name="p_new" placeholder=
                        "Key goes here" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Endpoint</td>
   <td><input id="forensiq_endpoint" name="p_new" placeholder=
                        "Forensiq endpoint" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Bid On Error</td>
   <td><input id="forensiq_bidonerror" name="p_new" placeholder=
                        "Should we bid if forensiq errors?" size="32" type="text" value=""></td>
   </tr>
   
   </table>
  
   
 </div>
</div>

<div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Application</h3>
   </div>
   <div class="panel-body">
   
   
    <table>
   
   <tr>
   <td>Stop on Load:</td>
   <td><input id="app_stopped" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>TTL:</td>
   <td><input id="app_ttl" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Pixel Track URL::</td>
   <td><input id="app_pixel_track" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>

   <tr>
   <td>Win URL:</td>
   <td><input id="app_winurl" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>

   <tr>
   <td>Redirect URL:</td>
   <td><input id="app_redirect" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>  
   
   </table>
   <br/><br/>
   
   
   <div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Logging</h3>
   </div>
   <div class="panel-body">
    <table>
   
   <tr>
   <td>Verbosity</td>
   <td><select class="selectpicker" id='verbosity_level'>
    <option>5</option>
    <option>4</option>
    <option>3</option>
    <option>2</option>
    <option>1</option>
    <option>-1</option>
    <option>-2</option>
    <option>-3</option>
    <option>-4</option>
    <option selected>-5</option>
  </select></td>
   </tr>
   
   <tr>
      <td>No Bid Reason&nbsp;</td>
   <td><select class="selectpicker" id='verbosity_nobidreason'>
    <option selected>true</option>
    <option>false</option>
  </select></td></td>
   </tr>
   
   
   </table>
 </div>
 
 
 <div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Geotags</h3>
   </div>
   <div class="panel-body">
   
   <table>
   
   <tr>
   <td>States</td>
   <td><input id="geotag_states" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Zipcodes</td>
   <td><input id="geotag_zipcodes" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   </table>
   
   
   
 </div>
</div>
 
 
 <div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Redis</h3>
   </div>
   <div class="panel-body">
   
   <table>
   
   <tr>
   <td>Hostname</td>
   <td><input id="redis_host" name="p_new" placeholder=
                        "Host" size="32" type="text" value="locallhost"></td>
   </tr>
   
   <tr>
      <td>Port</td>
   <td><input id="redis_port" name="p_new" placeholder=
                        "Host" size="32" type="text" value="6379"></td>
   </tr>
   
   <tr>
      <td>Win Channel</td>
   <td><input id="redis_win" name="p_new" placeholder=
                        "Host" size="32" type="text" value="wins"></td>
   </tr>
   
      <tr>
      <td>Bid Channel</td>
   <td><input id="redis_bid" name="p_new" placeholder=
                        "Host" size="32" type="text" value="bids"></td>
   </tr>
   
     <tr>
      <td>No-Bid Channel</td>
   <td><input id="redis_nobid" name="p_new" placeholder=
                        "Host" size="32" type="text" value="nobids"></td>
   </tr>
   
      <tr>
      <td>Requests Channel&nbsp;</td>
   <td><input id="redis_request" name="p_new" placeholder=
                        "Host" size="32" type="text" value="requests"></td>
   </tr>
   
   
      <tr>
      <td>Clicks Channel &nbsp;</td>
   <td><input id="redis_click" name="p_new" placeholder=
                        "Host" size="32" type="text" value="clicks"></td>
   </tr>
   <tr>
      <td>Logger Channel</td>
   <td><input id="redis_log" name="p_new" placeholder=
                        "Host" size="32" type="text" value="log"></td>
   </tr>
   
   
   </table>
   
 </div>
</div>
 
<div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Initial Campaigns</h3>
   </div>
   <div class="panel-body">
    <table id="addinititalloads">
   <tr>
   <th>Campaign Owner Name</th>
   <th>Campaign Ad Id</id>
   </tr>
    <tr id="row0">
                        <td><input id="p_new_forward_url" name="p_new_x"
                        placeholder="Name" size="50" type="text" value=
                        ""></td>

                        <td><input id="p_new_image_url" name="p_new"
                        placeholder="Id" size="30" type="text" value=
                        ""></td>

                            <a href="javascript:doDynoInitLoadCells();">Add</a>
                        </td>
                    </tr>
   </table>
 </div>
</div>

<div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Templates</h3>
   </div>
   <div class="panel-body">
 
                            <label for="default">Default</label> <input id=
                            "default" placeholder="Default template" size='120'
                            type="text">
                        <br>
                        <table id="addtemplate">
                            <tr>
                                <th>Exchange</th>
                                <th>Template</th>
                            </tr>
                            <tr id="row0">
                                <td><input id="p_new_exchange" name="p_new_x"
                                placeholder="exchange name" size="20" type=
                                "text" value=""></td>
                                <td><input id="p_new_template" name="p_new"
                                placeholder="template is here" size="100" type=
                                "text" value=""></td>
                                <td>
                                    <a href=
                                    "javascript:doDynoTemplate();">Add</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                    </div>
 
</div>
   
   
   
   
   
   
   
 </div>
</div>


            </div>

            <div class="tab-pane fade in active" id="status">
                Network status:
                <table id='system-status'>
                <tr>
                <th>Name</th>
                <th>Total</th>
                <th>Request</th>
                <th>Fraud</th>
                <th>Bid</th>
                <th>Nobid</th>
                <th>Win</th>
                <th>Pixel</th>
                <th>Click</th>
                <th>Errors</th>
                <th>%Bid</th>
                <th>%Win</th>
                <th>%Pixel</th>
                <th>%Click</th>
                <th>%Fraud</th>
                <th>Ad Spend</th>
                <th>QPS</th>
                <th>X-time(avg)</th>
                </tr>
                </table>
                
                <hr/>
                Operational Status:
                <table id='operstatus'>
                <tr>
                	<th>Name</th>
                	<th>Running</th>
                	<th>Campaigns</th>
                	<th>Log Level</th>
                	<th>Show No Bid Reason</th>
                	<th>Select</th>
                </tr>
                </table>
                <br/>
                Commands:
                <br/>
                <button type="button" class="btn btn-danger" id='stop-bidder' onclick='doStopBidder()'>Stop Bidder</button>
                <button type="button" class="btn btn-success" id='start-bidder' onclick='doStartBidder()'>Start Bidder</button>
                <button type="button" class="btn btn-warning" id='changeloglevel-bidder' onclick='doChangeLog()'>Change Log Level</button>
                <button type="button" class="btn btn-success" id='changenobidreason-bidder' onclick='doChangeNoBidReason()'>Change No Bid Reason</button>
                <button type="button" class="btn btn-danger" id='reload-bidder' onclick='doReloadBidder()'>Reload Campaigns</button>
                <br>
                <br/>
                
                  <input type="button" class="btn btn-primary btnSeccion" onclick="reloadStatus();" value="Refresh"></button>
                
                <hr/>
                <i><b>System Console</i></b>
                <table id="logger" border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable"/>
<thead>
<tr>
<th>Date</th>
<th>Sev</th>
<th>From</th>
<th>Source</th>
<th>Message</th>
</tr>
</thead>
<tbody class="scrollContent">
</tbody>
</table>

            </div>
            
                     
        </div>
                      
    </div>
    
          <footer>
        <p>&copy; <NAME>, <NAME>, RTB4FREE.ORG 2015<br/>Email: <EMAIL></p>
      </footer>   
      
    </div>
    </div>
</body>
<script>

function revert() {
    forensiqsClear();
    appClear();
	usersDyno.clear();
	seatsDyno.clear();
	initLoadsDyno.clear();
	reloadStatus();
	doFormLogin();
}

function forensiqsClear() {
	document.getElementById('forensiq_threshhold').value = '';
	document.getElementById('forensiq_ck').value = '';
	document.getElementById('forensiq_endpoint').value = '';
	document.getElementById('forensiq_bidonerror').value = '';
}

function appClear() {
	document.getElementById('app_stopped').value = '';
	document.getElementById('app_ttl').value = '';
	document.getElementById('app_pixel_track').value = '';
	document.getElementById("app_winurl").value = '';
	document.getElementById("app_redirect").value = '';
	
	document.getElementById("verbosity_level").value = '-5';
	document.getElementById("verbosity_nobidreason").value = "true";
	
	document.getElementById("geotag_states").value = "";
	document.getElementById("geotag_zipcodes").value = "";
}

function doFormLogin() {
	userName = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	console.log("U="+userName+", P="+password);
	
	//setTimeout(function(){window.location.href='campaign'},0);
	
	  msg = {};
	  msg.command = "loginAdmin";
	  msg.username = userName;
	  msg.password = password;
	  ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error) {
           		doModal(BootstrapDialog.TYPE_DANGER,"Error","Error logging in");
           		return;
           }
           else {
           
           	
				if (userName === 'demo')
					setDemoButtons();
           
				var ele = document.getElementById("login");
				ele.style.display = "none";
	
				ele = document.getElementById("bs-example");
				ele.style.display = "block";
				
	
		   		clearFields();
		   		
		   		fillInApp(data);
		   		
		   		fillInGeo(data);
		   		
		   		fillInVerbosity(data);
		   		
				fillInStatus(data);

				fillInUsers(data);
				
				fillInSeats(data);
	   			
	   			fillInInits(data);
	   			
	   			fillInOperStatus(data);
	   			
	   			fillInRedis(data);
	   			
	   			fillInCampaigns(data);
	   			
	   			fillInForensiq(data);
	   			
	   			/* templates */
	   			fillInTemplate(data);
     
	
	   		}

         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"Error",request.responseText);
         }});
    ////////////////////
}

/*
 * Respond to button click
 */
function doReloadStatus() {
	doModal(BootstrapDialog.TYPE_INFO,"Info","Status reloading");
	reloadStatus();
}

 function deleteTemplateRow(what) {
        console.log("DELETE WHAT: " + what);
        x = document.getElementById(what);
        console.log("val = " + x.value);
        tdyno.remove(what);
        }
        
function addTemplateRow(id1, id2) {
        o = document.getElementById(id1);
        vals = [];
        vals.push(o.value);
        o.value = "";
        o = document.getElementById(id2);
        vals.push(o.value);
        o.value = "";
        vals.push("");
        tdyno.add(vals); 
 }
 
function makeTemplate() {
 	var template = {};
    template.default = document.getElementById("default").value;
    template.exchange = {};
    table = document.getElementById("addtemplate");
    rows = table.rows;
    for (i = 2; i < rows.length; i++) {
    	a = rows[i].cells[0].children[0].value;
        b = rows[i].cells[1].children[0].value;
        campaign.template.exchange[a] = b;
    }  
    return template;
}

function fillInTemplate(data) {
	tdyno.clear();
	var template = data.template;
	document.getElementById("default").value = template.default;
	var exchange = template.exchange;
    for (var p in exchange) {
    	if( exchange.hasOwnProperty(p) ) {
        	tdyno.add([p,exchange[p],'']);
        } 
   }  
}

function fillInGeo(data) {
	document.getElementById("geotag_states").value = data.geotags.states;
	document.getElementById("geotag_zipcodes").value = data.geotags.zipcodes;
}

function fillInApp(data) {
	var app = data.app;
	document.getElementById('app_stopped').value = app.stopped;
	document.getElementById('app_ttl').value = app.ttl;
	document.getElementById('app_pixel_track').value = app['pixel-tracking-url'];
	document.getElementById("app_winurl").value = app.winurl;
	document.getElementById("app_redirect").value = app['redirect-url'];
	
	
}

function fillInVerbosity(data) {
	var v = data.verbosity;
	document.getElementById('verbosity_level').value = v.level;
	var vv = v['nobid-reason'];
	var x =  document.getElementById('verbosity_nobidreason');
    x.value = vv;
}

function fillInRedis(data) {

	document.getElementById('redis_host').value = data.redis.host;
	document.getElementById('redis_port').value = data.redis.port;
	document.getElementById('redis_win').value = data.redis.win;
	document.getElementById('redis_bid').value = data.redis.bid;
	document.getElementById('redis_nobid').value = data.redis.nobid;
	document.getElementById('redis_click').value = data.redis.click;
	document.getElementById('redis_log').value = data.redis.log;
	
}

function fillInForensiq(data) {

	if (typeof data.forensiq === 'undefined') {
		return;
	}

	document.getElementById('forensiq_threshhold').value = data.forensiq.threshhold;
	document.getElementById('forensiq_ck').value = data.forensiq.ck;
	document.getElementById('forensiq_endpoint').value = data.forensiq.endpoint;
	document.getElementById('forensiq_bidonerror').value = data.forensiq.bidOnError;

	
}

function fillInUsers(data) {
	var users = data.users;
	for (var i=0; i<users.length;i++) {
		var user = users[i];
		usersDyno.add([user.name,user.password,user.directory,user.phone,user.email,user.creditcard,'']);
	}
		
}

function fillInSeats(data) {
	var seats = data.seats;
	for (var i=0; i<seats.length;i++) {
		var seat = seats[i];
		seatsDyno.add([seat.name,seat.id,seat.bid,'']);
	}
}

function fillInInits(data) {
	var inits = data.initials;
	for (var i=0; i<inits.length;i++) {
		var camp = inits[i];
		initLoadsDyno.add([camp.name,camp.id,'']);
	}
}

function fillInOperStatus(data) {
	operDyno.clear();
	var summaries = data.summaries;
	for (var i=0; i<summaries.length;i++) {
		var summary = summaries[i];
		operDyno.add([summary.name,!summary.values.stopped,summary.values.ncampaigns,summary.values.loglevel,summary.values.nobidreason,'']);
	}
}

function fillInStatus(data) {
			var status = data.status;
	   			var total = 0, bid = 0, nobid = 0, win = 0, clicks = 0, pixels = 0, errors = 0, 
	   					percBid = 0, percWin, percPixel, percClick, spend = 0, total_qps = 0, request = 0, fraud = 0, percFraud = 0;
	   		    var d = new Date();
				var now = d.getMilliseconds();
				var qps = 0;
	   			
	   			for (var i=0; i<status.length;i++) {
	   				  var e = status[i];
	   				  var v = e.values;
	   				  var pbid = 0, pwin = 0;
	   				  if (v.bid + v.nobid != 0)
	   				  	pbid = Number( 100 * v.bid/(v.bid + v.nobid)).toFixed(2);
	   				  if (v.bid != 0)
	   				  	pwin = Number( 100 * v.win/v.bid).toFixed(2);
	   				  if (v.win == 0)
	   				  	ppix = 0;
	   				  else
	   				  	ppix = Number(100 * v.pixels/v.win).toFixed(6);
	   				  if (v.pixels == 0)
	   				  	pclc = Number(0).toFixed(6);
	   				  else
	   				    pclc = Number( 100 * v.clicks/v.win).toFixed(6);
	   				    
	   				  if (v.fraud == 0)
	   				  	percFraud = Number(0).toFixed(2);
	   				  else
	   				    percFraud = Number( 100 * v.fraud/v.request).toFixed(2)
	   				    
	   				  var spnd = Number(v.adspend).toFixed(6);
	   				 // sqps = Number(v.qps).toFixed(6);
	   				 if (v.avgx > 0)  {
	   				  	sqps = 4000 / v.avgx;
	   				  }
	   				  else
	   				  	sqps = 0.0;
	   				  total_qps += sqps;
	   				  spqs = Number(sqps).toFixed(6);
	   				  systemDyno.add([e.name, v.total,v.request,v.fraud,v.bid,v.nobid,v.win,v.pixels,v.clicks,v.errors,pbid,pwin,ppix,pclc,percFraud,spnd,sqps,Number(v.avgx).toFixed(6)]);
	   				  total += v.total;
	   				  bid += v.bid;
	   				  nobid += v.nobid;
	   				  win += v.win;
	   				  clicks += v.clicks;
	   				  pixels += v.pixels;
	   				  errors += v.errors;
	   				  spend += v.adspend;		
	   				  request += v.request;  
	   				  fraud += v.fraud;
	   			}
	   			percFraud = 0;
	   			percPix = percClc  = percWin = percBid = 0;
	   			if (bid+nobid != 0)
	   				percBid = Number(100 * bid/(bid+nobid)).toFixed(2);
	   			if (bid != 0)
	   				percWin = Number(100 * win/bid).toFixed(2);
	   			if (win != 0) { 		
	   				percPix = Number(100 * pixels/win).toFixed(6);
	   				percClc = Number(100 * clicks/win).toFixed(6);
	   			}
	   			if (fraud != 0) 
	   				percFraud = Number(fraud/request * 100).toFixed(2);
	   			else 
	   				percFraud = Number(0).toFixed(2);
	   		    sqps = Number(total_qps).toFixed(6);
	   			percClc = Number(percClc).toFixed(6);
	   			lastTime = now;
	   			spend = Number(spend).toFixed(6);
	   			systemDyno.add(['','','', '','','','','','','','','','','','','','','']);
	   			systemDyno.add(['Total', total,request,fraud,bid,nobid,win,pixels,clicks,errors,percBid,percWin,percPix, percClc,percFraud,spend, sqps,'na']);
	   			
			}

function reloadStatus() {

	  msg = {};
	  msg.command = "loginAdmin";
	  msg.username = userName;
	  msg.password = document.getElementById("password").value;
	  ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error) {
           		doModal(BootstrapDialog.TYPE_DANGER,"Error","Error logging in");
           		return;
           }
           else {
	   		
	   			systemDyno.clear();
	   		    fillInStatus(data);	
	   		    fillInOperStatus(data);
	   		
	   		}

         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"Error",request.responseText);
         }});
    ////////////////////
}



function clearFields() {

}
           
    function deleteSeats() {
    
    }
    
    function doDynoSeats() {
    
    }
   
   function doStopBidder() {
   BootstrapDialog.show({
    		icon: 'glyphicon glyphicon-send',
   			type: BootstrapDialog.TYPE_DANGER,
   			title: 'DANGER',
            message: 'You are about to stop the running bidders!',
            autospin: true,
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-danger',
                action: function(dialogRef) {
                    dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                	executeBidderCommand(userName,"stop","*",null);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function executeBidderCommand(userName,action,who,level) {
      msg = {};
	  msg.command = "executeCommand";
	  msg.username = userName;
	  msg.action = action;
	  msg.who = "*";
	  msg.level = level;
	  ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error) {
           		doModal(BootstrapDialog.TYPE_DANGER,"Error", message);
           		return;
           }
			
				console.log("OK STOPPED");

         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"Error",request.responseText);
         }});
    ////////////////////
   
   		console.log("-------------------> Stop");
   }
   
   function doStartBidder() {
   BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_INFO,
   			title: 'INFO',
            message: 'You are about to start the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-success',
                action: function(dialogRef) {
   					dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                	executeBidderCommand(userName,"start","*",null);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function executeStartBidders() {
   		console.log("-------------------> START");
   }
   
    function doChangeLog() {
  	 	BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_WARNING,
   			title: 'WARNING',
            message: function(dialogItself) {
				var $form = $('<form></form>');
        		//var $titleDrop = $('<input type="text" id="newlevel" />');
        		
        		var $titleDrop = "<select id='newlevel'>" +
  									"<option value='-5'>-5</option>" +
  									"<option value='-4'>-4</option>" +
  									"<option value='-3'>-3</option>" +
  									"<option value='-2'>-2</option>" +
  									"<option value='-1'>-1</option>" +
  									"<option value='1'>1</option>" +
  									"<option value='2'>2</option>" +
  									"<option value='3' selected>3</option>" +
  									"<option value='4'>4</option>" +
  								    "<option value='5'>5</option>" +
									"</select>";
        		
        		dialogItself.setData('field-title-drop', $titleDrop);   // Put it in dialog data's container then you can get it easier by using dialog.getData() later.
        		$form.append('You are about to change log levels<br/><label>New log level (-5 to 5)&nbsp; </label>').append($titleDrop);

        		return $form;
            },
          //  message: 'You are about to change the logging level of the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-warning',
                action: function(dialogRef) {
   					dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                    obj = document.getElementById("newlevel");
                    var value = obj.value
                	executeBidderCommand(userName,"loglevel","*",value);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
     function doChangeNoBidReason() {
  	 	BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_WARNING,
   			title: 'WARNING',
            message: function(dialogItself) {
				var $form = $('<form></form>');
        		//var $titleDrop = $('<input type="text" id="newlevel" />');
        		
        		var $titleDrop = "<select id='newlevel'>" +
  									"<option value='false'>false</option>" +
  									"<option value='true'>true</option>"
									"</select>";
        		
        		dialogItself.setData('field-title-drop', $titleDrop);   // Put it in dialog data's container then you can get it easier by using dialog.getData() later.
        		$form.append('You are about to change change the print no bid reason flag<br/><label>Print: &nbsp; </label>').append($titleDrop);

        		return $form;
            },
          //  message: 'You are about to change the logging level of the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-warning',
                action: function(dialogRef) {
   					dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                    obj = document.getElementById("newlevel");
                    var value = obj.value
                	executeBidderCommand(userName,"nobidreason","*",value);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function doReloadBidder() {
   BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_DANGER,
   			title: 'DANGER',
            message: 'You are about to reload all the campaigns of the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-danger',
                action: function(dialogItself) {
                	executeReloadBidders();
                	dialogItself.close();
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function setDemoButtons() {
     	$('#savechanges').addClass('disabled');
     	$('#start-bidder').addClass('disabled');
     	$('#stop-bidder').addClass('disabled');
     	$('#start-bidder').addClass('disabled');
     	$('#reload-bidder').addClass('disabled');
     	$('#changeloglevel').addClass('disabled');
     	$('#changenobidreason-bidder').addClass('disabled');
   }
   
   function setPaneOptions(panel) {
   		pane = panel;
   		
   		if (userName === 'demo')
   			return;
   			
   		if (panel === 'status' || status === 'configuration') {
   		   	$('#savechanges').addClass('disabled');
   		} else {
   		    $('#savechanges').removeClass('disabled');
   		}
   }
   
   function saveChanges() {
   	    alert("Save changes for: " + pane);
   	    
   	    var config = {};
   	    config.seats = {};
   	    
   	    config.forensiq = {};
   	    config.forensiq.threshhold = document.getElementById('forensiq_threshhold').value;
		config.forensiq.ck = document.getElementById('forensiq_ck').value;
		config.forensiq.endpoint = document.getElementById('forensiq_endpoint').value;
		config.forensiq.bidOnError = document.getElementById('forensiq_bidonerror').value;
   	    
   	    config.app = {};
   	    config.app.stopped = document.getElementById('app_stopped').value;
        config.app.ttl = document.getElementById('app_ttl').value;
        config.app['pixel-tracking-url'] = document.getElementById('app_pixel_track').value;
        config.app.winurl = document.getElementById("app_winurl").value;
        config.app['redirect-url'] = document.getElementById("app_redirect").value;
        
        config.app.verbosity = {};
        config.app.verbosity.level = document.getElementById('verbosity_level').value;
        config.app.verbosity['nobid-reason']  = document.getElementById('verbosity_nobidreason').value;
        
        config.app.geotags = {};
        config.app.geotags.states = document.getElementById('geotag_states').value;
        config.app.geotags.zipcodes = document.getElementById('geotag_zipcodes').value;
        
        config.app.redis = {};
        config.app.redis.host = document.getElementById('redis_host').value;
        config.app.redis.bid = document.getElementById('redis_bid').value
        config.app.redis.nobid = document.getElementById('redis_nobid').value;
        config.app.redis.win = document.getElementById('redis_win').value
        config.app.redis.requests = document.getElementById('redis_request').value;
        config.app.redis.logger = document.getElementById('redis_log').value;
        config.app.redis.clicks = document.getElementById('redis_click').value;
        config.app.redis.port = document.getElementById('redis_portk').value;
        
        config.app.template = {};
        config.app.template.default = '';
        config.app.template.exchange = {};
   	    
   	}
   
   function executeReloadBidders() {
   		console.log("-------------------> ChangeLog");
   }
   
     function updateStatus(running) {
    /** 
      * Update the status pane
      */
    table = document.getElementById("addstatus");
    rows = table.rows;
    for (var i = 2; i < rows.length; i++) {
        row = rows[i];
        cell = row.cells[0];
        label = cell.innerText;
        cell = row.cells[1];
        button = cell.children[0];
        text = button.value;
        button.style.background = "#A9A9A9";
            for (var j = 0; j<running.length;j++) {
                if (label == running[j]) {
                    button.value = "Stop";
                    button.style.background='#7FFF00';
                }
            }
        console.log(text);
    }
    }
    
    function deleteStatusRowById(id) {
    	table = document.getElementById("addstatus");
    	rows = table.rows;
   	  for (var i = 2; i < rows.length; i++) {
        row = rows[i];
        cell = row.cells[0];
        label = cell.innerText;
        if (label == id) {
            delid = row.id;
            campStatus.remove(delid);
            return;
        }
    }
    }
    
    
        function startStop(rowId) {
    
    if (document.getElementById("username").value === 'demo') {
    	doModal(BootstrapDialog.TYPE_ERROR,"Error","Demo login can't stop or start campaigns.");
    	return
    }
    
    console.log("A="+rowId);
    row = document.getElementById(rowId);
    cell = row.cells[0];
    a = cell.textContent;
    cell = row.cells[1];
    inp = cell.children[0];
    b = inp.value;
    campaign = getCampaign(a);
    msg = {};
    msg.username = userName;
    if (b == 'Start') {
        inp.value='Pending...';
        msg.command = 'startcampaign';
        msg.id = campaign.adId;
    } else {
        msg.command = 'stopcampaign';
        msg.id = campaign.adId;
        inp.value = "Start"
    }
    ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error)
                doModal(BootstrapDialog.TYPE_INFO,"Error",message);
               
           updateStatus(data.running);
         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"HTTP Error",request.responseText);
         }});
    ////////////////////
    }
    
    function getCampaign(id) {
    	for (var i = 0; i < camps.length; i++) {
        	var camp = camps[i];
        	if (camp.adId == id)
            	return camp;
    	}
    	return null;
    }
    
    
    function fillInCampaigns(data) {
        camps = data.campaigns;
        running = data.running;
        campStatus.clear();
        for (i = 0; i < camps.length; i++) {
            campaign = camps[i];
            value = campStatus.add([campaign.adId, '']);
            console.log("ADDED: " + value);
        }
        updateStatus(running);
    }
      
      
   //////////////////////////////

xcells = [];
   xcells.push("<input type='text' id='SUB_ID' size='20'value='' placeholder='exchange name' />");
   xcells.push("<input type='text' id='SUB_ID' size='100' value='' placeholder='template is here' />");
   xcells.push("<a href=\"javascript:deleteTemplateRow('ROW_ID');\">Del<\/a><\/td>");

  tdyno = new DynamicTable("addtemplate",xcells);     
      
   
    zcells = [];
    zcells.push('SUB_VALUE')
    zcells.push("<input type='button' onclick='startStop(\"ROW_ID\")' value='Start' id='ROW_ID' class='primary-btn col-xs-11 text-left' style=\"width:100px\"/>");
    campStatus = new DynamicTable("addstatus",zcells);
          
 seatCells = []
    seatCells.push("<input type='text' id='SUB_ID' size='50' value='' placeholder='Name' />");
    seatCells.push("<input type='text' id='SUB_ID' size='10' value='' placeholder='Endpoint' />");
    seatCells.push("<input type='text' id='SUB_ID' size='50' value='' placeholder='Id' />")
    seatCells.push("<a href=\"javascript:deleteSeat('ROW_ID');\">Del<\/a><\/td>");
    seatsDyno = new DynamicTable("addseats",seatCells);
    
    
 userCells = []
    userCells.push("<input type='text' id='SUB_ID' size='30' value='' placeholder='Name' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Password' />")
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Directory' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Phone-Number' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Email' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Credit-Card' />");
    userCells.push("<a href=\"javascript:deleteUser('ROW_ID');\">Del<\/a><\/td>");
    usersDyno = new DynamicTable("addusers",userCells);
    
 systemCells = [];
 	systemCells.push("<input type='text' id='SUB_ID' size='30' readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>"); 	
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemDyno = new DynamicTable("system-status",systemCells);
 	
operCells = [];
 	operCells.push("<input type='text' id='SUB_ID' size='30' readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='18'  readonly value=''/>");
 	operCells.push("<input type='checkbox' id=SUB_ID'  value='' checked/>");
 	operDyno = new DynamicTable("operstatus",operCells);

initLoadCells = []
    initLoadCells.push("<input type='text' id='SUB_ID' size='50' value='' placeholder='Name' />");
    initLoadCells.push("<input type='text' id='SUB_ID' size='30' value='' placeholder='Id' />");
    initLoadsDyno = new DynamicTable("addinititalloads",initLoadCells);
    
	lastTime = 0;
	
	
   logger = new Logger('logger','log',"localhost:7379");
	
	pane = 'status';		// current pane, starts in status
	
	userName = null;    // no user yet
	
	camps = null;
	running = null;
	
	doModal(BootstrapDialog.TYPE_INFO,"Info","You are logging in as 'demo', just press 'Sign In' to go to\nproceed to the campaign admin page");
 
	
 </script>

</html><commit_msg>Refresh the admin page<commit_after><!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <meta content="Bootstrap static html page for campaign administration."
    name="description">
    <meta content=
    "RTB,OpenRTB,JAVA,Advertising,real-time,campaign,administration" name=
    "keywords">
    <meta content="RTB4FREE" name="author">

    <title>RTB4FREE Monitor</title>
    <link rel="shortcut icon" href="images/alien.png">
    <link href=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
    rel="stylesheet">
    <link href=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"
    rel="stylesheet">
    <link href="bootstrap-dialog.css" rel="stylesheet">
    <script src=
    "https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script src="bootstrap-dialog.js"></script>
    <script src="js/rtb4free.js"></script>
    <style type="text/css">
.bs-example{
        margin: 20px;
    }
    
    .form-signin
{
    max-width: 330px;
    padding: 15px;
    margin: 0 auto;
}
.form-signin .form-signin-heading, .form-signin .checkbox
{
    margin-bottom: 10px;
}
.form-signin .checkbox
{
    font-weight: normal;
}
.form-signin .form-control
{
    position: relative;
    font-size: 16px;
    height: auto;
    padding: 10px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
.form-signin .form-control:focus
{
    z-index: 2;
}
.form-signin input[type="text"]
{
    margin-bottom: -1px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
.form-signin input[type="password"]
{
    margin-bottom: 10px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
.account-wall
{
    margin-top: 20px;
    padding: 40px 0px 20px 0px;
    background-color: #f7f7f7;
    -moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    -webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
}
.login-title
{
    color: #555;
    font-size: 18px;
    font-weight: 400;
    display: block;
}
.profile-img
{
    width: 96px;
    height: 96px;
    margin: 0 auto 10px;
    display: block;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    border-radius: 50%;
}
.need-help
{
    margin-top: 10px;
}
.new-account
{
    display: block;
    margin-top: 10px;
}

    </style>
</head>

<body>


 <div class="container">
 
    <div class="row" id="login">
        <div class="col-sm-6 col-md-4 col-md-offset-4">
            <h1 class="text-center login-title">Sign in to Monitor RTB4FREE</h1>
            <div >
                <form class="form">
                <input type="text" class="form-control" placeholder="Email" required autofocus id="username" value='demo'>
                <input type="password" class="form-control" placeholder="Password" required id="password" value='<PASSWORD>'>
                <input type="button" class="btn btn-primary btnSeccion" onclick="doFormLogin();" value="Sign In"></button>
                </form>
            </div>
         </div>
    </div>
    </div>

<script type="text/javascript">

function toggle(elementId) {
	var ele = document.getElementById(elementId);
	if(ele.style.display == "block") {
    		ele.style.display = "none";
  	}
	else {
		ele.style.display = "block";
	}
} 

</script>

        </div>
    </div>
</div>

 <div class="bs-example" style="display:none" id="bs-example">
           
  <div class="panel panel-primary">
   <div class="panel-heading">
      <h3 class="panel-title">RTB4FREE System Administration Page
      <a id='savechanges' href="#" onclick="saveChanges(); return false;" class="btn btn-success btn-sm"><i class="icon-white icon-heart"></i>Save Changes</a>
      		<a href="#" onclick="revert()" class="btn btn-info btn-sm"><i class="icon-white icon-heart"></i>Revert</a>
      	<a href="admin" class="btn btn-danger btn-sm"><i class="icon-white icon-heart"></i>Logout</a></h3>
   </div>
   <div class="panel-body">

        
        <p>This page is used to manage the operational RTB4FREE Bidder Farm</p>

</div>


   
            


        <ul class="nav nav-tabs" id="myTab">

            <li >
                <a data-toggle="tab" href="#users" onclick="setPaneOptions('users');">Users</a>
            </li>
            <li>
                <a data-toggle="tab" href="#configuration" onclick="setPaneOptions('config');">Configuration</a>
            </li>

            <li class='active'>
                <a data-toggle="tab" href="#status" onclick="setPaneOptions('status');">System Status</a>
            </li>
             <li >
                <a data-toggle="tab" href="#campaigns" onclick="setPaneOptions('users');">Campaigns</a>
            </li>
        </ul>

        <div class="tab-content" id="myTabContent">
        
        
        
        
     <div class="tab-pane fade" id="campaigns">
            
            
            <div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Current Users</h3>
   </div>
   <div class="panel-body">
    <input type="button" class="btn btn-primary btnSeccion" onclick="doReloadStatus();" value="Refresh"></button>
        <table id="addstatus" rules='all'>
                    <tr>
                        <th>Campaign</th>

                        <th>Action</th>
                    </tr>

                    <tr id="row0">
                        <td></td>

                        <td></td>
                    </tr>
                </table>
   
 </div>
</div>

   
            </div>     
        
        
        
        
        
        
        
        
        
        
        
       
        
            <div class="tab-pane fade" id="users">
            
            
            <div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Current Users</h3>
   </div>
   <div class="panel-body">
   
   <table id="addusers">
   <tr>
   <th>Name</th>
   <th>Password</th>
   <th>Directory</id>
   <th>Phone</th>
   <th>E-Mail</th>
   <th>Credit Card</th>
     <tr id="row0">
                        <td><input id="p_new_forward_url" name="p_new_x"
                        placeholder="Name" size="30" type="text" value=
                        ""></td>

                        <td><input id="p_new_image_url" name="p_new"
                        placeholder="Password" size="20" type="text" value=
                        ""></td>

                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Id" size="20" type="text" value=""></td>
                        
                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Phone" size="20" type="text" value=""></td>   
                        
                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Email" size="20" type="text" value=""></td>      
                        
                                  
                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Credit Authorization" size="20" type="text" value=""></td>      
                        <td>
                            <a href="javascript:doDynoSeats();">Add</a>
                        </td>
                    </tr>
   </table>
   
 </div>
</div>

   
            </div>

            <div class="tab-pane fade" id="configuration">


<div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Seats</h3>
   </div>
   <div class="panel-body">
   
   <table id="addseats">
   <tr>
   <th>Name</th>
   <th>Id</id>
   <th>Bid Endpoint</th>
   </tr>
    <tr id="row0">
                        <td><input id="p_new_forward_url" name="p_new_x"
                        placeholder="Name" size="50" type="text" value=
                        ""></td>

                        <td><input id="p_new_image_url" name="p_new"
                        placeholder="Id" size="10" type="text" value=
                        ""></td>

                        <td><input id="p_new_impid" name="p_new" placeholder=
                        "Bid Endpoint" size="50" type="text" value=""></td>

                        <td>
                            <a href="javascript:doDynoSeats();">Add</a>
                        </td>
                    </tr>
   </table>
   
 </div>
</div>

<div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Forensiq</h3>
   </div>
   <div class="panel-body">
   
    
   <table>
   
   <tr>
   <td>Threshhold</td>
   <td><input id="forensiq_threshhold" name="p_new" placeholder=
                        "Threshhold for no-bid" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>CK</td>
   <td><input id="forensiq_ck" name="p_new" placeholder=
                        "Key goes here" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Endpoint</td>
   <td><input id="forensiq_endpoint" name="p_new" placeholder=
                        "Forensiq endpoint" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Bid On Error</td>
   <td><input id="forensiq_bidonerror" name="p_new" placeholder=
                        "Should we bid if forensiq errors?" size="32" type="text" value=""></td>
   </tr>
   
   </table>
  
   
 </div>
</div>

<div class="panel panel-success">
   <div class="panel-heading">
      <h3 class="panel-title">Application</h3>
   </div>
   <div class="panel-body">
   
   
    <table>
   
   <tr>
   <td>Stop on Load:</td>
   <td><input id="app_stopped" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>TTL:</td>
   <td><input id="app_ttl" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Pixel Track URL::</td>
   <td><input id="app_pixel_track" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>

   <tr>
   <td>Win URL:</td>
   <td><input id="app_winurl" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>

   <tr>
   <td>Redirect URL:</td>
   <td><input id="app_redirect" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>  
   
   </table>
   <br/><br/>
   
   
   <div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Logging</h3>
   </div>
   <div class="panel-body">
    <table>
   
   <tr>
   <td>Verbosity</td>
   <td><select class="selectpicker" id='verbosity_level'>
    <option>5</option>
    <option>4</option>
    <option>3</option>
    <option>2</option>
    <option>1</option>
    <option>-1</option>
    <option>-2</option>
    <option>-3</option>
    <option>-4</option>
    <option selected>-5</option>
  </select></td>
   </tr>
   
   <tr>
      <td>No Bid Reason&nbsp;</td>
   <td><select class="selectpicker" id='verbosity_nobidreason'>
    <option selected>true</option>
    <option>false</option>
  </select></td></td>
   </tr>
   
   
   </table>
 </div>
 
 
 <div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Geotags</h3>
   </div>
   <div class="panel-body">
   
   <table>
   
   <tr>
   <td>States</td>
   <td><input id="geotag_states" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   <tr>
   <td>Zipcodes</td>
   <td><input id="geotag_zipcodes" name="p_new" placeholder=
                        "" size="32" type="text" value=""></td>
   </tr>
   
   </table>
   
   
   
 </div>
</div>
 
 
 <div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Redis</h3>
   </div>
   <div class="panel-body">
   
   <table>
   
   <tr>
   <td>Hostname</td>
   <td><input id="redis_host" name="p_new" placeholder=
                        "Host" size="32" type="text" value="locallhost"></td>
   </tr>
   
   <tr>
      <td>Port</td>
   <td><input id="redis_port" name="p_new" placeholder=
                        "Host" size="32" type="text" value="6379"></td>
   </tr>
   
   <tr>
      <td>Win Channel</td>
   <td><input id="redis_win" name="p_new" placeholder=
                        "Host" size="32" type="text" value="wins"></td>
   </tr>
   
      <tr>
      <td>Bid Channel</td>
   <td><input id="redis_bid" name="p_new" placeholder=
                        "Host" size="32" type="text" value="bids"></td>
   </tr>
   
     <tr>
      <td>No-Bid Channel</td>
   <td><input id="redis_nobid" name="p_new" placeholder=
                        "Host" size="32" type="text" value="nobids"></td>
   </tr>
   
      <tr>
      <td>Requests Channel&nbsp;</td>
   <td><input id="redis_request" name="p_new" placeholder=
                        "Host" size="32" type="text" value="requests"></td>
   </tr>
   
   
      <tr>
      <td>Clicks Channel &nbsp;</td>
   <td><input id="redis_click" name="p_new" placeholder=
                        "Host" size="32" type="text" value="clicks"></td>
   </tr>
   <tr>
      <td>Logger Channel</td>
   <td><input id="redis_log" name="p_new" placeholder=
                        "Host" size="32" type="text" value="log"></td>
   </tr>
   
   
   </table>
   
 </div>
</div>
 
<div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Initial Campaigns</h3>
   </div>
   <div class="panel-body">
    <table id="addinititalloads">
   <tr>
   <th>Campaign Owner Name</th>
   <th>Campaign Ad Id</id>
   </tr>
    <tr id="row0">
                        <td><input id="p_new_forward_url" name="p_new_x"
                        placeholder="Name" size="50" type="text" value=
                        ""></td>

                        <td><input id="p_new_image_url" name="p_new"
                        placeholder="Id" size="30" type="text" value=
                        ""></td>

                            <a href="javascript:doDynoInitLoadCells();">Add</a>
                        </td>
                    </tr>
   </table>
 </div>
</div>

<div class="panel panel-info">
   <div class="panel-heading">
      <h3 class="panel-title">Templates</h3>
   </div>
   <div class="panel-body">
 
                            <label for="default">Default</label> <input id=
                            "default" placeholder="Default template" size='120'
                            type="text">
                        <br>
                        <table id="addtemplate">
                            <tr>
                                <th>Exchange</th>
                                <th>Template</th>
                            </tr>
                            <tr id="row0">
                                <td><input id="p_new_exchange" name="p_new_x"
                                placeholder="exchange name" size="20" type=
                                "text" value=""></td>
                                <td><input id="p_new_template" name="p_new"
                                placeholder="template is here" size="100" type=
                                "text" value=""></td>
                                <td>
                                    <a href=
                                    "javascript:doDynoTemplate();">Add</a>
                                </td>
                            </tr>
                        </table>
                    </div>
                    </div>
 
</div>
   
   
   
   
   
   
   
 </div>
</div>


            </div>

            <div class="tab-pane fade in active" id="status">
                Network status:
                <table id='system-status'>
                <tr>
                <th>Name</th>
                <th>Total</th>
                <th>Request</th>
                <th>Fraud</th>
                <th>Bid</th>
                <th>Nobid</th>
                <th>Win</th>
                <th>Pixel</th>
                <th>Click</th>
                <th>Errors</th>
                <th>%Bid</th>
                <th>%Win</th>
                <th>%Pixel</th>
                <th>%Click</th>
                <th>%Fraud</th>
                <th>Ad Spend</th>
                <th>QPS</th>
                <th>X-time(avg)</th>
                </tr>
                </table>
                
                <hr/>
                Operational Status:
                <table id='operstatus'>
                <tr>
                	<th>Name</th>
                	<th>Running</th>
                	<th>Campaigns</th>
                	<th>Log Level</th>
                	<th>Show No Bid Reason</th>
                	<th>Select</th>
                </tr>
                </table>
                <br/>
                Commands:
                <br/>
                <button type="button" class="btn btn-danger" id='stop-bidder' onclick='doStopBidder()'>Stop Bidder</button>
                <button type="button" class="btn btn-success" id='start-bidder' onclick='doStartBidder()'>Start Bidder</button>
                <button type="button" class="btn btn-warning" id='changeloglevel-bidder' onclick='doChangeLog()'>Change Log Level</button>
                <button type="button" class="btn btn-success" id='changenobidreason-bidder' onclick='doChangeNoBidReason()'>Change No Bid Reason</button>
                <button type="button" class="btn btn-danger" id='reload-bidder' onclick='doReloadBidder()'>Reload Campaigns</button>
                <br>
                <br/>
                
                  <input type="button" class="btn btn-primary btnSeccion" onclick="reloadStatus();" value="Refresh"></button>
                
                <hr/>
                <i><b>System Console</i></b>
                <table id="logger" border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable"/>
<thead>
<tr>
<th>Date</th>
<th>Sev</th>
<th>From</th>
<th>Source</th>
<th>Message</th>
</tr>
</thead>
<tbody class="scrollContent">
</tbody>
</table>

            </div>
            
                     
        </div>
                      
    </div>
    
          <footer>
        <p>&copy; <NAME>, <NAME>, RTB4FREE.ORG 2015<br/>Email: <EMAIL></p>
      </footer>   
      
    </div>
    </div>
</body>
<script>

function revert() {
    forensiqsClear();
    appClear();
	usersDyno.clear();
	seatsDyno.clear();
	initLoadsDyno.clear();
	reloadStatus();
	doFormLogin();
}

function forensiqsClear() {
	document.getElementById('forensiq_threshhold').value = '';
	document.getElementById('forensiq_ck').value = '';
	document.getElementById('forensiq_endpoint').value = '';
	document.getElementById('forensiq_bidonerror').value = '';
}

function appClear() {
	document.getElementById('app_stopped').value = '';
	document.getElementById('app_ttl').value = '';
	document.getElementById('app_pixel_track').value = '';
	document.getElementById("app_winurl").value = '';
	document.getElementById("app_redirect").value = '';
	
	document.getElementById("verbosity_level").value = '-5';
	document.getElementById("verbosity_nobidreason").value = "true";
	
	document.getElementById("geotag_states").value = "";
	document.getElementById("geotag_zipcodes").value = "";
}

function doFormLogin() {
	userName = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	console.log("U="+userName+", P="+password);
	
	//setTimeout(function(){window.location.href='campaign'},0);
	
	  msg = {};
	  msg.command = "loginAdmin";
	  msg.username = userName;
	  msg.password = password;
	  ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error) {
           		doModal(BootstrapDialog.TYPE_DANGER,"Error","Error logging in");
           		return;
           }
           else {
           
           	
				if (userName === 'demo')
					setDemoButtons();
           
				var ele = document.getElementById("login");
				ele.style.display = "none";
	
				ele = document.getElementById("bs-example");
				ele.style.display = "block";
				
	
		   		clearFields();
		   		
		   		fillInApp(data);
		   		
		   		fillInGeo(data);
		   		
		   		fillInVerbosity(data);
		   		
				fillInStatus(data);

				fillInUsers(data);
				
				fillInSeats(data);
	   			
	   			fillInInits(data);
	   			
	   			fillInOperStatus(data);
	   			
	   			fillInRedis(data);
	   			
	   			fillInCampaigns(data);
	   			
	   			fillInForensiq(data);
	   			
	   			/* templates */
	   			fillInTemplate(data);
     
	
	   		}

         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"Error",request.responseText);
         }});
    ////////////////////
}

/*
 * Respond to button click
 */
function doReloadStatus() {
	doModal(BootstrapDialog.TYPE_INFO,"Info","Status reloading");
	reloadStatus();
}

 function deleteTemplateRow(what) {
        console.log("DELETE WHAT: " + what);
        x = document.getElementById(what);
        console.log("val = " + x.value);
        tdyno.remove(what);
        }
        
function addTemplateRow(id1, id2) {
        o = document.getElementById(id1);
        vals = [];
        vals.push(o.value);
        o.value = "";
        o = document.getElementById(id2);
        vals.push(o.value);
        o.value = "";
        vals.push("");
        tdyno.add(vals); 
 }
 
function makeTemplate() {
 	var template = {};
    template.default = document.getElementById("default").value;
    template.exchange = {};
    table = document.getElementById("addtemplate");
    rows = table.rows;
    for (i = 2; i < rows.length; i++) {
    	a = rows[i].cells[0].children[0].value;
        b = rows[i].cells[1].children[0].value;
        campaign.template.exchange[a] = b;
    }  
    return template;
}

function fillInTemplate(data) {
	tdyno.clear();
	var template = data.template;
	document.getElementById("default").value = template.default;
	var exchange = template.exchange;
    for (var p in exchange) {
    	if( exchange.hasOwnProperty(p) ) {
        	tdyno.add([p,exchange[p],'']);
        } 
   }  
}

function fillInGeo(data) {
	document.getElementById("geotag_states").value = data.geotags.states;
	document.getElementById("geotag_zipcodes").value = data.geotags.zipcodes;
}

function fillInApp(data) {
	var app = data.app;
	document.getElementById('app_stopped').value = app.stopped;
	document.getElementById('app_ttl').value = app.ttl;
	document.getElementById('app_pixel_track').value = app['pixel-tracking-url'];
	document.getElementById("app_winurl").value = app.winurl;
	document.getElementById("app_redirect").value = app['redirect-url'];
	
	
}

function fillInVerbosity(data) {
	var v = data.verbosity;
	document.getElementById('verbosity_level').value = v.level;
	var vv = v['nobid-reason'];
	var x =  document.getElementById('verbosity_nobidreason');
    x.value = vv;
}

function fillInRedis(data) {

	document.getElementById('redis_host').value = data.redis.host;
	document.getElementById('redis_port').value = data.redis.port;
	document.getElementById('redis_win').value = data.redis.win;
	document.getElementById('redis_bid').value = data.redis.bid;
	document.getElementById('redis_nobid').value = data.redis.nobid;
	document.getElementById('redis_click').value = data.redis.click;
	document.getElementById('redis_log').value = data.redis.log;
	
}

function fillInForensiq(data) {

	if (typeof data.forensiq === 'undefined') {
		return;
	}

	document.getElementById('forensiq_threshhold').value = data.forensiq.threshhold;
	document.getElementById('forensiq_ck').value = data.forensiq.ck;
	document.getElementById('forensiq_endpoint').value = data.forensiq.endpoint;
	document.getElementById('forensiq_bidonerror').value = data.forensiq.bidOnError;

	
}

function fillInUsers(data) {
	var users = data.users;
	for (var i=0; i<users.length;i++) {
		var user = users[i];
		usersDyno.add([user.name,user.password,user.directory,user.phone,user.email,user.creditcard,'']);
	}
		
}

function fillInSeats(data) {
	var seats = data.seats;
	for (var i=0; i<seats.length;i++) {
		var seat = seats[i];
		seatsDyno.add([seat.name,seat.id,seat.bid,'']);
	}
}

function fillInInits(data) {
	var inits = data.initials;
	for (var i=0; i<inits.length;i++) {
		var camp = inits[i];
		initLoadsDyno.add([camp.name,camp.id,'']);
	}
}

function fillInOperStatus(data) {
	operDyno.clear();
	var summaries = data.summaries;
	for (var i=0; i<summaries.length;i++) {
		var summary = summaries[i];
		operDyno.add([summary.name,!summary.values.stopped,summary.values.ncampaigns,summary.values.loglevel,summary.values.nobidreason,'']);
	}
}

function fillInStatus(data) {
			var status = data.status;
	   			var total = 0, bid = 0, nobid = 0, win = 0, clicks = 0, pixels = 0, errors = 0, 
	   					percBid = 0, percWin, percPixel, percClick, spend = 0, total_qps = 0, request = 0, fraud = 0, percFraud = 0;
	   		    var d = new Date();
				var now = d.getMilliseconds();
				var qps = 0;
	   			
	   			for (var i=0; i<status.length;i++) {
	   				  var e = status[i];
	   				  var v = e.values;
	   				  var pbid = 0, pwin = 0;
	   				  if (v.bid + v.nobid != 0)
	   				  	pbid = Number( 100 * v.bid/(v.bid + v.nobid)).toFixed(2);
	   				  if (v.bid != 0)
	   				  	pwin = Number( 100 * v.win/v.bid).toFixed(2);
	   				  if (v.win == 0)
	   				  	ppix = 0;
	   				  else
	   				  	ppix = Number(100 * v.pixels/v.win).toFixed(6);
	   				  if (v.pixels == 0)
	   				  	pclc = Number(0).toFixed(6);
	   				  else
	   				    pclc = Number( 100 * v.clicks/v.win).toFixed(6);
	   				    
	   				  if (v.fraud == 0)
	   				  	percFraud = Number(0).toFixed(2);
	   				  else
	   				    percFraud = Number( 100 * v.fraud/v.request).toFixed(2)
	   				    
	   				  var spnd = Number(v.adspend).toFixed(6);
	   				 // sqps = Number(v.qps).toFixed(6);
	   				 if (v.avgx > 0)  {
	   				  	sqps = 4000 / v.avgx;
	   				  }
	   				  else
	   				  	sqps = 0.0;
	   				  total_qps += sqps;
	   				  spqs = Number(sqps).toFixed(6);
	   				  systemDyno.add([e.name, v.total,v.request,v.fraud,v.bid,v.nobid,v.win,v.pixels,v.clicks,v.errors,pbid,pwin,ppix,pclc,percFraud,spnd,sqps,Number(v.avgx).toFixed(6)]);
	   				  total += v.total;
	   				  bid += v.bid;
	   				  nobid += v.nobid;
	   				  win += v.win;
	   				  clicks += v.clicks;
	   				  pixels += v.pixels;
	   				  errors += v.errors;
	   				  spend += v.adspend;		
	   				  request += v.request;  
	   				  fraud += v.fraud;
	   			}
	   			percFraud = 0;
	   			percPix = percClc  = percWin = percBid = 0;
	   			if (bid+nobid != 0)
	   				percBid = Number(100 * bid/(bid+nobid)).toFixed(2);
	   			if (bid != 0)
	   				percWin = Number(100 * win/bid).toFixed(2);
	   			if (win != 0) { 		
	   				percPix = Number(100 * pixels/win).toFixed(6);
	   				percClc = Number(100 * clicks/win).toFixed(6);
	   			}
	   			if (fraud != 0) 
	   				percFraud = Number(fraud/request * 100).toFixed(2);
	   			else 
	   				percFraud = Number(0).toFixed(2);
	   		    sqps = Number(total_qps).toFixed(6);
	   			percClc = Number(percClc).toFixed(6);
	   			lastTime = now;
	   			spend = Number(spend).toFixed(6);
	   			systemDyno.add(['','','', '','','','','','','','','','','','','','','']);
	   			systemDyno.add(['Total', total,request,fraud,bid,nobid,win,pixels,clicks,errors,percBid,percWin,percPix, percClc,percFraud,spend, sqps,'na']);
	   			
			}

function reloadStatus() {

	  msg = {};
	  msg.command = "loginAdmin";
	  msg.username = userName;
	  msg.password = document.getElementById("password").value;
	  ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error) {
           		doModal(BootstrapDialog.TYPE_DANGER,"Error","Error logging in");
           		return;
           }
           else {
	   		
	   			systemDyno.clear();
	   		    fillInStatus(data);	
	   		    fillInOperStatus(data);
	   		
	   		}

         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"Error",request.responseText);
         }});
    ////////////////////
}



function clearFields() {

}
           
    function deleteSeats() {
    
    }
    
    function doDynoSeats() {
    
    }
   
   function doStopBidder() {
   BootstrapDialog.show({
    		icon: 'glyphicon glyphicon-send',
   			type: BootstrapDialog.TYPE_DANGER,
   			title: 'DANGER',
            message: 'You are about to stop the running bidders!',
            autospin: true,
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-danger',
                action: function(dialogRef) {
                    dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                	executeBidderCommand(userName,"stop","*",null);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function executeBidderCommand(userName,action,who,level) {
      msg = {};
	  msg.command = "executeCommand";
	  msg.username = userName;
	  msg.action = action;
	  msg.who = "*";
	  msg.level = level;
	  ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error) {
           		doModal(BootstrapDialog.TYPE_DANGER,"Error", message);
           		return;
           }
			
				console.log("OK STOPPED");

         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"Error",request.responseText);
         }});
    ////////////////////
   
   		console.log("-------------------> Stop");
   }
   
   function doStartBidder() {
   BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_INFO,
   			title: 'INFO',
            message: 'You are about to start the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-success',
                action: function(dialogRef) {
   					dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                	executeBidderCommand(userName,"start","*",null);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function executeStartBidders() {
   		console.log("-------------------> START");
   }
   
    function doChangeLog() {
  	 	BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_WARNING,
   			title: 'WARNING',
            message: function(dialogItself) {
				var $form = $('<form></form>');
        		//var $titleDrop = $('<input type="text" id="newlevel" />');
        		
        		var $titleDrop = "<select id='newlevel'>" +
  									"<option value='-5'>-5</option>" +
  									"<option value='-4'>-4</option>" +
  									"<option value='-3'>-3</option>" +
  									"<option value='-2'>-2</option>" +
  									"<option value='-1'>-1</option>" +
  									"<option value='1'>1</option>" +
  									"<option value='2'>2</option>" +
  									"<option value='3' selected>3</option>" +
  									"<option value='4'>4</option>" +
  								    "<option value='5'>5</option>" +
									"</select>";
        		
        		dialogItself.setData('field-title-drop', $titleDrop);   // Put it in dialog data's container then you can get it easier by using dialog.getData() later.
        		$form.append('You are about to change log levels<br/><label>New log level (-5 to 5)&nbsp; </label>').append($titleDrop);

        		return $form;
            },
          //  message: 'You are about to change the logging level of the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-warning',
                action: function(dialogRef) {
   					dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                    obj = document.getElementById("newlevel");
                    var value = obj.value
                	executeBidderCommand(userName,"loglevel","*",value);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
     function doChangeNoBidReason() {
  	 	BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_WARNING,
   			title: 'WARNING',
            message: function(dialogItself) {
				var $form = $('<form></form>');
        		//var $titleDrop = $('<input type="text" id="newlevel" />');
        		
        		var $titleDrop = "<select id='newlevel'>" +
  									"<option value='false'>false</option>" +
  									"<option value='true'>true</option>"
									"</select>";
        		
        		dialogItself.setData('field-title-drop', $titleDrop);   // Put it in dialog data's container then you can get it easier by using dialog.getData() later.
        		$form.append('You are about to change change the print no bid reason flag<br/><label>Print: &nbsp; </label>').append($titleDrop);

        		return $form;
            },
          //  message: 'You are about to change the logging level of the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-warning',
                action: function(dialogRef) {
   					dialogRef.enableButtons(false);
                    dialogRef.setClosable(false)
                    obj = document.getElementById("newlevel");
                    var value = obj.value
                	executeBidderCommand(userName,"nobidreason","*",value);
                	setTimeout(function(){
                        dialogRef.close();
                        reloadStatus();
                    }, 5000);
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function doReloadBidder() {
   BootstrapDialog.show({
   			type: BootstrapDialog.TYPE_DANGER,
   			title: 'DANGER',
            message: 'You are about to reload all the campaigns of the selected bidders!',
            buttons: [
            {
                label: 'Proceed?',
                cssClass: 'btn-danger',
                action: function(dialogItself) {
                	executeReloadBidders();
                	dialogItself.close();
                }
            }, {
                label: 'Close',
                action: function(dialogItself){
                    dialogItself.close();
                }
            }]
        });
   }
   
   function setDemoButtons() {
     	$('#savechanges').addClass('disabled');
     	$('#start-bidder').addClass('disabled');
     	$('#stop-bidder').addClass('disabled');
     	$('#start-bidder').addClass('disabled');
     	$('#reload-bidder').addClass('disabled');
     	$('#changeloglevel').addClass('disabled');
     	$('#changenobidreason-bidder').addClass('disabled');
   }
   
   function setPaneOptions(panel) {
   		pane = panel;
   		
   		if (userName === 'demo')
   			return;
   			
   		if (panel === 'status' || status === 'configuration') {
   		   	$('#savechanges').addClass('disabled');
   		} else {
   		    $('#savechanges').removeClass('disabled');
   		}
   }
   
   function saveChanges() {
   	    alert("Save changes for: " + pane);
   	    
   	    var config = {};
   	    config.seats = {};
   	    
   	    config.forensiq = {};
   	    config.forensiq.threshhold = document.getElementById('forensiq_threshhold').value;
		config.forensiq.ck = document.getElementById('forensiq_ck').value;
		config.forensiq.endpoint = document.getElementById('forensiq_endpoint').value;
		config.forensiq.bidOnError = document.getElementById('forensiq_bidonerror').value;
   	    
   	    config.app = {};
   	    config.app.stopped = document.getElementById('app_stopped').value;
        config.app.ttl = document.getElementById('app_ttl').value;
        config.app['pixel-tracking-url'] = document.getElementById('app_pixel_track').value;
        config.app.winurl = document.getElementById("app_winurl").value;
        config.app['redirect-url'] = document.getElementById("app_redirect").value;
        
        config.app.verbosity = {};
        config.app.verbosity.level = document.getElementById('verbosity_level').value;
        config.app.verbosity['nobid-reason']  = document.getElementById('verbosity_nobidreason').value;
        
        config.app.geotags = {};
        config.app.geotags.states = document.getElementById('geotag_states').value;
        config.app.geotags.zipcodes = document.getElementById('geotag_zipcodes').value;
        
        config.app.redis = {};
        config.app.redis.host = document.getElementById('redis_host').value;
        config.app.redis.bid = document.getElementById('redis_bid').value
        config.app.redis.nobid = document.getElementById('redis_nobid').value;
        config.app.redis.win = document.getElementById('redis_win').value
        config.app.redis.requests = document.getElementById('redis_request').value;
        config.app.redis.logger = document.getElementById('redis_log').value;
        config.app.redis.clicks = document.getElementById('redis_click').value;
        config.app.redis.port = document.getElementById('redis_portk').value;
        
        config.app.template = {};
        config.app.template.default = '';
        config.app.template.exchange = {};
   	    
   	}
   
   function executeReloadBidders() {
   		console.log("-------------------> ChangeLog");
   }
   
     function updateStatus(running) {
    /** 
      * Update the status pane
      */
    table = document.getElementById("addstatus");
    rows = table.rows;
    for (var i = 2; i < rows.length; i++) {
        row = rows[i];
        cell = row.cells[0];
        label = cell.innerText;
        cell = row.cells[1];
        button = cell.children[0];
        text = button.value;
        button.style.background = "#A9A9A9";
            for (var j = 0; j<running.length;j++) {
                if (label == running[j]) {
                    button.value = "Stop";
                    button.style.background='#7FFF00';
                }
            }
        console.log(text);
    }
    }
    
    function deleteStatusRowById(id) {
    	table = document.getElementById("addstatus");
    	rows = table.rows;
   	  for (var i = 2; i < rows.length; i++) {
        row = rows[i];
        cell = row.cells[0];
        label = cell.innerText;
        if (label == id) {
            delid = row.id;
            campStatus.remove(delid);
            return;
        }
    }
    }
    
    
        function startStop(rowId) {
    
    if (document.getElementById("username").value === 'demo') {
    	doModal(BootstrapDialog.TYPE_ERROR,"Error","Demo login can't stop or start campaigns.");
    	return
    }
    
    console.log("A="+rowId);
    row = document.getElementById(rowId);
    cell = row.cells[0];
    a = cell.textContent;
    cell = row.cells[1];
    inp = cell.children[0];
    b = inp.value;
    campaign = getCampaign(a);
    msg = {};
    msg.username = userName;
    if (b == 'Start') {
        inp.value='Pending...';
        msg.command = 'startcampaign';
        msg.id = campaign.adId;
    } else {
        msg.command = 'stopcampaign';
        msg.id = campaign.adId;
        inp.value = "Start"
    }
    ////////////////////
        $.ajax({
         type: 'POST',
         url:'ajax',
         data: JSON.stringify(msg),
         dataType: 'json',
         success: function(data, textStatus, request){
           if (request.status == 204) {
            text = "";
           } else {
            text = request.responseText;
            data = JSON.parse(text);
            message = data.message;
            text = JSON.stringify(data,null,2);
            console.log("-----------------");
            console.log(text);
           }
           if (data.error)
                doModal(BootstrapDialog.TYPE_INFO,"Error",message);
               
           updateStatus(data.running);
         },
         error: function (request, textStatus, errorThrown) {
           doModal(BootstrapDialog.TYPE_INFO,"HTTP Error",request.responseText);
         }});
    ////////////////////
    }
    
    function getCampaign(id) {
    	for (var i = 0; i < camps.length; i++) {
        	var camp = camps[i];
        	if (camp.adId == id)
            	return camp;
    	}
    	return null;
    }
    
    
    function fillInCampaigns(data) {
        camps = data.campaigns;
        running = data.running;
        campStatus.clear();
        for (i = 0; i < camps.length; i++) {
            campaign = camps[i];
            value = campStatus.add([campaign.adId, '']);
            console.log("ADDED: " + value);
        }
        updateStatus(running);
    }
      
      
   //////////////////////////////

xcells = [];
   xcells.push("<input type='text' id='SUB_ID' size='20'value='' placeholder='exchange name' />");
   xcells.push("<input type='text' id='SUB_ID' size='100' value='' placeholder='template is here' />");
   xcells.push("<a href=\"javascript:deleteTemplateRow('ROW_ID');\">Del<\/a><\/td>");

  tdyno = new DynamicTable("addtemplate",xcells);     
      
   
    zcells = [];
    zcells.push('SUB_VALUE')
    zcells.push("<input type='button' onclick='startStop(\"ROW_ID\")' value='Start' id='ROW_ID' class='primary-btn col-xs-11 text-left' style=\"width:100px\"/>");
    campStatus = new DynamicTable("addstatus",zcells);
          
 seatCells = []
    seatCells.push("<input type='text' id='SUB_ID' size='50' value='' placeholder='Name' />");
    seatCells.push("<input type='text' id='SUB_ID' size='10' value='' placeholder='Endpoint' />");
    seatCells.push("<input type='text' id='SUB_ID' size='50' value='' placeholder='Id' />")
    seatCells.push("<a href=\"javascript:deleteSeat('ROW_ID');\">Del<\/a><\/td>");
    seatsDyno = new DynamicTable("addseats",seatCells);
    
    
 userCells = []
    userCells.push("<input type='text' id='SUB_ID' size='30' value='' placeholder='Name' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Password' />")
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Directory' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Phone-Number' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Email' />");
    userCells.push("<input type='text' id='SUB_ID' size='20' value='' placeholder='Credit-Card' />");
    userCells.push("<a href=\"javascript:deleteUser('ROW_ID');\">Del<\/a><\/td>");
    usersDyno = new DynamicTable("addusers",userCells);
    
 systemCells = [];
 	systemCells.push("<input type='text' id='SUB_ID' size='30' readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>"); 	
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	systemDyno = new DynamicTable("system-status",systemCells);
 	
operCells = [];
 	operCells.push("<input type='text' id='SUB_ID' size='30' readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='8'  readonly value=''/>");
 	operCells.push("<input type='text' id='SUB_ID' size='18'  readonly value=''/>");
 	operCells.push("<input type='checkbox' id=SUB_ID'  value='' checked/>");
 	operDyno = new DynamicTable("operstatus",operCells);

initLoadCells = []
    initLoadCells.push("<input type='text' id='SUB_ID' size='50' value='' placeholder='Name' />");
    initLoadCells.push("<input type='text' id='SUB_ID' size='30' value='' placeholder='Id' />");
    initLoadsDyno = new DynamicTable("addinititalloads",initLoadCells);
    
	lastTime = 0;
	
	
   logger = new Logger('logger','log',"localhost:7379");
	
	pane = 'status';		// current pane, starts in status
	
	userName = null;    // no user yet
	
	camps = null;
	running = null;
	
	doModal(BootstrapDialog.TYPE_INFO,"Info","You are logging in as 'demo', just press 'Sign In' to go to\nproceed to the campaign admin page");
 
	
 </script>

</html>

{'fraction_non_alphanumeric': 0.16869331050967049, 'fraction_numerical': 0.009748765747805484, 'mean_word_length': 1.9432292946669945, 'pattern_counts': {'":': 0, '<': 1397, '<?xml version=': 0, '>': 1383, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2432141', 'n_tokens_mistral': 32605, 'n_tokens_neox': 30115, 'n_words': 5238}