<?php
/**
*
* @ This file is created by http://DeZender.Net
* @ deZender (PHP7 Decoder for SourceGuardian Encoder)
*
* @ Version			:	4.1.0.1
* @ Author			:	DeZender
* @ Release on		:	29.08.2020
* @ Official site	:	http://DeZender.Net
*
*/

function my_error_handler($code, $message)
{
	echo sprintf('sprintf', $code);
	echo 'sprintf';
	return 'sprintf';
}

function function_added_to_every_file()
{
}

function randomCode()
{
	$salt = 'LIVEBOX0123456789';
	srand((float) microtime() * 1000000);

	for ($i = 0; $i <= 10; $i++) {
		$num = rand() % 33;
		$tmp = substr($salt, $num, 1);
		$pass = $pass . $tmp;
	}

	return $pass;
}

ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL);
$db = new SQLite3('./api/data/.boxbr_info.db');

if (isset($_POST['submit'])) {
	$code = randomCode();
	$res = $db->query('SELECT * FROM act WHERE activecode=\'' . $code . '\'');
	$row = $res->fetchArray();

	if ($row['act'] == $code) {
		$actcode = randomCode();
	}
	else {
		$actcode = $code;
	}

	$gurl = 'url';
	$db->exec('INSERT INTO act(title, activecode, macAddress, uid, username, password, url, apptype, appname, status) VALUES(\'' . $_POST['title'] . '\', \'' . $actcode . '\', \'' . $_POST['macAddress'] . '\', \'' . $_POST['uid'] . '\', \'' . $_POST['username'] . '\', \'' . $_POST['password'] . '\', \'' . $_POST['url'] . '\',  \'' . $_POST['apptype'] . '\', \'' . $_POST['appname'] . '\',\'' . $_POST['status'] . '\')');
	$db->close();
	header('Location: act.php');
}

