forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_privileges.lib.php
5297 lines (4866 loc) · 171 KB
/
server_privileges.lib.php
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* set of functions with the Privileges section in pma
*
* @package PhpMyAdmin
*/
use PMA\libraries\DatabaseInterface;
use PMA\libraries\Message;
use PMA\libraries\Response;
use PMA\libraries\Template;
use PMA\libraries\Util;
use PMA\libraries\URL;
/**
* Get Html for User Group Dialog
*
* @param string $username username
* @param bool $is_menuswork Is menuswork set in configuration
*
* @return string html
*/
function PMA_getHtmlForUserGroupDialog($username, $is_menuswork)
{
$html = '';
if (! empty($_REQUEST['edit_user_group_dialog']) && $is_menuswork) {
$dialog = PMA_getHtmlToChooseUserGroup($username);
$response = Response::getInstance();
if ($response->isAjax()) {
$response->addJSON('message', $dialog);
exit;
} else {
$html .= $dialog;
}
}
return $html;
}
/**
* Escapes wildcard in a database+table specification
* before using it in a GRANT statement.
*
* Escaping a wildcard character in a GRANT is only accepted at the global
* or database level, not at table level; this is why I remove
* the escaping character. Internally, in mysql.tables_priv.Db there are
* no escaping (for example test_db) but in mysql.db you'll see test\_db
* for a db-specific privilege.
*
* @param string $dbname Database name
* @param string $tablename Table name
*
* @return string the escaped (if necessary) database.table
*/
function PMA_wildcardEscapeForGrant($dbname, $tablename)
{
if (strlen($dbname) === 0) {
$db_and_table = '*.*';
} else {
if (strlen($tablename) > 0) {
$db_and_table = Util::backquote(
Util::unescapeMysqlWildcards($dbname)
)
. '.' . Util::backquote($tablename);
} else {
$db_and_table = Util::backquote($dbname) . '.*';
}
}
return $db_and_table;
}
/**
* Generates a condition on the user name
*
* @param string $initial the user's initial
*
* @return string the generated condition
*/
function PMA_rangeOfUsers($initial = '')
{
// strtolower() is used because the User field
// might be BINARY, so LIKE would be case sensitive
if ($initial === null || $initial === '') {
return '';
}
$ret = " WHERE `User` LIKE '"
. $GLOBALS['dbi']->escapeString($initial) . "%'"
. " OR `User` LIKE '"
. $GLOBALS['dbi']->escapeString(mb_strtolower($initial))
. "%'";
return $ret;
} // end function
/**
* Formats privilege name for a display
*
* @param array $privilege Privilege information
* @param boolean $html Whether to use HTML
*
* @return string
*/
function PMA_formatPrivilege($privilege, $html)
{
if ($html) {
return '<dfn title="' . $privilege[2] . '">'
. $privilege[1] . '</dfn>';
} else {
return $privilege[1];
}
}
/**
* Parses privileges into an array, it modifies the array
*
* @param array &$row Results row from
*
* @return void
*/
function PMA_fillInTablePrivileges(&$row)
{
$row1 = $GLOBALS['dbi']->fetchSingleRow(
'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
'ASSOC', $GLOBALS['userlink']
);
// note: in MySQL 5.0.3 we get "Create View', 'Show view';
// the View for Create is spelled with uppercase V
// the view for Show is spelled with lowercase v
// and there is a space between the words
$av_grants = explode(
'\',\'',
mb_substr(
$row1['Type'],
mb_strpos($row1['Type'], '(') + 2,
mb_strpos($row1['Type'], ')')
- mb_strpos($row1['Type'], '(') - 3
)
);
$users_grants = explode(',', $row['Table_priv']);
foreach ($av_grants as $current_grant) {
$row[$current_grant . '_priv']
= in_array($current_grant, $users_grants) ? 'Y' : 'N';
}
unset($row['Table_priv']);
}
/**
* Extracts the privilege information of a priv table row
*
* @param array|null $row the row
* @param boolean $enableHTML add <dfn> tag with tooltips
* @param boolean $tablePrivs whether row contains table privileges
*
* @global resource $user_link the database connection
*
* @return array
*/
function PMA_extractPrivInfo($row = null, $enableHTML = false, $tablePrivs = false)
{
if ($tablePrivs) {
$grants = PMA_getTableGrantsArray();
} else {
$grants = PMA_getGrantsArray();
}
if (! is_null($row) && isset($row['Table_priv'])) {
PMA_fillInTablePrivileges($row);
}
$privs = array();
$allPrivileges = true;
foreach ($grants as $current_grant) {
if ((! is_null($row) && isset($row[$current_grant[0]]))
|| (is_null($row) && isset($GLOBALS[$current_grant[0]]))
) {
if ((! is_null($row) && $row[$current_grant[0]] == 'Y')
|| (is_null($row)
&& ($GLOBALS[$current_grant[0]] == 'Y'
|| (is_array($GLOBALS[$current_grant[0]])
&& count($GLOBALS[$current_grant[0]]) == $_REQUEST['column_count']
&& empty($GLOBALS[$current_grant[0] . '_none']))))
) {
$privs[] = PMA_formatPrivilege($current_grant, $enableHTML);
} elseif (! empty($GLOBALS[$current_grant[0]])
&& is_array($GLOBALS[$current_grant[0]])
&& empty($GLOBALS[$current_grant[0] . '_none'])
) {
// Required for proper escaping of ` (backtick) in a column name
$grant_cols = array_map(
function($val) {
return Util::backquote($val);
},
$GLOBALS[$current_grant[0]]
);
$privs[] = PMA_formatPrivilege($current_grant, $enableHTML)
. ' (' . join(', ', $grant_cols) . ')';
} else {
$allPrivileges = false;
}
}
}
if (empty($privs)) {
if ($enableHTML) {
$privs[] = '<dfn title="' . __('No privileges.') . '">USAGE</dfn>';
} else {
$privs[] = 'USAGE';
}
} elseif ($allPrivileges
&& (! isset($_POST['grant_count']) || count($privs) == $_POST['grant_count'])
) {
if ($enableHTML) {
$privs = array('<dfn title="'
. __('Includes all privileges except GRANT.')
. '">ALL PRIVILEGES</dfn>'
);
} else {
$privs = array('ALL PRIVILEGES');
}
}
return $privs;
} // end of the 'PMA_extractPrivInfo()' function
/**
* Returns an array of table grants and their descriptions
*
* @return array array of table grants
*/
function PMA_getTableGrantsArray()
{
return array(
array(
'Delete',
'DELETE',
$GLOBALS['strPrivDescDelete']
),
array(
'Create',
'CREATE',
$GLOBALS['strPrivDescCreateTbl']
),
array(
'Drop',
'DROP',
$GLOBALS['strPrivDescDropTbl']
),
array(
'Index',
'INDEX',
$GLOBALS['strPrivDescIndex']
),
array(
'Alter',
'ALTER',
$GLOBALS['strPrivDescAlter']
),
array(
'Create View',
'CREATE_VIEW',
$GLOBALS['strPrivDescCreateView']
),
array(
'Show view',
'SHOW_VIEW',
$GLOBALS['strPrivDescShowView']
),
array(
'Trigger',
'TRIGGER',
$GLOBALS['strPrivDescTrigger']
),
);
}
/**
* Get the grants array which contains all the privilege types
* and relevant grant messages
*
* @return array
*/
function PMA_getGrantsArray()
{
return array(
array(
'Select_priv',
'SELECT',
__('Allows reading data.')
),
array(
'Insert_priv',
'INSERT',
__('Allows inserting and replacing data.')
),
array(
'Update_priv',
'UPDATE',
__('Allows changing data.')
),
array(
'Delete_priv',
'DELETE',
__('Allows deleting data.')
),
array(
'Create_priv',
'CREATE',
__('Allows creating new databases and tables.')
),
array(
'Drop_priv',
'DROP',
__('Allows dropping databases and tables.')
),
array(
'Reload_priv',
'RELOAD',
__('Allows reloading server settings and flushing the server\'s caches.')
),
array(
'Shutdown_priv',
'SHUTDOWN',
__('Allows shutting down the server.')
),
array(
'Process_priv',
'PROCESS',
__('Allows viewing processes of all users.')
),
array(
'File_priv',
'FILE',
__('Allows importing data from and exporting data into files.')
),
array(
'References_priv',
'REFERENCES',
__('Has no effect in this MySQL version.')
),
array(
'Index_priv',
'INDEX',
__('Allows creating and dropping indexes.')
),
array(
'Alter_priv',
'ALTER',
__('Allows altering the structure of existing tables.')
),
array(
'Show_db_priv',
'SHOW DATABASES',
__('Gives access to the complete list of databases.')
),
array(
'Super_priv',
'SUPER',
__(
'Allows connecting, even if maximum number of connections '
. 'is reached; required for most administrative operations '
. 'like setting global variables or killing threads of other users.'
)
),
array(
'Create_tmp_table_priv',
'CREATE TEMPORARY TABLES',
__('Allows creating temporary tables.')
),
array(
'Lock_tables_priv',
'LOCK TABLES',
__('Allows locking tables for the current thread.')
),
array(
'Repl_slave_priv',
'REPLICATION SLAVE',
__('Needed for the replication slaves.')
),
array(
'Repl_client_priv',
'REPLICATION CLIENT',
__('Allows the user to ask where the slaves / masters are.')
),
array(
'Create_view_priv',
'CREATE VIEW',
__('Allows creating new views.')
),
array(
'Event_priv',
'EVENT',
__('Allows to set up events for the event scheduler.')
),
array(
'Trigger_priv',
'TRIGGER',
__('Allows creating and dropping triggers.')
),
// for table privs:
array(
'Create View_priv',
'CREATE VIEW',
__('Allows creating new views.')
),
array(
'Show_view_priv',
'SHOW VIEW',
__('Allows performing SHOW CREATE VIEW queries.')
),
// for table privs:
array(
'Show view_priv',
'SHOW VIEW',
__('Allows performing SHOW CREATE VIEW queries.')
),
array(
'Create_routine_priv',
'CREATE ROUTINE',
__('Allows creating stored routines.')
),
array(
'Alter_routine_priv',
'ALTER ROUTINE',
__('Allows altering and dropping stored routines.')
),
array(
'Create_user_priv',
'CREATE USER',
__('Allows creating, dropping and renaming user accounts.')
),
array(
'Execute_priv',
'EXECUTE',
__('Allows executing stored routines.')
),
);
}
/**
* Displays on which column(s) a table-specific privilege is granted
*
* @param array $columns columns array
* @param array $row first row from result or boolean false
* @param string $name_for_select privilege types - Select_priv, Insert_priv
* Update_priv, References_priv
* @param string $priv_for_header privilege for header
* @param string $name privilege name: insert, select, update, references
* @param string $name_for_dfn name for dfn
* @param string $name_for_current name for current
*
* @return string $html_output html snippet
*/
function PMA_getHtmlForColumnPrivileges($columns, $row, $name_for_select,
$priv_for_header, $name, $name_for_dfn, $name_for_current
) {
$data = array(
'columns' => $columns,
'row' => $row,
'name_for_select' => $name_for_select,
'priv_for_header' => $priv_for_header,
'name' => $name,
'name_for_dfn' => $name_for_dfn,
'name_for_current' => $name_for_current
);
$html_output = Template::get('privileges/column_privileges')
->render($data);
return $html_output;
} // end function
/**
* Get sql query for display privileges table
*
* @param string $db the database
* @param string $table the table
* @param string $username username for database connection
* @param string $hostname hostname for database connection
*
* @return string sql query
*/
function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname)
{
if ($db == '*') {
return "SELECT * FROM `mysql`.`user`"
. " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'"
. " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "';";
} elseif ($table == '*') {
return "SELECT * FROM `mysql`.`db`"
. " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'"
. " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "'"
. " AND '" . $GLOBALS['dbi']->escapeString(Util::unescapeMysqlWildcards($db)) . "'"
. " LIKE `Db`;";
}
return "SELECT `Table_priv`"
. " FROM `mysql`.`tables_priv`"
. " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'"
. " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "'"
. " AND `Db` = '" . $GLOBALS['dbi']->escapeString(Util::unescapeMysqlWildcards($db)) . "'"
. " AND `Table_name` = '" . $GLOBALS['dbi']->escapeString($table) . "';";
}
/**
* Displays a dropdown to select the user group
* with menu items configured to each of them.
*
* @param string $username username
*
* @return string html to select the user group
*/
function PMA_getHtmlToChooseUserGroup($username)
{
$cfgRelation = PMA_getRelationsParam();
$groupTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['usergroups']);
$userTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['users']);
$userGroup = '';
if (isset($GLOBALS['username'])) {
$sql_query = "SELECT `usergroup` FROM " . $userTable
. " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'";
$userGroup = $GLOBALS['dbi']->fetchValue(
$sql_query, 0, 0, $GLOBALS['controllink']
);
}
$allUserGroups = array('' => '');
$sql_query = "SELECT DISTINCT `usergroup` FROM " . $groupTable;
$result = PMA_queryAsControlUser($sql_query, false);
if ($result) {
while ($row = $GLOBALS['dbi']->fetchRow($result)) {
$allUserGroups[$row[0]] = $row[0];
}
}
$GLOBALS['dbi']->freeResult($result);
// render the template
$data = array(
'allUserGroups' => $allUserGroups,
'userGroup' => $userGroup,
'params' => array('username' => $username)
);
$html_output = Template::get('privileges/choose_user_group')
->render($data);
return $html_output;
}
/**
* Sets the user group from request values
*
* @param string $username username
* @param string $userGroup user group to set
*
* @return void
*/
function PMA_setUserGroup($username, $userGroup)
{
$cfgRelation = PMA_getRelationsParam();
if (empty($cfgRelation['db']) || empty($cfgRelation['users']) || empty($cfgRelation['usergroups'])) {
return;
}
$userTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['users']);
$sql_query = "SELECT `usergroup` FROM " . $userTable
. " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username) . "'";
$oldUserGroup = $GLOBALS['dbi']->fetchValue(
$sql_query, 0, 0, $GLOBALS['controllink']
);
if ($oldUserGroup === false) {
$upd_query = "INSERT INTO " . $userTable . "(`username`, `usergroup`)"
. " VALUES ('" . $GLOBALS['dbi']->escapeString($username) . "', "
. "'" . $GLOBALS['dbi']->escapeString($userGroup) . "')";
} else {
if (empty($userGroup)) {
$upd_query = "DELETE FROM " . $userTable
. " WHERE `username`='" . $GLOBALS['dbi']->escapeString($username) . "'";
} elseif ($oldUserGroup != $userGroup) {
$upd_query = "UPDATE " . $userTable
. " SET `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup) . "'"
. " WHERE `username`='" . $GLOBALS['dbi']->escapeString($username) . "'";
}
}
if (isset($upd_query)) {
PMA_queryAsControlUser($upd_query);
}
}
/**
* Displays the privileges form table
*
* @param string $db the database
* @param string $table the table
* @param boolean $submit whether to display the submit button or not
*
* @global array $cfg the phpMyAdmin configuration
* @global resource $user_link the database connection
*
* @return string html snippet
*/
function PMA_getHtmlToDisplayPrivilegesTable($db = '*',
$table = '*', $submit = true
) {
$html_output = '';
$sql_query = '';
if ($db == '*') {
$table = '*';
}
if (isset($GLOBALS['username'])) {
$username = $GLOBALS['username'];
$hostname = $GLOBALS['hostname'];
$sql_query = PMA_getSqlQueryForDisplayPrivTable(
$db, $table, $username, $hostname
);
$row = $GLOBALS['dbi']->fetchSingleRow($sql_query);
}
if (empty($row)) {
if ($table == '*' && $GLOBALS['is_superuser']) {
$row = array();
if ($db == '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
} elseif ($table == '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
}
$res = $GLOBALS['dbi']->query($sql_query);
while ($row1 = $GLOBALS['dbi']->fetchRow($res)) {
if (mb_substr($row1[0], 0, 4) == 'max_') {
$row[$row1[0]] = 0;
} elseif (mb_substr($row1[0], 0, 5) == 'x509_'
|| mb_substr($row1[0], 0, 4) == 'ssl_'
) {
$row[$row1[0]] = '';
} else {
$row[$row1[0]] = 'N';
}
}
$GLOBALS['dbi']->freeResult($res);
} elseif ($table == '*') {
$row = array();
} else {
$row = array('Table_priv' => '');
}
}
if (isset($row['Table_priv'])) {
PMA_fillInTablePrivileges($row);
// get columns
$res = $GLOBALS['dbi']->tryQuery(
'SHOW COLUMNS FROM '
. Util::backquote(
Util::unescapeMysqlWildcards($db)
)
. '.' . Util::backquote($table) . ';'
);
$columns = array();
if ($res) {
while ($row1 = $GLOBALS['dbi']->fetchRow($res)) {
$columns[$row1[0]] = array(
'Select' => false,
'Insert' => false,
'Update' => false,
'References' => false
);
}
$GLOBALS['dbi']->freeResult($res);
}
unset($res, $row1);
}
// table-specific privileges
if (! empty($columns)) {
$html_output .= PMA_getHtmlForTableSpecificPrivileges(
$username, $hostname, $db, $table, $columns, $row
);
} else {
// global or db-specific
$html_output .= PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row);
}
$html_output .= '</fieldset>' . "\n";
if ($submit) {
$html_output .= '<fieldset id="fieldset_user_privtable_footer" '
. 'class="tblFooters">' . "\n"
. '<input type="hidden" name="update_privs" value="1" />' . "\n"
. '<input type="submit" value="' . __('Go') . '" />' . "\n"
. '</fieldset>' . "\n";
}
return $html_output;
} // end of the 'PMA_displayPrivTable()' function
/**
* Get HTML for "Require"
*
* @param array $row privilege array
*
* @return string html snippet
*/
function PMA_getHtmlForRequires($row)
{
$specified = (isset($row['ssl_type']) && $row['ssl_type'] == 'SPECIFIED');
$require_options = array(
array(
'name' => 'ssl_type',
'value' => 'NONE',
'description' => __(
'Does not require SSL-encrypted connections.'
),
'label' => 'REQUIRE NONE',
'checked' => ((isset($row['ssl_type'])
&& ($row['ssl_type'] == 'NONE'
|| $row['ssl_type'] == ''))
? 'checked="checked"'
: ''
),
'disabled' => false,
'radio' => true
),
array(
'name' => 'ssl_type',
'value' => 'ANY',
'description' => __(
'Requires SSL-encrypted connections.'
),
'label' => 'REQUIRE SSL',
'checked' => (isset($row['ssl_type']) && ($row['ssl_type'] == 'ANY')
? 'checked="checked"'
: ''
),
'disabled' => false,
'radio' => true
),
array(
'name' => 'ssl_type',
'value' => 'X509',
'description' => __(
'Requires a valid X509 certificate.'
),
'label' => 'REQUIRE X509',
'checked' => (isset($row['ssl_type']) && ($row['ssl_type'] == 'X509')
? 'checked="checked"'
: ''
),
'disabled' => false,
'radio' => true
),
array(
'name' => 'ssl_type',
'value' => 'SPECIFIED',
'description' => '',
'label' => 'SPECIFIED',
'checked' => ($specified ? 'checked="checked"' : ''),
'disabled' => false,
'radio' => true
),
array(
'name' => 'ssl_cipher',
'value' => (isset($row['ssl_cipher'])
? htmlspecialchars($row['ssl_cipher']) : ''
),
'description' => __(
'Requires that a specific cipher method be used for a connection.'
),
'label' => 'REQUIRE CIPHER',
'checked' => '',
'disabled' => ! $specified,
'radio' => false
),
array(
'name' => 'x509_issuer',
'value' => (isset($row['x509_issuer'])
? htmlspecialchars($row['x509_issuer']) : ''
),
'description' => __(
'Requires that a valid X509 certificate issued by this CA be presented.'
),
'label' => 'REQUIRE ISSUER',
'checked' => '',
'disabled' => ! $specified,
'radio' => false
),
array(
'name' => 'x509_subject',
'value' => (isset($row['x509_subject'])
? htmlspecialchars($row['x509_subject']) : ''
),
'description' => __(
'Requires that a valid X509 certificate with this subject be presented.'
),
'label' => 'REQUIRE SUBJECT',
'checked' => '',
'disabled' => ! $specified,
'radio' => false
),
);
$html_output = Template::get('privileges/require_options')
->render(array('require_options' => $require_options));
return $html_output;
}
/**
* Get HTML for "Resource limits"
*
* @param array $row first row from result or boolean false
*
* @return string html snippet
*/
function PMA_getHtmlForResourceLimits($row)
{
$limits = array(
array(
'input_name' => 'max_questions',
'name_main' => 'MAX QUERIES PER HOUR',
'value' => (isset($row['max_questions']) ? $row['max_questions'] : '0'),
'description' => __(
'Limits the number of queries the user may send to the server per hour.'
)
),
array(
'input_name' => 'max_updates',
'name_main' => 'MAX UPDATES PER HOUR',
'value' => (isset($row['max_updates']) ? $row['max_updates'] : '0'),
'description' => __(
'Limits the number of commands that change any table '
. 'or database the user may execute per hour.'
)
),
array(
'input_name' => 'max_connections',
'name_main' => 'MAX CONNECTIONS PER HOUR',
'value' => (isset($row['max_connections']) ? $row['max_connections'] : '0'),
'description' => __(
'Limits the number of new connections the user may open per hour.'
)
),
array(
'input_name' => 'max_user_connections',
'name_main' => 'MAX USER_CONNECTIONS',
'value' => (isset($row['max_user_connections']) ?
$row['max_user_connections'] : '0'),
'description' => __(
'Limits the number of simultaneous connections '
. 'the user may have.'
)
)
);
$html_output = Template::get('privileges/resource_limits')
->render(array('limits' => $limits));
$html_output .= '</fieldset>' . "\n";
return $html_output;
}
/**
* Get the HTML snippet for routine specific privileges
*
* @param string $username username for database connection
* @param string $hostname hostname for database connection
* @param string $db the database
* @param string $routine the routine
* @param string $url_dbname url encoded db name
*
* @return string $html_output
*/
function PMA_getHtmlForRoutineSpecificPrivilges(
$username, $hostname, $db, $routine, $url_dbname
) {
$header = PMA_getHtmlHeaderForUserProperties(
false, $url_dbname, $db, $username, $hostname,
$routine, 'routine'
);
$sql = "SELECT `Proc_priv`"
. " FROM `mysql`.`procs_priv`"
. " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'"
. " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "'"
. " AND `Db` = '"
. $GLOBALS['dbi']->escapeString(Util::unescapeMysqlWildcards($db)) . "'"
. " AND `Routine_name` LIKE '" . $GLOBALS['dbi']->escapeString($routine) . "';";
$res = $GLOBALS['dbi']->fetchValue($sql);
$privs = PMA_parseProcPriv($res);
$routineArray = array(PMA_getTriggerPrivilegeTable());
$privTableNames = array(__('Routine'));
$privCheckboxes = PMA_getHtmlForGlobalPrivTableWithCheckboxes(
$routineArray, $privTableNames, $privs
);
$data = array(
'username' => $username,
'hostname' => $hostname,
'database' => $db,
'routine' => $routine,
'grantCount' => count($privs),
'privCheckboxes' => $privCheckboxes,
'header' => $header,
);
$html_output = Template::get('privileges/edit_routine_privileges')
->render($data);
return $html_output;
}
/**
* Get routine privilege table as an array
*
* @return privilege type array
*/
function PMA_getTriggerPrivilegeTable()
{
$routinePrivTable = array(
array(
'Grant',
'GRANT',
__(
'Allows user to give to other users or remove from other users '
. 'privileges that user possess on this routine.'
)
),
array(
'Alter_routine',
'ALTER ROUTINE',
__('Allows altering and dropping this routine.')
),
array(
'Execute',
'EXECUTE',
__('Allows executing this routine.')
)
);
return $routinePrivTable;
}
/**
* Get the HTML snippet for table specific privileges
*
* @param string $username username for database connection
* @param string $hostname hostname for database connection
* @param string $db the database
* @param string $table the table
* @param array $columns columns array
* @param array $row current privileges row
*
* @return string $html_output
*/
function PMA_getHtmlForTableSpecificPrivileges(
$username, $hostname, $db, $table, $columns, $row
) {
$res = $GLOBALS['dbi']->query(
'SELECT `Column_name`, `Column_priv`'
. ' FROM `mysql`.`columns_priv`'
. ' WHERE `User`'
. ' = \'' . $GLOBALS['dbi']->escapeString($username) . "'"
. ' AND `Host`'
. ' = \'' . $GLOBALS['dbi']->escapeString($hostname) . "'"
. ' AND `Db`'
. ' = \'' . $GLOBALS['dbi']->escapeString(
Util::unescapeMysqlWildcards($db)
) . "'"
. ' AND `Table_name`'
. ' = \'' . $GLOBALS['dbi']->escapeString($table) . '\';'
);
while ($row1 = $GLOBALS['dbi']->fetchRow($res)) {
$row1[1] = explode(',', $row1[1]);
foreach ($row1[1] as $current) {
$columns[$row1[0]][$current] = true;
}
}
$GLOBALS['dbi']->freeResult($res);
unset($res, $row1, $current);
$html_output = '<input type="hidden" name="grant_count" '
. 'value="' . count($row) . '" />' . "\n"
. '<input type="hidden" name="column_count" '
. 'value="' . count($columns) . '" />' . "\n"
. '<fieldset id="fieldset_user_priv">' . "\n"
. '<legend data-submenu-label="' . __('Table') . '">' . __('Table-specific privileges')
. '</legend>'
. '<p><small><i>'
. __('Note: MySQL privilege names are expressed in English.')
. '</i></small></p>';
// privs that are attached to a specific column
$html_output .= PMA_getHtmlForAttachedPrivilegesToTableSpecificColumn(
$columns, $row
);
// privs that are not attached to a specific column