Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         SecureFormSwitcher
6
 * @author          WebsiteBaker Project, D Woellbrink
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.2
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: tool.php 2070 2014-01-03 01:21:42Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/SecureFormSwitcher/tool.php $
14
 * @lastmodified    $Date: 2014-01-03 02:21:42 +0100 (Fri, 03 Jan 2014) $
15
 *
16
 */
17

    
18
// Must include code to stop this file being access directly
19
if(defined('WB_PATH') == false)
20
{
21
	die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
22
}
23

    
24
// load module language file
25
$mod_path = (dirname(__FILE__));
26
$mod_rel = str_replace('\\','/',str_replace(WB_PATH,'',$mod_path));
27
$sModulesUrl = WB_URL.$mod_rel;
28
//echo realpath($mod_rel);
29
require_once( $mod_path.'/language_load.php' );
30
// callback function for settings name
31
function converttoupper($val, $key, $vars) {
32
	$vars[0][$key] = strtoupper($key);
33
	$vars[1][$vars[0][$key]] = ($val);
34
}
35

    
36
// create backlinks
37
$js_back =  ADMIN_URL.'/admintools/tool.php?tool=SecureFormSwitcher';
38
$backlink =  ADMIN_URL.'/admintools/index.php';
39

    
40
$FileNotFound = '&nbsp;';
41
// defaults settings
42
$default_cfg = array(
43
	'secure_form_module' => '',
44
	'wb_secform_secret' => '5609bnefg93jmgi99igjefg',
45
	'wb_secform_secrettime' => '86400',
46
	'wb_secform_timeout' => '7200',
47
	'wb_secform_tokenname' => 'formtoken',
48
	'wb_secform_usefp' => 'true',
49
	'fingerprint_with_ip_octets' => '2',
50
);
51
$setting = $default_cfg;
52
$MultitabTarget = WB_PATH.'/framework/SecureForm.mtab.php';
53
// get stored settings to set in mask
54
$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'settings` ';
55
$sql .= 'WHERE `name` = \'secure_form_module\'';
56
$sql .=    'OR `name`=\'fingerprint_with_ip_octets\' ';
57
$sql .=    'OR `name`=\'wb_secform_usefp\' ';
58
$sql .=    'OR `name`=\'wb_secform_tokenname\' ';
59
$sql .=    'OR `name`=\'wb_secform_timeout\' ';
60
$sql .=    'OR `name`=\'wb_secform_secrettime\' ';
61
$sql .=    'OR `name`=\'wb_secform_secret\' ';
62
if($res = $database->query($sql) ) {
63
	if($res->numRows() > 0) {
64
		while($rec = $res->fetchRow(MYSQL_ASSOC)) {
65
	        $setting[$rec['name']] = $rec['value'];
66
		}
67
	} else {
68
		// add missing values
69
		db_update_key_value('settings', $setting );
70
	}
71
}
72

    
73
$action = 'show';
74
$action = isset($_POST['save_settings']) ? 'save_settings' : $action;
75
$action = isset($_POST['save_settings_default']) ? 'save_settings_default' : $action;
76
$action = isset($_POST['save_settings']) ? 'save_settings' : $action;
77
//$action = isset($_POST['cancel']) ? 'cancel' : $action;
78

    
79
switch ($action) :
80
	case 'save_settings':
81
		$cfg = array(
82
			'secure_form_module' => (isset($_POST['ftan_switch']) ? $_POST['ftan_switch'] : 'mtab'),
83
			'wb_secform_secret' => (isset($_POST['wb_secform_secret']) ? $_POST['wb_secform_secret'] : $setting['wb_secform_secret'] ),
84
			'wb_secform_secrettime' => (isset($_POST['wb_secform_secrettime']) ? $_POST['wb_secform_secrettime'] : $setting['wb_secform_secrettime'] ),
85
			'wb_secform_timeout' => (isset($_POST['wb_secform_timeout']) ? $_POST['wb_secform_timeout'] : $setting['wb_secform_timeout'] ),
86
			'wb_secform_tokenname' => (isset($_POST['wb_secform_tokenname']) ? $_POST['wb_secform_tokenname'] : $setting['wb_secform_tokenname'] ),
87
			'wb_secform_usefp' => (isset($_POST['wb_secform_usefp']) ? $_POST['wb_secform_usefp'] : $setting['wb_secform_usefp'] ),
88
			'fingerprint_with_ip_octets' => (isset($_POST['fingerprint_with_ip_octets']) ? $_POST['fingerprint_with_ip_octets'] : $setting['fingerprint_with_ip_octets'] ),
89
		);
90
		// unset($_POST);
91
		$_SESSION['CFG'] = $cfg;
92
		break;
93
	case 'save_settings_default':
94
		$cfg = $default_cfg;
95
		$cfg['secure_form_module'] = $setting['secure_form_module'];
96
		break;
97
endswitch;
98

    
99
switch ($action) :
100
	case 'save_settings':
101
	case 'save_settings_default':
102
		if (!$admin->checkFTAN())
