Commit graph

45 commits

Author SHA1 Message Date
Wolvan
04ed40608d Shamelessly shill my Ko-Fi
Maybe someone wants to help cover server costs I have to pay every month
2022-06-30 18:53:48 +02:00
Wolvan
c9ef07880a Fix IP Deduplication check behind proxy
Turns out using `X-Forwarded-For` appends each proxy's IP. This leads
to being able to easily circumvent IP duplication checking especially
behind hosts like cloudflare that use different routes each time to
reach the destination server.
Now the IP is being split at all commas, as hosts are comma separated in
the header and uses the first IP it can get.
2022-02-13 02:51:21 +01:00
Wolvan
8bf0155142 Fix multiple MySQL issues
The first issue is an invalid option to the MySQL connector in the form
of the table prefix. It instead gets set as a private prop on the
storage class and then removed from the options object.

The second and more important issue is that the field to store the
duplication check data ended up being too small too quickly, causing it
to quickly fail to write a full JSON string and leading to an error
while retrieving the poll. An `ALTER` statement during init is used to
make sure the datatype is now a `MEDIUMTEXT`. With 16MB it should fill
up way less quickly than previously.
2022-02-04 20:34:21 +01:00
Wolvan
f68ff6dbd2 Implement favicon and embbed icon
Thanks to Shydale for lending me their OC checkbox.
She a cute.
2022-02-02 22:13:07 +01:00
Wolvan
59a2733df6 Use git commit hash instead of version for dev
This way people can go straight to the commit that has caused the dev
page to be built and it is clear what version the site is based on.
2022-01-30 19:24:54 +01:00
Wolvan
ee4e83bebc Implement MySQL table prefix
The table prefix can be used to differentiate installs on the same
MySQL database. By default, no prefix is set.
2022-01-30 17:54:18 +01:00
Wolvan
59f1c7db6e Appease crawlers and embbeders
`<meta>` tags have been added to relay information for websites trying
to pull information from the page (like discord) as well as web crawlers
to index the page.
2022-01-30 17:46:59 +01:00
Wolvan
afc7bbad01 Implement header based safety features
Using the `helmet` package, a certain set of security critical headers
are set to prevent XSS attacks and the like.
2022-01-30 16:59:11 +01:00
Wolvan
26a42333fe Add QR Code to poll pages
This way, people can easily just use their QR readers to reach the
voting page. The QR is constructed via Google Charts API and the URL is
based on the HOST header of the request.
2022-01-30 16:49:05 +01:00
Wolvan
2f40091c6f Sort entries by votes
The entries on the result page are now ordered by the amount of
votes they got. This should make discerning a winner much easier.
2022-01-29 22:16:49 +01:00
Wolvan
cfa150cc42 Move API and document it
The API has been moved to a /api path to distinguish it from the form
submission path and make it clear it is a callable API.
The API also has been rudimentarily documented.
2022-01-12 21:11:09 +01:00
Wolvan
5260cfb7da Remove unecessary ID column
The strings are unique and do that job just fine.
2022-01-12 19:57:51 +01:00
Wolvan
ce2601642b Add version of software to footer
The version also includes a link to the github repo tag of that
version's release build.
2022-01-12 19:53:30 +01:00
Wolvan
ab151cb732 Use CSRF token to discourage botting
A suggestion to avoid stupid bots to vote on polls was a token that gets
checked to a session cookie on vote submission.
2022-01-12 19:46:45 +01:00
Wolvan
6a155f2eb4 Remove vote API
This could easily be used to rig votes and doesn't really make sense.
2022-01-12 19:20:59 +01:00
Wolvan
39d14aff1c Deduplicate entries
Duplicate entries were deduplicated during saving but not checked for
when verifying for at least 2 options set. This lead to being able to
have polls with only a single vote.
Now deduplication is run at the start of the creation function.
2022-01-11 22:04:10 +01:00
Wolvan
cb0ec9dfa1 Add non-JS way of adding options
A new button has been added (which gets automatically removed by JS)
that lets a user add a new option.
Also, an XSS exploit has been fixed.
2022-01-11 21:00:44 +01:00
Wolvan
1ad2c8c1a0 Fix SQL connection on wakeup in heroku
When a heroku dyno goes into sleep mode it loses connection to the
backend database. Once it is woken back up, no more reads or
writes could be done anymore due to a dead connection. This change
reinstates a new db connection when the connection is fatally
terminated.
2022-01-10 21:46:22 +01:00
Wolvan
bdf5ad1b1c Fix number parsing from replacer vars 2022-01-08 17:44:39 +01:00
Wolvan
74729b1e9c Add a couple more projects to the footer
As well as optimize the footer for small screens.
2022-01-08 16:23:27 +01:00
Wolvan
f403165f76 Prevent cross site scripting attacks 2022-01-08 16:16:40 +01:00
Wolvan
aee9ed796e Fix results page design
Fix the length of the bar when it is at 100% as well as an issue where
division by NaN happens when no votes have been given yet.
2022-01-08 16:15:46 +01:00
Wolvan
7887fa360b Fix votes from breaking server side rendering 2022-01-08 16:12:51 +01:00
Wolvan
0545d90c3f Implement different backend types
Including to the previous flatfile storage, a new storage for MySQL has
been added to store polls in a database.
The amount of possible Poll Options has also been reduced to 20.
2022-01-08 16:12:04 +01:00
Wolvan
df5b3e5c10 Fix copyright 2022-01-06 21:36:48 +01:00
Wolvan
927d2666e9 Satisfy tests to npm i doesn't fail 2022-01-06 21:28:32 +01:00
Wolvan
e9aaedb494 Implement auto update
Every 5 seconds the system attempts to fetch the most recent vote state
of the poll and display it to the user.
2022-01-06 20:44:29 +01:00
Wolvan
dca2cc3eeb Create results page
The page displays the amount of votes, percentage and bars for quick
visual comparison, as well as a pie chart created with google charts.
2022-01-06 19:52:53 +01:00
Wolvan
76b8d0bbc5 Allow voting via form 2022-01-06 15:31:17 +01:00
Wolvan
edff19fb5b Create voting page
This page displays all options that have been set on creation. Thanks to
`textFit` the texts in the title and options automatically get sized
correctly. The create poll button has also been renamed to submit-button
to make it more universal on other pages.
2022-01-04 22:25:05 +01:00
Wolvan
5b5dc9d922 Serverside render footer
This way it's easy to add new links or a changed copyright to the footer
on all pages.
2022-01-04 22:11:27 +01:00
Wolvan
c00ea29b4f Implement Form Expansion
If more than 3 options are written down, additional inputs will load in
to allow more options. The maximum cap of options currently is set to
255 but can be configured in Config.ts.
Likewise, the input length can also be controlled from there.
2022-01-01 14:36:25 +01:00
Wolvan
3287260962 Disable qs library
Being able to pass JSON objects in a query string is unneeded and
possibly insecure, thus should be avoided if possible.
2022-01-01 13:13:38 +01:00
Wolvan
9fa3eabad1 Make frontend js-less
The frontend should work without having JS enabled. JS will enhance the
experience but should under no circumstance be necessary.
To achieve this, the entire entry system has been turned into a form
that posts its values to a new backend path specifically made to take
form responses. Instead of returning an API response, it also redirects
the browser to either the voting page on successful creation or the
frontpage with a bunch of get parameters that are used to prefill the
form in a server-side rendering process.
An error parameter is also given but there is no way to display said
error for now.
2022-01-01 04:13:24 +01:00
Wolvan
2f41df7264 Allow only 300 characters max
This prevents people from going crazy with gigabytes of data.
2021-12-29 19:26:07 +01:00
Wolvan
e83766309a First steps towards functional frontend
Polls and their results can now be accessed as long as they are found on
the backend.
2021-12-29 18:21:22 +01:00
Wolvan
1507ea6d33 Fix config loading of boolean values
Setting values from config is a little tricky, but I think this makes it
work properly now.
2021-12-29 17:04:23 +01:00
Wolvan
16ca2ee8b1 Fix relative pathing issues
Running from a subdirectory makes the entire script a bit cumbersome
to wrap around when it comes to relative paths. They should now all work
properly though.
Paths that are relative to the Project Root now work as expected (eg.
package.json path) and other paths like the data and config path are
based on the current execution directory.
2021-12-29 15:25:43 +01:00
Wolvan
8a304c763b Only save valid options
Empty options are not valid options
2021-12-29 14:24:33 +01:00
Wolvan
d383d501f1 Ignore casing in dupe check mode 2021-12-29 14:23:34 +01:00
Wolvan
584d0092d8 Avoid ambigous characters in IDs
The issue with ambigous characters is that they are hard to write
when only seeing them, as one could confuse 0 for O with certain
typefaces for example.
Ambiguity is lessened by removing `Oo0Iil1` from the possible charset.
In order to keep a big enough pool of IDs the ID length changed from 6
to 8 characters instead, which seems like an OK tradeoff.
2021-12-29 14:13:35 +01:00
Wolvan
9d80a009ca Create rudimentary poll backend
This is currently untested, but the backend allows creating a new poll,
getting results of an existing poll, voting and retrieving info of a
poll for display purposes.
Recaptcha is not yet implemented at this stage.
2021-12-29 01:02:18 +01:00
Wolvan
8c3001042b Build frontend loader system
A custom server-side renderer is used to deliver pages to the client
with values defined on load. This makes templating easier.
2021-12-28 23:49:18 +01:00
Wolvan
1031a4c36f Implement backend and frontend loading
This system lets a server modularly load backend and frontend and allows
hosting each of the parts on separate services.
2021-12-28 23:47:30 +01:00
Wolvan
8bc3f7fe36 Initial commit
This code serves as an application framework of sorts and is totally not
stolen from some of my other projects.
2021-12-28 21:11:19 +01:00