Beispiel #1
0
 public function query($sql, $as_object = FALSE)
 {
     if (preg_match("/OFFSET ([0-9]+)/i", $sql, $matches)) {
         list($replace, $offset) = $matches;
         $sql = str_replace($replace, '', $sql);
     }
     if (preg_match("/LIMIT ([0-9]+)/i", $sql, $matches)) {
         list($replace, $limit) = $matches;
         $sql = str_replace($replace, '', $sql);
     }
     if (isset($limit) || isset($offset)) {
         if (!isset($offset)) {
             $sql = preg_replace("/^(SELECT|DELETE|UPDATE)\\s/i", "\$1 TOP " . $limit . ' ', $sql);
         } else {
             $ob_count = (int) preg_match_all('/ORDER BY/i', $sql, $ob_matches, PREG_OFFSET_CAPTURE);
             if ($ob_count < 1) {
                 $over = 'ORDER BY (SELECT 0)';
             } else {
                 $ob_last = array_pop($ob_matches[0]);
                 $orderby = strrchr($sql, $ob_last[0]);
                 $over = preg_replace('/[^,\\s]*\\.([^,\\s]*)/i', 'inner_tbl.$1', $orderby);
                 $sql = substr($sql, 0, $ob_last[1]);
             }
             // Add ORDER BY clause as an argument for ROW_NUMBER()
             $sql = "SELECT ROW_NUMBER() OVER ({$over}) AS KOHANA_DB_ROWNUM, * FROM ({$sql}) AS inner_tbl";
             $start = $offset + 1;
             $end = $offset + $limit;
             $sql = "WITH outer_tbl AS ({$sql}) SELECT * FROM outer_tbl WHERE KOHANA_DB_ROWNUM BETWEEN {$start} AND {$end}";
         }
     }
     return parent::query($sql, $as_object);
 }
Beispiel #2
0
<?php

