Esempio n. 1
0
    }
    /**
     * exportRows
     *
     * @param string $table
     * @param array  $sql
     *
     * @return  void
     */
    public static function exportRows($table, &$sql)
    {
        $stat = static::$db->query('SELECT * FROM ' . $table);
        $query = 'INSERT ' . $table . ' VALUES (%s)';
        while ($row = $stat->fetch_object()) {
            $values = array();
            foreach (get_object_vars($row) as $k => $v) {
                $values[] = "'" . static::$db->real_escape_string($v) . "'";
            }
            $sql[] = sprintf($query, implode(', ', $values));
        }
    }
}
// Set error handler
BackupApplication::registerErrorHandler();
$app = new BackupApplication($options);
try {
    $app->execute();
} catch (Exception $e) {
    http_response_code($e->getCode());
    echo $e->getMessage();
}
Esempio n. 2
0
            $to_eval = sprintf('$var = (isset($VAR%d) ? $VAR%d : null);', $i, $i);
            eval($to_eval);
            if (!is_null($var)) {
                $retval[] = $var;
            }
        }
        return $retval;
    }
}
class BackupApplication extends Silex\Application
{
    use Silex\Application\TranslationTrait;
    use Silex\Application\TwigTrait;
    use Silex\Application\MonologTrait;
}
$app = new BackupApplication();
$app['debug'] = true;
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/logs/app.log'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/templates'));
$bpc = new BackupPcInterface($app, $config['host'], $config['port'], $config['secret']);
$app->get('/', function () use($app) {
    return $app['twig']->render('index.html.twig');
});
$app->get('/host/', function () use($app, $bpc, $config) {
    $app->log('Fetching hosts');
    return json_encode($bpc->getHosts());
});
$app->get('/host/{hostname}', function ($hostname) use($app, $bpc) {
    $app->log('Fetching information for Host ' . $hostname);
    return json_encode($bpc->getHost($hostname));
});