Browse Source

site-commit

master
art.dambrine 5 years ago
commit
8fd7dfcff4
  1. 1
      .gitignore
  2. 11
      bdd.php.dist
  3. 4
      css/font-awesome.min.css
  4. 70
      css/style.css
  5. 39
      entete.php
  6. 31
      get_avancement.php
  7. 12
      head.php
  8. 45
      index.php
  9. 40
      pieddepage.php
  10. 45
      provenance.php
  11. 48
      recent.php
  12. 201
      robot.php
  13. 54
      site_info.php
  14. 76
      top.php

1
.gitignore

@ -0,0 +1 @@
bdd.php

11
bdd.php.dist

@ -0,0 +1,11 @@
<?php
// connexion a la base
try {
$bdd = new PDO('mysql:host=<ip>;dbname=<dbname>','<USER>','<PWD>', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch(PDOException $e)
{
echo " Erreur de connexion, contactez l'administrateur du site !";
}

4
css/font-awesome.min.css

File diff suppressed because one or more lines are too long

70
css/style.css

@ -0,0 +1,70 @@
form {
text-align: center;
/* display: inline-block; */
}
form .form-example {
margin-bottom: 20px;
}
form .form-example input {
text-align: center;
}
#number {
text-align: center;
width: 44px;
}
#site {
font-size: 18px;
line-height: 140%;
}
#sites-recents{
font-size: 18px;
}
#URL {
width: 434px;
/*width: 70vw;*/
}
#progressbar {
width:400px;
height: 40px;
}
#td-padding {
padding-left: 15px;
text-align: center;
}
.table-head-top-50{
font-weight: bold;
}
@media (max-width: 700px) {
#progressbar {
width: 70vw;
}
#URL {
width: 80vw;
}
#site {
font-size: 15px;
line-height: 120%;
}
.content-inside {
padding-left: 25px; /* -20 pour le tableau, faire une div + 20 pour le texte */
padding-bottom: 150px;
}
.text-padding{
padding-left: 20px;
}
}

39
entete.php

@ -0,0 +1,39 @@
<!-- En tête de la page -->
<header id="header-desktop">
<div class="wrapper" id="entete">
<h1>Robot Index<span class="green">.</span></h1>
<nav>
<ul>
<li><a href="/">Robot</a></li>
<li><a href="/recent.php">Sites</a></li>
<li><a href="/top.php">Top 50</a></li>
</ul>
</nav>
</div>
</header>
<header id="header-smartphone">
<div id="entete">
<!-- Top Navigation Menu Smartphone -->
<div class="topnav">
<h1 id="nav-title">Robot Index<span class="green">.</span></h1>
<div id="myLinks">
<ul>
<li><a href="/">Robot</a></li>
<li><a href="/recent.php">Sites</a></li>
<li><a href="/top.php">Top 50</a></li>
</ul>
</div>
<a href="javascript:void(0);" class="ham-icon" onclick="myFunction()">
<img id="ham-ico" src="https://art-dambrine.ovh/learning/css/hamburger.png">
<img id="cross-ico" src="https://art-dambrine.ovh/learning/css/cross.png">
</a>
</div>
</div>
</header>

31
get_avancement.php