/**
 * Script to display agent edit result
 *************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
/* checks */
$error = array();
# for edit check old details
if ($_POST['action'] == "edit" || $_POST['action'] == "delete") {
    # old
    $agent_old = $Admin->fetch_object("scanAgents", "id", $_POST['id']);
    // invalid id
    if ($agent_old === false) {
        $error[] = "Invalid agent Id";
    }
    // remove type and code if direct
    if (@$agent_old->type == "direct") {
        unset($_POST['type'], $_POST['code']);
    }
}
# die if direct and delete
if (@$agent_old->type == "direct" && $_POST['action'] == "delete") {
Beispiel #3
0
$resolve_config['clionly'] = true;
# if true it can only be run from CLI
$resolve_config['emptyonly'] = true;
# if true it will only update the ones without DNS entry!
$resolve_config['subnets'] = array();
# which subnets to check - by id
# example -> array(1,3,5)	will only update subnets with id 1,3,5
# 	you can get id's and descriptions with following MySQL query:
#	select `id`,`description` from `subnets`;
$resolve_config['verbose'] = true;
# verbose response - prints results, cron will email it to you!
# include required scripts
require dirname(__FILE__) . '/../functions.php';
require dirname(__FILE__) . '/../../functions/classes/class.Thread.php';
# initialize objects
$Database = new Database_PDO();
$Admin = new Admin($Database, false);
$Subnets = new Subnets($Database);
$DNS = new DNS($Database);
$Result = new Result();
// set to 1 in case of errors
ini_set('display_errors', 0);
error_reporting(E_ERROR);
# cli required
if ($resolve_config['clionly'] && !defined('STDIN')) {
    $Result->show_cli("cli only\n", true);
} elseif (!$resolve_config['clionly'] && !defined('STDIN')) {
    $User = new User($Database);
    # verify that user is logged in
    $User->check_user_session();
}
Beispiel #4
0
 public function datatype($type)
 {
     static $types = array('nvarchar' => array('type' => 'string'), 'ntext' => array('type' => 'string'), 'tinyint' => array('type' => 'int', 'min' => '0', 'max' => '255'));
     if (isset($types[$type])) {
         return $types[$type];
     }
     return parent::datatype($type);
 }
Beispiel #5
0
<?php

# required functions
if (!is_object(@$User)) {
    require dirname(__FILE__) . '/../../../functions/functions.php';
    # classes
    $Database = new Database_PDO();
    $User = new User($Database);
    $Tools = new Tools($Database);
}
# user must be authenticated
$User->check_user_session();
?>


<!-- stats table -->
<table class="table table-condensed table-hover">

	<!-- sections -->
	<tr>
		<td class="title"><?php 
print _('Number of Sections');
?>
</td>
		<td><?php 
print $Database->numObjects("sections");
?>
</td>
	</tr>

	<!-- subnets -->
Beispiel #6
0
<?php

/**
 *	Edit authentication method
 *
 */
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Admin = new Admin($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# validate csrf cookie
$_POST['csrf_cookie'] == $_SESSION['csrf_cookie'] ?: $Result->show("danger", _("Invalid CSRF cookie"), true);
# get action
$action = $_POST['action'];
//for adding remove id
if ($action == "add") {
    unset($_POST['id']);
} else {
    //check id
    if (!is_numeric($_POST['id'])) {
        $Result->show("danger", _("Invalid ID"), true);
    }
}
# set update query
$values = array("id" => @$_POST['id'], "type" => $_POST['type'], "description" => @$_POST['description']);
# add params
Beispiel #7
0
 *	to main phpipam server.
 *
 *	Script must be called with update/discover argument
 *
 *	Documentation available here :
 *
 */
/* require classes */
require 'functions/functions.php';
require 'config.php';
# start phpipam-agent class
try {
    // for database connections
    if ($config['type'] == "mysql") {
        // open db connection
        $Database = new Database_PDO($config['db']['user'], $config['db']['pass'], $config['db']['host'], $config['db']['port'], $config['db']['name']);
        // test connection, will throw exception if it fails
        $Database->connect();
        // new scan object
        $Scan = new Scan($Database);
    } else {
        // scan without DB connection
        $Database = false;
    }
    // initialize and make default checks
    $phpipam_agent = new phpipamAgent($Database);
    // set scan type - status update (update) or discover, must be provided via argv[1]
    $phpipam_agent->set_scan_type($argv[1]);
    // execute
    $phpipam_agent->execute();
    // update scan time
Beispiel #8
0
<?php

/**
 *	Format and submit instructions to database
 **********************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# execute
#
#	we do it directly because we permit html tags for instructions
#
try {
    $Database->updateObject("instructions", array("id" => 1, "instructions" => $_POST['instructions']), "id");
} catch (Exception $e) {
    $Result->show("danger", _("Error: ") . $e->getMessage(), false);
    write_log("Instructions updated", "Failed to update instructions<hr>" . $e->getMessage(), 2, $User->username);
}
# ok
write_log("Instructions updated", "Instructions updated succesfully", 0, $User->username);
$Result->show("success", _("Instructions updated successfully"), true);
Beispiel #9
0
require dirname(__FILE__) . '/classes/class.Scan.php';
//Class for Scanning and pinging
require dirname(__FILE__) . '/classes/class.DNS.php';
//Class for DNS management
require dirname(__FILE__) . '/classes/class.PowerDNS.php';
//Class for PowerDNS management
require dirname(__FILE__) . '/classes/class.FirewallZones.php';
//Class for firewall zone management
require dirname(__FILE__) . '/classes/class.Admin.php';
//Class for Administration
require dirname(__FILE__) . '/classes/class.Mail.php';
//Class for Mailing
# save settings to constant
if ($_GET['page'] != "install") {
    # database object
    $Database = new Database_PDO();
    # try to fetch settings
    try {
        $settings = $Database->getObject("settings", 1);
    } catch (Exception $e) {
        $settings = false;
    }
    if ($settings !== false) {
        define(SETTINGS, json_encode($settings));
    }
}
/**
 * create links function
 *
 *	if rewrite is enabled in settings use rewrite, otherwise ugly links
 *
Beispiel #10
0
<?php

/**
 *	Format and submit instructions to database
 **********************************************/
/* functions */
require dirname(__FILE__) . '/../../../functions/functions.php';
# initialize user object
$Database = new Database_PDO();
$User = new User($Database);
$Result = new Result();
$Log = new Logging($Database, $User->settings);
# verify that user is logged in
$User->check_user_session();
# validate csrf cookie
$User->csrf_cookie("validate", "instructions", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
# validate ID
if ($_POST['id'] == "1" || $_POST['id'] == "2") {
    // update
    if ($Database->objectExists("instructions", $_POST['id'])) {
        print "update";
        try {
            $Database->updateObject("instructions", array("id" => $_POST['id'], "instructions" => $_POST['instructions']), "id");
        } catch (Exception $e) {
            $Result->show("danger", _("Error: ") . $e->getMessage(), false);
            $Log->write("Instructions updated", "Failed to update instructions<hr>" . $e->getMessage(), 1);
        }
    } else {
        try {
            $Database->insertObject("instructions", array("id" => $_POST['id'], "instructions" => $_POST['instructions']), false, true, false);
        } catch (Exception $e) {