aboutsummaryrefslogtreecommitdiffstats
path: root/admin/ws_checker.php
blob: e887da3a27258134fecab26b2cb9447bdf86b0b1 (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery                           |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch        : BSF (Best So Far)
// | file          : $RCSfile$
// | last update   : $Date$
// | last modifier : $Author$
// | revision      : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

// Next evolution... 
// Out of parameter WS management
// The remainer objective is to check 
//  -  Does Web Service working properly?
//  -  Does any access return something really?
//     Give a way to check to the webmaster...
// These questions are one of module name explanations (checker).

if((!defined("PHPWG_ROOT_PATH")) or (!$conf['allow_web_services']))
{
  die('Hacking attempt!');
}
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');

/**
 * include ws_functions in only managed from ws_checker but 
 * if ws_methods would be generalized in the code this one would be promoted
 * somewhere else... Maybe very soon because it can be in plugins.
 * */ 
include_once( PHPWG_ROOT_PATH .'include/ws_functions.inc.php' );

// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok                      |
// +-----------------------------------------------------------------------+
check_status(ACCESS_ADMINISTRATOR);

// accepted queries
$req_type_list = official_req();

//--------------------------------------------------------- update informations

// Is a new access required?

if (isset($_POST['wsa_submit']))
{
// Check $_post (Some values are commented - maybe a future use)
$add_partner = htmlspecialchars( $_POST['add_partner'], ENT_QUOTES);
$add_target = check_target( $_POST['add_target']) ;
$add_end = ( is_numeric($_POST['add_end']) ) ? $_POST['add_end']:0;
$add_request = htmlspecialchars( $_POST['add_request'], ENT_QUOTES);
$add_high = 'true'; // ( $_POST['add_high'] == 'true' ) ? 'true':'false';
$add_normal = 'true'; // ( $_POST['add_normal'] == 'true' ) ? 'true':'false';
$add_limit = ( is_numeric($_POST['add_limit']) ) ? $_POST['add_limit']:1; 
$add_comment = htmlspecialchars( $_POST['add_comment'], ENT_QUOTES);
if ( strlen($add_partner) < 8 )
{ // TODO What? Complete with some MD5...
}
  $query = '
INSERT INTO '.WEB_SERVICES_ACCESS_TABLE.' 
( `name` , `access` , `start` , `end` , `request` , 
  `high` , `normal` , `limit` , `comment` ) 
VALUES (' . "
  '$add_partner', '$add_target',
  NOW(), 
  ADDDATE( NOW(), INTERVAL $add_end DAY),
  '$add_request', '$add_high', '$add_normal', '$add_limit', '$add_comment' );";

  pwg_query($query);
  
  $template->assign_block_vars(
    'update_result',
    array(
      'UPD_ELEMENT'=> $lang['ws_adding_legend'].$lang['ws_success_upd'],
      )
  );
}

// Next, Update selected access
if (isset($_POST['wsu_submit']))
{
  $upd_end = ( is_numeric($_POST['upd_end']) ) ? $_POST['upd_end']:0;
  $settxt = ' end = ADDDATE(NOW(), INTERVAL '. $upd_end .' DAY)';

  if ((isset($_POST['selection'])) and (trim($settxt) != ''))
  {
    $uid = (int) $_POST['selection'];
    $query = '
    UPDATE '.WEB_SERVICES_ACCESS_TABLE.' 
    SET '.$settxt.'
    WHERE id = '.$uid.'; ';
    pwg_query($query);
    $template->assign_block_vars(
      'update_result',
      array(
        'UPD_ELEMENT'=> $lang['ws_update_legend'].$lang['ws_success_upd'],
        )
    );
  } else {
    $template->assign_block_vars(
      'update_result',
      array(
        'UPD_ELEMENT'=> $lang['ws_update_legend'].$lang['ws_failed_upd'],
        )
    );
  }
}
// Next, Delete selected access

if (isset($_POST['wsX_submit']))
{
  if ((isset($_POST['delete_confirmation']))
   and (isset($_POST['selection'])))
  {
    $uid = (int) $_POST['selection'];
    $query = 'DELETE FROM '.WEB_SERVICES_ACCESS_TABLE.'
               WHERE id = '.$uid.'; ';
    pwg_query($query);
    $template->assign_block_vars(
      'update_result',
      array(
        'UPD_ELEMENT'=> $lang['ws_delete_legend'].$lang['ws_success_upd'],
        )
    );
  } else {
    $template->assign_block_vars(
      'update_result',
      array(
        'UPD_ELEMENT'=> $lang['Not selected / Not confirmed']
        .$lang['ws_failed_upd'],
        )
    );
  } 
}



$template->assign_vars(
  array(
    'DEFLT_HIGH_YES' => '',
    'DEFLT_HIGH_NO' => 'checked',
    'DEFLT_NORMAL_YES' => '',
    'DEFLT_NORMAL_NO' => 'checked',
    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=web_service',    
    )
  );

// Build where
$where = '';
$order = ' ORDER BY `id` DESC' ;

$query = '
SELECT *
  FROM '.WEB_SERVICES_ACCESS_TABLE.'
WHERE 1=1  '
.$where.
' '
.$order.
';';
$result = pwg_query($query);
$acc_list = mysql_num_rows($result);
$result = pwg_query($query);
// +-----------------------------------------------------------------------+
// |                             template init                             |
// +-----------------------------------------------------------------------+

$template->set_filenames(
  array(
    'ws_checker' => 'admin/ws_checker.tpl'
    )
  );

$selected = 'selected="selected"';
$num=0;
if ( $acc_list > 0 )
{
  $template->assign_block_vars(
    'acc_list', array() );
}

// Access List
while ($row = mysql_fetch_array($result))
{
  $num++;
  $template->assign_block_vars(
    'acc_list.access',
     array(
       'CLASS' => ($num % 2 == 1) ? 'row1' : 'row2',
       'ID'               => $row['id'],
       'NAME'             => 
         (is_adviser()) ? '*********' : $row['name'],       
       'TARGET'           => $row['access'],
       'END'              => $row['end'],
       'REQUEST'          => $row['request'],
       'LIMIT'            => $row['limit'],
       'COMMENT'          => $row['comment'],
       'SELECTED'         => '',
     )
  );
}

$template->assign_block_vars(
  'add_request',
   array(
     'VALUE'=> '',
     'CONTENT' => '',
     'SELECTED' => $selected,
   )
);
foreach ($req_type_list as $value) {

  $template->assign_block_vars(
    'add_request',
     array(
       'VALUE'=> $value,
       'CONTENT' => $value,
       'SELECTED' => '',
     )
  );
}

foreach ($conf['ws_allowed_limit'] as $value) {
  $template->assign_block_vars(
    'add_limit',
     array(
       'VALUE'=> $value,
       'CONTENT' => $value,
       'SELECTED' => ($conf['ws_allowed_limit'][0] == $value) ? $selected:'',
     )
  );
}

// Postponed Start Date 
// By default 0, 1, 2, 3, 5, 7, 14 or 30 days
foreach ($conf['ws_postponed_start'] as $value) {
  $template->assign_block_vars(
    'add_start',
     array(
       'VALUE'=> $value,
       'CONTENT' => $value,
       'SELECTED' => ($conf['ws_postponed_start'][0] == $value) ? $selected:'',
     )
  );
}

// Durations (Allowed Web Services Period)
// By default 10, 5, 2, 1 year(s) or 6, 3, 1 month(s) or 15, 10, 7, 5, 1, 0 day(s)
foreach ($conf['ws_durations'] as $value) {
  $template->assign_block_vars(
    'add_end',
     array(
       'VALUE'=> $value,
       'CONTENT' => $value,
       'SELECTED' => ($conf['ws_durations'][3] == $value) ? $selected:'',
     )
  );
  if ( $acc_list > 0 )
  {
    $template->assign_block_vars(
      'acc_list.upd_end',
       array(
         'VALUE'=> $value,
         'CONTENT' => $value,
         'SELECTED' => ($conf['ws_durations'][3] == $value) ? $selected:'',
       )
    );
  }
}

//----------------------------------------------------------- sending html code

$template->assign_var_from_handle('ADMIN_CONTENT', 'ws_checker');
?>