├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── bin ├── start.js └── test.js ├── doc └── stats-pinchito.es-2023-10-03.html ├── lib ├── core │ ├── counter.js │ ├── domain.js │ ├── env.js │ ├── format.js │ └── stats.js ├── db │ ├── counter.js │ ├── mongo.js │ ├── query.js │ └── stats.js ├── page │ ├── common.js │ ├── home.js │ ├── options.js │ └── stats.js └── server │ ├── counter.js │ ├── file.js │ ├── home.js │ ├── ping.js │ ├── setup.js │ └── stats.js ├── package.json ├── public ├── favicon.png ├── img │ ├── isologo-brown.svg │ ├── isologo-orange.svg │ ├── isologo-white.svg │ ├── isologo-yellow.svg │ ├── old-style.svg │ ├── outline-brown.svg │ ├── outline-orange.svg │ ├── outline-white.svg │ ├── outline-yellow.svg │ ├── solid-brown.svg │ ├── solid-orange.svg │ ├── solid-yellow.svg │ ├── white-brown.svg │ ├── white-orange.svg │ └── white-yellow.svg └── main.css └── test ├── api.js ├── counter.js ├── domain.js ├── pages.js └── setup.js /.eslintrc: -------------------------------------------------------------------------------- 1 | --- 2 | env: 3 | node: true 4 | mocha: true 5 | es6: true 6 | extends: eslint:recommended 7 | parserOptions: 8 | sourceType: module 9 | ecmaVersion: 14 10 | rules: 11 | no-inner-declarations: 0 12 | no-unused-vars: 13 | - error 14 | - args: after-used 15 | no-console: 0 16 | no-constant-condition: 0 17 | indent: 18 | - error 19 | - tab 20 | max-len: 21 | - off 22 | - tabWidth: 4 23 | linebreak-style: 24 | - error 25 | - unix 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | package-lock.json 45 | 46 | # Snowpack dependency directory (https://snowpack.dev/) 47 | web_modules/ 48 | 49 | # TypeScript cache 50 | *.tsbuildinfo 51 | 52 | # Optional npm cache directory 53 | .npm 54 | 55 | # Optional eslint cache 56 | .eslintcache 57 | 58 | # Optional stylelint cache 59 | .stylelintcache 60 | 61 | # Microbundle cache 62 | .rpt2_cache/ 63 | .rts2_cache_cjs/ 64 | .rts2_cache_es/ 65 | .rts2_cache_umd/ 66 | 67 | # Optional REPL history 68 | .node_repl_history 69 | 70 | # Output of 'npm pack' 71 | *.tgz 72 | 73 | # Yarn Integrity file 74 | .yarn-integrity 75 | 76 | # dotenv environment variable files 77 | .env 78 | .env.development.local 79 | .env.test.local 80 | .env.production.local 81 | .env.local 82 | 83 | # parcel-bundler cache (https://parceljs.org/) 84 | .cache 85 | .parcel-cache 86 | 87 | # Next.js build output 88 | .next 89 | out 90 | 91 | # Nuxt.js build / generate output 92 | .nuxt 93 | dist 94 | 95 | # Gatsby files 96 | .cache/ 97 | # Comment in the public line in if your project uses Gatsby and not Next.js 98 | # https://nextjs.org/blog/next-9-1#public-directory-support 99 | # public 100 | 101 | # vuepress build output 102 | .vuepress/dist 103 | 104 | # vuepress v2.x temp and cache directory 105 | .temp 106 | .cache 107 | 108 | # Docusaurus cache and generated files 109 | .docusaurus 110 | 111 | # Serverless directories 112 | .serverless/ 113 | 114 | # FuseBox cache 115 | .fusebox/ 116 | 117 | # DynamoDB Local files 118 | .dynamodb/ 119 | 120 | # TernJS port file 121 | .tern-port 122 | 123 | # Stores VSCode versions used for testing VSCode extensions 124 | .vscode-test 125 | 126 | # yarn v2 127 | .yarn/cache 128 | .yarn/unplugged 129 | .yarn/build-state.yml 130 | .yarn/install-state.gz 131 | .pnp.* 132 | 133 | # private files 134 | private 135 | 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Logo for librecounter 2 | 3 | # LibreCounter Stats 4 | 5 | Free, libre and open website statistics. 6 | GDPR compliant: no cookies, no tracking done in the browser, 7 | no IP addresses stored, no marketing or advertising done (or even possible). 8 | 9 | LibreCounter provides website traffic analysis and statistics for free at 10 | [librecounter.org](https://librecounter.org/). 11 | 12 | ## How to Use 13 | 14 | Simply add the following snippet to your website, 15 | in all pages that you want analyzed: 16 | 17 | ```html 18 | 19 | 20 | 21 | ``` 22 | 23 | After that stats will be collected for every page view, 24 | and users clicking on the logo will be taken to 25 | [https://librecounter.org/[site]/show](https://librecounter.org/[site]/show) 26 | replacing `[site]` with your domain name. 27 | Stats will be public for all your visitors to see. 28 | 29 | ![Example stats using LibreCounter.](https://github.com/alexfernandez/librecounter/assets/876570/b32839b4-369a-4e86-801e-ce034f2920f1) 30 | 31 | That is it! No configuration needed on the server at all. 32 | You can see an example on [the author's blog](https://pinchito.es/). 33 | 34 | Technical details: the `referrerPolicy` is added to make sure that the browser sends the whole page URL to the server, 35 | otherwise sometimes it only sends the website (as `https://example.org/`) 36 | so LibreCounter cannot know which page the user is visiting. 37 | 38 | Keep in mind that stats are still open for anyone that knows that you are using it, 39 | by following the link to https://librecounter.org/[example.org]/show. 40 | There is currently no way to make the stats private. 41 | If you want to hide stats for a sensitive domain 42 | (like an integration domain you don't want to show), 43 | please let [the author](https://github.com/alexfernandez/) 44 | know to add it to the hide list so that stats are not stored at all. 45 | 46 | There are a host of visualiation options on the [official website](https://librecounter.org/options). 47 | 48 | ## API 49 | 50 | The API allows you to count visits and to get stats. 51 | 52 | ### `/count` 53 | 54 | If you want to count a visit but don't want to add an image, 55 | or just cannot, 56 | you can use the endpoint `/count`. For instance: 57 | 58 | https://librecounter.org/count?url=http://example.org/mypage&userAgent=roboto/1.0 59 | 60 | Invoking this endpoint will count as a visit to the site `example.org`, page `/mypage`, 61 | with userAgent `roboto/1.0`. 62 | You can in fact use whatever programming language to invoke the endpoint, 63 | even a simple `wget` will do: 64 | 65 | ```shell 66 | wget https://librecounter.org/count?url=http://example.org/mypage&userAgent=roboto/1.0 67 | ``` 68 | 69 | Be sure to URL-encode the URL and user agent parameters or they will be chopped up as part of the query string. 70 | 71 | ### `/[site]/siteStats` 72 | 73 | Get stats for your site. Replace `[site]` with the domain for your site like `example.org`. 74 | For instance: 75 | 76 | https://librecounter.org/example.org/siteStats 77 | 78 | Parameters: 79 | 80 | * `days`: number of last days to get, default 30. 81 | 82 | ### `/[site]/pageStats` 83 | 84 | Get stats for a single page of your site. Replace `[site]` with the domain for your site like `example.org`, 85 | and add a `page` parameter. 86 | For instance: 87 | 88 | https://librecounter.org/example.org/pageStats?page=/ 89 | 90 | Parameters: 91 | 92 | * `page`: the page to get, mandatory. 93 | * `days`: number of last days to get, default 30. 94 | 95 | ## The Project 96 | 97 | It's a simple project with less than 1000 lines of code on 2024-01-14. 98 | It uses the free IP database from Maxmind via 99 | [`geoip-lite`](https://npmjs.com/package/geoip-lite), 100 | and the awesome package [`node-device-detector`](https://www.npmjs.com/package/node-device-detector). 101 | No data is leaked outside as all lookups are done locally. 102 | 103 | ### Server Installation 104 | 105 | To run your own instance simply download the repo and install all dependencies: 106 | 107 | ```shell 108 | git clone https://github.com/alexfernandez/librecounter 109 | npm install 110 | npm start 111 | ``` 112 | 113 | That should do it! 114 | For no-hassle use please use the [official website](https://librecounter.org/). 115 | 116 | ### Server Configuration 117 | 118 | You can create a file `.env` and add it at the root of the project, 119 | with the following variables in the usual [dotenv format](https://www.npmjs.com/package/dotenv): 120 | 121 | * `BACKEND_MONGODB_URL`: URL to connect to MongoDB including password, 122 | default value: `mongodb://localhost:27017/librecounter`. 123 | * `BACKEND_DOMAIN_HIDELIST`: comma-separated list of domains to hide: 124 | not store or show stats at all. Default value: empty string. 125 | 126 | ## Analytics, Counter or Tracking? 127 | 128 | LibreCounter is a small step beyond the old website counters 129 | that kept track of how many people had visited to your website. 130 | It stores analytics for those visitors: 131 | by day, page, country of origin, browser and OS. 132 | 133 | LibreCounter performs **no tracking**: it does not keep track of what visitors did on your site, 134 | just counts independent visits to each page. 135 | IP addresses or user agents are not correlated between page visits. 136 | In particular, IP addresses and user agents are not stored at all. 137 | 138 | ## Data Stored 139 | 140 | In case you want to audit what data is stored per page view, 141 | all technical details are in 142 | [the class `Counter`](https://github.com/alexfernandez/librecounter/blob/main/lib/core/counter.js): 143 | 144 | * day of the view (as 2023-10-06), 145 | * country of origin (as read from the IP address by [geoip-lite](https://www.npmjs.com/package/geoip-lite)), 146 | * site and page visited, 147 | * type of device (desktop, smartphone, tablet..), 148 | * browser used (Chrome, Firefox, Safari...), 149 | * operating system (Windows, GNU/Linux, Android...), 150 | * and platform (x64, x32, amd...). 151 | 152 | That is it! 153 | The package [geoip-lite](https://www.npmjs.com/package/geoip-lite) 154 | is used for reading the country locally: no data leaves the server. 155 | For device identification the package 156 | [node-device-detector](https://www.npmjs.com/package/node-device-detector) 157 | is used, again locally so no data leaves the server. 158 | 159 | ## Help Wanted 160 | 161 | If you want the package to support your favorite feature please open a merge request. 162 | 163 | ## Known Limitations 164 | 165 | Some characters can be modified in pages when displayed: 166 | the small dollar sign `﹩` is replaced by the regular dollar sign `$`, 167 | and the leading dot `․` by the regular dot `.'. 168 | This is done to sidestep 169 | [limitations in MongoDB field names](https://stackoverflow.com/questions/12397118/mongodb-dot-in-key-name). 170 | 171 | # Rationale 172 | 173 | The idea of creating free and open stats came after the GDPR: 174 | it became quite obnoxious to add something like Google Analytics to your webpage, 175 | with the cookie warning. 176 | Also Google Analytics became more and more obnoxious itself, 177 | to the point where it looks like Google is not interested in having people use their free product. 178 | 179 | Other tools are usually expensive, 180 | and still have in-browser tracking. 181 | Sadly neither [GitHub](https://github.com/orgs/community/discussions/31474) 182 | nor [Gitlab](https://gitlab.com/gitlab-org/gitlab-pages/-/issues/189) 183 | provide server-side analytics. 184 | 185 | LibreCounter does server-side analytics, 186 | no cookies, free software, open for everyone to use. 187 | 188 | ## ePrivacy Directive 189 | 190 | The [ePrivacy directive](https://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX%3A32002L0058) 191 | of 2002 is even more strict than the GDPR. 192 | In article 6 it states that traffic data should be deleted or anonymized right away. 193 | LibreCounter does not store traffic data (user agent, IP address), 194 | just anonymized aggregates. 195 | 196 | ## Guarantees 197 | 198 | The code is running on a private server using Linode (now Akamai). 199 | There are no guarantees of any kind: 200 | I intend to provide this service to the community as long as I am able to do it. 201 | However, if your use case requires it I may provide a full code audit to verify the running code. 202 | 203 | Since you are just adding an external image you should not have any GDPR obligations, 204 | the operator of the private server does (i.e. myself). 205 | Always a good idea to consult with your lawyers if you want to be sure though. 206 | 207 | 208 | You can bring up your own instance since the code is completely free. 209 | 210 | ## Eye of Horus 211 | 212 | The logo is a play on the [eye of Horus](https://en.wikipedia.org/wiki/Eye_of_Horus), 213 | to give you special powers of observation 214 | and at the same time bring protection to your website against the GDPR. 215 | It also helps ward off from people trying to profit from your visitors. 216 | 217 | ## Copyright 218 | 219 | (C) 2023 Alex Fernández and [contributors](https://github.com/alexfernandez/librecounter/graphs/contributors). 220 | Visual identity contributed by [Fullcircle](https://fullcircle.es/). 221 | Licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html), 222 | which in a nutshell means that you should make the code public if you distribute it. 223 | No need to do anything if you just run it on your own website. 224 | 225 | -------------------------------------------------------------------------------- /bin/start.js: -------------------------------------------------------------------------------- 1 | import Fastify from 'fastify' 2 | import setup from '../lib/server/setup.js' 3 | 4 | 5 | async function start() { 6 | const app = Fastify({ 7 | logger: { 8 | level: 'info', 9 | }, 10 | }) 11 | try { 12 | await setup(app) 13 | await app.listen({port: 11893, host: '0.0.0.0'}) 14 | } catch (error) { 15 | app.log.error(error) 16 | process.exit(1) 17 | } 18 | } 19 | 20 | start() 21 | 22 | -------------------------------------------------------------------------------- /bin/test.js: -------------------------------------------------------------------------------- 1 | import testApi from '../test/api.js' 2 | import testPages from '../test/pages.js' 3 | import testCounter from '../test/counter.js' 4 | import testDomains from '../test/domain.js' 5 | import {close} from '../lib/db/mongo.js' 6 | 7 | await testApi() 8 | await testPages() 9 | await testCounter() 10 | await testDomains() 11 | await close() 12 | 13 | -------------------------------------------------------------------------------- /doc/stats-pinchito.es-2023-10-03.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LibreCounter stats for pinchito.es 5 | 6 | 7 | 8 | 9 | 10 | 11 |

