Quellcode durchsuchen

Better installer, util sql scripts added.

Iñigo Valentin vor 5 Jahren
Ursprung
Commit
01edc8e2d3
7 geänderte Dateien mit 79 neuen und 82 gelöschten Zeilen
  1. 7 0
      .gitignore
  2. 9 6
      README.md
  3. 1 0
      application/page/Runes_Page.php
  4. 45 63
      install
  5. BIN
      installer/data_empty.sqlite
  6. 17 13
      installer/recreate_data_db.sql
  7. 0 0
      installer/recreate_key_db.sql

+ 7 - 0
.gitignore

@@ -4,6 +4,12 @@ util/
 parser/
 data/*.sqlite
 
+# Custom scripts
+install_to_*
+
+# Database backups
+application/sw.sqlite_*
+
 # Autogenerated files
 .php_pid
 *.log
@@ -11,6 +17,7 @@ doc/.tmp
 application/API/v2/bin/__pycache__/
 
 #IDE / OS files
+.buildpath
 .kateproject.d/
 .kateproject
 .project

+ 9 - 6
README.md

@@ -2,20 +2,23 @@
 
 Assistant for Summoners War players.
 
-Keep tabs on your monsr, runes, inventory, teams, run logs, skillps...
-Get reports onwhich runes should be replaced, which monster to skillup next, or victory rate on different areas.
+Keep tabs on your monsters, runes, inventory, teams, run logs, skillps...
 
-Includes a plugin for [sw-wxporter](https://github.com/Xzandro/sw-exporter/) to easily ipmort your profile.
+Get reports on which runes should be replaced, which monster to skillup next, or victory rate on different areas.
+
+Optimize your runesfor maximum efficiency.
+
+Includes a plugin for [sw-exporter](https://github.com/Xzandro/sw-exporter/) to easily import your profile.
 
 ### Requeriments
 
- * PHP (version 7 recommended, not fuly tested on preious versions)
- * SQLite
+ * PHP (version 7.4 or higher recommended, not fully tested on preious versions)
+ * SQLite (version >= 3)
 
 ### Setting it up
 
 1. Install the basic data. Just run the [install script](install). It will check all requeriments and initialize the databases.
-2. It is designed to run on the built-in PHP web server, but with a bit of work can be made to work on apache. By default, it runs on por 80, and it's publicly visible. Iy you want to change that, it's easy enough to edit the [config file](config). To start it, just run the `start_server` script.
+2. It is designed to run on the built-in PHP web server, but with a bit of work can be made to work on Apache. By default, it runs on por 80, and it's publicly visible. If you want to change that, it's easy enough to edit the [config file](config). To start it, just run the `start_server` script.
 3. Create an user. As of now, there is no frontend for doing so, so it must be inserted directly into the database:
 ```
 $ sqlite3 data/sw.sqlite

+ 1 - 0
application/page/Runes_Page.php

@@ -69,6 +69,7 @@
             $this->view = PATH::VIEW . "runes.php";
             $this->parse_filters();
             $s = $this->build_query();
+error_log($s);
             $this->filters["GROUP"] = 1;
             $q = $db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){

+ 45 - 63
install

@@ -19,78 +19,60 @@ then
     exit -3
 fi
 
-if [ "$(command -v node)" == "" ]
-then
-    echo "NODE.js is not installed. Install it and try again."
-    exit -4
-fi
-
-# TODO: FIX, not working for this module
-#if ! node -r requireg /dev/null 2> /dev/null
-#then
-#    echo "NODE.js module requireg is not installed. Install it and try again."
-#    exit -5
-#fi
-
-
-if ! node -r dateformat /dev/null 2> /dev/null
-then
-    echo "NODE.js module dateformat is not installed. Install it and try again."
-    exit -5
-fi
-
-if ! node -r request /dev/null 2> /dev/null
-then
-    echo "NODE.js module request is not installed. Install it and try again."
-    exit -6
-fi
-
-if ! node -r querystring /dev/null 2> /dev/null
-then
-    echo "NODE.js module querystring is not installed. Install it and try again."
-    exit -7
-fi
-
-if ! node -r http /dev/null 2> /dev/null
-then
-    echo "NODE.js module http is not installed. Install it and try again."
-    exit -8
-fi
-
-if ! node -r fs /dev/null 2> /dev/null
-then
-    echo "NODE.js module fs is not installed. Install it and try again."
-    exit -9
-fi
-
-clear_keys=0
-clear_data=0
+reinstall=0
 for i in "$@"
 do
-    if [[ $i == "--clear-keys" ]] ; then
-        clear_keys=1;
-    elif [[ $i == "--clear-data" ]] ; then
-        clear_data=1;
+    if [[ $i == "--reinstall" ]] ; then
+        reinstall=1;
     fi
 done
 
-
-if [ -f $SCRIPTPATH/application/sw.sqlite ] && [ $clear_keys == 0 ]
+if [ -f $SCRIPTPATH/data/sw.sqlite ] && [ $reinstall == 0 ]
 then
-    echo "Key database exist. It will not be overwritten. Use the --clear-keys argument to override."
-else
-    echo "Setting up keys..."
-    rm $SCRIPTPATH/application/sw.sqlite
-    sqlite3 $SCRIPTPATH/application/sw.sqlite < $SCRIPTPATH/install_data/install_base.sql
-fi
-
-if [ -f $SCRIPTPATH/data/sw.sqlite ] && [ $clear_data == 0 ]
-then
-    echo "User data database exist. It will not be overwritten. Use the --clear-data argument to override."
+    echo "User data database exist. It will not be overwritten. Use the --reinstall argument to override."
 else
     echo "Setting up user tables..."
     rm $SCRIPTPATH/data/sw.sqlite
-    sqlite3 $SCRIPTPATH/data/sw.sqlite < $SCRIPTPATH/install_data/install_data.sql
+    cp $SCRIPTPATH/installer/data_empty.sqlite $SCRIPTPATH/data/sw.sqlite
 fi
 
+# Ask for admin user and password
+correct=0
+while [ $correct -eq 0 ]
+do
+    read -p "Enter admin username:" $user
+    if [[ $user =~ ^[a-zA-Z0-9]{4, 32}$ ]]
+    then
+        correct=1
+    else
+        echo "Invalid username. Use numbers or letters. Length must be between 4 and 32 characters."
+    fi
+done
+correct=0
+while [ $correct -eq 0]
+do
+    read -p "Enter admin email:" $mail
+    if [[ $mail =~ ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$ ]]
+    then
+        correct=1
+    else
+        echo "Invalid email."
+    fi
+match=0
+while [ $match -eq 0 ]
+do
+    read -s -p "Enter password:" $password
+    read -s -p "Enter password:" $passwordRepeat
+    if [ "$password" = "$passwordRepeat" ]
+    then
+        match=1
+    else
+        echo "Paswords do not match"
+    fi
+done
+hash=$(echo -n $password | sha256sum)
+api=$(head -1 <(fold -w 16  <(tr -dc 'a-zA-Z0-9' < /dev/urandom)))
+
+query="INSERT INTO USER VALUES (0, '$user', '$mail', '$hash', '$api', 1, 0);"
+
 echo "All done. You can start the web server by typing ./start_server or edit the config file for the server options"

BIN
installer/data_empty.sqlite


+ 17 - 13
install_data/install_data.sql → installer/recreate_data_db.sql

@@ -1,9 +1,15 @@
-CREATE TABLE player(
-    uid INT PRIMARY KEY NOT NULL,
-    name TEXT NOT NULL UNIQUE,
+CREATE TABLE user(
+    id INT PRIMARY KEY NOT NULL,
+    username TEXT NOT NULL UNIQUE,
     mail TEXT NOT NULL UNIQUE,
     password TEXT NOT NULL,
     api_key TEXT NOT NULL UNIQUE,
+    admin INT NOT NULL CHECK(admin IN (0, 1)) DEFAULT 0,
+    current_mode INT NOT NULL CHECK(current_mode IN (0, 1)) DEFAULT 0
+);
+CREATE TABLE player(
+    uid INT PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL UNIQUE,
     mana INT NOT NULL CHECK (mana >= 0),
     crystal INT NOT NULL CHECK (crystal >= 0),
     country TEXT,
@@ -38,9 +44,15 @@ CREATE TABLE player(
     top_rank_siege INT DEFAULT 0,
     top_rank_wboss INT DEFAULT 0,
     top_rank_toan INT DEFAULT 0,
-    top_rank_toah INT DEFAULT 0,
+    top_rank_toah INT DEFAULT 0
+);
+CREATE TABLE user_player(
+    user INT NOT NULL REFERENCES user(id),
+    uid INT NOT NULL REFERENCES player(uid),
     public INT NOT NULL DEFAULT 0 CHECK(public IN (0, 1)),
-    mode INT NOT NULL CHECK(mode IN (0, 1)) DEFAULT 0
+    main INT NOT NULL DEFAULT 0 CHECK(main IN (0, 1)),
+    alias TEXT,
+    PRIMARY KEY (user, uid)
 );
 CREATE TABLE record(
     uid INT NOT NULL REFERENCES player(id),
@@ -321,14 +333,6 @@ CREATE TABLE run_drop_item(
     amount INT NOT NULL CHECK(amount > 0),
     PRIMARY KEY (run, item)
 );
-CREATE TABLE filter(
-    uid INT NOT NULL REFERENCES player(id),
-    id INT NOT NULL PRIMARY KEY,
-    page TEXT NOT NULL,
-    name INT NOT NULL,
-    description TEXT,
-    condition TEXT NOT NULL
-);
 CREATE TABLE team(
     uid INT NOT NULL REFERENCES player(id),
     id INT NOT NULL PRIMARY KEY,

+ 0 - 0
install_data/install_base.sql → installer/recreate_key_db.sql