@ -0,0 +1,31 @@
<?php
if (isset($_GET['port'])){
$port = $_GET['port'];
$port = (int) $port;
if ($port>8090) die();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://art-dambrine.ovh:".$port,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}

12
head.php

@ -0,0 +1,12 @@
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://art-dambrine.ovh/learning/css/font-awesome.min.css">
<link rel="stylesheet" href="https://art-dambrine.ovh/learning/css/bootstrap.min.css">
<link rel="stylesheet" href="https://art-dambrine.ovh/learning/css/styles.css">
<link rel="stylesheet" href="css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Robot Index</title>
</head>

45
index.php

@ -0,0 +1,45 @@
<?php /* Projet learning 2019 */
include("head.php");
include("entete.php");
?>
<!-- Corps de la page -->
<div class="content">
<div class="content-inside">
<h2>Robot Index</h2>
<p>
Notre robot teste et indexe les liens du site de votre choix <br> <br>
Commencez par copier l'adresse d'un site depuis la barre d'adresse de votre navigateur.
</p>
<br/>
<form action="robot.php" method="POST" class="form-example">
<div class="form-example">
<label for="name"><strong>URL</strong></label>
<input type="url" name="URL" id="URL" placeholder="Collez ici l'URL" required>
</div>
<div class="form-example">
<label for="number">Nombre de pages à parcourir </label>
<input type="number" name="number" id="number" value="30" min ="1" max="50" required>
</div>
<div class="form-example">
<input type="submit" value="Lancez le Robot !">
</div>
</form>
<br>
<h3><a style="color: #0C62A6;" href="top.php">Voir le Top 50 des liens indexés</a></h3>
<h3><a style="color: #0C62A6;" href="recent.php">Voir les résultats des sites testés récemment</a></h3>
</div>
</div>
<?php include("pieddepage.php");

40
pieddepage.php

@ -0,0 +1,40 @@
<!-- Pied de la page -->
<footer id="footer">
<a href="#"><img class="gotopbtn" src="https://art-dambrine.ovh/learning/css/up-arrow.png" title="up-arrow" alt="up-arrow"></a>
<div class="container">
<div class="copyright">Copyright © 2019<span class="green">.</span> Arthur Dambrine & Seth Bio Yara<span class="green">.</span></div>
</div>
</footer>
<script>
function myFunction() {
var x = document.getElementById("myLinks");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
var y = document.getElementById("header-smartphone");
var title = document.getElementById("nav-title");
if (x.style.display === "block") {
y.style.margin = "0px 0px 165px 0px"; /* Aggrandissement du header à l'apparition du menu */
title.style.padding = "14px 16px 0px 16px";
} else {
y.style.margin = "0px 0px 0px 0px";
title.style.padding = "14px 16px";
}
var cross = document.getElementById("cross-ico");
var ham = document.getElementById("ham-ico");
if (x.style.display === "block") {
cross.style.display = "block";
ham.style.display = "none";
} else {
cross.style.display = "none";
ham.style.display = "block";
}
}
</script>

45
provenance.php

@ -0,0 +1,45 @@
<?php /* Projet learning 2019 */
ini_set('display_errors', 1);
error_reporting(~0);
include("head.php");
include("entete.php");
include("bdd.php");
?>
<!-- Corps de la page -->
<div class="content">
<div class="content-inside">
<h1> <strong>Sites référençant le site</strong> <?php echo $_GET["link"]; ?><h1>
<h3>testés par <strong>Robot Index</strong></h3>
<table class="tab-result">
<tbody>
<?php
//phpinfo();
$requete = $bdd -> prepare('
SELECT site_id FROM robot.LINK WHERE link = ?;
');
$requete->execute(array($_GET["link"]));
while ($donnes = $requete->fetch()){
echo '<tr><th><a style="color: #0C62A6;" id="sites-recents" href="site_info.php?url='.$donnes['site_id'].' ">' . parse_url($donnes['site_id'], PHP_URL_HOST). '</a></th></tr>';
}
// site_info.php?url=http://www.arngren.net
?>
</tbody>
</table>
</div>
</div>
<?php include("pieddepage.php");

48
recent.php

@ -0,0 +1,48 @@
<?php /* Projet learning 2019 */
ini_set('display_errors', 1);
error_reporting(~0);
include("head.php");
include("entete.php");
include("bdd.php");
?>
<!-- Corps de la page -->
<div class="content">
<div class="content-inside">
<h1>Sites testés il y a peu</h1>
<h3>par <strong>Robot Index</strong></h3>
<p> <strong>Cliquez sur les liens</strong> pour afficher le résultat des tests<p>
<table class="tab-result">
<tbody>
<?php
//phpinfo();
$requete = $bdd -> prepare('
SELECT url, creation_date as "most_recent"
FROM robot.SITE
WHERE length(url) > 2 AND url NOT like "%cdn%" AND url like "%.%" AND url NOT like "%:%:%"
ORDER BY creation_date DESC
LIMIT 20;
');
$requete->execute();
while ($donnes = $requete->fetch()){
echo '<tr><th><a style="color: #0C62A6;" id="sites-recents" href="site_info.php?url='.$donnes['url'].' ">' . parse_url($donnes['url'], PHP_URL_HOST). '</a></th></tr>';
}
// site_info.php?url=http://www.arngren.net
?>
</tbody>
</table>
</div>
</div>
<?php include("pieddepage.php");

201
robot.php

@ -0,0 +1,201 @@
<?php
/* Defining a PHP Function */
function availablePort($min_port, $max_port) {
for($port = $min_port; $port <= $max_port; $port++){
// create curl resource
$ch = curl_init();
// set url ---> /!\ IMPORTANT Laisser en http (nécessaire)
curl_setopt($ch, CURLOPT_URL, "http://art-dambrine.ovh:".$port);
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
//echo $output;
if($output == null){
//echo $port.' is unused port </br>';
return $port;
} else {
echo 'Robot is busy.</br>';
if($port == $max_port)
return false;
}
}
}
//function isWorkingSite($url)
function isSiteAvailible($url){
// Check, if a valid url is provided
if(!filter_var($url, FILTER_VALIDATE_URL)){
return false;
}
// Initialize cURL
$curlInit = curl_init($url);
// Set options
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,true);
curl_setopt($curlInit,CURLOPT_NOBODY,true);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
// Get response
$response = curl_exec($curlInit);
// Close a cURL session
curl_close($curlInit);
return $response?true:false;
}
/* Projet learning 2019 */
include("head.php");
include("entete.php");
$regex_url = "%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu" ;
$url = $_POST['URL'];
$urlIsVerified = false;
$clean_url = $url;
if (preg_match($regex_url, $url))
{
$scheme = parse_url($url, PHP_URL_SCHEME);
$domain = parse_url($url, PHP_URL_HOST);
$clean_url = $scheme."://".$domain;
$urlIsVerified = true;
}
?>
<!-- Corps de la page -->
<div class="content">
<div class="content-inside">
<h2>Robot Index</h2> <br>
<?php
$iterations = $_POST['number'];
if ($iterations >= 50){
$iterations = 50;
}
echo'<div id="site"><p>';
if ($launchJava = isSiteAvailible($_POST['URL'])){
echo $clean_url;
} else {
echo '<p>Désolé ' . $url .' n\'est pas une url valide pour notre robot <br>';
echo 'Pouvez vous utiliser une url copiée directement
<br> depuis la barre d\'adresse du navigateur ? :) </p>';
}
echo'</p></div>';
echo '<p>';
echo '</br>';
echo 'Pages à visiter : '. $iterations;
echo '</br>';
// Tester si $_POST['URL'] est une URL valide
// Checkin what port to use for the JAVA Robot WebServer
$available_port = availablePort(8085, 8088);
echo 'Notification port : <strong id="port">' . $available_port .'</strong><br>';
$java_shell_exec = "cd /var/www/java &&
nohup java -cp mysql-connector-java.jar:RobotIndex.jar robotindex.RobotIndex " .$clean_url. " " . $iterations . " " .$available_port." &";
// code JAVA exec
if($launchJava && $urlIsVerified && $available_port!=false){
//echo 'Launch JAVA cmd :' . $java_shell_exec;
echo '</br>';
// to execute a command in background <3
pclose(popen($java_shell_exec, 'r'));
} else {
echo 'Essayer une url differente.';
}
echo '</p>';
?>
<br/>
<h4>Dialog-box: </h4>
<p id="dialogbox"></p>
<div class="text-center" style="margin-left: auto; margin-right:auto;">
<progress id="progressbar" value="0" max="100"></progress>
</div>
</div>
</div>
<script>
// Boîte de dialogue pour afficher l'avancement
function loopNotif()
{
//Continuez le traitement après la pause dans cette fonction
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("../get_avancement.php?port=" + document.getElementById("port").textContent, requestOptions)
.then(function(response) {
return response.text();
})
.then(function(myText) {
//console.log("TEST: result :" + myText);
var dialogbox = document.getElementById("dialogbox");
previous = dialogbox.textContent;
console.log("previous: " + previous);
if(myText==""){
myText = "rien a afficher";
if(previous!="" && previous != "rien a afficher"){
console.log("changer de page!!!");
// Simulate an HTTP redirect:
var url = document.getElementById("site");
window.location.replace("site_info.php?url=" + url.textContent);
}
}
// Parse JSON here and get progression :
//myText
const json = myText;
const obj = JSON.parse(json);
// obj.progression; pourcentage de progression
document.getElementById("progressbar").value = obj.progression;
dialogbox.textContent = obj.message;
})
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
setInterval(loopNotif, 1000);
</script>
<?php include("pieddepage.php");

54
site_info.php

@ -0,0 +1,54 @@
<?php /* Projet learning 2019 */
ini_set('display_errors', 1);
error_reporting(~0);
if (isset($_GET['url'])){
include("head.php");
include("entete.php");
include("bdd.php");
?>
<!-- Corps de la page -->
<div class="content">
<div class="content-inside">
<h2>Robot Index</h2>
<?php echo '<h4>' . $_GET['url'] . '</h4></br>';?>
<table class="tab-result">
<tbody>
<?php
//phpinfo();
$requete = $bdd -> prepare('
SELECT url, creation_date, link, score
FROM SITE, LINK
WHERE url = site_id
AND url = ? AND length(link) > 2 AND link NOT like "%cdn%" AND link like "%.%"
ORDER BY score DESC;
');
$requete->execute(array($_GET['url']));
// Declaration du tableau associatif
while ($donnes = $requete->fetch()){
echo '<tr><th>' . $donnes['link'] . '</th>';
echo '<td id="td-padding">' . $donnes['score'] . '</td></tr>';
}
?>
</tbody>
</table>
<h4 style="margin-top:30px;"><a style="color: #0C62A6;" href="index.php">Relancer une recherche</a></h4>
</div>
</div>
<?php include("pieddepage.php");
} else {
echo 'Manque un parametre url';
} // fin du isset

76
top.php

@ -0,0 +1,76 @@
<?php /* Projet learning 2019 */
ini_set('display_errors', 1);
error_reporting(~0);
include("head.php");
include("entete.php");
include("bdd.php");
// SELECT count(*) FROM robot.SITE WHERE url NOT like "%:%:%";
$requete = $bdd -> prepare('
SELECT count(*)
FROM robot.SITE
WHERE url NOT like "%:%:%";');
$requete->execute();
$nbsites = $requete->fetch();
?>
<!-- Corps de la page -->
<div class="content">
<div class="content-inside">
<div class="text-padding">
<h1>Top 50 des liens</h1>
<h3>trouvés par <strong>Robot Index</strong></h3>
<p> <strong>Liens externes apparus</strong> le plus souvent parmi les <strong> <?php echo $nbsites['count(*)'] ?> sites </strong> testés avec notre robot<p>
<p> <strong>O : occurences</strong> somme des apparitions de ce lien - <strong>P : pertinence</strong> nombre de sites visant ce lien.<p>
</div>
<table class="tab-result">
<tbody>
<?php
//phpinfo();
$requete = $bdd -> prepare('
SELECT link, sum(score) as "sum" , count(link) as "from_nb_sites"
FROM LINK
WHERE length(link) > 2 AND link NOT like "%cdn%" AND link like "%.%"
GROUP BY link
HAVING count(link) > 1
ORDER BY count(link) DESC
LIMIT 50;
');
$requete->execute();
echo '<div class="tab-top-50">
<tr class="table-head-top-50">
<td>Liens</td>
<td id ="td-padding">O</td>
<td id ="td-padding">P</td>
</tr>';
while ($donnes = $requete->fetch()){
echo '<tr><th><a style="color: #0C62A6;" href="//'.$donnes['link'].'">' . $donnes['link'] . '</a></th>';
echo '<td id ="td-padding">' . $donnes['sum'] . '</td>';
//echo '<td id ="td-padding">' . $donnes['from_nb_sites'] . '</td></tr> </div">';
echo '<td id ="td-padding"><a style="color: #0C62A6;" href="provenance.php?link='.$donnes['link'].' ">' . $donnes['from_nb_sites']. '</a></td></tr> </div">';
// <a style="color: #0C62A6;" href="provenance.php?url='.$donnes['link'].' ">' . $donnes['from_nb_sites']. '</a>
}
?>
</tbody>
</table>
</div>
</div>
<?php include("pieddepage.php");
Loading…
Cancel
Save