Skip to content

Commit

Permalink
New code !
Browse files Browse the repository at this point in the history
Adding login, signin, config file.....
  • Loading branch information
azlux committed Jun 12, 2019
1 parent 618889f commit 68b2fd7
Show file tree
Hide file tree
Showing 19 changed files with 462 additions and 218 deletions.
13 changes: 0 additions & 13 deletions .htaccess

This file was deleted.

65 changes: 43 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
# simple-shortener
# simple-shortener by Azlux

<p>Simple shortener working with MySQL or SQLite database in php and small javascript functions.<br /><br />
This shortener create a ID for every user to have a list of short url create by user (working with cookie). The user can add comments for the link to find it faster into its history.<br />
<br/>
Nice shortcut added. The shortcut will create a new short url of your current page when you click on it.<br /><br />
Simple shortener working with MySQL or SQLite database in PHP.
The goal is to create a simple and KISS shortener without dependencies.
The user can add comments for the link to find it faster into its history.


Nice shortcut added. The shortcut will create a new short url of your current page when you click on it.
Writed to work into subfolder. (don't need to be at the root)
</p>

=======
<p>
File installation.php to execute at first access. This php file need the +w mode on the folder (only the first time, you can remove the writing after the install) is you choose the SQlite database<br />
</p>

=============
#####Nginx configuration :
## Installation :
-
- Copy `config.example.php` to `config.php`
- Set you config file
- Call `installation.php` to setup the database
- delete `installation.php`
- Create a user, the first one will be an admin (allow you to see no connected shorted links)


### Nginx configuration :

```NGINX
if (!-e $request_filename) {
rewrite ^/([^/]*)$ /index.php?site=$1 last;
location / {
rewrite ^/(.*)$ /index.php?site=$1 last;
try_files $uri $uri/ /index.php;
}
location /assets {
try_files $uri =404;
}
location /favicon.ico {
try_files $uri =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
```
Think about remove access to the sqlite file (and .htaccess) with :
```NGINX
location ~* \.(sqlite3|ht)$ {
deny all;
deny all;
}
```
#####Apache configuration (.htaccess) :
tested and approved :) (delete the file if you are on nginx)
### Apache configuration (.htaccess) :
(delete the file if you are on nginx)


<br/>
####Credit :<p>
### Credit :<p>
Based on code provided by [SilouFR](https://github.com/SilouFr)
</p>

7 changes: 3 additions & 4 deletions commun.css → assets/css/commun.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ body {
font-family: Verdana, Arial, serif;
font-size: 12px;
color: #595441;
background: url("sunset.png") no-repeat fixed;
background-size: cover;
text-align: center;
margin-top: 0;
padding-top: 10px;
Expand All @@ -12,10 +12,9 @@ body {
max-width: 400px;
margin: 50px auto 0 auto;
min-height: 150px;
background: rgba(255, 255, 255, 0.40);
text-align: left;
padding: 5px 20px 10px 20px;
border: 3px solid #2a85b3;
border: 3px solid;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border-radius: 20px;
Expand Down Expand Up @@ -184,4 +183,4 @@ body {
}
.forkit:hover span:last-child {
opacity: 1;
}
}
8 changes: 8 additions & 0 deletions assets/css/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
background-color: #23232f;
}
#content {
background: rgba(255, 255, 255, 0.08);
border-color: #e1e1e1;
}

2 changes: 1 addition & 1 deletion list.css → assets/css/list.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ body {
font-family: Verdana, Arial, serif;
font-size: 12px;
color: #595441;
background: url("sunset.png") no-repeat fixed;
background: url("/assets/img/sunset.png") no-repeat fixed;
text-align:center;
margin-top:0;
padding-top:10px;
Expand Down
7 changes: 7 additions & 0 deletions assets/css/white.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
background-color: #dddddd;
}
#content {
background: rgba(255, 255, 255, 0.40);
border-color: #2a85b3;
}
File renamed without changes
Binary file added assets/img/portal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
4 changes: 4 additions & 0 deletions assets/js/cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function bookmark() {
document.getElementById("bookmark").setAttribute('href', "javascript:(function () {var d = document;var w = window;var enc = encodeURIComponent;var f = '" + window.location.href + "index.php';var l = d.location;var p = '?shorten=' + enc(l.href) + '&comment=' + enc(d.title) + '&userID="+getID()+"';var u = f + p;var a = function () {if (!w.open(u))l.href = u;};if (/Firefox/.test(navigator.userAgent))setTimeout(a, 0); else a();void(0);})();");
}
bookmark();
21 changes: 21 additions & 0 deletions bdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
require 'config.php';


if (DATABASE_TYPE == "mysql") {
try {
$connexion = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DATABASE.';charset=utf8', MYSQL_USER, MYSQL_PASSWORD);
$connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
elseif (DATABASE_TYPE == "sqlite3") {
try {
$connexion = new PDO("sqlite:".SQLITE3_FILE);
$connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
?>
19 changes: 19 additions & 0 deletions config.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
define('DATABASE_TYPE', 'mysql'); //mysql or sqlite3

// useless if sqlite3 is selected
define('MYSQL_HOST', 'localhost');
define('MYSQL_DATABASE', 'url');
define('MYSQL_USER', 'url');
define('MYSQL_PASSWORD', '******');

//useless if mysql is selected
define('SQLITE3_FILE', './database.sqlite3');

define('DEFAULT_URL', 'https://azlux.fr'); // omit the trailing slash!
define('URL_SIZE', 5); // The lenght of your short created links
define('WEB_THEME', 'white'); // dark or white
define('PUBLIC_INSTANCE', 'false'); // true to allow no connected people to create short url. The admin can see no connected short URL created.
define('ALLOW_SIGNIN', 'false'); // true to allow people to signin on there own

?>
23 changes: 0 additions & 23 deletions cookie.js

This file was deleted.

Binary file added favicon.ico
Binary file not shown.
Loading

0 comments on commit 68b2fd7

Please sign in to comment.