forked from asiacny/ContentAggregators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
5823 lines (5441 loc) · 234 KB
/
admin.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
//
// Project: phpLiteAdmin (http://www.phpliteadmin.org/)
// Version: 1.9.7.1
// Summary: PHP-based admin tool to manage SQLite2 and SQLite3 databases on the web
// Last updated: 2016-12-14
// Developers:
// Dane Iracleous (daneiracleous@gmail.com)
// Ian Aldrighetti (ian.aldrighetti@gmail.com)
// George Flanagin & Digital Gaslight, Inc (george@digitalgaslight.com)
// Christopher Kramer (crazy4chrissi@gmail.com, http://en.christosoft.de)
// Ayman Teryaki (http://havalite.com)
// Dreadnaut (dreadnaut@gmail.com, http://dreadnaut.altervista.org)
//
//
// Copyright (C) 2016, phpLiteAdmin
//
// 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, either version 3 of the License, or
// (at your option) any later version.
//
// 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, see <http://www.gnu.org/licenses/>.
//
// ////////////////////////////////////////////////////////////////////////
//
// Please report any bugs you may encounter to our issue tracker here:
// https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open
//
// This is sample configuration file
//
// You can configure phpliteadmin in one of 2 ways:
// 1. Rename phpliteadmin.config.sample.php to phpliteadmin.config.php and change parameters in there.
// You can set only your custom settings in phpliteadmin.config.php. All other settings will be set to defaults.
// 2. Change parameters directly in main phpliteadmin.php file
//
// Please see https://bitbucket.org/phpliteadmin/public/wiki/Configuration for more details
//password to gain access
$password = 'admin';
//directory relative to this file to search for databases (if false, manually list databases in the $databases variable)
$directory = '.';
//whether or not to scan the subdirectories of the above directory infinitely deep
$subdirectories = false;
//if the above $directory variable is set to false, you must specify the databases manually in an array as the next variable
//if any of the databases do not exist as they are referenced by their path, they will be created automatically
$databases = array(
array(
'path'=> 'log.db',
'name'=> 'log'
),
);
/* ---- Interface settings ---- */
// Theme! If you want to change theme, save the CSS file in same folder of phpliteadmin or in folder "themes"
$theme = 'phpliteadmin.css';
// the default language! If you want to change it, save the language file in same folder of phpliteadmin or in folder "languages"
// More about localizations (downloads, how to translate etc.): https://bitbucket.org/phpliteadmin/public/wiki/Localization
$language = 'cn';
// set default number of rows. You need to relog after changing the number
$rowsNum = 30;
// reduce string characters by a number bigger than 10
$charsNum = 300;
// maximum number of SQL queries to save in the history
$maxSavedQueries = 10;
/* ---- Custom functions ---- */
//a list of custom functions that can be applied to columns in the databases
//make sure to define every function below if it is not a core PHP function
$custom_functions = array(
'md5', 'sha1', 'time', 'strtotime',
// add the names of your custom functions to this array
/* 'leet_text', */
);
// define your custom functions here
/*
function leet_text($value)
{
return strtr($value, 'eaAsSOl', '344zZ01');
}
*/
/* ---- Advanced options ---- */
//changing the following variable allows multiple phpLiteAdmin installs to work under the same domain.
$cookie_name = 'pla3412';
//whether or not to put the app in debug mode where errors are outputted
$debug = false;
// the user is allowed to create databases with only these extensions
$allowed_extensions = array('db','db3','sqlite','sqlite3');
// English language-texts.
// Read our wiki on how to translate: https://bitbucket.org/phpliteadmin/public/wiki/Localization
$lang = array(
"direction" => "LTR",
"date_format" => 'g:ia \o\n F j, Y (T)', // see http://php.net/manual/en/function.date.php for what the letters stand for
"ver" => "version",
"for" => "for",
"to" => "to",
"go" => "Go",
"yes" => "Yes",
"no" => "No",
"sql" => "SQL",
"csv" => "CSV",
"csv_tbl" => "Table that CSV pertains to",
"srch" => "Search",
"srch_again" => "Do Another Search",
"login" => "Log In",
"logout" => "Logout",
"view" => "View",
"confirm" => "Confirm",
"cancel" => "Cancel",
"save_as" => "Save As",
"options" => "Options",
"no_opt" => "No options",
"help" => "Help",
"installed" => "installed",
"not_installed" => "not installed",
"done" => "done",
"insert" => "Insert",
"export" => "Export",
"import" => "Import",
"rename" => "Rename",
"empty" => "Empty",
"drop" => "Drop",
"tbl" => "Table",
"chart" => "Chart",
"err" => "ERROR",
"act" => "Action",
"rec" => "Records",
"col" => "Column",
"cols" => "Columns",
"rows" => "row(s)",
"edit" => "Edit",
"del" => "Delete",
"add" => "Add",
"backup" => "Backup database file",
"before" => "Before",
"after" => "After",
"passwd" => "Password",
"passwd_incorrect" => "Incorrect password.",
"chk_ext" => "Checking supported SQLite PHP extensions",
"autoincrement" => "Autoincrement",
"not_null" => "Not NULL",
"attention" => "Attention",
"none" => "None",
"as_defined" => "As defined",
"expression" => "Expression",
"sqlite_ext" => "SQLite extension",
"sqlite_ext_support" => "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use %s until you install at least one of them.",
"sqlite_v" => "SQLite version",
"sqlite_v_error" => "It appears that your database is of SQLite version %s but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow %s to create it automatically or recreate it manually as SQLite version %s.",
"report_issue" => "The problem cannot be diagnosed properly. Please file an issue report at",
"sqlite_limit" => "Due to the limitations of SQLite, only the field name and data type can be modified.",
"php_v" => "PHP version",
"new_version" => "There is a new version!",
"db_dump" => "database dump",
"db_f" => "database file",
"db_ch" => "Change Database",
"db_event" => "Database Event",
"db_name" => "Database name",
"db_rename" => "Rename Database",
"db_renamed" => "Database '%s' has been renamed to",
"db_del" => "Delete Database",
"db_path" => "Path to database",
"db_size" => "Size of database",
"db_mod" => "Database last modified",
"db_create" => "Create New Database",
"db_vac" => "The database, '%s', has been VACUUMed.",
"db_not_writeable" => "The database, '%s', does not exist and cannot be created because the containing directory, '%s', is not writable. The application is unusable until you make it writable.",
"db_setup" => "There was a problem setting up your database, %s. An attempt will be made to find out what's going on so you can fix the problem more easily",
"db_exists" => "A database, other file or directory of the name '%s' already exists.",
"exported" => "Exported",
"struct" => "Structure",
"struct_for" => "structure for",
"on_tbl" => "on table",
"data_dump" => "Data dump for",
"backup_hint" => "Hint: To backup your database, the easiest way is to %s.",
"backup_hint_linktext" => "download the database-file",
"total_rows" => "a total of %s rows",
"total" => "Total",
"not_dir" => "The directory you specified to scan for databases does not exist or is not a directory.",
"bad_php_directive" => "It appears that the PHP directive, 'register_globals' is enabled. This is bad. You need to disable it before continuing.",
"page_gen" => "Page generated in %s seconds.",
"powered" => "Powered by",
"free_software" => "This is free software.",
"please_donate" => "Please donate.",
"remember" => "Remember me",
"no_db" => "Welcome to %s. It appears that you have selected to scan a directory for databases to manage. However, %s could not find any valid SQLite databases. You may use the form below to create your first database.",
"no_db2" => "The directory you specified does not contain any existing databases to manage, and the directory is not writable. This means you can't create any new databases using %s. Either make the directory writable or manually upload databases to the directory.",
"create" => "Create",
"created" => "has been created",
"create_tbl" => "Create new table",
"create_tbl_db" => "Create new table on database",
"create_trigger" => "Creating new trigger on table",
"create_index" => "Creating new index on table",
"create_index1" => "Create Index",
"create_view" => "Create new view on database",
"trigger" => "Trigger",
"triggers" => "Triggers",
"trigger_name" => "Trigger name",
"trigger_act" => "Trigger Action",
"trigger_step" => "Trigger Steps (semicolon terminated)",
"when_exp" => "WHEN expression (type expression without 'WHEN')",
"index" => "Index",
"indexes" => "Indexes",
"index_name" => "Index name",
"name" => "Name",
"unique" => "Unique",
"seq_no" => "Seq. No.",
"emptied" => "has been emptied",
"dropped" => "has been dropped",
"renamed" => "has been renamed to",
"altered" => "has been altered successfully",
"inserted" => "inserted",
"deleted" => "deleted",
"affected" => "affected",
"blank_index" => "Index name must not be blank.",
"one_index" => "You must specify at least one index column.",
"docu" => "Documentation",
"license" => "License",
"proj_site" => "Project Site",
"bug_report" => "This may be a bug that needs to be reported at",
"return" => "Return",
"browse" => "Browse",
"fld" => "Field",
"fld_num" => "Number of Fields",
"fields" => "Fields",
"type" => "Type",
"operator" => "Operator",
"val" => "Value",
"update" => "Update",
"comments" => "Comments",
"specify_fields" => "You must specify the number of table fields.",
"specify_tbl" => "You must specify a table name.",
"specify_col" => "You must specify a column.",
"tbl_exists" => "Table of the same name already exists.",
"show" => "Show",
"show_rows" => "Showing %s row(s). ",
"showing" => "Showing",
"showing_rows" => "Showing rows",
"query_time" => "(Query took %s sec)",
"syntax_err" => "There is a problem with the syntax of your query (Query was not executed)",
"run_sql" => "Run SQL query/queries on database '%s'",
"recent_queries" => "Recent Queries",
"full_texts" => "Show full texts",
"no_full_texts" => "Shorten long texts",
"ques_empty" => "Are you sure you want to empty the table '%s'?",
"ques_drop" => "Are you sure you want to drop the table '%s'?",
"ques_drop_view" => "Are you sure you want to drop the view '%s'?",
"ques_del_rows" => "Are you sure you want to delete row(s) %s from table '%s'?",
"ques_del_db" => "Are you sure you want to delete the database '%s'?",
"ques_column_delete" => "Are you sure you want to delete column(s) %s from table '%s'?",
"ques_del_index" => "Are you sure you want to delete index '%s'?",
"ques_del_trigger" => "Are you sure you want to delete trigger '%s'?",
"ques_primarykey_add" => "Are you sure you want to add a primary key for the column(s) %s in table '%s'?",
"export_struct" => "Export with structure",
"export_data" => "Export with data",
"add_drop" => "Add DROP TABLE",
"add_transact" => "Add TRANSACTION",
"fld_terminated" => "Fields terminated by",
"fld_enclosed" => "Fields enclosed by",
"fld_escaped" => "Fields escaped by",
"fld_names" => "Field names in first row",
"rep_null" => "Replace NULL by",
"rem_crlf" => "Remove CRLF characters within fields",
"put_fld" => "Put field names in first row",
"null_represent" => "NULL represented by",
"import_suc" => "Import was successful.",
"import_into" => "Import into",
"import_f" => "File to import",
"rename_tbl" => "Rename table '%s' to",
"rows_records" => "row(s) starting from record # ",
"rows_aff" => "row(s) affected. ",
"as_a" => "as a",
"readonly_tbl" => "'%s' is a view, which means it is a SELECT statement treated as a read-only table. You may not edit or insert records.",
"chk_all" => "Check All",
"unchk_all" => "Uncheck All",
"with_sel" => "With Selected",
"no_tbl" => "No table in database.",
"no_chart" => "If you can read this, it means the chart could not be generated. The data you are trying to view may not be appropriate for a chart.",
"no_rows" => "There are no rows in the table for the range you selected.",
"no_sel" => "You did not select anything.",
"chart_type" => "Chart Type",
"chart_bar" => "Bar Chart",
"chart_pie" => "Pie Chart",
"chart_line" => "Line Chart",
"lbl" => "Labels",
"empty_tbl" => "This table is empty.",
"click" => "Click here",
"insert_rows" => "to insert rows.",
"restart_insert" => "Restart insertion with ",
"ignore" => "Ignore",
"func" => "Function",
"new_insert" => "Insert As New Row",
"save_ch" => "Save Changes",
"def_val" => "Default Value",
"prim_key" => "Primary Key",
"tbl_end" => "field(s) at end of table",
"query_used_table" => "Query used to create this table",
"query_used_view" => "Query used to create this view",
"create_index2" => "Create an index on",
"create_trigger2" => "Create a new trigger",
"new_fld" => "Adding new field(s) to table '%s'",
"add_flds" => "Add Fields",
"edit_col" => "Editing column '%s'",
"vac" => "Vacuum",
"vac_desc" => "Large databases sometimes need to be VACUUMed to reduce their footprint on the server. Click the button below to VACUUM the database '%s'.",
"event" => "Event",
"each_row" => "For Each Row",
"define_index" => "Define index properties",
"dup_val" => "Duplicate values",
"allow" => "Allowed",
"not_allow" => "Not Allowed",
"asc" => "Ascending",
"desc" => "Descending",
"warn0" => "You have been warned.",
"warn_passwd" => "You are using the default password, which can be dangerous. You can change it easily at the top of %s.",
"warn_dumbass" => "You didn't change the value dumbass ;-)",
"counting_skipped" => "Counting of records has been skipped for some tables because your database is comparably big and some tables don't have primary keys assigned to them so counting might be slow. Add a primary key to these tables or %sforce counting%s.",
"sel_state" => "Select Statement",
"delimit" => "Delimiter",
"back_top" => "Back to Top",
"choose_f" => "Choose File",
"instead" => "Instead of",
"define_in_col" => "Define index column(s)",
"delete_only_managed" => "You can only delete databases managed by this tool!",
"rename_only_managed" => "You can only rename databases managed by this tool!",
"db_moved_outside" => "You either tried to move the database into a directory where it cannot be managed anylonger, or the check if you did this failed because of missing rights.",
"extension_not_allowed" => "The extension you provided is not within the list of allowed extensions. Please use one of the following extensions",
"add_allowed_extension" => "You can add extensions to this list by adding your extension to \$allowed_extensions in the configuration.",
"directory_not_writable" => "The database-file itself is writable, but to write into it, the containing directory needs to be writable as well. This is because SQLite puts temporary files in there for locking.",
"tbl_inexistent" => "Table %s does not exist",
// errors that can happen when ALTER TABLE fails. You don't necessarily have to translate these.
"alter_failed" => "Altering of Table %s failed",
"alter_tbl_name_not_replacable" => "could not replace the table name with the temporary one",
"alter_no_def" => "no ALTER definition",
"alter_parse_failed" =>"failed to parse ALTER definition",
"alter_action_not_recognized" => "ALTER action could not be recognized",
"alter_no_add_col" => "no column to add detected in ALTER statement",
"alter_pattern_mismatch"=>"Pattern did not match on your original CREATE TABLE statement",
"alter_col_not_recognized" => "could not recognize new or old column name",
"alter_unknown_operation" => "Unknown ALTER operation!",
/* Help documentation */
"help_doc" => "Help Documentation",
"help1" => "SQLite Library Extensions",
"help1_x" => "%s uses PHP library extensions that allow interaction with SQLite databases. Currently, %s supports PDO, SQLite3, and SQLiteDatabase. Both PDO and SQLite3 deal with version 3 of SQLite, while SQLiteDatabase deals with version 2. So, if your PHP installation includes more than one SQLite library extension, PDO and SQLite3 will take precedence to make use of the better technology. However, if you have existing databases that are of version 2 of SQLite, %s will be forced to use SQLiteDatabase for only those databases. Not all databases need to be of the same version. During the database creation, however, the most advanced extension will be used.",
"help2" => "Creating a New Database",
"help2_x" => "When you create a new database, the name you entered will be appended with the appropriate file extension (.db, .db3, .sqlite, etc.) if you do not include it yourself. The database will be created in the directory you specified as the \$directory variable.",
"help3" => "Tables vs. Views",
"help3_x" => "On the main database page, there is a list of tables and views. Since views are read-only, certain operations will be disabled. These disabled operations will be apparent by their omission in the location where they should appear on the row for a view. If you want to change the data for a view, you need to drop that view and create a new view with the appropriate SELECT statement that queries other existing tables. For more information, see <a href='http://en.wikipedia.org/wiki/View_(database)' target='_blank'>http://en.wikipedia.org/wiki/View_(database)</a>",
"help4" => "Writing a Select Statement for a New View",
"help4_x" => "When you create a new view, you must write an SQL SELECT statement that it will use as its data. A view is simply a read-only table that can be accessed and queried like a regular table, except it cannot be modified through insertion, column editing, or row editing. It is only used for conveniently fetching data.",
"help5" => "Export Structure to SQL File",
"help5_x" => "During the process for exporting to an SQL file, you may choose to include the queries that create the table and columns.",
"help6" => "Export Data to SQL File",
"help6_x" => "During the process for exporting to an SQL file, you may choose to include the queries that populate the table(s) with the current records of the table(s).",
"help7" => "Add Drop Table to Exported SQL File",
"help7_x" => "During the process for exporting to an SQL file, you may choose to include queries to DROP the existing tables before adding them so that problems do not occur when trying to create tables that already exist.",
"help8" => "Add Transaction to Exported SQL File",
"help8_x" => "During the process for exporting to an SQL file, you may choose to wrap the queries around a TRANSACTION so that if an error occurs at any time during the importation process using the exported file, the database can be reverted to its previous state, preventing partially updated data from populating the database.",
"help9" => "Add Comments to Exported SQL File",
"help9_x" => "During the process for exporting to an SQL file, you may choose to include comments that explain each step of the process so that a human can better understand what is happening.",
"help10" => "Partial Indexes",
"help10_x" => "Partial indexes are indexes over a subset of the rows of a table specified by a WHERE clause. Note this requires at least SQLite 3.8.0 and database files with partial indexes won't be readable or writable by older versions. See the <a href='https://www.sqlite.org/partialindex.html' target='_blank'>SQLite documentation.</a>"
);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//there is no reason for the average user to edit anything below this comment
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//- Initialization
// load optional configuration file
$config_filename = './phpliteadmin.config.php';
if (is_readable($config_filename))
{
include_once $config_filename;
}
//constants 1
define("PROJECT", "phpLiteAdmin");
define("VERSION", "1.9.7.1");
define("PAGE", basename(__FILE__));
define("FORCETYPE", false); //force the extension that will be used (set to false in almost all circumstances except debugging)
define("SYSTEMPASSWORD", $password); // Makes things easier.
define('PROJECT_URL','http://www.phpliteadmin.org/');
define('DONATE_URL','http://www.phpliteadmin.org/donate/');
define('VERSION_CHECK_URL','https://www.phpliteadmin.org/current_version.php');
define('PROJECT_BUGTRACKER_LINK','<a href="https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open" target="_blank">https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open</a>');
define('PROJECT_INSTALL_LINK','<a href="https://bitbucket.org/phpliteadmin/public/wiki/Installation" target="_blank">https://bitbucket.org/phpliteadmin/public/wiki/Installation</a>');
// Resource output (css and javascript files)
// we get out of the main code as soon as possible, without inizializing the session
if (isset($_GET['resource']))
{
Resources::output($_GET['resource']);
exit();
}
// don't mess with this - required for the login session
ini_set('session.cookie_httponly', '1');
session_start();
// generate CSRF token
if (empty($_SESSION['token']))
{
if (function_exists('mcrypt_create_iv'))
{
$_SESSION['token'] = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
} else {
$_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32));
}
}
$token = $_SESSION['token'];
$token_html = '<input type="hidden" name="token" value="'.$token.'" />';
// checking CSRF token
if($_SERVER['REQUEST_METHOD'] === 'POST' || isset($_GET['download'])) // all POST forms need tokens! downloads are protected as well
{
if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['token']))
$check_token=$_POST['token'];
elseif($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['token']))
$check_token=$_GET['token'];
if (!isset($check_token))
{
die("CSRF token missing");
}
elseif ((function_exists('hash_equals') && !hash_equals($_SESSION['token'], $check_token)) ||
(!function_exists('hash_equals') && $_SESSION['token']!==$check_token) ) // yes, timing attacks might be possible here. update your php ;)
{
die("CSRF token is wrong - please try to login again");
}
}
if($debug==true)
{
ini_set("display_errors", 1);
error_reporting(E_STRICT | E_ALL);
} else
{
@ini_set("display_errors", 0);
}
// start the timer to record page load time
$pageTimer = new MicroTimer();
// load language file
if($language != 'en') {
$temp_lang=$lang;
if(is_file('languages/lang_'.$language.'.php'))
include('languages/lang_'.$language.'.php');
elseif(is_file('lang_'.$language.'.php'))
include('lang_'.$language.'.php');
$lang = array_merge($temp_lang, $lang);
unset($temp_lang);
}
// version-number added so after updating, old session-data is not used anylonger
// cookies names cannot contain symbols, except underscores
define("COOKIENAME", preg_replace('/[^a-zA-Z0-9_]/', '_', $cookie_name . '_' . VERSION) );
// stripslashes if MAGIC QUOTES is turned on
// This is only a workaround. Please better turn off magic quotes!
// This code is from http://php.net/manual/en/security.magicquotes.disabling.php
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
//data types array
$sqlite_datatypes = array("INTEGER", "REAL", "TEXT", "BLOB","NUMERIC","BOOLEAN","DATETIME");
//available SQLite functions array (don't add anything here or there will be problems)
$sqlite_functions = array("abs", "hex", "length", "lower", "ltrim", "random", "round", "rtrim", "trim", "typeof", "upper");
//- Support functions
//function that allows SQL delimiter to be ignored inside comments or strings
function explode_sql($delimiter, $sql)
{
$ign = array('"' => '"', "'" => "'", "/*" => "*/", "--" => "\n"); // Ignore sequences.
$out = array();
$last = 0;
$slen = strlen($sql);
$dlen = strlen($delimiter);
$i = 0;
while($i < $slen)
{
// Split on delimiter
if($slen - $i >= $dlen && substr($sql, $i, $dlen) == $delimiter)
{
array_push($out, substr($sql, $last, $i - $last));
$last = $i + $dlen;
$i += $dlen;
continue;
}
// Eat comments and string literals
foreach($ign as $start => $end)
{
$ilen = strlen($start);
if($slen - $i >= $ilen && substr($sql, $i, $ilen) == $start)
{
$i+=strlen($start);
$elen = strlen($end);
while($i < $slen)
{
if($slen - $i >= $elen && substr($sql, $i, $elen) == $end)
{
// SQL comment characters can be escaped by doubling the character. This recognizes and skips those.
if($start == $end && $slen - $i >= $elen*2 && substr($sql, $i, $elen*2) == $end.$end)
{
$i += $elen * 2;
continue;
}
else
{
$i += $elen;
continue 3;
}
}
$i++;
}
continue 2;
}
}
$i++;
}
if($last < $slen)
array_push($out, substr($sql, $last, $slen - $last));
return $out;
}
//function to scan entire directory tree and subdirectories
function dir_tree($dir)
{
$path = '';
$stack[] = $dir;
while($stack)
{
$thisdir = array_pop($stack);
if($dircont = scandir($thisdir))
{
$i=0;
while(isset($dircont[$i]))
{
if($dircont[$i] !== '.' && $dircont[$i] !== '..')
{
$current_file = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i];
if(is_file($current_file))
{
$path[] = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i];
}
elseif (is_dir($current_file))
{
$path[] = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i];
$stack[] = $current_file;
}
}
$i++;
}
}
}
return $path;
}
//the function echo the help [?] links to the documentation
function helpLink($name)
{
global $lang;
return "<a href='?help=1' onclick='openHelp(\"".$name."\"); return false;' class='helpq' title='".$lang['help'].": ".$name."' target='_blank'><span>[?]</span></a>";
}
// function to encode value into HTML just like htmlentities, but with adjusted default settings
function htmlencode($value, $flags=ENT_QUOTES, $encoding ="UTF-8")
{
return htmlentities($value, $flags, $encoding);
}
// 22 August 2011: gkf added this function to support display of
// default values in the form used to INSERT new data.
function deQuoteSQL($s)
{
return trim(trim($s), "'");
}
// reduce string chars
function subString($str)
{
global $charsNum;
if($charsNum > 10 && (!isset($_SESSION[COOKIENAME.'fulltexts']) || !$_SESSION[COOKIENAME.'fulltexts']) && strlen($str)>$charsNum)
{
$str = substr($str, 0, $charsNum).'...';
}
return $str;
}
// checks the (new) name of a database file
function checkDbName($name)
{
global $allowed_extensions;
$info = pathinfo($name);
if(isset($info['extension']) && !in_array($info['extension'], $allowed_extensions))
{
return false;
} else
{
return (!is_file($name) && !is_dir($name));
}
}
// check whether a path is a db managed by this tool
// requires that $databases is already filled!
// returns the key of the db if managed, false otherwise.
function isManagedDB($path)
{
global $databases;
foreach($databases as $db_key => $database)
{
if($path == $database['path'])
{
// a db we manage. Thats okay.
// return the key.
return $db_key;
}
}
// not a db we manage!
return false;
}
// from a typename of a colun, get the type of the column's affinty
// see http://www.sqlite.org/datatype3.html section 2.1 for rules
function get_type_affinity($type)
{
if (preg_match("/INT/i", $type))
return "INTEGER";
else if (preg_match("/(?:CHAR|CLOB|TEXT)/i", $type))
return "TEXT";
else if (preg_match("/BLOB/i", $type) || $type=="")
return "NONE";
else if (preg_match("/(?:REAL|FLOA|DOUB)/i", $type))
return "REAL";
else
return "NUMERIC";
}
//- Check user authentication, login and logout
$auth = new Authorization(); //create authorization object
// check if user has attempted to log out
if (isset($_POST['logout']))
$auth->revoke();
// check if user has attempted to log in
else if (isset($_POST['login']) && isset($_POST['password']))
$auth->attemptGrant($_POST['password'], isset($_POST['remember']));
//- Actions on database files and bulk data
if ($auth->isAuthorized())
{
//- Create a new database
if(isset($_POST['new_dbname']))
{
if($_POST['new_dbname']=='')
{
// TODO: Display an error message (do NOT echo here. echo below in the html-body!)
}
else
{
$str = preg_replace('@[^\w-.]@','', $_POST['new_dbname']);
$dbname = $str;
$dbpath = $str;
if(checkDbName($dbname))
{
$tdata = array();
$tdata['name'] = $dbname;
$tdata['path'] = $directory.DIRECTORY_SEPARATOR.$dbpath;
if(isset($_POST['new_dbtype']))
$tdata['type'] = $_POST['new_dbtype'];
else
$tdata['type'] = 3;
$td = new Database($tdata);
$td->query("VACUUM");
} else
{
if(is_file($dbname) || is_dir($dbname)) $dbexists = true;
else $extension_not_allowed=true;
}
}
}
//- Scan a directory for databases
if($directory!==false)
{
if($directory[strlen($directory)-1]==DIRECTORY_SEPARATOR) //if user has a trailing slash in the directory, remove it
$directory = substr($directory, 0, strlen($directory)-1);
if(is_dir($directory)) //make sure the directory is valid
{
if($subdirectories===true)
$arr = dir_tree($directory);
else
$arr = scandir($directory);
$databases = array();
$j = 0;
for($i=0; $i<sizeof($arr); $i++) //iterate through all the files in the databases
{
if($subdirectories===false)
$arr[$i] = $directory.DIRECTORY_SEPARATOR.$arr[$i];
if(@!is_file($arr[$i])) continue;
$con = file_get_contents($arr[$i], NULL, NULL, 0, 60);
if(strpos($con, "** This file contains an SQLite 2.1 database **", 0)!==false || strpos($con, "SQLite format 3", 0)!==false)
{
$databases[$j]['path'] = $arr[$i];
if($subdirectories===false)
$databases[$j]['name'] = basename($arr[$i]);
else
$databases[$j]['name'] = $arr[$i];
$databases[$j]['writable'] = is_writable($databases[$j]['path']);
$databases[$j]['writable_dir'] = is_writable(dirname($databases[$j]['path']));
$databases[$j]['readable'] = is_readable($databases[$j]['path']);
$j++;
}
}
// 22 August 2011: gkf fixed bug #50.
sort($databases);
if(isset($tdata))
{
foreach($databases as $db_id => $database)
{
if($database['path'] == $tdata['path'])
{
$_SESSION[COOKIENAME.'currentDB'] = $database;
break;
}
}
}
}
else //the directory is not valid - display error and exit
{
echo "<div class='confirm' style='margin:20px;'>".$lang['not_dir']."</div>";
exit();
}
}
else
{
for($i=0; $i<sizeof($databases); $i++)
{
if(!file_exists($databases[$i]['path']))
{
// the file does not exist and will be created when clicked, if permissions allow to
$databases[$i]['writable'] = is_writable(dirname($databases[$i]['path']));
$databases[$i]['writable_dir'] = is_writable(dirname($databases[$i]['path']));
$databases[$i]['readable'] = is_writable(dirname($databases[$i]['path']));
}
else
{
$databases[$i]['writable'] = is_writable($databases[$i]['path']);
$databases[$i]['writable_dir'] = is_writable(dirname($databases[$i]['path']));
$databases[$i]['readable'] = is_readable($databases[$i]['path']);
}
}
sort($databases);
}
// we now have the $databases array set. Check whethet currentDB is a managed Db (is in this array)
if(isset($_SESSION[COOKIENAME.'currentDB']) && isManagedDB($_SESSION[COOKIENAME.'currentDB']['path']) === false)
unset($_SESSION[COOKIENAME.'currentDB']);
//- Delete an existing database
if(isset($_GET['database_delete']))
{
$dbpath = $_POST['database_delete'];
// check whether $dbpath really is a db we manage
$checkDB = isManagedDB($dbpath);
if($checkDB !== false)
{
unlink($dbpath);
unset($_SESSION[COOKIENAME.'currentDB']);
unset($databases[$checkDB]);
} else die($lang['err'].': '.$lang['delete_only_managed']);
}
//- Rename an existing database
if(isset($_GET['database_rename']))
{
$oldpath = $_POST['oldname'];
$newpath = $_POST['newname'];
$oldpath_parts = pathinfo($oldpath);
$newpath_parts = pathinfo($newpath);
// only rename?
$newpath = $oldpath_parts['dirname'].DIRECTORY_SEPARATOR.basename($_POST['newname']);
if($newpath != $_POST['newname'] && $subdirectories)
{
// it seems that the file should not only be renamed but additionally moved.
// we need to make sure it stays within $directory...
$new_realpath = realpath($newpath_parts['dirname']).DIRECTORY_SEPARATOR;
$directory_realpath = realpath($directory).DIRECTORY_SEPARATOR;
if(strpos($new_realpath, $directory_realpath)===0)
{
// its okay, the new directory is within $directory
$newpath = $_POST['newname'];
}
else die($lang['err'].': '.$lang['db_moved_outside']);
}
if(checkDbName($newpath))
{
$checkDB = isManagedDB($oldpath);
if($checkDB !==false )
{
rename($oldpath, $newpath);
$databases[$checkDB]['path'] = $newpath;
$databases[$checkDB]['name'] = basename($newpath);
$_SESSION[COOKIENAME.'currentDB'] = $databases[$checkDB];
$justrenamed = true;
}
else die($lang['err'].': '.$lang['rename_only_managed']);
}
else
{
if(is_file($newpath) || is_dir($newpath)) $dbexists = true;
else $extension_not_allowed = true;
}
}
//- Export (download a dump) an existing database
if(isset($_POST['export']))
{
$export_filename = str_replace(array("\r", "\n"), '',$_POST['filename']); // against http header injection (php < 5.1.2 only)
if($_POST['export_type']=="sql")
{
header('Content-Type: text/sql');
header('Content-Disposition: attachment; filename="'.$export_filename.'.'.$_POST['export_type'].'";');
if(isset($_POST['tables']))
$tables = $_POST['tables'];
else
{
$tables = array();
$tables[0] = $_POST['single_table'];
}
$drop = isset($_POST['drop']);
$structure = isset($_POST['structure']);
$data = isset($_POST['data']);
$transaction = isset($_POST['transaction']);
$comments = isset($_POST['comments']);
$db = new Database($_SESSION[COOKIENAME.'currentDB']);
echo $db->export_sql($tables, $drop, $structure, $data, $transaction, $comments);
}
else if($_POST['export_type']=="csv")
{
header("Content-type: application/csv");
header('Content-Disposition: attachment; filename="'.$export_filename.'.'.$_POST['export_type'].'";');
header("Pragma: no-cache");
header("Expires: 0");
if(isset($_POST['tables']))
$tables = $_POST['tables'];
else
{
$tables = array();
$tables[0] = $_POST['single_table'];
}
$field_terminate = $_POST['export_csv_fieldsterminated'];
$field_enclosed = $_POST['export_csv_fieldsenclosed'];
$field_escaped = $_POST['export_csv_fieldsescaped'];
$null = $_POST['export_csv_replacenull'];
$crlf = isset($_POST['export_csv_crlf']);
$fields_in_first_row = isset($_POST['export_csv_fieldnames']);
$db = new Database($_SESSION[COOKIENAME.'currentDB']);
echo $db->export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row);
}
exit();
}
//- Import a file into an existing database
if(isset($_POST['import']))
{
$db = new Database($_SESSION[COOKIENAME.'currentDB']);
$db->registerUserFunction($custom_functions);
if($_POST['import_type']=="sql")
{
$data = file_get_contents($_FILES["file"]["tmp_name"]);
$importSuccess = $db->import_sql($data);
}
else
{
$field_terminate = $_POST['import_csv_fieldsterminated'];
$field_enclosed = $_POST['import_csv_fieldsenclosed'];
$field_escaped = $_POST['import_csv_fieldsescaped'];
$null = $_POST['import_csv_replacenull'];
$fields_in_first_row = isset($_POST['import_csv_fieldnames']);
$importSuccess = $db->import_csv($_FILES["file"]["tmp_name"], $_POST['single_table'], $field_terminate, $field_enclosed, $field_escaped, $null, $fields_in_first_row);
}
}
//- Download (backup) a database file (as SQLite file, not as dump)
if(isset($_GET['download']) && isManagedDB($_GET['download'])!==false)
{
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.basename($_GET['download']).'";');
header("Pragma: no-cache");
header("Expires: 0");
readfile($_GET['download']);
exit;
}
}
//- HTML: output starts here
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- Copyright <?php echo date("Y").' '.PROJECT.' ('.PROJECT_URL.')'; ?> -->
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<link rel="shortcut icon" href="?resource=favicon" />
<title><?php echo PROJECT ?></title>
<?php
//- HTML: css/theme include
if(isset($_GET['theme'])) $theme = basename($_GET['theme']);
// allow themes to be dropped in subfolder "themes"
if(is_file('themes/'.$theme)) $theme = 'themes/'.$theme;
if (file_exists($theme))
// an external stylesheet exists - import it
echo "<link href='{$theme}' rel='stylesheet' type='text/css' />", PHP_EOL;
else
// only use the default stylesheet if an external one does not exist
echo "<link href='?resource=css' rel='stylesheet' type='text/css' />", PHP_EOL;
// HTML: output help text, then exit
if(isset($_GET['help']))
{
//help section array
$help = array
(
$lang['help1'] => sprintf($lang['help1_x'], PROJECT, PROJECT, PROJECT), $lang['help2'] => $lang['help2_x'], $lang['help3'] => $lang['help3_x'],
$lang['help4'] => $lang['help4_x'], $lang['help5'] => $lang['help5_x'], $lang['help6'] => $lang['help6_x'],
$lang['help7'] => $lang['help7_x'], $lang['help8'] => $lang['help8_x'], $lang['help9'] => $lang['help9_x'], $lang['help10'] => $lang['help10_x']
);
?>
</head>
<body style="direction:<?php echo $lang['direction']; ?>;">
<div id='help_container'>
<?php