103
		{
104
// 			if(!$admin_header) { $admin->print_header(); }
105
			$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],$_SERVER['REQUEST_URI']);
106
		}
107
		if(file_exists($MultitabTarget)) {
108
			$val = ( isset($_POST['ftan_switch'])  ? ($_POST['ftan_switch']) : 'mtab');
109
		} else {
110
			$cfg['secure_form_module'] = '';
111
			$FileNotFound = $SFS_TEXT['FILE_FORMTAB_NOT_GOUND'];
112
		}
113

    
114
		db_update_key_value('settings', $cfg );
115
		// check if there is a database error, otherwise say successful
116
		if(!$admin_header) { $admin->print_header(); }
117
		if($database->is_error()) {
118
			$admin->print_error($database->get_error(), $js_back);
119
		} else {
120
            if(isset($_SESSION['CFG'])) { unset($_SESSION['CFG']);}
121
			$admin->print_success($MESSAGE['PAGES_SAVED'], $js_back);
122
		}
123
		break;
124
endswitch;
125

    
126
// set template file and assign module and template block
127
$oSecureTpl = new Template(WB_PATH.'/modules/SecureFormSwitcher/htt','keep');
128
// $tpl = new Template(dirname($admin->correct_theme_source('switchform.htt')),'keep');
129
$oSecureTpl->set_file('page', 'switchform.htt');
130
$oSecureTpl->debug = false; // false, true
131
$oSecureTpl->set_block('page', 'main_block', 'main');
132

    
133
$checked  = ($setting['secure_form_module']!='');
134
$target   = ($checked) ? '.'.$setting['secure_form_module'] : '';
135
$target   = WB_PATH.'/framework/SecureForm'.$target.'.php';
136
$ftanMode = ($checked ? $SFS_TEXT['SECURE_FORM'] : $SFS_TEXT['SECURE_FORMMTAB']);
137

    
138
$SingleTabStatus = intval($checked==false);
139
$MultitabStatus = intval($checked==true);
140
$NotFoundClass = '';
141
$HiddenClass = 'none';
142
$FileNotFound = '';
143
if(!file_exists($MultitabTarget)) {
144
	$SingleTabStatus = true;
145
	$MultitabStatus = false;
146
	$FileNotFound = $SFS_TEXT['FILE_FORMTAB_NOT_FOUND'];
147
	$HiddenClass = 'warning';
148
}
149

    
150
// convert settings name to upper
151
array_walk($setting,'converttoupper', array(&$search, &$replace ));
152

    
153
$oSecureTpl->set_var($replace);
154
$oSecureTpl->set_var(array(
155
	'FTAN' => $admin->getFTAN(),
156
	'ADMIN_URL' => ADMIN_URL,
157
	'WB_URL' => WB_URL,
158
	'URL_VIEW' => WB_URL,
159
	'THEME_URL' => THEME_URL,
160
	'SERVER_REQUEST_URI' => $_SERVER['REQUEST_URI'],
161
	'TEXT_CANCEL' => $TEXT['CANCEL'],
162
	'BACKLINK' => $backlink,
163
	'TEXT_INFO' => $SFS_TEXT['INFO'],
164
	'TEXT_SUBMIT' => $SFS_TEXT['SUBMIT'],
165
	'TEXT_MSUBMIT' => $SFS_TEXT['RESET_SETTINGS'],
166
	'TXT_HEADING' => $SFS_TEXT['SECURE_FORM'.strtoupper($setting['secure_form_module'])],
167
	'SELECTED' => ( ($SingleTabStatus) ? ' checked="checked"' : ''),
168
	'SELECTED_TAB' => ( ($MultitabStatus) ? ' checked="checked"' : ''),
169
	'SUBMIT_TYPE' => ($checked ? 'multitab' : 'singletab'),
170
	'MODULES_URL' => $sModulesUrl,
171
	'MSELECTED' => '',
172
	'MSELECTED_TAB' => '',
173
	'DISPLAY_MISSING_MTAB' =>  $HiddenClass,
174
//	'DISPLAY_RIGHT_SUBMIT' =>  ( ($MultitabStatus) ? '' : 'none'),
175
	'FTAN_COLOR' => ($checked ? 'grey' : 'norm'),
176
	'TXT_SUBMIT_FORM' => $SFS_TEXT['SUBMIT_FORM'],
177
	'TXT_SUBMIT_FORMTAB' => $SFS_TEXT['SUBMIT_FORMTAB'],
178
	'FILE_FORMTAB_WARNING' => $NotFoundClass,
179
	'FILE_FORMTAB_NOT_FOUND' => $FileNotFound,
180
	)
181
);
182

    
183
$oSecureTpl->set_var(array(
184
		'USEIP_SELECTED' => '',
185
		'TXT_SECFORM_USEIP' => $CAPTION['WB_SECFORM_USEIP'],
186
		'TEXT_DEFAULT_SETTINGS' => $HEADING['DEFAULT_SETTINGS'],
187
		'USEIP_DEFAULT' => $default_cfg['fingerprint_with_ip_octets'],
188
		'USEFP_CHECKED_TRUE' => (($setting['wb_secform_usefp']=='true') ? ' checked="checked"' : ''),
189
		'USEFP_CHECKED_FALSE' => (($setting['wb_secform_usefp']=='false') ? ' checked="checked"' : ''),
190
		'TEXT_DEFAULT_SETTINGS' => $HEADING['DEFAULT_SETTINGS'],
191
	)
192
);
193

    
194
foreach($HELP as $key=>$value)
195
{
196
	$sHelp[$key] = $value;
197
	$oSecureTpl->set_var('p_'.strtolower($key),  p($sHelp[$key],$CAPTION[$key] ));
198
//	echo ' {p_'.strtolower($key).'}<br />';
199
}
200

    
201
$oSecureTpl->set_block('main_block', 'useip_mtab_loop', 'mtab_loop');
202
	for($x=0; $x < 5; $x++) {
203
		// iu value == default set first option with standardtext
204
		if(intval($default_cfg['fingerprint_with_ip_octets'])==$x ) {
205
			$oSecureTpl->set_var(array(
206
					'USEIP_VALUE' => $x,
207
					'USEIP_DEFAULT_SELECTED' => ((intval($setting['fingerprint_with_ip_octets'])==$x) ? ' selected="selected"' : ''),
208
					'USEIP_SELECTED' => '',
209
					)
210
			);
211
		} else {
212
			$oSecureTpl->set_var(array(
213
					'USEIP_VALUE' => $x,
214
					'USEIP_SELECTED' => ((intval($setting['fingerprint_with_ip_octets'])==$x) && (intval($setting['fingerprint_with_ip_octets'])!=intval($default_cfg['fingerprint_with_ip_octets'])) ? ' selected="selected"' : ''),
215
				)
216
			);
217
		}
218
		$oSecureTpl->parse('mtab_loop','useip_mtab_loop', true);
219
	}