LibreCounter stats for pinchito.es

12 |

Stats per day

13 | 2023-10-01: 21
2023-10-02: 176
2023-10-03: 70 14 |

Stats per page

15 | /: 180
/2012/developer-discipline: 2
/2012/performance-review: 1
/2012/reporting-problems-part-2: 1
/2013/human-body-engineered-system: 1
/2013/modo-cluster: 1
/2013/nodejs-rapido-como-el-rayo: 2
/2013/pruebas-de-carga: 3
/2016/nginx-balancer: 1
/2017/origins-language: 1
/2018/more-golang-adventures: 1
/2019/high-speeds: 1
/2020/curso-escalabilidad: 1
/2020/curso-escalabilidad-2: 3
/2020/insane-plane-prices: 1
/2020/repaso-propositos: 1
/2021/repaso-propositos-2020: 1
/2021/understanding-einstein: 2
/2022/building-bridges: 1
/2022/propositos-2022: 1
/2023/climate-change-screens: 1
/2023/job-search: 50
/2023/propositos-2023: 1
/2023/una-vida-sin-fisuras: 3
/about: 1
/cv: 5 16 |

Stats per country

17 | AE: 2
AR: 1
AU: 1
BO: 1
BR: 1
CA: 1
CL: 1
CO: 4
CZ: 1
DE: 6
ES: 139
FR: 2
GB: 4
IE: 1
IL: 8
IT: 1
MX: 2
PK: 1
RO: 12
TH: 1
US: 75 18 |

