Category: Frameworks

All about penetration testing frameworks!

Debian, Django, Python

Apache2 and Django installation on Debian

Install Apache2 sudo apt-get install apache2 -y sudo rm -f /var/www/html/index.html && sudo touch /var/www/html/index.html sudo a2enmod ssl sudo a2ensite default-ssl sudo service apache2 restartsudo apt-get install apache2 -y sudo rm -f /var/www/html/index.html && sudo touch /var/www/html/index.html sudo a2enmod ssl sudo a2ensite default-ssl sudo service apache2 restart Install Python 3 sudo apt-get install python3 -y …

CakePHP, PHP

List table columns in cakephp 3

List table columns $db = \Cake\Datasource\ConnectionManager::get(’default’); $collection = $db->schemaCollection(); $table= $collection->describe(’tablename’); $columns = $table->columns();$db = \Cake\Datasource\ConnectionManager::get(‘default’); $collection = $db->schemaCollection(); $table= $collection->describe(‘tablename’); $columns = $table->columns();

CakePHP, PHP

CakePHP 3 – Format Datetime in words

To use TimeHelper you have to enable it first. To enable a helper in your view, add the name of the helper to the controller’s $helpers array: class MyController extends AppController { public $helpers = [’Time’]; }class MyController extends AppController { public $helpers = [‘Time’]; } Each helper is exposed as a public property in …

CakePHP, PHP

Simple JSON response with CakePHP 3

CakePHP 3 Book – Chapter JSON and XML views Controller code: namespace App\Controller;   class MyJsonController extends AppController { public function initialize() { parent::initialize(); $this->loadComponent(’RequestHandler’); }   public function index() { $customers[’id’] = ‘123’; $this->set(’customers’, $customers); $this->set(’_serialize’, [’customers’]); } }namespace App\Controller; class MyJsonController extends AppController { public function initialize() { parent::initialize(); $this->loadComponent(‘RequestHandler’); } public function …

CakePHP, PHP

Custom Finder Method in CakePHP 3

In your Table Model create a method and name it, findMymethod, ‘find’ prefix is mandatory, for ex. public function findOffline(Query $query, array $options) { $query->where([ ‘online’ => false, ]); return $query; }public function findOffline(Query $query, array $options) { $query->where([ ‘online’ => false, ]); return $query; } Usage: $customers = TableRegistry::get(’Customers’); $query = $customers->find(’offline’); //or $query …

CakePHP, PHP

How to limit records per page from view using CakePHP 3

Place the following code in your view: <div id="recperpage"> <?=$this->Form->create(null, [ ‘url’ => [’controller’ => ‘mycontroller’, ‘action’ => ‘index’], ‘id’ => ‘myformid’, ])?> Records per page: <?=$this->Form->select(’recperpageval’, [5=>5, 10=>10, 20=>20, 50=>50, 100=>100, 250=>250, 500=>500], [’default’ => 20, ‘onchange’=>’onSelectSubmit("myformid")’] ) ?> <?=$this->Form->end()?> </div><div id="recperpage"> <?=$this->Form->create(null, [ ‘url’ => [‘controller’ => ‘mycontroller’, ‘action’ => ‘index’], ‘id’ => …

CakePHP, PHP

How to enable Paginator in CakePHP 3

Let’s see how can we enable and initialize the CakePHP built-in Paginator Component so we can use it in our views. class MyController extends AppController { //Loading Templates from a File //This will load the file located at config/paginator-templates.php public $helpers = [ ‘Paginator’ => [’templates’ => ‘paginator-templates’] ];   //Define the default query conditions …

CakePHP, PHP

Get MySQL version in CakePHP 3

You need to import ConnectionManager: use CakeDatasourceConnectionManager;use CakeDatasourceConnectionManager; $stmt = ConnectionManager::get(’default’)->query(’SELECT version() as v’); $stmt->execute(); echo $stmt->fetch(’assoc’)[’v’];$stmt = ConnectionManager::get(‘default’)->query(‘SELECT version() as v’); $stmt->execute(); echo $stmt->fetch(‘assoc’)[‘v’]; More on executing CakePHP custom queries, here.

CakePHP, PHP

Sanitize data coming out of the database in cakephp 3

A security measure that most programmers forget to take when building database oriented applications is to sanitize-validate data coming out of the database. Let’s see how can we sanitize our data in cakePHP 3. cakePHP 3 book – Entities Create your Entity for ex. Country: namespace AppModelEntity;   use CakeORMEntity;   class Country extends Entity …