include 'includes/header.php';
echo "\r" . '<!-- [ Main Content ] start -->' . "\r" . '    <div class="pcoded-main-container">' . "\r" . '        <div class="pcoded-wrapper">' . "\r" . '            <div class="pcoded-content">' . "\r" . '                <div class="pcoded-inner-content">' . "\r" . '                    <div class="main-body">' . "\r" . '                        <div class="page-wrapper">' . "\r" . '                            <!-- [ Main Content ] start -->' . "\r" . '                            <div class="row">' . "\r" . '                    <!-- Column -->' . "\r" . '                    <div class="col-lg-12">' . "\r" . '                       <div class="card mb-4">' . "\r\t\t\t" . '<div class="card-header bg-primary py-3">' . "\r" . '                ' . "\t" . '<h4 align="center" class="m-0 font-weight-bold text-white"><i class="fas fa-code" style="font-size:20px">&nbsp;&nbsp;</i>Add A ActiveCode</h4>' . "\r" . '                ' . "\t\t\t" . '</div>' . "\r" . '                         <div class="card-body">' . "\r\t\t\t\t\t\t" . '<form method="post">' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="title"><strong>Service Name</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="title" name="title" type="text" required/>' . "\r" . '                                </div>' . "\r" . '                                <!--' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>Activecode</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="act" name="act" type="text"/>' . "\r" . '                                    ' . "\r" . '                                    <button class="input-group btn btn-danger" onclick="javascript:getact()" name="getcoder" type="button" value="GetAct"><span class="icon text-white-50"><i class="fa fa-code"></i>&nbsp;&nbsp;</span><span class="text"> Auto generate a code</span></button>' . "\r" . '                                </div>' . "\r" . '                                -->' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="macAddress"><strong>Mac Address</strong></label>' . "\r" . '                                    <input class="form-control text-primary" maxlength="17" id="macAddress" name="macAddress" type="text"/>' . "\r" . '                                </div>' . "\r" .
'                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>SERVICE URL</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="url" name="url" type="url"/>' . "\r" . '                                </div>' . "\r" .  '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>Username</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="username" name="username" type="text" required/>' . "\r" . '                                </div>' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>Password</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="password" name="password" type="text" required/>' . "\r" . '                                </div>' . "\r" . '<!--' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>Service DNS</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="url" name="url" type="text"/>' . "\r" . '                                </div>' . "\r" . ' -->' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>App Type</strong></label>' . "\r\t\t\t\t\t\t\t\t\t" . '  <select class="input-group form-control type" id="apptype" name="apptype">' . "\r\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op0" value="0" >Dual TV/Vod' . "\r\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op1" value="1" >Only TV' . "\r\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op2" value="2" >Only Vod' . "\r\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\t\t\t\t\t\t\t\t\t" . '  </select>' . "\r" . '                                    </div>' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="appname"><strong>App Name</strong></label>' . "\r" . '                                    <input class="form-control text-primary" id="appname" name="appname" type="text"/>' . "\r" . '                                </div>' . "\r" . '                                ' . "\r" . '                                <div class="form-group">' . "\r" . '                                    <label class="form-label " for="url"><strong>Status</strong></label>' . "\r\t\t\t\t\t\t\t\t\t" . '  <select class="input-group form-control type" id="status" name="status">' . "\r\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op1" value="1" >ACTIVE' . "\r\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\t\t\t\t\t\t\t\t\t\t" . '  <option data-value="op0" value="0" >INACTIVE' . "\r\t\t\t\t\t\t\t\t\t\t" . '  </option>' . "\r\t\t\t\t\t\t\t\t\t" . '  </select>' . "\r" . '                                    </div>' . "\r" . '                                ' . "\r" . '                                <div align="center" class="form-group">' . "\r\t\t\t\t\t\t\t\t\t\t" . '<br>' . "\r\t\t\t\t\t\t\t\t\t\t" . '<button class="btn btn-danger" name="submit" type="submit"><span class="icon text-white-50"><i class="fa fa-plus"></i>&nbsp;&nbsp;</span><span class="text"> Add A Code</span></button>' . "\r" . '                                </div>' . "\r" . '                            </form>' . "\r" . '                            </div>' . "\r" . '                        </div>' . "\r" . '                    </div>' . "\r" . '                    <!-- Column -->' . "\r" . '                </div>' . "\r" . '            </div>' . "\r" . '            <!-- ============================================================== -->' . "\r" . '            <!-- End Container fluid  -->' . "\r" . '            <!-- ============================================================== -->' . "\r" . '        </div>' . "\r" . '        <!-- ============================================================== -->' . "\r" . '        <!-- End Page wrapper  -->' . "\r" . '        <!-- ============================================================== -->' . "\r" . '    </div>' . "\r" . ' ' . "\r" . '<script src="http://code.jquery.com/jquery-latest.js"></script>' . "\r" . '       <script type="text/javascript">' . "\r" . '// @require http://code.jquery.com/jquery-latest.js' . "\r" . '// ==/UserScript==' . "\r" . 'document.getElementById("macAddress").addEventListener(\'keyup\', function() { ' . "\r" . '  var mac = document.getElementById(\'macAddress\').value;' . "\r" . '  var macs = mac.split(\':\').join(\'\');' . "\r" . '  macs = chunk(macs, 2).join(\':\');' . "\r" . '  document.getElementById(\'macAddress\').value = macs.toString();' . "\r" . '});' . "\r\r" . 'function chunk(str, n) {' . "\r" . '    var ret = [];' . "\r" . '    var i;' . "\r" . '    var len;' . "\r\r" . '    for(i = 0, len = str.length; i < len; i += n) {' . "\r" . '       ret.push(str.substr(i, n))' . "\r" . '    }' . "\r\r" . '    return ret' . "\r" . '};' . "\r\r" . '    </script>' . "\r" . ' <script type="text/javascript">' . "\r\r" . '            function getact() {' . "\r\r" . '                var alfabeto = "ABCDEFGHIJKLMNOPQRSTUVXWYZ";' . "\r\r" . '                // letras aleatorias' . "\r" . '                var letras = [];' . "\r" . '                for (var i = 0; i < 10; ++i)' . "\r" . '                    letras[i] = alfabeto.charAt(Math.floor(Math.random() * 25));' . "\r\r" . '                // numero aleatorios' . "\r" . '                var numeros = [];' . "\r" . '                for (var i = 0; i < 10; ++i) {' . "\r" . '                    var sorteio = Math.floor(Math.random() * 9);' . "\r\r" . '                    if (sorteio == 0)' . "\r" . '                        sorteio = 1; // 1 - 9' . "\r\r" . '                    numeros[i] = sorteio;' . "\r" . '                }' . "\r\r" . '                var senha = letras.join(\'\') + numeros.join(\'\');' . "\r" . '                var letras = letras.join(\'\');' . "\r" . '                var numeros = numeros.join(\'\');' . "\r\r" . '                document.getElementById(\'act\').value = letras;' . "\r" . '            }' . "\r" . '        </script>         ' . "\r" . '    ' . "\r";
include 'includes/functions.php';
echo '   ';

?>