Stats per browser

19 | Android Browser: 1
Chrome: 156
Chrome Mobile: 24
Chrome Mobile iOS: 1
DuckDuckGo Privacy Browser: 2
Firefox: 4
Firefox Mobile: 1
Headless Chrome: 1
LinkedIn: 12
Microsoft Edge: 1
MIUI Browser: 3
Mobile Safari: 6
Samsung Browser: 1
Twitter: 1 20 |

Stats per OS

21 | Android: 32
GNU/Linux: 25
iOS: 20
Mac: 47
Windows: 89 22 | 23 | 24 | Fork me on GitHub 25 | 26 | 27 | -------------------------------------------------------------------------------- /lib/core/counter.js: -------------------------------------------------------------------------------- 1 | import geoip from 'geoip-lite' 2 | import DeviceDetector from 'node-device-detector' 3 | 4 | const detector = new DeviceDetector({ 5 | clientIndexes: true, 6 | deviceIndexes: true, 7 | deviceAliasCode: false, 8 | }) 9 | 10 | 11 | export class Counter { 12 | constructor(ip, headers) { 13 | this.day = this.getDay() 14 | const {country} = this.lookupGeoip(ip, headers) 15 | this.stats = {country} 16 | const referer = headers['referer'] 17 | this.setReferer(referer) 18 | const userAgent = headers['user-agent'] 19 | this.setUserAgent(userAgent) 20 | } 21 | 22 | getDay() { 23 | const timestamp = new Date() 24 | return timestamp.toISOString().substring(0, 10) 25 | } 26 | 27 | setReferer(referer) { 28 | if (!referer) { 29 | return 30 | } 31 | const url = new URL(referer) 32 | this.site = url.host 33 | this.page = url.pathname 34 | } 35 | 36 | setUserAgent(userAgent) { 37 | if (!userAgent) { 38 | return 39 | } 40 | const device = this.getDevice(userAgent) 41 | // transfer to stats 42 | for (const key in device) { 43 | this.stats[key] = device[key] 44 | } 45 | } 46 | 47 | getDevice(userAgent) { 48 | if (!userAgent) { 49 | return null 50 | } 51 | const device = detector.detect(userAgent) 52 | return { 53 | type: device.device.type, 54 | os: device.os.name, 55 | platform: device.os.platform, 56 | browser: device.client.name, 57 | } 58 | } 59 | 60 | lookupGeoip(ip, headers) { 61 | if (ip != '127.0.0.1') { 62 | return geoip.lookup(ip) 63 | } 64 | const realIp = headers['x-real-ip'] 65 | if (!realIp) { 66 | return {} 67 | } 68 | return geoip.lookup(realIp) 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /lib/core/domain.js: -------------------------------------------------------------------------------- 1 | import {} from './env.js' 2 | 3 | const domainHideList = process.env['BACKEND_DOMAIN_HIDELIST'] || '' 4 | const domainsToHide = domainHideList.split(',') 5 | 6 | 7 | export function isDomainHidden(domain) { 8 | if (domainsToHide.includes(domain)) { 9 | return true 10 | } 11 | if (domain.startsWith('localhost:')) { 12 | return true 13 | } 14 | if (domain.startsWith('127.0.0.1')) { 15 | return true 16 | } 17 | return false 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lib/core/env.js: -------------------------------------------------------------------------------- 1 | import dotenv from 'dotenv' 2 | 3 | dotenv.config() 4 | 5 | -------------------------------------------------------------------------------- /lib/core/format.js: -------------------------------------------------------------------------------- 1 | 2 | const maxLabelLength = 30 3 | const maxStats = 10 4 | 5 | 6 | export function encodePage(page) { 7 | if (!page) { 8 | return null 9 | } 10 | return page.replaceAll('.', '․').replaceAll('$', '﹩') 11 | } 12 | 13 | export function decodePage(page) { 14 | if (!page) { 15 | return null 16 | } 17 | return page.replaceAll('﹩', '$').replaceAll('․', '.') 18 | } 19 | 20 | export function shorten(label) { 21 | if (!label) { 22 | return '' 23 | } 24 | if (label.length <= maxLabelLength) { 25 | return label 26 | } 27 | return label.substring(0, maxLabelLength) + '…' 28 | } 29 | 30 | 31 | export function getTop10(stats) { 32 | stats.sort((a, b) => b.value - a.value) 33 | return { 34 | sites: getSites(stats), 35 | labels: getLabels(stats), 36 | data: getData(stats), 37 | } 38 | } 39 | 40 | function limitTop10(array) { 41 | return array.slice(0, maxStats) 42 | } 43 | 44 | function getSites(stats) { 45 | const sites = stats.map(site => site.key) 46 | if (sites.length <= maxStats) { 47 | return sites 48 | } 49 | return [... limitTop10(sites), '…rest'] 50 | } 51 | 52 | function getLabels(stats) { 53 | return getSites(stats).map(shorten) 54 | } 55 | 56 | function getData(stats) { 57 | const data = stats.map(site => site.value) 58 | if (data.length <= maxStats) { 59 | return data 60 | } 61 | const sum = data.slice(maxStats).reduce((a, b) => a + b) 62 | return [... limitTop10(data), sum] 63 | } 64 | 65 | -------------------------------------------------------------------------------- /lib/core/stats.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export class Stats { 4 | constructor() { 5 | this.total = 0 6 | this.byDay = [] 7 | } 8 | 9 | addDay(day, value) { 10 | this.byDay.push({day, value}) 11 | this.total += value 12 | } 13 | 14 | addBySection(section, key, value) { 15 | if (!key) { 16 | return 17 | } 18 | if (typeof value == 'object') { 19 | // at one point the value was stored as an object due to a bug 20 | return 21 | } 22 | const name = 'by' + section.substring(0, 1).toUpperCase() + section.substring(1) 23 | if (!this[name]) { 24 | this[name] = {} 25 | } 26 | const bySection = this[name] 27 | if (typeof bySection != 'object') { 28 | // at one point it was stored as a number due to a bug 29 | return 30 | } 31 | bySection[key] = (bySection[key] || 0) + value 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /lib/db/counter.js: -------------------------------------------------------------------------------- 1 | import {upsertOne} from './mongo.js' 2 | import {isDomainHidden} from '../core/domain.js' 3 | import {encodePage} from '../core/format.js' 4 | 5 | 6 | export async function storeCounter(counter) { 7 | if (!counter.site || !counter.page) { 8 | console.log('Missing site or page') 9 | return 10 | } 11 | if (isDomainHidden(counter.site)) { 12 | console.log(`Domain ${counter.site} is hidden`) 13 | return 14 | } 15 | const update = {total: 1} 16 | for (const field in counter.stats) { 17 | const value = counter.stats[field] 18 | if (value) { 19 | const key = `${field}:${value}` 20 | update[key] = 1 21 | } 22 | } 23 | const page = encodePage(counter.page) 24 | const pageKey = `page:${page}` 25 | const updateWithPage = {...update, [pageKey]: 1} 26 | await upsertOne('sites', {site: counter.site, day: counter.day}, {$inc: updateWithPage}) 27 | await upsertOne('pages', {site: counter.site, day: counter.day, page: counter.page}, {$inc: update}) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lib/db/mongo.js: -------------------------------------------------------------------------------- 1 | import {MongoClient} from 'mongodb' 2 | import {} from '../core/env.js' 3 | 4 | let client 5 | const db = getDb() 6 | 7 | 8 | function getDb() { 9 | const connectionString = process.env['BACKEND_MONGODB_URL'] || 'mongodb://localhost:27017/librecounter' 10 | client = new MongoClient(connectionString, {maxPoolSize: 4}) 11 | return client.db('librecounter') 12 | } 13 | 14 | export async function createIndex(name, index) { 15 | await db.collection(name).createIndex(index) 16 | } 17 | 18 | export async function insertOne(name, value) { 19 | const collection = db.collection(name) 20 | return await collection.insertOne(value) 21 | } 22 | 23 | export async function upsertOne(name, query, value) { 24 | const collection = db.collection(name) 25 | return await collection.updateOne(query, value, {upsert: true}) 26 | } 27 | 28 | export async function findAll(name, query, projection) { 29 | const collection = db.collection(name) 30 | return await collection.find(query, {projection}).toArray() 31 | } 32 | 33 | export async function findOne(name, query, projection) { 34 | const collection = db.collection(name) 35 | return await collection.findOne(query, {projection}) 36 | } 37 | 38 | export async function close() { 39 | await client.close() 40 | } 41 | 42 | -------------------------------------------------------------------------------- /lib/db/query.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export class SiteQuery { 4 | constructor(site, days) { 5 | this.site = site 6 | this.days = days 7 | } 8 | 9 | setLastDays(offset) { 10 | this.startDay = getDay(-offset) 11 | } 12 | 13 | getQuery() { 14 | const startDay = getDay(-this.days) 15 | const endDay = getDay(1) 16 | return { 17 | site: this.site, 18 | day: { 19 | $gt: startDay, 20 | $lt: endDay, 21 | } 22 | 23 | } 24 | } 25 | } 26 | 27 | export class PageQuery extends SiteQuery { 28 | constructor(site, page, days) { 29 | super(site, days) 30 | this.page = page 31 | } 32 | 33 | getQuery() { 34 | const query = super.getQuery() 35 | query.page = this.page 36 | return query 37 | } 38 | } 39 | 40 | export function getDay(diff) { 41 | const date = new Date() 42 | if (diff) { 43 | date.setDate(date.getDate() + diff) 44 | } 45 | return date.toISOString().substring(0, 10) 46 | } 47 | 48 | -------------------------------------------------------------------------------- /lib/db/stats.js: -------------------------------------------------------------------------------- 1 | import {createIndex, findAll, findOne} from './mongo.js' 2 | import {getDay} from './query.js' 3 | import {isDomainHidden} from '../core/domain.js' 4 | import {decodePage} from '../core/format.js' 5 | import {Stats} from '../core/stats.js' 6 | 7 | 8 | await init() 9 | 10 | async function init() { 11 | await createIndex('sites', {site: 1, day: 1}) 12 | await createIndex('pages', {site: 1, day: 1, page: 1}) 13 | } 14 | 15 | export async function readLatestSites() { 16 | const day = getDay() 17 | const all = await findAll('sites', {day}, {site: 1, total: 1}) 18 | const filtered = all.filter(stats => !isDomainHidden(stats.site)) 19 | return filtered.map(stats => ({key: stats.site, value: stats.total})) 20 | } 21 | 22 | export async function readSiteStats(query) { 23 | if (isDomainHidden(query.site)) { 24 | return new Stats() 25 | } 26 | const array = await findAll('sites', query.getQuery()) 27 | return buildStats(array) 28 | } 29 | 30 | function buildStats(array) { 31 | const stats = new Stats() 32 | for (const element of array) { 33 | stats.addDay(element.day, element.total) 34 | for (const field in element) { 35 | const [section, key] = readSectionKey(field) 36 | stats.addBySection(section, key, element[field]) 37 | } 38 | } 39 | return stats 40 | } 41 | 42 | export async function readPageStats(query) { 43 | if (isDomainHidden(query.site)) { 44 | return new Stats() 45 | } 46 | const array = await findAll('pages', query.getQuery()) 47 | return buildStats(array) 48 | } 49 | 50 | function readSectionKey(field) { 51 | const parts = field.split(':') 52 | if (parts.length < 2) { 53 | return [field, null] 54 | } 55 | const key = parts[0] 56 | const value = parts.slice(1).join(':') 57 | if (key != 'page') { 58 | return [key, value] 59 | } 60 | return [key, decodePage(value)] 61 | } 62 | 63 | export async function readVisitorToday(site) { 64 | const day = getDay() 65 | const {total} = await findOne('sites', {day, site}, {total: 1}) || {} 66 | return total || 0 67 | } 68 | 69 | -------------------------------------------------------------------------------- /lib/page/common.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export function createHead(title) { 4 | return ` 5 | 6 | 7 | 8 | 9 | ${title} 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | ` 20 | } 21 | 22 | export function createFooter() { 23 | return ` 24 | 31 | 32 | 33 | ` 34 | } 35 | 36 | function configureChartJs() { 37 | return `Chart.register(ChartDataLabels) 38 | const plugin = { 39 | id: 'background', 40 | beforeDraw: (chart, args, opts) => { 41 | if (!opts.color) { 42 | return; 43 | } 44 | const {ctx, chartArea} = chart; 45 | ctx.fillStyle = opts.color; 46 | ctx.fillRect(chartArea.left, chartArea.top, chartArea.width, chartArea.height) 47 | } 48 | } 49 | Chart.register(plugin)` 50 | } 51 | 52 | -------------------------------------------------------------------------------- /lib/page/home.js: -------------------------------------------------------------------------------- 1 | import {getTop10} from '../core/format.js' 2 | import {createHead, createFooter} from './common.js' 3 | 4 | 5 | export function createHome(latestSites) { 6 | const {sites, labels, data} = getTop10(latestSites) 7 | const barHeight = 25 8 | const height = (barHeight + 15) * (data.length + 1) 9 | return `${createHead('LibreCounter Stats')} 10 |
11 | 14 |

15 | GDPR Compliant Analytics for your Site 16 |

17 |

18 | Free, libre, open source 19 | analytics for your site. 20 | No installation or configuration required. 21 |

22 |
23 |
24 |

Top Sites Today

25 |
26 |
27 |
28 | 29 |
30 |
31 |
32 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | ${createRows(sites, data)} 85 | 86 |
SitePage views
87 |

How to Use

88 |

89 | Add the following HTML snippet to your site: 90 |

91 | 95 |

96 | That's it! 97 | Your stats will start to be collected with every page view. 98 | When a user clicks on the LibreCounter logo they will be taken to the stats collected 99 | at https://librecounter.org/[site]/show, 100 | where [site] is your domain name (e.g. example.org). 101 |

102 |

103 | There are more options available. 104 |

105 | 106 |

Compliance

107 |

108 | LibreCounter is GDPR compliant by default: no browser tracking done, 109 | no IPs or user agents stored anywhere. 110 |

111 |

112 | Since no cookies are used you don't need to add a disclaimer to your site. 113 |

114 |
115 | ${createFooter()}` 116 | } 117 | 118 | function createRows(sites, data) { 119 | const rows = [] 120 | for (let index = 0; index < sites.length; index++) { 121 | const label = sites[index] 122 | const row = ` 123 | 124 | ${label == '…rest' ? label : `${sites[index]}`} 125 | 126 | ${data[index]} 127 | ` 128 | rows.push(row) 129 | } 130 | return rows.join('\n') 131 | } 132 | 133 | -------------------------------------------------------------------------------- /lib/page/options.js: -------------------------------------------------------------------------------- 1 | import {createHead, createFooter} from './common.js' 2 | 3 | 4 | export function createOptions() { 5 | return `${createHead('LibreCounter Options')} 6 |
7 | 11 |

12 | Analytics Options 13 |

14 |

15 | There are a few visualization and accounting options that you can control. 16 |

17 |
18 | 19 |
20 |

Default

21 |

22 | The default style is to show a logotype 23 | (technically an isotype), 24 | with brown background and white symbols. 25 | To use it, simply add the following HTML snippet to your site: 26 |

27 | 31 | 32 |

33 | The "unsafe-url" referrer policy is there to make sure that the browser 34 | sends the whole referrer to LibreCounter, 35 | so it can do its thing and attribute the page correctly. 36 |

37 | 38 |

Color and Style

39 |

40 | To match your site better you can choose from a variety of colors, 41 | all within the Egyptian theme: 42 | brown, orange, yellow and sometimes white. 43 | You can also pick your favorite style. 44 |

45 |

46 | solid (default): 47 | 48 | 49 | 50 |

51 | 52 |

53 | white: 54 | 55 | 56 | 57 |

58 | 59 |

60 | outline: 61 | 62 | 63 | 64 | 65 |

66 | 67 |

isologo: 68 | 69 | 70 | 71 |

72 | 73 |

74 | To add to your site just pick style and color and join them with a dash: 75 | [style]-[color].svg, 76 | and use this instead of counter.svg. 77 | E.g. outline-orange.svg will give you an outline in orange: 78 |

79 | 83 | 84 |

Old Style Counter

85 |

86 | This style is an homage to old-time counters, 87 | but with LibreCounter stats. 88 |

89 | 90 |

91 | Watch the counter grow every time you reload the page! 92 |

93 |

94 | To use it, simply add the following HTML snippet to your site: 95 |

96 | 100 | 101 |

Unique Visitors

102 |

103 | If you want to count unique visitors to your website instead of page views, 104 | just add unique.svg to your site instead of counter.svg: 105 |

106 | 110 |

111 | This makes LibreCounter send the header cache-control: max-age=1800, private, 112 | so that the image is cached in your browser across multiple page views, 113 | for half an hour. 114 |

115 | 116 |

Hidden Counter

117 |

118 | If you prefer your stats to be hidden the HTML snippet to add is even simpler: 119 |

120 | 122 |

123 | Keep in mind that your stats may still appear in the list of top sites on the home page. 124 |

125 | 126 |

Bring Your Own Style

127 |

128 | If you would like to have a custom style for your site, 129 | why not create it yourself? 130 | Pull requests are welcome! 131 |

132 |
133 | ${createFooter()}` 134 | } 135 | 136 | -------------------------------------------------------------------------------- /lib/page/stats.js: -------------------------------------------------------------------------------- 1 | import {getTop10} from '../core/format.js' 2 | import {createHead, createFooter} from './common.js' 3 | 4 | const dayOptions = [1, 3, 7, 14, 30] 5 | 6 | export function createStatsPage(query, stats) { 7 | const showingDays = query.days == 1 ? 'day' : `${query.days} days` 8 | return `${createHead(`LibreCounter Stats for ${query.site}`)} 9 |
10 | 13 |

14 | ${getTitle(query, stats)} 15 |

16 |
17 |
18 |

19 | Showing data for the last ${showingDays}. Change to show: 20 | ${getDayLinks(query.days)} 21 | days. 22 |

23 |
24 |

Stats per day

25 | ${createTimeSeries(stats.byDay)} 26 |
27 |
28 |
29 |

Stats per page

30 | ${createHorizontalChart(stats.byPage, 'pages', '#934147')} 31 |
32 |
33 |

Stats per country

34 | ${createHorizontalChart(stats.byCountry, 'countries', '#cc7658')} 35 |
36 |
37 |

Stats per browser

38 | ${createHorizontalChart(stats.byBrowser, 'browsers', '#dbaf61')} 39 |
40 |
41 |

Stats per OS

42 | ${createHorizontalChart(stats.byOs, 'os', '#507589')} 43 |
44 |
45 |
46 | ${createFooter()}` 47 | } 48 | 49 | function getTitle(query, stats) { 50 | if (!stats?.total) { 51 | return `No stats for ${query.site} yet` 52 | } 53 | return `Analytics for ${query.site}` 54 | } 55 | 56 | function getDayLinks(current) { 57 | const links = dayOptions.map(days => getLink(days, current)) 58 | return links.join(', ') 59 | } 60 | 61 | function getLink(days, current) { 62 | if (days == current) { 63 | return String(days) 64 | } 65 | return `${days}` 66 | } 67 | 68 | function createTimeSeries(stats) { 69 | if (!stats?.length) { 70 | return 'No stats yet' 71 | } 72 | const canvasId = 'chart-time' 73 | stats.sort((a, b) => a.day.localeCompare(b.day)) 74 | const labels = stats.map(dayStats => dayStats.day) 75 | const data = stats.map(dayStats => dayStats.value) 76 | return ` 77 |
78 | 79 |
80 | 120 | ` 121 | } 122 | 123 | function createHorizontalChart(map, label, color) { 124 | if (!map) { 125 | return 'No stats yet' 126 | } 127 | const {labels, data} = massageMap(map) 128 | const barHeight = 25 129 | const height = (barHeight + 15) * (data.length + 1) 130 | const canvasId = 'chart-' + label 131 | return ` 132 |
133 | 134 |
135 | 178 | ` 179 | } 180 | 181 | function massageMap(map) { 182 | const stats = Object.entries(map).map(([key, value]) => ({key, value})) 183 | return getTop10(stats) 184 | } 185 | 186 | -------------------------------------------------------------------------------- /lib/server/counter.js: -------------------------------------------------------------------------------- 1 | import {promises as fs} from 'fs' 2 | import {serveStaticFile} from './file.js' 3 | import {storeCounter} from '../db/counter.js' 4 | import {readVisitorToday} from '../db/stats.js' 5 | import {Counter} from '../core/counter.js' 6 | 7 | const defaultPath = 'public/img/solid-brown.svg' 8 | const svgType = 'image/svg+xml' 9 | const oldStyleLogo = String(await fs.readFile('public/img/old-style.svg')) 10 | const maxCacheUnique = 1800 11 | 12 | 13 | export default async function setup(app) { 14 | app.get('/counter.svg', counter) 15 | app.get('/unique.svg', uniqueCounter) 16 | app.get('/oldStyle.svg', oldStyleCounter) 17 | app.get('/:file.svg', logoCounter) 18 | app.get('/count', count) 19 | } 20 | 21 | /** 22 | * Request: no parameters required. 23 | * Response: librecounter SVG. 24 | * No auth required. 25 | */ 26 | async function counter(request, reply) { 27 | const counter = new Counter(request.ip, request.headers) 28 | await storeCounter(counter) 29 | reply.header('cache-control', 'no-store, private') 30 | return await serveStaticFile(defaultPath, svgType, request, reply) 31 | } 32 | 33 | /** 34 | * Same interface as counter() 35 | */ 36 | async function uniqueCounter(request, reply) { 37 | const counter = new Counter(request.ip, request.headers) 38 | await storeCounter(counter) 39 | reply.header('cache-control', `max-age=${maxCacheUnique}, private`) 40 | return await serveStaticFile(defaultPath, svgType, request, reply) 41 | } 42 | 43 | /** 44 | * Same interface as counter() 45 | */ 46 | async function oldStyleCounter(request, reply) { 47 | const counter = new Counter(request.ip, request.headers) 48 | await storeCounter(counter) 49 | reply.type(svgType) 50 | reply.header('cache-control', 'no-store, private') 51 | const visitor = await readVisitorToday(counter.site) 52 | const count = padVisitor(visitor) 53 | return replaceCount(count) 54 | } 55 | 56 | /** 57 | * Request: query parameters: 58 | * - url: URL to visit. 59 | * - userAgent: the user agent that paid the visit. 60 | * Response: {ok}. 61 | * No auth required. 62 | */ 63 | async function count(request) { 64 | const counter = new Counter(request.ip, request.headers) 65 | counter.setReferer(request.query.url) 66 | counter.setUserAgent(request.query.userAgent) 67 | await storeCounter(counter) 68 | return {ok: true} 69 | } 70 | 71 | function padVisitor(count) { 72 | const string = String(count) 73 | if (string.length > 4) { 74 | return `+${string.substring(string.length - 3)}` 75 | } 76 | return '0'.repeat(4 - string.length) + string 77 | } 78 | 79 | function replaceCount(count) { 80 | let counted = oldStyleLogo 81 | for (const c of count) { 82 | counted = counted.replace('>X<', `>${c}<`) 83 | } 84 | return counted 85 | } 86 | 87 | /** 88 | * Request: no parameters required. 89 | * Response: requested (styled) SVG. 90 | * No auth required. 91 | */ 92 | async function logoCounter(request, reply) { 93 | const counter = new Counter(request.ip, request.headers) 94 | await storeCounter(counter) 95 | reply.header('cache-control', 'no-store, private') 96 | const path = `public/img/${request.params.file}.svg` 97 | return await serveStaticFile(path, svgType, request, reply) 98 | } 99 | 100 | -------------------------------------------------------------------------------- /lib/server/file.js: -------------------------------------------------------------------------------- 1 | import {promises as fs} from 'fs' 2 | 3 | const filesByPath = new Map() 4 | 5 | 6 | class File { 7 | constructor(path, mime) { 8 | this.path = path 9 | this.mime = mime 10 | this.contents = null 11 | this.lastModified = 0 12 | } 13 | 14 | async readContents() { 15 | try { 16 | const stats = await fs.stat(this.path) 17 | if (!this.contents) { 18 | this.lastModified = stats.mtimeMs 19 | this.contents = await fs.readFile(this.path) 20 | } 21 | const since = stats.mtimeMs 22 | if (since > this.lastModified) { 23 | console.log(`Reloading ${this.path}`) 24 | this.contents = await fs.readFile(this.path) 25 | this.lastModified = since 26 | } 27 | return this.contents 28 | } catch(exception) { 29 | if (exception.code != 'ENOENT') { 30 | console.error(`Error accessing ${this.path}: ${JSON.stringify(exception)}`) 31 | } 32 | return null 33 | } 34 | } 35 | } 36 | 37 | export async function serveStaticFile(path, mime, request, reply) { 38 | if (!filesByPath.has(path)) { 39 | filesByPath.set(path, new File(path, mime)) 40 | } 41 | const file = filesByPath.get(path) 42 | const contents = await file.readContents() 43 | if (!contents) { 44 | reply.status(404) 45 | return 'File not found' 46 | } 47 | reply.type(file.mime) 48 | return contents 49 | } 50 | 51 | -------------------------------------------------------------------------------- /lib/server/home.js: -------------------------------------------------------------------------------- 1 | import {serveStaticFile} from './file.js' 2 | import {readLatestSites} from '../db/stats.js' 3 | import {createHome} from '../page/home.js' 4 | import {createOptions} from '../page/options.js' 5 | 6 | 7 | export default async function setup(app) { 8 | app.get('/', serveHome) 9 | app.get('/options', serveOptions) 10 | app.get('/favicon.ico', await serveFile('public/favicon.png', 'image/png')) 11 | app.get('/favicon.png', await serveFile('public/favicon.png', 'image/png')) 12 | app.get('/main.css', await serveFile('public/main.css', 'text/css')) 13 | app.get('/img/:file.svg', serveSvgLogo) 14 | } 15 | 16 | async function serveFile(path, mime) { 17 | return async function(request, reply) { 18 | return serveStaticFile(path, mime, request, reply) 19 | } 20 | } 21 | 22 | async function serveSvgLogo(request, reply) { 23 | const path = `public/img/${request.params.file}.svg` 24 | const mime = 'image/svg+xml' 25 | return serveStaticFile(path, mime, request, reply) 26 | } 27 | 28 | /** 29 | * Request: no parameters. 30 | * Response: home page. 31 | * No auth required. 32 | */ 33 | async function serveHome(request, reply) { 34 | const latestSites = await readLatestSites() 35 | reply.type('text/html') 36 | return createHome(latestSites) 37 | } 38 | 39 | /** 40 | * Request: no parameters. 41 | * Response: page with old style counter. 42 | * No auth required. 43 | */ 44 | async function serveOptions(request, reply) { 45 | reply.type('text/html') 46 | return createOptions() 47 | } 48 | 49 | -------------------------------------------------------------------------------- /lib/server/ping.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | export default async function setup(app) { 5 | app.get('/ping', ping) 6 | } 7 | 8 | /** 9 | * Request: no parameters required. 10 | * Response: {ok}. 11 | * No auth required. 12 | */ 13 | async function ping() { 14 | return {ok: true} 15 | } 16 | 17 | -------------------------------------------------------------------------------- /lib/server/setup.js: -------------------------------------------------------------------------------- 1 | import homePlugin from './home.js' 2 | import pingPlugin from './ping.js' 3 | import counterPlugin from './counter.js' 4 | import statsPlugin from './stats.js' 5 | 6 | 7 | export default function setup(app) { 8 | app.register(homePlugin) 9 | app.register(pingPlugin) 10 | app.register(counterPlugin) 11 | app.register(statsPlugin) 12 | app.log.info('plugins loaded') 13 | return app 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lib/server/stats.js: -------------------------------------------------------------------------------- 1 | import {SiteQuery, PageQuery} from '../db/query.js' 2 | import {readSiteStats, readPageStats} from '../db/stats.js' 3 | import {createStatsPage} from '../page/stats.js' 4 | 5 | const defaultDays = 14 6 | 7 | 8 | export default async function setup(app) { 9 | app.get('/:site/siteStats', fetchSiteStats) 10 | app.get('/:site/pageStats', fetchPageStats) 11 | app.get('/referer/show', showReferer) 12 | app.get('/:site/show', show) 13 | } 14 | 15 | /** 16 | * Request params: site. 17 | * Query params: 18 | * - days: show data only for the latest days, default 30. 19 | * Response: {ok}. 20 | * No auth required. 21 | */ 22 | async function fetchSiteStats(request) { 23 | const days = request.query.days || defaultDays 24 | const query = new SiteQuery(request.params.site, days) 25 | return await readSiteStats(query) 26 | } 27 | 28 | /** 29 | * Request params: site. 30 | * Query params: 31 | * - page: the page to show. 32 | * - days: show data only for the latest days, default 30. 33 | * Response: {ok}. 34 | * No auth required. 35 | */ 36 | async function fetchPageStats(request) { 37 | const days = request.query.days || defaultDays 38 | const query = new PageQuery(request.params.site, days) 39 | return await readPageStats(query) 40 | } 41 | 42 | /** 43 | * Request params: site. 44 | * Response: complete web page. 45 | * No auth required. 46 | */ 47 | async function show(request, reply) { 48 | const days = request.query.days || defaultDays 49 | const query = new SiteQuery(request.params.site, days) 50 | const stats = await readSiteStats(query) 51 | reply.type('text/html') 52 | return createStatsPage(query, stats) 53 | } 54 | 55 | /** 56 | * No parameters. 57 | * Response: redirect to stats of referer. 58 | * No auth required. 59 | */ 60 | async function showReferer(request, reply) { 61 | const referer = request.headers.referer 62 | const url = new URL(referer) 63 | const site = url.host 64 | reply.redirect(`/${site}/show`) 65 | } 66 | 67 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "librecounter", 3 | "version": "1.0", 4 | "description": "Free and open website statistics", 5 | "type": "module", 6 | "main": "index.js", 7 | "scripts": { 8 | "dev": "supervisor bin/start.js", 9 | "start": "node bin/start.js", 10 | "test": "node bin/test.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/alexfernandez/librecounter.git" 15 | }, 16 | "keywords": [ 17 | "stats", 18 | "analytics", 19 | "counter", 20 | "web" 21 | ], 22 | "author": "alexfernandeznpm@gmail.com", 23 | "license": "GPL-3.0-or-later", 24 | "bugs": { 25 | "url": "https://github.com/alexfernandez/librecounter/issues" 26 | }, 27 | "homepage": "https://github.com/alexfernandez/librecounter#readme", 28 | "devDependencies": { 29 | "eslint": "^8.56.0", 30 | "pino-pretty": "^10.2.3", 31 | "supervisor": "^0.12.0" 32 | }, 33 | "dependencies": { 34 | "dotenv": "^16.3.1", 35 | "fastify": "^4.23.2", 36 | "geoip-lite": "^1.4.7", 37 | "mongodb": "^6.1.0", 38 | "node-device-detector": "^2.0.16" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/midudev/librecounter/41a13f991a84a29cc533788f99afae4f26ba7ba6/public/favicon.png -------------------------------------------------------------------------------- /public/img/isologo-brown.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 27 | 29 | 33 | 40 | 47 | 51 | 55 | 59 | 63 | 67 | 71 | 75 | 79 | 83 | 87 | 91 | 95 | 99 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /public/img/isologo-orange.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 27 | 29 | 33 | 40 | 47 | 51 | 55 | 59 | 63 | 67 | 71 | 75 | 79 | 83 | 87 | 91 | 95 | 99 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /public/img/isologo-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 27 | 29 | 33 | 40 | 47 | 51 | 55 | 59 | 63 | 67 | 71 | 75 | 79 | 83 | 87 | 91 | 95 | 99 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /public/img/isologo-yellow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 27 | 29 | 33 | 40 | 47 | 51 | 55 | 59 | 63 | 67 | 71 | 75 | 79 | 83 | 87 | 91 | 95 | 99 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /public/img/old-style.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 41 | 43 | 51 | 56 | 57 | 65 | 70 | 71 | 79 | 84 | 85 | 86 | 91 | 99 | 107 | 115 | 123 | X 134 | X 145 | X 156 | X 167 | you are visitor 178 | today 189 | 190 | 191 | -------------------------------------------------------------------------------- /public/img/outline-brown.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 32 | 36 | 40 | 44 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /public/img/outline-orange.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 32 | 36 | 40 | 44 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /public/img/outline-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 32 | 36 | 40 | 44 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /public/img/outline-yellow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 32 | 36 | 40 | 44 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /public/img/solid-brown.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 34 | 36 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /public/img/solid-orange.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 34 | 36 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /public/img/solid-yellow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 34 | 36 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /public/img/white-brown.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 34 | 36 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /public/img/white-orange.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 34 | 36 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /public/img/white-yellow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 28 | 30 | 34 | 36 | 40 | 44 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /public/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #f9f6f2; 3 | font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif; 4 | font-size: 12pt; 5 | font-weight: 400; 6 | line-height: 1.75em; 7 | color: #333333; 8 | margin: 40px; 9 | } 10 | 11 | h1 { 12 | font-size: 16pt; 13 | color: #191919; 14 | } 15 | 16 | h2 { 17 | margin-top: 2em; 18 | font-size: 14pt; 19 | color: #191919; 20 | } 21 | 22 | div.logo { 23 | max-width: 280px; 24 | margin-bottom: 30px; 25 | } 26 | 27 | div.canvas { 28 | max-width: 500px; 29 | } 30 | 31 | footer { 32 | margin-top: 5em; 33 | } 34 | 35 | table, td, th { 36 | border: 1px solid #a99c8b; 37 | border-collapse: collapse; 38 | padding: 5px; 39 | } 40 | 41 | table { 42 | margin: 20px; 43 | } 44 | 45 | textarea { 46 | background-color: #ece3d8; 47 | } 48 | 49 | .graphs { 50 | display: grid; 51 | grid-template-columns: 1fr 1fr; 52 | gap: 0px; 53 | } 54 | 55 | .graph { 56 | padding-left: 20px; 57 | } 58 | 59 | .title { 60 | display: flex; 61 | gap: 15px; 62 | flex-direction: row; 63 | align-items: center; 64 | } 65 | 66 | img { 67 | vertical-align: middle; 68 | } 69 | 70 | img.isologo { 71 | max-width: 10em; 72 | } 73 | 74 | .oldStyle { 75 | width: 100px; 76 | } 77 | 78 | a { 79 | transition: color 0.2s ease-in-out, border-color 0.2s ease-in-out; 80 | color: #507589; 81 | border-bottom: dashed 1px #7391a1; 82 | text-decoration: none; 83 | } 84 | 85 | a:hover { 86 | border-bottom-color: transparent; 87 | color: #6188873 !important; 88 | } 89 | 90 | a:visited { 91 | color: #365161; 92 | border-bottom: dashed 1px #4b6f84; 93 | } 94 | 95 | .imageLink { 96 | border: none; 97 | } 98 | 99 | .action { 100 | font-size: 14pt; 101 | } 102 | 103 | @media screen and (max-width: 1150px) { 104 | .graphs { 105 | grid-template-columns: 1fr; 106 | } 107 | 108 | table { 109 | max-width: 800px; 110 | } 111 | } 112 | 113 | @media screen and (max-width: 600px) { 114 | body { 115 | margin: 20px; 116 | } 117 | 118 | .graphs { 119 | grid-template-columns: 1fr; 120 | } 121 | 122 | div.canvas { 123 | max-width: 400px; 124 | } 125 | table { 126 | max-width: 400px; 127 | } 128 | 129 | div.logo { 130 | margin-bottom: 20px; 131 | } 132 | } 133 | 134 | -------------------------------------------------------------------------------- /test/api.js: -------------------------------------------------------------------------------- 1 | import {app} from './setup.js' 2 | import {getDay} from '../lib/db/query.js' 3 | import {site, userAgent} from './setup.js' 4 | 5 | const path = '/mypage.fi' 6 | 7 | 8 | async function testCounter() { 9 | await testCountPage(path) 10 | await testCountPage('/') 11 | } 12 | 13 | async function testCountPage(page) { 14 | const response = await app.inject({ 15 | url: `/count?url=http://${site}${page}&userAgent=${userAgent}`, 16 | method: 'GET', 17 | }) 18 | console.assert(response.statusCode == 200, 'could not count') 19 | const result = response.json() 20 | console.assert(result.ok, 'did not count') 21 | } 22 | 23 | async function testSiteStats() { 24 | const response = await app.inject({ 25 | url: `/${site}/siteStats`, 26 | method: 'GET', 27 | headers: {'user-agent': 'testbot/1.0'}, 28 | }) 29 | console.assert(response.statusCode == 200, 'could not stats') 30 | const result = response.json() 31 | console.assert(result.byDay, 'has no days') 32 | console.assert(Array.isArray(result.byDay), 'byDay is not an array') 33 | const day = getDay() 34 | const found = result.byDay.filter(dayStats => dayStats.day == day) 35 | console.assert(found.length == 1, 'no data today') 36 | console.assert(found[0].value > 0, 'no value today') 37 | console.assert(result.byPage, 'has no pages') 38 | console.assert(result.byPage[path], 'has no path') 39 | } 40 | 41 | async function testLastDays() { 42 | const response = await app.inject({ 43 | url: `/${site}/siteStats?days=1`, 44 | method: 'GET', 45 | headers: {'user-agent': 'testbot/1.0'}, 46 | }) 47 | console.assert(response.statusCode == 200, 'could not stats') 48 | const result = response.json() 49 | console.assert(result.byDay, 'has no days') 50 | console.assert(result.byDay.length == 1, 'should only have one day') 51 | const dayStats = result.byDay[0] 52 | const day = getDay() 53 | console.assert(dayStats.day == day, 'should only have today') 54 | console.assert(dayStats.value > 0, 'no value today') 55 | } 56 | 57 | async function testPageStats() { 58 | const response = await app.inject({ 59 | url: `/${site}/pageStats?page=${path}`, 60 | method: 'GET', 61 | headers: {'user-agent': 'testbot/1.0'}, 62 | }) 63 | console.assert(response.statusCode == 200, 'could not get page stats') 64 | const result = response.json() 65 | console.assert(result.byDay, 'has no days') 66 | console.assert(!result.byPage, 'should have no page') 67 | } 68 | 69 | export default async function test() { 70 | await testCounter() 71 | await testSiteStats() 72 | await testPageStats() 73 | await testLastDays() 74 | } 75 | 76 | -------------------------------------------------------------------------------- /test/counter.js: -------------------------------------------------------------------------------- 1 | import {app, site, userAgent} from './setup.js' 2 | 3 | 4 | async function testCounter(url, name) { 5 | const response = await app.inject({ 6 | url, 7 | method: 'GET', 8 | headers: { 9 | 'user-agent': userAgent, 10 | referer: `https://${site}/myPage.fo` 11 | }, 12 | }) 13 | console.assert(response.statusCode == 200, `could not count ${name}`) 14 | console.assert(response.payload.includes('