source: tags/build-A01/admin/ws_checker.php @ 17152

Last change on this file since 17152 was 1670, checked in by vdigital, 18 years ago

Externalization of common functions of web service.

File size: 10.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-12-15 23:16:37 +0200 (ven., 15 dec. 2006) $
10// | last modifier : $Author: vdigital $
11// | revision      : $Revision: 1658 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28// Next evolution...
29// Out of parameter WS management
30// The remainer objective is to check
31//  -  Does Web Service working properly?
32//  -  Does any access return something really?
33//     Give a way to check to the webmaster...
34// These questions are one of module name explainations (checker).
35
36if((!defined("PHPWG_ROOT_PATH")) or (!$conf['allow_web_services']))
37{
38  die('Hacking attempt!');
39}
40include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
41
42// +-----------------------------------------------------------------------+
43// | Check Access and exit when user status is not ok                      |
44// +-----------------------------------------------------------------------+
45check_status(ACCESS_ADMINISTRATOR);
46
47
48// accepted queries
49$req_type_list = official_req();
50
51//--------------------------------------------------------- update informations
52
53// Is status temporary changed?
54if (isset($_POST['wss_submit']))
55{
56  $ws_status = get_boolean( $_POST['ws_status'] );      // Requested status
57  $ws_update = $lang['ws_success_upd'];  // Normal update
58  if ($conf['allow_web_services'] == false and $ws_status == true )
59  { /* Set true is disallowed */
60    $ws_status = false;
61    $ws_update = $lang['ws_disallowed'];
62  }
63  if ( $ws_status !== true and $ws_status !== false )
64  { /* Avoiding SQL injection by no change */
65    $ws_status = $conf['ws_status'];
66  }
67  if ($conf['ws_status'] == $ws_status)
68  {
69    $ws_update = $lang['ws_disallowed'];
70  }
71  else
72  {
73    $query = '
74UPDATE '.CONFIG_TABLE.' SET
75 value = \''.boolean_to_string($ws_status).'\'
76WHERE param = \'ws_status\'
77 AND value <> \''.boolean_to_string($ws_status).'\'
78;';
79    pwg_query($query);
80    $conf['ws_status'] = $ws_status;
81  }
82  $template->assign_block_vars(
83    'update_result',
84    array(
85      'UPD_ELEMENT'=> $lang['ws_set_status'].': '.$ws_update,
86      )
87  );
88}
89
90// Next, is a new access required?
91
92if (isset($_POST['wsa_submit']))
93{
94// Check $_post
95$add_partner = htmlspecialchars( $_POST['add_partner'], ENT_QUOTES);
96$add_access = check_target( $_POST['add_access']) ;
97$add_start = ( is_numeric($_POST['add_start']) ) ? $_POST['add_start']:0; 
98$add_end = ( is_numeric($_POST['add_end']) ) ? $_POST['add_end']:0;
99$add_request = ( ctype_alpha($_POST['add_request']) ) ?
100  $_POST['add_request']:'';
101$add_high = ( $_POST['add_high'] == 'true' ) ? 'true':'false';
102$add_normal = ( $_POST['add_normal'] == 'true' ) ? 'true':'false';
103$add_limit = ( is_numeric($_POST['add_limit']) ) ? $_POST['add_limit']:1; 
104$add_comment = htmlspecialchars( $_POST['add_comment'], ENT_QUOTES);
105if ( strlen($add_partner) < 8 )
106{
107}
108  $query = '
109INSERT INTO '.WEB_SERVICES_ACCESS_TABLE.'
110( `name` , `access` , `start` , `end` , `request` ,
111  `high` , `normal` , `limit` , `comment` )
112VALUES (' . "
113  '$add_partner', '$add_access',
114  ADDDATE( NOW(), INTERVAL $add_start DAY),
115  ADDDATE( NOW(), INTERVAL $add_end DAY),
116  '$add_request', '$add_high', '$add_normal', '$add_limit', '$add_comment' );";
117
118  pwg_query($query);
119 
120  $template->assign_block_vars(
121    'update_result',
122    array(
123      'UPD_ELEMENT'=> $lang['ws_adding_legend'].$lang['ws_success_upd'],
124      )
125  );
126}
127
128// Next, Update selected access
129if (isset($_POST['wsu_submit']))
130{
131  $upd_end = ( is_numeric($_POST['upd_end']) ) ? $_POST['upd_end']:0;
132  $settxt = ' end = ADDDATE(NOW(), INTERVAL '. $upd_end .' DAY)';
133
134  if ((isset($_POST['selection'])) and (trim($settxt) != ''))
135  {
136    $uid = (int) $_POST['selection'];
137    $query = '
138    UPDATE '.WEB_SERVICES_ACCESS_TABLE.'
139    SET '.$settxt.'
140    WHERE id = '.$uid.'; ';
141    pwg_query($query);
142    $template->assign_block_vars(
143      'update_result',
144      array(
145        'UPD_ELEMENT'=> $lang['ws_update_legend'].$lang['ws_success_upd'],
146        )
147    );
148  } else {
149    $template->assign_block_vars(
150      'update_result',
151      array(
152        'UPD_ELEMENT'=> $lang['ws_update_legend'].$lang['ws_failed_upd'],
153        )
154    );
155  }
156}
157// Next, Delete selected access
158
159if (isset($_POST['wsX_submit']))
160{
161  if ((isset($_POST['delete_confirmation']))
162   and (isset($_POST['selection'])))
163  {
164    $uid = (int) $_POST['selection'];
165    $query = 'DELETE FROM '.WEB_SERVICES_ACCESS_TABLE.'
166               WHERE id = '.$uid.'; ';
167    pwg_query($query);
168    $template->assign_block_vars(
169      'update_result',
170      array(
171        'UPD_ELEMENT'=> $lang['ws_delete_legend'].$lang['ws_success_upd'],
172        )
173    );
174  } else {
175    $template->assign_block_vars(
176      'update_result',
177      array(
178        'UPD_ELEMENT'=> $lang['Not selected / Not confirmed']
179        .$lang['ws_failed_upd'],
180        )
181    );
182  } 
183}
184
185
186$ws_status = $conf['ws_status'];
187$template->assign_vars(
188  array(
189    'L_CURRENT_STATUS' => ( $ws_status == true ) ? 
190       $lang['ws_enable']:$lang['ws_disable'],
191    'STATUS_YES' => ( $ws_status == true ) ? '':'checked', 
192    'STATUS_NO' => ( $ws_status == true ) ? 'checked':'', 
193    'DEFLT_HIGH_YES' => '',
194    'DEFLT_HIGH_NO' => 'checked',
195    'DEFLT_NORMAL_YES' => '',
196    'DEFLT_NORMAL_NO' => 'checked',
197    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=web_service',   
198    )
199  );
200
201// Build where
202$where = '';
203$order = ' ORDER BY `id` DESC' ;
204
205$query = '
206SELECT *
207  FROM '.WEB_SERVICES_ACCESS_TABLE.'
208WHERE 1=1  '
209.$where.
210' '
211.$order.
212';';
213$result = pwg_query($query);
214$acc_list = mysql_num_rows($result);
215$result = pwg_query($query);
216// +-----------------------------------------------------------------------+
217// |                             template init                             |
218// +-----------------------------------------------------------------------+
219
220$template->set_filenames(
221  array(
222    'ws_checker' => 'admin/ws_checker.tpl'
223    )
224  );
225
226$checked = 'checked="checked"';
227$selected = 'selected="selected"';
228$num=0;
229if ( $acc_list > 0 )
230{
231  $template->assign_block_vars(
232    'acc_list', array() );
233}
234
235// Access List
236while ($row = mysql_fetch_array($result))
237{
238  $num++;
239  $template->assign_block_vars(
240    'acc_list.access',
241     array(
242       'CLASS' => ($num % 2 == 1) ? 'row1' : 'row2',
243       'ID'               => $row['id'],
244       'NAME'             => 
245         (is_adviser()) ? '*********' : $row['name'],       
246       'ACCESS'           => $row['access'],
247       'START'            => $row['start'],
248       'END'              => $row['end'],
249       'FORCE'            => $row['request'],
250       'HIGH'             => $row['high'],
251       'NORMAL'           => $row['normal'],
252       'LIMIT'            => $row['limit'],
253       'COMMENT'          => $row['comment'],
254       'SELECTED'         => '',
255     )
256  );
257}
258
259$template->assign_block_vars(
260  'add_request',
261   array(
262     'VALUE'=> '',
263     'CONTENT' => '',
264     'SELECTED' => $selected,
265   )
266);
267foreach ($req_type_list as $value) {
268
269  $template->assign_block_vars(
270    'add_request',
271     array(
272       'VALUE'=> $value,
273       'CONTENT' => $lang['ws_'.$value],
274       'SELECTED' => '',
275     )
276  );
277}
278
279$columns = array (
280       'ID'               => 'id',
281       'ws_KeyName'       => 'name', 
282       'ws_Access'        => 'ws_access',
283       'ws_Start'         => 'ws_start',
284       'ws_End'           => 'ws_end',
285       'ws_Request'       => 'ws_request',
286       'ws_High'          => 'ws_high',
287       'ws_Normal'        => 'ws_normal',
288       'ws_Limit'         => 'ws_limit',
289       'ws_Comment'       => 'ws_comment',
290);
291
292foreach ($conf['ws_allowed_limit'] as $value) {
293  $template->assign_block_vars(
294    'add_limit',
295     array(
296       'VALUE'=> $value,
297       'CONTENT' => $value,
298       'SELECTED' => ($conf['ws_allowed_limit'][0] == $value) ? $selected:'',
299     )
300  );
301}
302
303// Postponed Start Date
304// By default 0, 1, 2, 3, 5, 7, 14 or 30 days
305foreach ($conf['ws_postponed_start'] as $value) {
306  $template->assign_block_vars(
307    'add_start',
308     array(
309       'VALUE'=> $value,
310       'CONTENT' => $value,
311       'SELECTED' => ($conf['ws_postponed_start'][0] == $value) ? $selected:'',
312     )
313  );
314}
315
316// Durations (Allowed Web Services Period)
317// By default 10, 5, 2, 1 year(s) or 6, 3, 1 month(s) or 15, 10, 7, 5, 1, 0 day(s)
318foreach ($conf['ws_durations'] as $value) {
319  $template->assign_block_vars(
320    'add_end',
321     array(
322       'VALUE'=> $value,
323       'CONTENT' => $value,
324       'SELECTED' => ($conf['ws_durations'][3] == $value) ? $selected:'',
325     )
326  );
327  if ( $acc_list > 0 )
328  {
329    $template->assign_block_vars(
330      'acc_list.upd_end',
331       array(
332         'VALUE'=> $value,
333         'CONTENT' => $value,
334         'SELECTED' => ($conf['ws_durations'][3] == $value) ? $selected:'',
335       )
336    );
337  }
338}
339
340//----------------------------------------------------------- sending html code
341
342$template->assign_var_from_handle('ADMIN_CONTENT', 'ws_checker');
343?>
Note: See TracBrowser for help on using the repository browser.