1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
<?php
namespace Alpha\Controller;
use Alpha\Util\Logging\Logger;
use Alpha\Util\Config\ConfigProvider;
use Alpha\Util\Security\SecurityUtils;
use Alpha\Util\Http\Request;
use Alpha\Util\Http\Response;
use Alpha\View\View;
use Alpha\View\Widget\SmallTextBox;
use Alpha\View\Widget\Button;
use Alpha\Controller\Front\FrontController;
use Alpha\Model\Type\SmallText;
class GenSecureQueryStringController extends Controller implements ControllerInterface
{
private static $logger = null;
public function __construct()
{
self::$logger = new Logger('GenSecureQueryStringController');
self::$logger->debug('>>__construct()');
parent::__construct('Admin');
$this->setTitle('Generate Secure Query Strings');
self::$logger->debug('<<__construct');
}
public function doGET($request)
{
self::$logger->debug('>>doGET($request=['.var_export($request, true).'])');
$body = View::displayPageHead($this);
$body .= $this->renderForm();
$body .= View::displayPageFoot($this);
self::$logger->debug('<<doGET');
return new Response(200, $body, array('Content-Type' => 'text/html'));
}
public function doPOST($request)
{
self::$logger->debug('>>doPOST($request=['.var_export($request, true).'])');
$params = $request->getParams();
$body = View::displayPageHead($this);
$body .= '<p class="alert alert-success">';
if (isset($params['QS'])) {
$body .= FrontController::generateSecureURL($params['QS']);
self::$logger->action('Generated the secure URL in admin: '.FrontController::generateSecureURL($params['QS']));
}
$body .= '</p>';
$body .= $this->renderForm();
$body .= View::displayPageFoot($this);
self::$logger->debug('<<doPOST');
return new Response(200, $body, array('Content-Type' => 'text/html'));
}
private function renderForm()
{
$config = ConfigProvider::getInstance();
$html = '<p>Use this form to generate secure (encrypted) URLs which make use of the Front Controller. Always be sure to specify an action controller'.
' (act) at a minimum.</p>';
$html .= '<p>Example 1: to generate a secure URL for viewing article object 00000000001, enter <em>act=Alpha\Controller\ArticleController&ActiveRecordID=00000000001</em></p>';
$html .= '<p>Example 2: to generate a secure URL for viewing an Atom news feed of the articles, enter'.
' <em>act=Alpha\Controller\FeedController&ActiveRecordType=Alpha\Model\Article&type=Atom</em></p>';
$html .= '<form action="'.$this->request->getURI().'" method="post" accept-charset="UTF-8"><div class="form-group">';
$string = new SmallTextBox(new SmallText(''), 'Parameters', 'QS');
$html .= $string->render();
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut');
$temp = new Button('submit', 'Generate', $fieldname);
$html .= $temp->render();
$html .= '</div></form>';
return $html;
}
}