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('/'); }
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); }
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); $user->api_key = $security->salt_sha1(); $user->save(); } catch (PDOException $e) {
//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 () { global $db, $f3;
#!/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:
$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; if (isset($params['queries'])) { $queries = (int) $params['queries']; $queries = $queries < 1 ? 1 : ($queries > 500 ? 500 : $queries); }
<?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; } }