not_bob

not_bob wrote

Reply to by nook_

Can confim. This works. I've placed quite a few bets.

1

not_bob wrote (edited )

In the near future I plan to be writing more little toys like this. Then plan is to have a toys.notbob.i2p site with a list of useful things.

Here is code what what I have running. You can see an example of it running here https://5gn3ca4z4occksx2cnwbcrun2mum2eg2c7zgfi7k7fetruwzmdiq.b32.i2p/count.html

To use it, you need include code like the following.

<img src="https://5gn3ca4z4occksx2cnwbcrun2mum2eg2c7zgfi7k7fetruwzmdiq.b32.i2p/conter.cgi?page=123456789k&color=green" height=40> 

Pick a number. That will be your site number. Or, you can use a new number for each html page. But, any page with the same number will increment that number's count.

As for the color. Use normal color names. They should work. No hex colors. If you do not specify a color then it will default to black text. The background will be transparent.

Anyone is welcome to use this freely. Enjoy!

 #!/usr/bin/perl  # code by notbob.i2p  use warnings; use Fcntl ':flock'; # Import LOCK_* constants use Time::HiRes qw(usleep); # For sub-second sleeping use CGI qw/:standard/;  $site = param("site"); $site =~ s/\D//g;  $color = param("color");  $color = lc($color); $color =~ s/[^a-z]//g;  if ( $color eq "" ) { $color = "black"; }  print("Content-type: image/svg+xml\n\n");  # File to store the page counter my $counterFile = "/comhtml/5gn3ca4z4occksx2cnwbcrun2mum2eg2c7zgfi7k7fetruwzmdiq.b32.i2p/counter/$site.txt";  # Function to read the current counter value sub read_counter {  my ($filename) = @_;  open(my $fh, '<', $filename) or die "Cannot open file $filename: $!";  flock($fh, LOCK_SH); # Shared lock for reading  my $counter = <$fh>;  chomp($counter);  close($fh);  return $counter; }  # Function to increment and save the counter sub save_counter {  my ($filename, $counter) = @_;  open(my $fh, '>', $filename) or die "Cannot open file $filename: $!";  while (!flock($fh, LOCK_EX | LOCK_NB)) {  # If the file is locked, wait a short time and try again  usleep(100000); # 100 milliseconds  }  print $fh $counter;  close($fh); }  # Read current counter value from file my $counter = -e $counterFile ? read_counter($counterFile) : 0;  # Increment the counter $counter++;  # Save updated counter value to file save_counter($counterFile, $counter);  # Generate HTML page counter span #print "Content-Type: text/html\n\n"; #print "<span id=\"counter\">$counter</span>\n";  print "<svg width=\"100\" height=\"50\" xmlns=\"https://www.w3.org/2000/svg\">  <text x=\"10\" y=\"40\" font-family=\"Arial\" font-size=\"40\" fill=\"$color\">$counter</text> </svg>";  

To use this, you will also need to create a counter directory on the webserver and give it read-write permission for whatever webserver you are running.

2

not_bob wrote

I have added a way to change the color. just add &color=color to the end of the url and it will change the text color. The background will be transparent.

You can use any normal color name, red, green, blue, purple, orange, plum, and so on. If you don't like these colors, try others.

if you do not specify a color it will default to black. If you try an invalid color, it will default to black.

2

not_bob wrote (edited )

I have written a counter you can use in a static site.

To use the counter just include the following code in your html.

<img src="https://5gn3ca4z4occksx2cnwbcrun2mum2eg2c7zgfi7k7fetruwzmdiq.b32.i2p/counter.cgi?site=123842384" height=30>

Change the site number to a random number, and that will be your site number. Feel free to adjust the height to anything you want, the output is a svg file, so it will scale.

You could even use a different site number for each page on your site. Each site has it's own unique count.

As for logging. That server logs access just as any other normal webserver does. I do not share the data with anyone, and the only identifying information that is collected by the server is the b32 of the client who hits the site and the time/date.

2

not_bob wrote

If you have a static site, you are limited to using someone else's counter. There is no way to run PHP code from a static site. Also, even if you were to use JavaScript, there is no way for your static site to store that data. So, still not an option.

The only real solution with such a site is to use someone else's counter as you mention in #2.

Not all I2P users have a clearnet outproxy configured. So, using a clearnet service is not the best option. Possible privacy issues aside.

I have a counter on the front of my notbob page. If you mouse over the van on the upper left side you will see a little box with a green graph. While it does not currently show the count, it still counts.

It would not be hard to write a multi-user count. I could likely code one up that would work for anyone pretty quickly. Something basic that just displays a number.

You would embed it into the html code with <img src="https://countersite.i2p/cgi-bin/counter.cgi?site=324832483">

Note the random number. There would be no need for me to even know what site it's counting for.

And, that would all you would have to do on your end. That is if you just want a count. If you want graphs and more complex breakdowns, that's another story.

But, a simple one would be easy. And, as for privacy, so long as you trust the person who's counter you are using, then you are good.

Feel free to hit me up on IRC if you want to discuss this further.

As for discussion, this is a good place to do it.

2