220

    
221
$oSecureTpl->set_block('main_block', 'show_mtab_block', 'show_mtab');
222
$oSecureTpl->set_block('main_block', 'mtab_block', 'mtab');
223
if($checked) {
224
	$oSecureTpl->set_var(array(
225
			'TEXT_ENABLED' => $SFS_TEXT['ON'],
226
			'TEXT_DISABLED' => $SFS_TEXT['OFF'],
227
			'TXT_SECFORM_TOKENNAME' => $CAPTION['WB_SECFORM_TOKENNAME'],
228
			'TXT_SECFORM_TIMEOUT' => $CAPTION['WB_SECFORM_TIMEOUT'],
229
			'TXT_SECFORM_SECRETTIME' => $CAPTION['WB_SECFORM_SECRETTIME'],
230
			'TXT_SECFORM_SECRET' => $CAPTION['WB_SECFORM_SECRET'],
231
			'TXT_SECFORM_USEFP' => $CAPTION['WB_SECFORM_USEFP'],
232
			'SECFORM_USEFP' => 'true',
233
		)
234
	);
235

    
236
	$oSecureTpl->parse('mtab','mtab_block', true);
237
	$oSecureTpl->parse('show_mtab','show_mtab_block', true);
238
} else  {
239
	$oSecureTpl->parse('mtab', '');
240
	$oSecureTpl->parse('show_mtab', '');
241
}
242

    
243
// Parse template object
244
$oSecureTpl->parse('main', 'main_block', false);
245
$output = $oSecureTpl->finish($oSecureTpl->parse('output', 'page'));
246
unset($oSecureTpl);
247
print $output;
248

    
249

    
250
/**
251
 * p()
252
 *
253
 * @param string $text
254
 * @param string $caption
255
 * @return
256
 */
257
function p($sTooltip,$sCaption)
258
{
259
	global $admin;
260
	$retVal  = 'onmouseover="return overlib(';
261
	$retVal .= '\''.$sTooltip.'\',';
262
	$retVal .= 'CAPTION,\''.$sCaption.'\',';
263
	$retVal .= 'FGCOLOR,\'#ffffff\',';
264
	$retVal .= 'BGCOLOR,\'#557c9e\',';
265
	$retVal .= 'BORDER,1,';
266
//	$retVal .= 'WIDTH,';
267
//	$retVal .= 'HEIGHT,';
268
//	$retVal .= 'STICKY,';
269
	$retVal .= 'CAPTIONSIZE,\'13px\',';
270
	$retVal .= 'CLOSETEXT,\'X\',';
271
	$retVal .= 'CLOSESIZE,\'16px\',';
272
	$retVal .= 'CLOSECOLOR,\'#ffffff\',';
273
	$retVal .= 'TEXTSIZE,\'12px\',';
274
	$retVal .= 'VAUTO,';
275
	$retVal .= 'HAUTO,';
276
//	$retVal .= 'MOUSEOFF,';
277
	$retVal .= 'WRAP,';
278
	$retVal .= 'CELLPAD,5';
279
	$retVal .= ')" onmouseout="return nd();"';
280
//	$retVal .= '';
281

    
282
	return $retVal;
283
}
(8-8/11)