diff --git a/.gitignore b/.gitignore
index 02cab5f..5e09c19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,3 @@ dist/.goat.ignore
dist/.goat.token
dist/.goat.url
dist/.links.db
-dist/phpliteadmin.config.php
diff --git a/README.md b/README.md
index 9fefce2..0d1561b 100644
--- a/README.md
+++ b/README.md
@@ -20,10 +20,10 @@ There's a few hardcoded URLs in there that you'll have to fix yourself.
One day I'll create a config file for that.
The database at `.links.db` is automatically created when you visit the main page.
-## Configuration
-### phpLiteAdmin
-You may override settings from `phpliteadmin.php` in the file `phpliteadmin.config.php`.
+You can access the database from the command line using something like
+[VisiData](https://www.visidata.org/install/).
+## Configuration
### GoatCounter
GoatCounter is disabled unless the `.goat.token` and `.goat.url` files exist.
diff --git a/dist/index.php b/dist/index.php
index ed76b8b..9c49eba 100644
--- a/dist/index.php
+++ b/dist/index.php
@@ -5,10 +5,6 @@ include_once("goatcounter.php");
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
switch ($path) {
- case "/admin":
- $_SERVER["PHP_SELF"] = $path;
- include("phpliteadmin.php");
- exit();
case "/favicon.ico":
header("Location: https://fwdekker.com/favicon.ico");
exit();
@@ -47,7 +43,7 @@ if ($target != null && !$needs_confirmation) {
-
+
fwdkr.co
diff --git a/dist/phpliteadmin.php b/dist/phpliteadmin.php
deleted file mode 100644
index 55b64c0..0000000
--- a/dist/phpliteadmin.php
+++ /dev/null
@@ -1,6243 +0,0 @@
-.
-//
-// ////////////////////////////////////////////////////////////////////////
-//
-// 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 (set an empty password to disable authentication completely)
-$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'=> 'database1.sqlite',
- 'name'=> 'Database 1'
- ),
- array(
- 'path'=> 'database2.sqlite',
- 'name'=> 'Database 2'
- ),
-);
-
-
-/* ---- 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 = 'en';
-
-// 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', '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');
-
-// BLOBs are displayed and edited as hex string
-$hexblobs = false;
-
-// 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", // here, the noun SQL view is meant, not the verb "to 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",
- "download" => "Download",
- "open_in_browser" => "Open in browser",
-
- "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.",
- "db_blank" => "The database name cannot be blank.",
-
- "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.",
- "dir_not_executable" => "The directory you specified cannot be scanned for databases as %s has no execute permissions on it. On Linux, use 'chmod +x %s' to fix this.",
-
- "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_table_empty" => "Are you sure you want to empty the table(s) '%s'?",
- "ques_table_drop" => "Are you sure you want to drop the table(s) / view(s) '%s'?",
- "ques_row_delete" => "Are you sure you want to delete row(s) %s from table '%s'?",
- "ques_database_delete" => "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_index_delete" => "Are you sure you want to delete index '%s'?",
- "ques_trigger_delete" => "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",
- "max_file_size" => "Maximum file size",
- "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'.",
- "vac_on_empty"=>"Rebuild database file to recover unused space (Vacuum)",
- "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_mbstring" =>"The mbstring extension is not installed or not enabled in your PHP. As long as you stick to ASCII characters, everything will work, but you may experience strange bugs with multibyte characters. Better install and enable mbstring!",
- "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.",
- "database_not_writable" => "The database-file is not writable, so its content cannot be changed in any way.",
- "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",
- "col_inexistent" => "Column %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 http://en.wikipedia.org/wiki/View_(database)",
- "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 SQLite documentation.",
- "help11" => "Maximum size of file uploads",
- "help11_x" => "The maximum size of file uploads is determined by three PHP settings: upload_max_filesize, post_max_size and memory_limit. The smallest of these three limits the maximum size for file uploads. To upload larger files, adjust these values in your php.ini file."
-
-);
-
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-// there is no reason for the average user to edit anything below this comment
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-// Authorization class
-// Maintains user's logged-in state and security of application
-//
-
-class Authorization
-{
- private $authorized;
- private $login_failed;
- private $system_password_encrypted;
-
- public function __construct()
- {
- // first, make sure a CSRF token is generated
- $this->generateToken();
- // second, check for possible CSRF attacks. to protect logins, this is done before checking login
- $this->checkToken();
-
- // the salt and password encrypting is probably unnecessary protection but is done just
- // for the sake of being very secure
- if(!isset($_SESSION[COOKIENAME.'_salt']) && !isset($_COOKIE[COOKIENAME.'_salt']))
- {
- // create a random salt for this session if a cookie doesn't already exist for it
- $_SESSION[COOKIENAME.'_salt'] = self::generateSalt(22);
- }
- else if(!isset($_SESSION[COOKIENAME.'_salt']) && isset($_COOKIE[COOKIENAME.'_salt']))
- {
- // session doesn't exist, but cookie does so grab it
- $_SESSION[COOKIENAME.'_salt'] = $_COOKIE[COOKIENAME.'_salt'];
- }
-
- // salted and encrypted password used for checking
- $this->system_password_encrypted = md5(SYSTEMPASSWORD."_".$_SESSION[COOKIENAME.'_salt']);
-
- $this->authorized =
- // no password
- SYSTEMPASSWORD == ''
- // correct password stored in session
- || isset($_SESSION[COOKIENAME.'password']) && hash_equals($_SESSION[COOKIENAME.'password'], $this->system_password_encrypted)
- // correct password stored in cookie
- || isset($_COOKIE[COOKIENAME]) && isset($_COOKIE[COOKIENAME.'_salt']) && hash_equals(md5(SYSTEMPASSWORD."_".$_COOKIE[COOKIENAME.'_salt']), $_COOKIE[COOKIENAME]);
- }
-
- public function attemptGrant($password, $remember)
- {
- $hashed_password = crypt(SYSTEMPASSWORD, '$2a$07$'.self::generateSalt(22).'$');
- if (hash_equals($hashed_password, crypt($password, $hashed_password))) {
- if ($remember) {
- // user wants to be remembered, so set a cookie
- $expire = time()+60*60*24*30; //set expiration to 1 month from now
- setcookie(COOKIENAME, $this->system_password_encrypted, $expire, null, null, null, true);
- setcookie(COOKIENAME."_salt", $_SESSION[COOKIENAME.'_salt'], $expire, null, null, null, true);
- } else {
- // user does not want to be remembered, so destroy any potential cookies
- setcookie(COOKIENAME, "", time()-86400, null, null, null, true);
- setcookie(COOKIENAME."_salt", "", time()-86400, null, null, null, true);
- unset($_COOKIE[COOKIENAME]);
- unset($_COOKIE[COOKIENAME.'_salt']);
- }
-
- $_SESSION[COOKIENAME.'password'] = $this->system_password_encrypted;
- $this->authorized = true;
- return true;
- }
-
- $this->login_failed = true;
- return false;
- }
-
- public function revoke()
- {
- //destroy everything - cookies and session vars
- setcookie(COOKIENAME, "", time()-86400, null, null, null, true);
- setcookie(COOKIENAME."_salt", "", time()-86400, null, null, null, true);
- unset($_COOKIE[COOKIENAME]);
- unset($_COOKIE[COOKIENAME.'_salt']);
- session_unset();
- session_destroy();
- $this->authorized = false;
- // start a new session and generate a new CSRF token for the login form
- session_start();
- $this->generateToken();
- }
-
- public function isAuthorized()
- {
- return $this->authorized;
- }
-
- public function isFailedLogin()
- {
- return $this->login_failed;
- }
-
- public function isPasswordDefault()
- {
- return SYSTEMPASSWORD == 'admin';
- }
-
- private static function generateSalt($saltSize)
- {
- $set = 'ABCDEFGHiJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- $setLast = strlen($set) - 1;
- $salt = '';
- while ($saltSize-- > 0) {
- $salt .= $set[mt_rand(0, $setLast)];
- }
- return $salt;
- }
-
- private function generateToken()
- {
- // generate CSRF token
- if (empty($_SESSION[COOKIENAME.'token']))
- {
- if (function_exists('random_bytes')) // introduced in PHP 7.0
- {
- $_SESSION[COOKIENAME.'token'] = bin2hex(random_bytes(32));
- }
- elseif (function_exists('openssl_random_pseudo_bytes')) // introduced in PHP 5.3.0
- {
- $_SESSION[COOKIENAME.'token'] = bin2hex(openssl_random_pseudo_bytes(32));
- }
- else
- {
- // For PHP 5.2.x - This case can be removed once we drop support for 5.2.x
- $_SESSION[COOKIENAME.'token'] = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
- }
- }
- }
-
- private function checkToken()
- {
- // 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(!hash_equals($_SESSION[COOKIENAME.'token'], $check_token))
- {
- die("CSRF token is wrong - please try to login again");
- }
- }
- }
-
-}
-// Database class
-// Generic database abstraction class to manage interaction with database without worrying about SQLite vs. PHP versions
-//
-class Database
-{
- protected $db; //reference to the DB object
- protected $type; //the extension for PHP that handles SQLite
- protected $data;
- protected $lastResult;
- protected $alterError;
- protected $debugOutput ='';
-
- public function __construct($data)
- {
- global $lang, $params;
- $this->data = $data;
- try
- {
- if(!file_exists($this->data["path"]) && !is_writable(dirname($this->data["path"]))) //make sure the containing directory is writable if the database does not exist
- {
- echo "