update environment files

dotnetflags
not manx 5 years ago
parent dda1e2f26e
commit a38bab1f99
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

@ -1,18 +1,14 @@
{ {
"AllowedHosts": "*", "AllowedHosts": "*",
"dbconfig": { "dbconfig": {
"connectionstring": "Server=localhost;Port=3306;User ID=user;Password=default;Database=bantflags", "connectionstring": "Server=localhost;Port=3306;User ID=user;Password=password;Database=bantflags",
"poolsize": 2 "poolsize": 2,
"boards": [
"bant",
"nap",
"srsbsn"
]
}, },
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"webroot": "/var/www/html", "webroot": "/var/www/html",
"staging-password": "supersecretpassword" "staging-password": "supersecretpassword"
} }

@ -1,54 +1,38 @@
CREATE DATABASE IF NOT EXISTS bantflags; DROP DATABASE IF EXISTS `bantflags`;
CREATE DATABASE `bantflags`;
USE bantflags; USE `bantflags`;
CREATE USER IF NOT EXISTS flags@localhost IDENTIFIED BY 'default'; CREATE USER IF NOT EXISTS flags@localhost IDENTIFIED BY 'default';
GRANT ALL PRIVILEGES ON bantflags.* TO flags@localhost; GRANT ALL PRIVILEGES ON bantflags.* TO flags@localhost;
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
CREATE TABLE `flags` (
CREATE TABLE IF NOT EXISTS `flags` ( `id` int(10) NOT NULL AUTO_INCREMENT,
`id` INT(10) NOT NULL AUTO_INCREMENT, `flag` varchar(100) NOT NULL DEFAULT '0',
`flag` VARCHAR(100) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE INDEX `flag` (`flag`) UNIQUE KEY `flag` (`flag`)
) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=0
;
CREATE TABLE IF NOT EXISTS `posts` ( CREATE TABLE `posts` (
`id` INT(10) NOT NULL AUTO_INCREMENT, `id` int(10) NOT NULL AUTO_INCREMENT,
`post_nr` INT(10) NOT NULL DEFAULT '0', `post_nr` int(10) NOT NULL DEFAULT '0',
`board` VARCHAR(5) NOT NULL DEFAULT 'bant', `board` varchar(10) NOT NULL DEFAULT 'bant',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE INDEX `post_nr` (`post_nr`) UNIQUE KEY `post_nr_board` (`post_nr`,`board`)
) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=0
;
CREATE TABLE IF NOT EXISTS `postflags` ( CREATE TABLE `postflags` (
`id` INT(10) NOT NULL AUTO_INCREMENT, `id` int(10) NOT NULL AUTO_INCREMENT,
`post_nr` INT(10) NOT NULL DEFAULT '0', `post_nr` int(10) NOT NULL DEFAULT '0',
`flag` INT(10) NOT NULL DEFAULT '0', `flag` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
INDEX `flag` (`flag`), KEY `flag` (`flag`),
INDEX `post_nr` (`post_nr`), KEY `post_nr` (`post_nr`),
CONSTRAINT `flag` FOREIGN KEY (`flag`) REFERENCES `flags` (`id`) ON DELETE CASCADE, CONSTRAINT `flag` FOREIGN KEY (`flag`) REFERENCES `flags` (`id`) ON DELETE CASCADE,
CONSTRAINT `post_nr` FOREIGN KEY (`post_nr`) REFERENCES `posts` (`id`) CONSTRAINT `post_nr` FOREIGN KEY (`post_nr`) REFERENCES `posts` (`id`)
) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=0
;
DROP PROCEDURE IF EXISTS insert_post;
DELIMITER $$ DELIMITER $$
CREATE DEFINER=`flags`@`localhost` PROCEDURE `insert_post`( CREATE DEFINER=`flags`@`localhost` PROCEDURE `insert_post`(
IN `@post_nr` INT, IN `@post_nr` INT,
@ -58,16 +42,11 @@ LANGUAGE SQL
NOT DETERMINISTIC NOT DETERMINISTIC
CONTAINS SQL CONTAINS SQL
SQL SECURITY DEFINER SQL SECURITY DEFINER
COMMENT ''
BEGIN BEGIN
INSERT IGNORE INTO `posts` (`post_nr`, `board`) VALUES (`@post_nr`, `@board`); INSERT IGNORE INTO `posts` (`post_nr`, `board`) VALUES (`@post_nr`, `@board`);
END END
$$ $$
DELIMITER ;
DROP PROCEDURE IF EXISTS insert_post_flags;
DELIMITER $$
CREATE DEFINER=`flags`@`localhost` PROCEDURE `insert_post_flags`( CREATE DEFINER=`flags`@`localhost` PROCEDURE `insert_post_flags`(
IN `@post_nr` INT, IN `@post_nr` INT,
IN `@flag` VARCHAR(100) IN `@flag` VARCHAR(100)
@ -76,7 +55,6 @@ LANGUAGE SQL
NOT DETERMINISTIC NOT DETERMINISTIC
CONTAINS SQL CONTAINS SQL
SQL SECURITY DEFINER SQL SECURITY DEFINER
COMMENT ''
BEGIN BEGIN
insert into postflags (post_nr, flag) VALUES ( insert into postflags (post_nr, flag) VALUES (
(select id from posts where post_nr = `@post_nr`), (select id from posts where post_nr = `@post_nr`),
@ -84,58 +62,39 @@ insert into postflags (post_nr, flag) VALUES (
); );
END END
$$ $$
DELIMITER ;
DROP PROCEDURE IF EXISTS rename_flag;
DELIMITER $$
CREATE DEFINER=`flags`@`localhost` PROCEDURE `rename_flag`( CREATE DEFINER=`flags`@`localhost` PROCEDURE `rename_flag`(
IN `@old` VARCHAR(100), IN `@old` VARCHAR(100),
IN `@new` VARCHAR(100) IN `@new` VARCHAR(100)
) )
LANGUAGE SQL LANGUAGE SQL
NOT DETERMINISTIC NOT DETERMINISTIC
CONTAINS SQL CONTAINS SQL
SQL SECURITY DEFINER SQL SECURITY DEFINER
COMMENT ''
BEGIN BEGIN
UPDATE flags SET flags.flag = `@new` WHERE flags.flag = `@old`; UPDATE flags SET flags.flag = `@new` WHERE flags.flag = `@old`;
END END
$$ $$
DELIMITER ;
DROP PROCEDURE IF EXISTS delete_flag;
DELIMITER $$
CREATE DEFINER=`flags`@`localhost` PROCEDURE `delete_flag`( CREATE DEFINER=`flags`@`localhost` PROCEDURE `delete_flag`(
IN `@flag` VARCHAR(100) IN `@flag` VARCHAR(100)
) )
LANGUAGE SQL LANGUAGE SQL
NOT DETERMINISTIC NOT DETERMINISTIC
CONTAINS SQL CONTAINS SQL
SQL SECURITY DEFINER SQL SECURITY DEFINER
COMMENT ''
BEGIN BEGIN
DELETE flags.* FROM flags WHERE flags.flag = `@flag`; DELETE flags.* FROM flags WHERE flags.flag = `@flag`;
END END
$$ $$
DELIMITER ;
DROP PROCEDURE IF EXISTS insert_flag;
DELIMITER $$
CREATE DEFINER=`flags`@`localhost` PROCEDURE `insert_flag`( CREATE DEFINER=`flags`@`localhost` PROCEDURE `insert_flag`(
IN `@flag` VARCHAR(100) IN `@flag` VARCHAR(100)
) )
LANGUAGE SQL LANGUAGE SQL
NOT DETERMINISTIC NOT DETERMINISTIC
CONTAINS SQL CONTAINS SQL
SQL SECURITY DEFINER SQL SECURITY DEFINER
COMMENT ''
BEGIN BEGIN
INSERT INTO `flags` (`flag`) VALUES (`@flag`); INSERT INTO `flags` (`flag`) VALUES (`@flag`);
END END

@ -0,0 +1,36 @@
events {
worker_connections 768;
}
http {
types {
text/html html htm shtm;
text/css css;
image/gif gif;
image/jpeg jpg jpeg;
image/png png;
}
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
charset utf-8;
index index.htm index.html;
server {
root /var/www/flags;
server_name flags.plum.moe;
listen 80;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_cache_bypass $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
}
}
}

@ -5,18 +5,19 @@ originally based on [[https://github.com/flaghunters/Extra-Flags-for-4chan][extr
[[https://flags.plum.moe/bantflags.user.js][Install bantflags]] [[https://flags.plum.moe/bantflags.user.js][Install bantflags]]
** Userscript ** Userscript
The userscript uses of =GM_xmlhttpRequest= to get and post flags with The userscript uses of ~GM_xmlhttpRequest~ to get and post flags with
the backend . A user's flags are stored between pages using the backend . A user's flags are stored between pages using
=GM_setValue= and =GM_getValue=. ~GM_setValue~ and ~GM_getValue~.
Old versions of GreaseMonkey will be able to recieve updates to the Old versions of GreaseMonkey will be able to recieve updates to the
script through the =@updateURL= and =@downloadURL= directives, though script through the ~@updateURL~ and ~@downloadURL~ directives, though
these were depricated sometime in GreaseMonkey 3.x and updates are these were depricated sometime in GreaseMonkey 3.x and updates are
only checked from the location the script was downloaded from so be only checked from the location the script was downloaded from so be
careful where you upload links. careful where you upload links.
On self hosting, changing =back_end= to your domain /should/ be all On self hosting, changing ~back_end~ to your domain /should/ be all
you need to do, but don't take this as fact. you need to do, but don't take this as fact. I haven't tested the
example nginx config.
The userscript has been designed specifically to target ECMAScript The userscript has been designed specifically to target ECMAScript
2015 (ES6), making liberal use of arrow functions, and const/let 2015 (ES6), making liberal use of arrow functions, and const/let
@ -43,56 +44,40 @@ declarations. Update your hecking browser.
2) Clone and build the BantFlags solution. 2) Clone and build the BantFlags solution.
3) Create the database using [[https://github.com/C-xC-c/BantFlags/blob/master/Environment/database.sql][database.sql]]. 3) Create the database using [[https://github.com/C-xC-c/BantFlags/blob/master/Environment/database.sql][database.sql]].
- *Change the password*. - *Change the password*.
4) configure =BantFlags/appsettings.example.json= with your connection 4) configure ~BantFlags/appsettings.example.json~ with your connection
string and webroot (where you'll serve the flags from *without a string and webroot (where you'll serve the flags from *without a
trailing slash*) and rename it to =appsettings.json= trailing slash*) and rename it to ~appsettings.json~
- See below for an example appsettings.json. - [[./BantFlags/appsettings.example.json][example appsettings.json]]
- ASP.NET Core applications look for a folder called =wwwroot= in - ASP.NET Core applications look for a folder called ~wwwroot~ in
the same directory as the application for static files. However the same directory as the application for static files. However
you can choose to logically seperate these by providing a vaild you can choose to logically seperate these by providing a vaild
directory to =webroot=. directory to ~webroot~.
- That is to say, if the bantflags application is in - That is to say, if the bantflags application is in
=/var/www/bantflags/BantFlags.dll=, the program will look for ~/var/www/bantflags/BantFlags.dll~, the program will look for
the folder =/var/www/bantflags/wwwroot/= to host static content, the folder ~/var/www/bantflags/wwwroot/~ to host static content,
or whatever directory is provided to =wwwroot=. or whatever directory is provided to ~wwwroot~.
5) If you're hosting on your GNU/Linux distribution of choice, Create a 5) If you're hosting on your GNU/Linux distribution of choice, Create a
folder called =keys= in the same directory as the bantflags folder called ~keys~ in the same directory as the bantflags
executable. executable.
- E.G. =/var/www/bantflags/keys/= - E.G. ~/var/www/bantflags/keys/~
- This is because ASP.NET Core uses some cryptic bullshit anti - This is because ASP.NET Core uses some cryptic bullshit anti
forgery token when processing HTML forms, and it's unable to forgery token when processing HTML forms, and it's unable to
persistantly store the decryption keys in memory on persistantly store the decryption keys in memory on
GNU/Linux. This directory will store said keys when you or GNU/Linux. This directory will store said keys when you or
users upload flags to /upload. The path uses users upload flags to /upload. The path uses
=AppDomain.CurrentDomain.BaseDirectory= internally, ~AppDomain.CurrentDomain.BaseDirectory~ internally,
I.E. wherever the program is. I.E. wherever the program is.
6) Add flags to the backend by uploading them to the flag console (/Upload). 6) Add flags to the backend by uploading them to the flag console (/Upload).
- Flags must be 16x11 pixels and under 15kb. Their names must not - Flags must be 16x11 pixels and under 15kb. Their names must not
exceed 100 characters and cannot contain either "||" or ",". exceed 100 characters and cannot contain either "||" or ",".
7) Configure your webserver of choice to forward requests to kestral 7) Configure your webserver of choice to forward requests to kestral
- [[https://github.com/C-xC-c/BantFlags/blob/master/Environment/nginx.conf][Example nginx config.]] - [[https://github.com/C-xC-c/BantFlags/blob/master/Environment/nginx.conf][Example nginx config.]]
8) Run with =dotnet BantFlags.dll= or create a service to run it as a 8) Run with ~dotnet BantFlags.dll~ or create a service to run it as a
daemon. daemon.
- [[https://github.com/C-xC-c/BantFlags/blob/master/Environment/bantflags.service][Example systemd service.]] - [[https://github.com/C-xC-c/BantFlags/blob/master/Environment/bantflags.service][Example systemd service.]]
9) ??? 9) ???
10) profit. 10) profit.
**** Example appsettings.json
#+BEGIN_SRC javascript
{
"dbconfig": {
"connectionstring": "Server=localhost;Port=3306;User ID=user;Password=password;Database=bantflags",
"poolsize": 2,
"boards": [
"bant",
"nap",
"srsbsn"
]
},
"webroot": "/var/www/html",
"staging-password": "supersecretpassword"
}
#+END_SRC
*** Database *** Database
Tables look like this: Tables look like this:
@ -109,13 +94,13 @@ Tables look like this:
| 1 | 1 | 1 | | 1 | 1 | 1 |
| 2 | 1 | 2 | | 2 | 1 | 2 |
| 2 | 2 | 2 | | 2 | 2 | 2 |
where post_nr and flag in *postflags* are the id fields in their where ~post_nr~ and ~flag~ in *postflags* are the id fields in their
respective tables. respective tables.
*** API *** API
The backend exposes three endpoints for the userscript to get and post The backend exposes three endpoints for the userscript to get and post
flags. Flags themselves are hosted from the =flags/= directory. This flags. Flags themselves are hosted from the ~flags/~ directory. This
will be whatever value you gave to =webroot= (or will be whatever value you gave to ~webroot~ (or
=/path/to/bantflags/wwwroot/= if no value is provided) + =flags/=. ~/path/to/bantflags/wwwroot/~ if no value is provided) + ~flags/~.
| route | purpse | | route | purpse |
|------------+--------------------------------------------| |------------+--------------------------------------------|
@ -126,7 +111,7 @@ will be whatever value you gave to =webroot= (or
** Backwards Compatibility ** Backwards Compatibility
The API is 1:1 compatable with all previous versions of The API is 1:1 compatable with all previous versions of
bantflags. Further improvements are achieved by encoding a =version= bantflags. Further improvements are achieved by encoding a ~version~
variable when poking endpoints which allows for breaking changes in variable when poking endpoints which allows for breaking changes in
the script and backend while guaranteeing data can be parsed on both the script and backend while guaranteeing data can be parsed on both
ends. See [[https://github.com/C-xC-c/BantFlags/tree/master/Docs/][Docs/{endpoint}]] for changes and compatibility. ends. See [[https://github.com/C-xC-c/BantFlags/tree/master/Docs/][Docs/{endpoint}]] for changes and compatibility.

Loading…
Cancel
Save