function Set($f3) { if (!\Check::confirm('POST.password')) { $this->flash('Konfirmasi Password Tidak Cocok'); $f3->reroute($f3->get('URI')); } $post = $f3->get('POST'); $db_host = $post['DB_HOST']; $db_name = $post['DB_NAME']; $db_user = $post['DB_USER']; $db_pass = $post['DB_PASS']; $dsn = "mysql:host={$db_host};port=3306;dbname={$db_name}"; $db = new \DB\SQL($dsn, $db_user, $db_pass); try { $db->begin(); $db->exec(explode(';', $f3->read('installation/install.sql'))); $user = new \DB\SQL\Mapper($db, 'user'); $user->username = $post['username']; $user->password = \Bcrypt::instance()->hash($post['password']); $user->type = 1; $user->save(); $key = bin2hex(openssl_random_pseudo_bytes(32)); $data = "[globals]\nDEBUG=0\nAUTOLOAD=\"controller/;model/\"\nUI=\"view/\"\nAPP_KEY=\"{$key}\"\nDB_SET=\"{$dsn}\"\nDB_USER=\"{$db_user}\"\nDB_PASS=\"{$db_pass}\""; $f3->write('config/config.ini', $data); $f3->write('config/route.ini', $f3->read('installation/route.ini')); $db->commit(); $this->flash('Success... Silahkan Hapus Folder Installation', 'success'); } catch (Exception $e) { $db->rollback(); $this->flash($e->getMessage()); $f3->reroute('/'); } $f3->reroute('/'); }
public function localChapterDB() { if ($db = new \DB\SQL('sqlite:data/chapters.sq3')) { $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $db; } else { return FALSE; } }
function __construct() { $f3 = Base::instance(); // Connect to the database $db = new DB\SQL($f3->get('db')); if (file_exists('setup.sql')) { // Initialize database with default setup $db->exec(explode(';', $f3->read('setup.sql'))); // Make default setup inaccessible rename('setup.sql', 'setup.$ql'); } // Use database-managed sessions new DB\SQL\Session($db); // Save frequently used variables $this->db = $db; }
public function beforeRoute($f3) { $token = $f3->get('HEADERS.Authorization'); if ($token) { // Validate token try { $user = JWT::decode($token, $f3->get('key'), array('HS256')); $db = new DB\SQL($f3->get('main_db'), $f3->get('main_username'), $f3->get('main_password')); $result = $db->exec("SELECT id FROM users WHERE id = ?", $user->id); if (!$result) { $f3->reroute('/api/unauthorized'); } $f3->set('REQUEST.user', $user); } catch (Exception $e) { $f3->reroute('/api/unauthorized'); } } else { $f3->reroute('/api/unauthorized'); } }
public function send() { // Check message length $messages = []; if (strlen($this->message_content) > MAX_LENGTH) { // If greater than maximum message length, // divide the message into chunks $messages = str_split($this->message_content, MAX_CHUNK_LENGTH); } else { // Else send the single message $messages[] = $this->message_content; } // Send every message $f3 = Base::instance(); $db = new DB\SQL($f3->get('smsd_db'), $f3->get('smsd_username')); foreach ($messages as $message) { $db->exec("INSERT INTO outbox(DestinationNumber, TextDecoded, CreatorID) \n VALUES (?, ?, 'Beyond SMS Gateway API v{$f3->get('version')}')", [1 => $this->recipient_phone_number, 2 => $message]); } // return the number of messages sent return count($messages); }
$f3->set("error", "PCRE version is out of date"); } // Check for MySQL PDO if (!in_array("mysql", PDO::getAvailableDrivers())) { $f3->set("error", "MySQL PDO driver is not avaialble."); } // Check for GD library if (!function_exists("imagecreatetruecolor")) { $f3->set("warning", "GD library is not available. Profile pictures and file thumbnails will not work until it is installed."); } // Run installation process if post data received if ($_POST) { $post = $_POST; try { // Connect to database $db = new \DB\SQL("mysql:host=" . $post["db-host"] . ";port=" . $post["db-port"] . ";dbname=" . $post["db-name"], $post["db-user"], $post["db-pass"]); // Run installation scripts $install_db = file_get_contents("db/database.sql"); $db->exec(explode(";", $install_db)); // Create admin user $f3->set("db.instance", $db); $security = \Helper\Security::instance(); $user = new \Model\User(); $user->role = "admin"; $user->rank = 5; // superadmin $user->name = "Admin"; $user->username = $post["user-username"] ?: "admin"; $user->email = $post["user-email"]; $user->salt = $security->salt(); $user->password = $security->hash($post["user-password"] ?: "admin", $user->salt);
$RIDEDISTANCE = 2583; //Average distance a person can ride in 10 minutes (m) $DRIVEDISTANCE = 6666; //Distance that can be driven in 10 minutes based on a 40km/h average speed (m) $BASEURL = "http://planr.ballarathackerspace.org.au/"; $CLIENTURL = $BASEURL . "sims/web/"; $APIURL = $BASEURL . "sims/api/"; // Kickstart the framework $f3 = (require 'lib/base.php'); //$f3->set('CACHE','memcache=localhost'); $f3->set('CACHE', FALSE); $f3->set('DEBUG', 1); if ((double) PCRE_VERSION < 7.9) { trigger_error('PCRE version is out of date'); } $db = new \DB\SQL('mysql:host=localhost;port=3306;dbname=sims', 'rat', '2Jr8tKH6rHZt4jTf'); $CATEGORIES = $db->exec('SELECT DISTINCT category FROM points'); $NUMSERVICES = count($CATEGORIES); // Load configuration $f3->config('config.ini'); $f3->route('GET /', function ($f3) { $classes = array('Base' => array('hash', 'json', 'session'), 'Cache' => array('apc', 'memcache', 'wincache', 'xcache'), 'DB\\SQL' => array('pdo', 'pdo_dblib', 'pdo_mssql', 'pdo_mysql', 'pdo_odbc', 'pdo_pgsql', 'pdo_sqlite', 'pdo_sqlsrv'), 'DB\\Jig' => array('json'), 'DB\\Mongo' => array('json', 'mongo'), 'Auth' => array('ldap', 'pdo'), 'Bcrypt' => array('mcrypt', 'openssl'), 'Image' => array('gd'), 'Lexicon' => array('iconv'), 'SMTP' => array('openssl'), 'Web' => array('curl', 'openssl', 'simplexml'), 'Web\\Geo' => array('geoip', 'json'), 'Web\\OpenID' => array('json', 'simplexml'), 'Web\\Pingback' => array('dom', 'xmlrpc')); $f3->set('classes', $classes); $f3->set('content', 'welcome.htm'); echo View::instance()->render('layout.htm'); }); $f3->route('GET /userref', function ($f3) { $f3->set('content', 'userref.htm'); echo View::instance()->render('layout.htm'); }); $f3->route('GET /services', function () {
#!/usr/bin/php5 <?php error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); set_time_limit(0); $BASE_DIR = dirname(__DIR__); require $BASE_DIR . '/vendor/autoload.php'; use Clio\Console; $f3 = Base::instance(); $f3->set('BASE_DIR', $BASE_DIR); $f3->set('CONFIG_DIR', $BASE_DIR . "/app/config"); $f3->set('AUTOLOAD', $BASE_DIR . '/app/lib/'); $f3->config($f3->get('CONFIG_DIR') . '/config.master.ini', true); $DB = new DB\SQL('mysql:host=' . $f3->get("DB_HOST") . ';port=' . $f3->get("DB_PORT") . ';dbname=' . $f3->get("DB_NAME") . '', $f3->get('DB_USER'), $f3->get('DB_PASS'), array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); $DB->exec("SET NAMES utf8"); $f3->set('DB', $DB); $f3->route('GET *', function ($f3, $params) { $COMMAND = $f3->get('URI'); switch ($COMMAND) { case 'start': $f3->reroute('command/start', false); break; case 'setup': $f3->reroute('command/setup', false); break; case 'installdaemon': $f3->reroute('command/installdaemon', false); break; case 'uninstalldaemon': $f3->reroute('command/uninstalldaemon', false); break; default:
$result = $db->exec('SELECT id, message FROM Fortune'); $result[] = array('id' => 0, 'message' => 'Additional fortune added at request time.'); $mtx = \Matrix::instance(); $mtx->sort($result, 'message'); $f3->set('result', $result); echo \Template::instance()->render('fortune.html'); }); $f3->route(array('GET /update-raw', 'GET /update-raw/@queries'), function ($f3, $params) { /** @var Base $f3 */ $queries = 1; if (isset($params['queries'])) { $queries = (int) $params['queries']; $queries = $queries < 1 ? 1 : ($queries > 500 ? 500 : $queries); } $dbc = $f3->get('DBS'); $db = new \DB\SQL($dbc[0], $dbc[1], $dbc[2], array(\PDO::ATTR_PERSISTENT => TRUE)); $result = array(); for ($i = 0; $i < $queries; $i++) { $id = mt_rand(1, 10000); $row = array('id' => $id, 'randomNumber' => $db->exec('SELECT randomNumber FROM World WHERE id = ?', $id, 0, false)); $rnu = mt_rand(1, 10000); $row['randomNumber'] = $rnu; $db->exec('UPDATE World SET randomNumber = :ranNum WHERE id = :id', array(':ranNum' => $rnu, ':id' => $id), 0, false); $result[] = $row; } header("Content-type: application/json"); echo json_encode($result); }); $f3->route(array('GET /update-orm', 'GET /update-orm/@queries'), function ($f3, $params) { /** @var Base $f3 */ $queries = 1;
<?php // Kickstart the framework $f3 = (require 'lib/base.php'); $f3->set('DEBUG', 1); if ((double) PCRE_VERSION < 7.9) { trigger_error('PCRE version is out of date'); } $db = new DB\SQL('sqlite:database.sqlite'); $db->exec("\nDROP TABLE IF EXISTS `Objects`;\n\t\t\nCREATE TABLE `Objects` (\n `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL,\n `Name` CHAR(256) NULL DEFAULT NULL,\n `Properties` MEDIUMTEXT NULL DEFAULT NULL,\n PRIMARY KEY (`id`)\n);\n\n-- ---\n-- Table 'Properties'\n-- \n-- ---\n\nDROP TABLE IF EXISTS `Properties`;\n\t\t\nCREATE TABLE `Properties` (\n `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL,\n `Name` INTEGER NULL DEFAULT NULL,\n PRIMARY KEY (`id`)\n);\n\n-- ---\n-- Table 'Contents'\n-- \n-- ---\n\nDROP TABLE IF EXISTS `Contents`;\n\t\t\nCREATE TABLE `Contents` (\n `id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL,\n `Propertie` INT NULL DEFAULT NULL,\n `Content` INTEGER NULL DEFAULT NULL,\nKEY (`id`)\n);\n\n-- ---\n-- Foreign Keys \n-- ---\n"); $f3->route('GET /', function ($f3) { echo $db->log(); }); require 'view/admin.php'; $f3->run();
echo json_encode(["status" => "ERR", "description" => "Invalid username or password."]); } } else { // Send error: wrong username or password echo json_encode(["status" => "ERR", "description" => "Invalid username or password."]); } }); $f3->route('GET /api/unauthorized', function () { header('Content-type: application-json'); echo json_encode(["status" => "ERR", "description" => "You don't have access to this service."]); }); // DEVELOPMENT ONLY // REGISTER USER $f3->route('GET /api/@user/@password', function ($f3) { header('Content-type: application/json'); $db = new DB\SQL($f3->get('main_db'), $f3->get('main_username'), $f3->get('main_password')); $crypt = Bcrypt::instance(); $success = $db->exec("INSERT INTO users (username, password) VALUES (:username, :password)", [':username' => $f3->get('PARAMS.user'), ':password' => $crypt->hash($f3->get('PARAMS.password'))]); if ($success) { echo json_encode(["status" => "OK"]); } else { echo json_encode(["status" => "ERR", "description" => "Invalid username or password."]); } }); // Route: POST /api/sms // Args: // - recipient_phone_number: string // - message_content: string $f3->route('POST /api/sms', 'API->sendSMS'); // Run the app $f3->run();
public static function testConfig($dsnTest) { $fw = \Base::instance(); // Options $options = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_PERSISTENT => TRUE); if ($fw['POST.new.db5.driver'] == "mysql") { $options5 = $options + [\PDO::MYSQL_ATTR_COMPRESS => TRUE]; } else { $options5 = $options; } if ($fw['POST.new.db3.driver'] == "mysql") { $options += [\PDO::MYSQL_ATTR_COMPRESS => TRUE]; } // MySQL-specific attribute foreach ($dsnTest as $server => $dsn) { if ($dsn == NULL) { $test[$server] = 1; } else { // reset connection unset($dbTest); // Test db connection try { $dbTest = new \DB\SQL($dsn, $fw["POST.new.{$server}.user"], $fw["POST.new.{$server}.pass"], $options); $test[$server] = 2; if ($server == "db5") { try { $dbTest->exec('SELECT 1 FROM `' . $fw['POST.new.db5.dbname'] . '`.`' . $fw['POST.new.db5.prefix'] . 'config`'); echo $dbTest->count() . "xxxx"; $test[$server] = 3; } catch (PDOException $e) { echo "nichts"; $test[$server] = 2; $fw['POST.new.db5.error'] = $e->getMessage(); } } elseif ($server == "db3") { $probeSQL = "SELECT `tableprefix`, `sitekey`, `sitename` \r\n\t\t\t\t\t\t\t\t\t\tFROM `{$fw['POST.new.db3.dbname']}`.`{$fw['POST.new.db3.settings']}fanfiction_settings`"; if ($fw['POST.new.db3.sitekey'] > "") { try { $probe = $dbTest->exec($probeSQL . " WHERE `sitekey` LIKE :sitekey", [':sitekey' => $fw['POST.new.db3.sitekey']]); $test['data'] = 2; if ($dbTest->count() !== 1) { $test[1] = 1; } } catch (PDOException $e) { $test['data'] = 0; } } else { try { $probe = $dbTest->exec($probeSQL); if ($dbTest->count() === 1) { $test['data'] = 2; $fw['POST.new.db3.sitekey'] = $probe[0]['sitekey']; } else { $test['data'] = 1; } } catch (PDOException $e) { $test['data'] = 0; } } if ($test['data'] == 2) { $fw['POST.new.db3_prefix'] = $probe[0]['tableprefix']; $fw['POST.new.data.sitename'] = $probe[0]['sitename']; } } // probe for supported charset (MySQL only) if ($fw["POST.new.{$server}.driver"] == "mysql") { try { $dbTest->query("SET NAMES 'UTF8MB4'"); $fw["POST.new.{$server}.charset"] = "UTF8MB4"; } catch (PDOException $e) { $fw["POST.new.{$server}.charset"] = "UTF8"; } } } catch (PDOException $e) { echo $server; $test[$server] = 0; $fw["POST.new.error.{$server}"] = $e->getMessage(); $fw["POST.new.{$server}.charset"] = ""; } } } return $test; }
<?php // Kickstart the framework $f3 = (require 'lib/base.php'); $db = new \DB\SQL('mysql:host=localhost;port=3306;dbname=test', 'admin', ''); //$db=new \DB\SQL('mysql:host=mysql.hostinger.pl;port=3306;dbname=u387000275_paczk','u387000275_paczk','paczka123'); $res = $db->exec("SELECT * FROM need"); //var_dump($res); $f3->set('DEBUG', 1); if ((double) PCRE_VERSION < 7.9) { trigger_error('PCRE version is out of date'); } // Load configuration $f3->config('config.ini'); $f3->route('GET /', function ($f3) { $classes = array('Base' => array('hash', 'json', 'session'), 'Cache' => array('apc', 'memcache', 'wincache', 'xcache'), 'DB\\SQL' => array('pdo', 'pdo_dblib', 'pdo_mssql', 'pdo_mysql', 'pdo_odbc', 'pdo_pgsql', 'pdo_sqlite', 'pdo_sqlsrv'), 'DB\\Jig' => array('json'), 'DB\\Mongo' => array('json', 'mongo'), 'Auth' => array('ldap', 'pdo'), 'Bcrypt' => array('mcrypt', 'openssl'), 'Image' => array('gd'), 'Lexicon' => array('iconv'), 'SMTP' => array('openssl'), 'Web' => array('curl', 'openssl', 'simplexml'), 'Web\\Geo' => array('geoip', 'json'), 'Web\\OpenID' => array('json', 'simplexml'), 'Web\\Pingback' => array('dom', 'xmlrpc')); $f3->set('classes', $classes); $f3->set('content', 'welcome.htm'); echo View::instance()->render('layout.htm'); }); $f3->route('GET /userref', function ($f3) { $f3->set('content', 'userref.htm'); echo View::instance()->render('layout.htm'); }); $f3->route('GET /', function ($f3) { global $db; $res = $db->exec("SELECT * FROM need"); $f3->set("needs", "lala"); echo View::instance()->render('view/index.php'); }); $f3->route('GET /editgifts', function ($f3) {
static function setAllIdNamePares() { if (UserController::$idNamePare == null) { $query = "SELECT id, org_name\n\t\t\t\t FROM users\n\t\t\t\t WHERE is_active > 0\n\t\t\t\t"; $f3 = Base::instance(); $db = new DB\SQL($f3->get('db_dns') . $f3->get('db_name'), $f3->get('db_user'), $f3->get('db_pass')); $result = $db->exec($query); $return_array = array(); foreach ($result as $row) { $return_array[$row['id']] = $row['org_name']; } UserController::$idNamePare = $return_array; return $return_array; } else { return UserController::$idNamePare; } }
/** * fat-free framework application * execute with call to FFMVC\App\Run();. * * @author Vijay Mahrra <*****@*****.**> * @copyright (c) Copyright 2013 Vijay Mahrra * @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html) */ function Run() { // @see http://fatfreeframework.com/quick-reference#autoload $f3 = (require_once 'lib/bcosca/fatfree-core/base.php'); $f3->set('AUTOLOAD', __DIR__ . ';bcosca/fatfree-core/;lib/'); // initialise application Main::start($f3); // user feedback messages helper, inisialise so methods can be called statically $messages = Helpers\Messages::instance(); $messages->init(); // setup database connection params // @see http://fatfreeframework.com/databases $db = null; if (!empty($f3->get('db.driver') || $f3->get('db.dsn') || $f3->get('db.http_dsn'))) { if ($http_dsn = $f3->get('db.http_dsn')) { if (preg_match('/^(?<driver>[^:]+):\\/\\/(?<username>[^:]+):(?<password>[^@]+)@(?<hostname>[^:]+):(?<port>[\\d]+)?\\/(?<database>.+)/', $http_dsn, $m)) { $f3->set('db.dsn', sprintf('%s:host=%s;port=%d;dbname=%s', $m['driver'], $m['hostname'], $m['port'], $m['database'])); $f3->mset(array('db.driver' => $m['driver'], 'db.hostname' => $m['hostname'], 'db.port' => $m['port'], 'db.name' => $m['database'], 'db.username' => $m['username'], 'db.password' => $m['password'])); } } elseif (empty($f3->get('db.dsn'))) { $f3->set('db.dsn', sprintf('%s:host=%s;port=%d;dbname=%s', $f3->get('db.driver'), $f3->get('db.hostname'), $f3->get('db.port'), $f3->get('db.name'))); } if ($f3->get('db.driver') !== 'sqlite') { if ($dsn = $f3->get('db.dsn')) { $db = new \DB\SQL($dsn, $f3->get('db.username'), $f3->get('db.password')); } } else { $dsn = $f3->get('db.dsn'); $dsn = substr($dsn, 0, strpos($dsn, '/')) . realpath('../') . substr($dsn, strpos($dsn, '/')); $db = new \DB\SQL($dsn); // attach any other sqlite databases - this example uses the full pathname to the db if ($f3->exists('db.sqlite.attached')) { $attached = $f3->get('db.sqlite.attached'); $st = $db->prepare('ATTACH :filename AS :dbname'); foreach ($attached as $dbname => $filename) { $st->execute(array(':filename' => $filename, ':dbname' => $dbname)); } } } } \Registry::set('db', $db); // cli start if (PHP_SAPI == 'cli') { $f3->route('GET /doc/@page', function ($f3, $params) { $filename = 'doc/' . strtoupper($params['page']) . '.md'; if (!file_exists($filename)) { die("Documentation Error!\n\nNo such document exists!\n"); } else { echo $f3->read($filename); } }); // @see http://fatfreeframework.com/routing-engine //load routes from ini file $f3->config('config/routes-cli.ini'); } else { // web start // custom error handler if debugging $f3->set('ONERROR', function () use($f3) { // recursively clear existing output buffers: while (ob_get_level()) { ob_end_clean(); } if ($f3->get('ERROR.code') == '404' && stristr($f3->get('PATH'), '/api') == false) { include_once 'templates/www/error/404.phtml'; } else { $debug = $f3->get('DEBUG'); if (stristr($f3->get('PATH'), '/api') !== false) { $response = Helpers\Response::instance(); $data = array('service' => 'API', 'version' => 1, 'time' => time(), 'method' => $f3->get('VERB')); $e = $f3->get('ERROR'); $data['error'] = array('code' => substr($f3->snakecase(str_replace(' ', '', $e['status'])), 1), 'description' => $e['code'] . ' ' . $e['text']); if ($debug == 3) { // show the $e['trace'] but it's in HTML! } $params = array('http_status' => $e['code']); $return = $f3->get('REQUEST.return'); switch ($return) { case 'xml': $response->xml($data, $params); break; default: case 'json': $response->json($data, $params); } } else { include_once $debug < 3 ? 'templates/www/error/error.phtml' : 'templates/www/error/debug.phtml'; } } // http://php.net/manual/en/function.ob-end-flush.php ob_end_flush(); }); // clean ALL incoming user input by default foreach (array('GET', 'POST') as $var) { $input = $f3->get($var); if (is_array($input) && count($input)) { $cleaned = array(); $request = array(); foreach ($input as $k => $v) { $k = strtolower(trim($f3->clean($k))); $v = $f3->clean($v); $cleaned[$k] = $v; $request[$k] = $v; } $f3->set($var, $cleaned); $f3->set('REQUEST', array_merge($f3->get('COOKIE', array()), $request)); } } // @see http://fatfreeframework.com/optimization $f3->route('GET /minify/@type', function ($f3, $args) { $type = $args['type']; $path = $f3->get('UI') . $type . '/'; $files = str_replace('../', '', $_GET['files']); // close potential hacking attempts echo \Web::instance()->minify($files, null, true, $path); }, $f3->get('minify.ttl')); $f3->route('GET /doc/@page', function ($f3, $params) { $filename = 'doc/' . strtoupper($params['page']) . '.md'; echo \View::instance()->render('www/header.phtml'); if (!file_exists($filename)) { echo '<h1>Documentation Error</h1><p>No such document exists!</p>'; $f3->status(404); } else { echo \Markdown::instance()->convert($f3->read($filename)); } echo \View::instance()->render('www/footer.phtml'); }, $f3->get('doc.ttl')); $f3->config('config/routes.ini'); } $f3->run(); // terminate application Main::finish($f3); }