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