<repo_name>gammafp/vergatarioShorten<file_sep>/public/js/libs/gammajax.js
var Gammajax = function() {
    var solicitud = new XMLHttpRequest();
    function init(metodo, form) {
        var formulario = form;
        var envio = JSON.stringify(formulario.datos);
        solicitud.onreadystatechange = formulario.funcion;
        solicitud.open('POST', formulario.url, true);
        solicitud.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
        solicitud.send(envio);
    }

    return {
        'post' : function(form) {
            init('POST', form);
        },
        'get' : function(form) {
            init('GET', form);
        }
    };
};
var gammajax = new Gammajax();
// var obj = new Gammajax();
// obj.post({
//     'url' : 'http://localhost/conversor',
//     'datos' : {"nombre":"Francisco"},
//     'funcion' : prueba
// });
<file_sep>/RESGUARDO/app.js
var express = require('express'),
	bodyParser = require('body-parser'),
	cnf = require('./conf'),
	favicon = require('serve-favicon'),
	path = require('path'),
	mongoose = require('mongoose');

/* Modelos de base de datos */
var user_schema = require('./models/User'),
	db_lnk = cnf.db.host,

	db = mongoose.createConnection(db_lnk),
	users = db.model('users', user_schema);


/* Anti Ddos */
// var Ddos = require('ddos');
// var ddos = new Ddos;
// users.find(function(err, user) {
// 	if(err) {
// 		console.log(err);
// 	} else {
// 		console.log(user);
// 	}
// });
/* Variables personales */
var criptoVergatario = require('./libs/modulo_encriptacion/criptoVergatario');

var app = express();
// app.use(ddos.express);
// Paquetes a usar
// app.use(ddos.express);

// Midleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(favicon(path.join(__dirname + '\\public\\favicon.ico')));

app.use(express.static(__dirname + '\\public'));
app.use("/static", express.static(__dirname + '\\public'));


app.get('/', function(req, res) {
	res.sendFile('index.html');
});

app.get('/login', function(req, res) {
	res.sendFile(__dirname + '\\public\\pruebaFacebook.html');
});

// Conversor de enlaces
app.post('/conversor', function(req, res) {
	/*
		Estructura de los herrores y mensajes
		{
			error : false // tambien puede ser true
			msg : 'Aquí el mensaje o la respuesta sastifactoria del error'
		}
	*/
	var entrada = req.body.vergatario;
	if(entrada === undefined) {
		res.json({error: true, msg: 'El elemento está indefinido'});
	} else {
		if(!entrada.startsWith('http')) {
			entrada = 'http://'+entrada;
		}
		res.json({error: false, msg: cnf.hostAcortador + criptoVergatario(req.body.vergatario)});
		// Si todo es correcto acá iria la entrada a la base de datos
	}

});

var ip = process.env.OPENSHIFT_NODEJS_IP || cnf.ip;
var port = process.env.OPENSHIFT_NODEJS_PORT || cnf.port;
app.listen(port, ip, function() {
	console.log('#-----------------------------------------------------------------------#');
	console.log('#--| Acceda a la página escribiendo http://localhost en el navegador |--#');
	console.log('#-----------------------------------------------------------------------#');
});
<file_sep>/tests/mongoStart.js
var exec = require('child_process').exec;
var command = "mongod";
child = exec(command, function(err, stdout, stderr) {
	if(error !== null) {
		console.log('exec error: ' + error);
	}
});
module.export = child;
<file_sep>/desktop.ini
[.ShellClassInfo]
InfoTip=Carpeta sincronizada con MEGA
IconResource=C:\Users\gammafp\AppData\Local\MEGAsync\MEGAsync.exe,3
<file_sep>/controllers/rutas.js
/*
	Estructura de los herrores y mensajes
	{
		error : false // tambien puede ser true
		msg : 'Aquí el mensaje o la respuesta sastifactoria del error'
	}
*/
var criptoVergatario = require('../libs/modulo_encriptacion/criptoVergatario');
var patron = /^(http|https)\:\/\/[a-z0-9\.-]+\.[a-z]{2,4}/gi;
var cnf = require('../conf');
exports.convertidor = function(req, res, next) {
	var entrada = req.body.vergatario;
	if(entrada === undefined || entrada === '') {
		res.json({error: true, msg: 'El elemento está indefinido'});
	} else {
		if(!entrada.startsWith('http')) {
			entrada = 'http://'+entrada;
		}
		if (!patron.test(entrada)) {
			res.json({error: true, msg: 'Esto no es una URL correcta.'});
		} else {
			// Si todo es correcto acá iria la entrada a la base de datos
			res.json({error: false, msg: cnf.hostAcortador + criptoVergatario(req.body.vergatario)});
		}
	}
};
<file_sep>/public/js/libs/efectos.js

// efecto modal del materialize
$('.modal-trigger').leanModal({
  dismissible: true, // Modal can be dismissed by clicking outside of the modal
  opacity: 0.5, // Opacity of modal background
  in_duration: 300, // Transition in duration
  out_duration: 200, // Transition out duration
});
<file_sep>/public/index.html
<!DOCTYPE html>
<html lang="es">
<head>
	<title>{{title}}</title>
	<link rel="stylesheet" href="css/main.css">
	<link rel="stylesheet" href="css/transiciones.css">
	<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
	<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.21/vue.min.js"></script> -->
	<script src="js/libs/vue.js"></script>
	<script src="js/libs/gammajax.js"></script>
</head>
<body>
	<nav class="cyan darken-1" role="navigation">
		<div class="nav-wrapper container">
			<a id="logo-container" href="#" class="brand-logo"><img src="/img/top_cat.png" alt="" /></a>
			<ul class="right hide-on-med-and-down">
				<li>
					<!-- Trigger registro -->
					<button data-target="registro" class="btn modal-trigger orange lighten-1" type="submit">registrate</button>
				</li>
				<li>
					<!-- Trigger login todavia en desarrollo -->
					<button class="btn waves-effect white" type="submit"><span class="orange-text text-lighten-1">login</span></button>
				</li>
			</ul>
		</div>
	</nav>
	<!-- Acortador url-->
	<div class="row center">
		<div class="center container">
			<form id="conversor" class="blue-grey lighten-5 z-depth-2" v-on:submit.prevent="submit">
				<!-- <input class="browser-default" type="url" id="inputUrl" placeholder=" Aqui van las urls" v-model="cambio" transition="fade" v-if="mostrar" autofocus size="40"> -->
				<input class="browser-default" type="text" id="inputUrl" placeholder=" Aqui van las urls" v-model="cambio" transition="fade" v-if="mostrar" autofocus size="40">
			</form>
		</div>
		<div class="container">
			<ul class="center hide-on-large-only">
				<li>
					<button class="btn waves-effect waves-light orange lighten-1" type="submit">registrate</button>
				</li>
				<li>
					<button class="btn waves-effect waves-light white" type="submit"> <span class="orange-text text-lighten-1">login</span></button>
				</li>
			</ul>
		</div>
	</div>
	<!-- tarjetas -->
	<div class="container">
		<div class="section">
			<div class="row">
				<div class="col s12 m4">
					<div class="card">
						<div class="card-content">
							<div class="icon-block">
								<h2 class="center orange-text text-lighten-1"><i class="material-icons">equalizer</i></h2>
								<h5 class="center">Lorem ipsum dolor sit amet</h5>
								<p class="light">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
									irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
							</div>
						</div>
					</div>
				</div>
				<div class="col s12 m4">
					<div class="card">
						<div class="card-content">
							<div class="icon-block">
								<h2 class="center orange-text text-lighten-1"><i class="material-icons">group</i></h2>
								<h5 class="center">Lorem ipsum dolor sit amet</h5>
								<p class="light">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
									irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
							</div>
						</div>
					</div>
				</div>
				<div class="col s12 m4">
					<div class="card">
						<div class="card-content">
							<div class="icon-block">
								<h2 class="center orange-text text-lighten-1"><i class="material-icons">settings</i></h2>
								<h5 class="center">Lorem ipsum dolor sit amet</h5>
								<p class="light">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
									irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- Estructura registro -->
	<div id="registro" class="modal">
		<div class="modal-content">
			<div class="row">
				<div><button class="btn indigo darken-4" v-on:click="facebook">FACEBOOK</button></div>
				<div><button class="btn blue accent-3">TWITTER</button></div>
				<div><button class="btn red accent-4">GMAIL</button></div>
				<div><button class="btn teal accent-4">EMAIL</button></div>
			</div>
		</div>
		<div class="modal-footer">
			<a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Aceptar</a>
		</div>
	</div>

	<footer class="page-footer cyan darken-1">
		<div class="container">
			<div class="row">
				<div class="col l6 s6">
					<h5 class="white-text">Nuestra Bio</h5>
					<p class="grey-text text-lighten-4"></p>
				</div>
				<div class="right-align col l6 s6">
					<h5 class="white-text">Redes Sociales</h5>
					<ul>
						<li><a class="white-text" href="#!">github</a></li>
						<li><a class="white-text" href="#!">twitter</a></li>
						<li><a class="white-text" href="#!">face</a></li>
					</ul>
				</div>
			</div>
		</div>
		<div class="footer-copyright">
			<div class="container">
			</div>
		</div>
	</footer>

	<!-- scripts -->
	<script src="js/main.js"></script>
	<script src="js/libs/efectos.js"></script>
</body>

</html>
<file_sep>/libs/modulo_encriptacion/criptoVergatario.js
var Base62 = require('base62');
var crypto = require('crypto');

var criptoVergatario = function (url) {
    var final = Base62.encode(parseInt(crypto.createHash('md5').update(url).digest("hex"), 16));
    var conteo = final.length;
    var salida = '';
    for(var i = 0; i < conteo; i++) {
        salida += final[Math.floor(Math.random() * (conteo - 0 +1))];
    }
    return salida.substr(0, 5);
}

module.exports = criptoVergatario;
