Fin du dossier megaprocess, encore de nouvelles classesx

This commit is contained in:
Mysaa 2021-06-06 12:29:03 +02:00
parent fba5123944
commit 228f54d140
19 changed files with 530 additions and 5595 deletions

View File

@ -1,18 +1,19 @@
<?php
session_start();
include_once 'clazz/Zincluder.php';
/*
$me = new Membre();
$me->connect();
if($me->isAdminLevelLowerThan(15)){
$me = new Membre($_SESSION ['session_id']);
$me->connect($_SESSION ['session_mdp']);
if(!$me->isConnected()){
echo 'Your must being connected to have access to this page';
exit;
}elseif($me->isAdminLevelLowerThan(15)){
echo 'Your admin level is too low (15 or more required)';
exit;
}elseif(!isset($_POST['command'])){
echo 'Please set an command in the URL (POST method ,name:"command")';
exit;
}
*/
function isAlphaNumeric($char){
return isAlphabetic($char) or isNumeric($char);
}
@ -97,7 +98,7 @@ function readOperator($command,$endChar = 'abcdefghijklmnopqrstuvwxytABCDEFGHIJK
$tPos = $pos;
while ($tPos<$maxPos) {
//echo $reading;
$reading .= $command[$pos];
$reading .= $command[$tPos];
$tPos+=1;
if(in_array($reading,$operators,TRUE))
$lastOperator=$reading;
@ -153,7 +154,7 @@ $command=$_POST['command'].' ';
$nommes=array();
$pos=0;
while ($pos<strlen($command)) {
echo $pos;
$nomme = array();
$type=$command[$pos];
if(isAlphabetic($type)){
@ -171,6 +172,7 @@ while ($pos<strlen($command)) {
}elseif ($type === "@"){
$nomme[0] = "@";
$nomme[1] = readSelector($command);
//TODO Add @Selector[]:var type ':' support
}
elseif ($type === ' ')break;
else error($pos, 'Unexpected char "'.$command[$pos].'" , cannot get the term type');
@ -179,10 +181,12 @@ while ($pos<strlen($command)) {
}
//DEBUG
/*
echo '<pre>';
print_r($nommes);
echo '</pre>';
*/
function exception($reason){
echo 'An exception occurred : '.$reason;
@ -209,8 +213,12 @@ if($nommes[0][0] == 'a'){
switch ($nommes[1][1][0]){
case 'Membre':
$objectsToSet = Membre::getFromAttributes($nommes[1][1][1]);
echo '<br/><pre>';
print_r($objectsToSet);
echo '</pre>';
break;
case 'Projet':
//TODO add others class support
break;
case 'Version':
break;
@ -219,13 +227,50 @@ if($nommes[0][0] == 'a'){
case 'Message':
break;
default:
exception('Unknown selector class : '.$nommes[1][1][0]);
exception('Unknown selector class :'.$nommes[1][1][0]);
}
if($objectsToSet === NULL)
exception('Not any object match the specified selector');
echo '<pre>';
if($nommes[2][0] !== 'a')
exception('Le troisième paramètre doit etre une chaine de commande (chaine de caractères alphanumériques commensant par une lettre sans guillemets');
if($nommes[3][0] !== '"' and $nommes[3][0] !== '0' and $nommes[3][0] !== ':')
exception('Le quatrième paramètre doit etre une variable (chaine de caractères entre guillemets, nombre ou variable de selecteur');
$attributeToSetName = $nommes[2][1];
$varToSet = $nommes[3];
//TODO add @Selector[]:var support
foreach($objectsToSet as $objectToSet){
$objectToSet->setAttribute($attributeToSetName,$varToSet[1],$varToSet[0]);
}
echo 'SET the value '.$varToSet[1].' at attribute '.$attributeToSetName.' of '.count($objectsToSet).' objects';
break;
case 'GET':
/*
GET selector
*/
if(count($nommes) !== 2)
exception('La fonction n\'a pas recu le bon nombre d\'arguments (2)');
if($nommes[1][0] !== '@')
exception('Le deuxième argument doit etre un selecteur');
$objectsToSet=NULL;
switch ($nommes[1][1][0]){
case 'Membre':
$objectsToSet = Membre::getFromAttributes($nommes[1][1][1]);
break;
case 'Projet':
//TODO add others class support
break;
case 'Version':
break;
case 'Discussion':
break;
case 'Message':
break;
default:
exception('Unknown selector class :'.$nommes[1][1][0]);
}
echo '<br/><pre>';
print_r($objectsToSet);
echo '</pre>';
echo '</pre>';+
break;
case 'DELETE':

View File

@ -2,8 +2,8 @@
class Langage{
//FIXME const
static $java = new Langage(0, "Java", "jar java javadoc");
static $vba = new Langage(1, "VBA", "xlsm vb");
public static $java;
public static $vba;
protected static $languages = array();
@ -12,7 +12,7 @@ class Langage{
protected $avalivableFiles;//String "jar xlsx javadoc" in constructor , stored as a string array
protected function __construct($ID,$name,$avalivableFiles){
public function __construct($ID,$name,$avalivableFiles){
$this->ID = $ID;
$this->name = $name;
$this->avalivableFiles = explode(" ",$avalivableFiles);
@ -52,4 +52,6 @@ class Langage{
return NULL;
}
}
}
Langage::$java = new Langage(0, "Java", "jar java javadoc");
Langage::$vba = new Langage(1, "VBA", "xlsm vb");

View File

@ -31,8 +31,7 @@ class Membre {
}
public function connect($password) {
$this->connected = password_verify ( $this->pass, $rep ['mdp'] );
$this->connected = password_verify ($password, $this->hashedPassword );
return $this->connected;
}
@ -57,7 +56,7 @@ class Membre {
}
private function decodeData($data) {
$jsonData = json_decode ( $data );
$jsonData = json_decode ( $data ,TRUE);
// Set the data's required_banner if it is defined , otherwise sets the DEFAULT_BANNER
$this->requiredBanner = $jsonData ['requiredBanner'] ?? self::DEFAULT_BANNER;
$this->personnalMessage = $jsonData ['personnalMessage'] ?? NULL;
@ -126,6 +125,81 @@ class Membre {
return Membre::PASSWORD_CHANGED;
}
public function setAttribute($attribute,$value,$valueType){
$json=FALSE;
switch ($attribute){
case 'ID':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'pseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'hashedPseudo':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'adminLevel':
if($valueType !== '0'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($value);
break;
case 'dateCreation':
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$value.'"';
break;
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
case 'personnalMessage':
$json=TRUE;
if($valueType !== '"'){
echo 'Error : the type "'.$valueType.'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($value).'"';
break;
default:
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
$restrictionValues[] = $value;
if($json){
//TODO Set command for json
}else{
$command = 'UPDATE membres SET ' . $attribute . '=' . $value . ' WHERE ID=' . $this->ID;
}
echo $command.'</br>';
$req = $GLOBALS['bdd']->prepare($command);
$req->execute(array());
if($req->errorInfo()[0] != 0){
echo 'Eine MYSQL Exception hat geworft. Einschuldigung';
exit;
}
}
/**
*
* @return Objects which matchs the specified restrictions
@ -142,38 +216,65 @@ class Membre {
try {
switch ($attribute){
case 'ID':
$value = intval($restriction[2]);
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'pseudo':
$value = '"'.strval($restriction[2]).'"';//FIXME escaped chars (',",\n,\t ...)
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'hashedPseudo':
$value = '"'.strval($restriction[2]).'"';
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'adminLevel':
$value = intval($restriction[2]);
if($restriction[2][0] !== '0'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = intval($restriction[2][1]);
$operator = Utility::getIntegerSqlOperator($restriction[1]);
break;
case 'dateCreation':
//FIXME y ä pâs là vàlüè
$value=""
$operator = 'convert(datetime, "'.Utility::getDateSqlOperator($restriction[1]).'")';
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.$restriction[2][1].'"';
$operator = Utility::getDateSqlOperator($restriction[1]);
break;
case 'requiredBanner':
case 'requiredBanner'://FIXME jsonMysqlProblem
$json=TRUE;
$value = "'".strval($restriction[2])."'";
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
case 'personnalMessage':
$json=TRUE;
$value = "'".strval($restriction[2])."'";
if($restriction[2][0] !== '"'){
echo 'Error : the type "'.$restriction[2][0].'" is not allowed for the attribute '.$attribute;
exit;
}
$value = '"'.strval($restriction[2][1]).'"';
$operator = Utility::getStringSqlOperator($restriction[1]);
break;
default:
echo 'Unknown attribute "'.$attribute.'" for the class Membre';
echo 'Undefined attribute "'.$attribute.'" for the class Membre';
exit;
}
}catch(InvalidOperatorException $e){
@ -182,7 +283,6 @@ class Membre {
}
$restrictionValues[] = $value;
if($json){
$whereCommand = '((data->"$.'.$attribute.'" IS NOT NULL) AND (data->"$.'.$attribute.'" '.$operator.' ? ))';
}else{
@ -190,17 +290,20 @@ class Membre {
}
$whereCommands[] = $whereCommand;
}
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
$wherePart = "";
if(count($whereCommands) >0)
$wherePart = 'WHERE '.implode(' AND ',$whereCommands);
$req = $GLOBALS['bdd']->prepare('SELECT * FROM membres '.$wherePart);
$command = 'SELECT * FROM membres '.$wherePart;
$req = $GLOBALS['bdd']->prepare($command);
$req->execute($restrictionValues);
if($req->errorInfo()[0] == 0)
echo 'A SQL exception occured ...';
echo $command.'</br>';
if($req->errorInfo()[0] != 0)
echo 'Erreur SQL, veuillez verifier les selecteurs';
$out = array();
while($rep = $req->fetch())
$out[] = new Membre($rep['ID']);
//Choose return value
switch(count($out)){
case 0:

64
clazz/Projet.php Normal file
View File

@ -0,0 +1,64 @@
<?php
class Projet{
protected $ID;
protected $name;
protected $dateCreation;
protected $owner;
protected $secondaryOwners;
protected $valid;
public function __construct($ID){
$this->ID = $ID;
$req = $GLOBALS['bdd']->prepare('SELECT * FROM projets WHERE ID=?');
$req->execute(array($ID));
if($rep = $req->fetch()){
$this->valid = TRUE;
$this->name = $rep['name'];
$this->owner = new Membre($rep['ownerID']);
$this->dateCreation = $rep['dateCreation'];
$this->secondaryOwners = array();
foreach (explode(';',$rep['secondaryOwners']) AS $secondaryOwner)
$this->secondaryOwners[] = new Membre($secondaryOwner);
}else{
$this->valid = FALSE;
}
}
public function exists(){
return $this->valid;
}
public function __toString(){
$out = 'Projet\n';
$out .= '\tID:' . $this->ID . '\n';
$out .= '\tName:' . $this->name . '\n';
$out .= '\tOwner:{' . substr(str_replace('\n\t',';',$this->owner->__toString()),0,-1) . '}\n';
foreach($this->secondaryOwners AS $secondaryOwner)
$out .= '\tSecondary owner:{' . substr(str_replace('\n\t',';',$secondaryOwner->__toString()),0,-1) . '}\n';
$out .= '\tDate of creation:' . $this->dateCreation . '\n';
return out;
}
//Getters
public function getID(){
return $this->ID;
}
public function getName(){
return $this->name;
}
public function getOwner(){
return $this->owner;
}
public function getSecondaryOwners(){
return $this->secondaryOwners;
}
public function getDateCreation(){
return $this->dateCreation;
}
}

View File

@ -6,6 +6,7 @@ try{
die ('Erreur : ' . $e->getMessage());
}
//TODO all exceptions in functions must be returns (make handle too)
//TODO in the classes , do more test of exists in setters
include_once 'clazz/Utility.class.php';
include_once 'clazz/Langage.class.php';

View File

@ -1,62 +0,0 @@
#adminDialogAnswer{
display:block;
background-color:black;
color:white;
height: 150px;
overflow:scroll;
}
#setFormObject , #setChampsForm{
display:inline-block;
text-align: center;
height: inherit;
}
#setFormObject{
width:25%;
}
#setChampsForm{
width:75%;
}
#setDiv{
border:5px double grey;
}
#send{
width:100%;
}
.fullscreen{
position:fixed;
top:0;
right:0;
width:100%;
height:100%;
vertical-align:middle;
background-color: #222;
opacity:0.97;
}
.screen-vertical-centered{
text-align:center;
margin-top: 50vh;
transform: translateY(-50%);
}
.screen-horizontal-centered{
display:inline;
opacity:1;
font-size:42px;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}

View File

@ -13,20 +13,6 @@
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
--><!--
3.14159265358979323846264338327950288419716939
______________________________________________
__________$$$$$$$$$$$$$$$$$$$$$$$$$$__________
__________$$$$$$$$$$$$$$$$$$$$$$$$$$__________
_______________$$$_________$$$________________
_______________$$$_________$$$________________
_______________$$$_________$$$________________
_______________$$$_________$$$________________
_______________$$$_________$$$________________
_______________$$$_________$$$________________
______________$$$__________$$$________________
_____________$$$___________$$$________________
______________________________________________
-->
<?php
include_once('includes/inter.php');

View File

@ -155,6 +155,7 @@ function getVersions($pid = NULL) {
$req->execute ( array (
$pid
) );
// ADDPOINT langage
$versions = array (
array (),
array ()
@ -216,7 +217,6 @@ function getMessages($discut = NULL) {
$req->closeCursor ();
return array_slice ( $rep, 0, - 1, TRUE );
}
function getDiscuts() {
$req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions ORDER BY date_creation DESC" );
$rep = array ();

View File

@ -84,6 +84,19 @@
</div>
</article>
<!--article id="logicAxiom">
<h2 class="articleTitle"><strong>Axiomes de la logique</strong></h2>
<a class="articlePic" href="tempPreMega/godel.png"><img src="tempPreMega/godel.png" width="128" /></a>
<div class="articleText">
<ul>
<li></li>
<ul>
</div>
</article-->
<article id="administration">
<h2 class="articleTitle"><strong>Administration</strong></h2>

262
inter.php Normal file
View File

@ -0,0 +1,262 @@
<?php
include_once 'includes/bdd.php';
function isConnected($sid = NULL, $mdp = NULL) {
if (! isset ( $sid ) or ! isset ( $mdp )) {
$sid = $_SESSION ['session_id'];
$mdp = $_SESSION ['session_mdp'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
if ($rep = $req->fetch ()) {
$connected = password_verify ( $mdp, $rep ['mdp'] );
} else {
$connected = FALSE;
}
$req->closeCursor ();
return $connected;
}
function getAdminLevel($sid = NULL, $mdp = NULL) {
if (! isset ( $sid ) or ! isset ( $mdp )) {
$sid = $_SESSION ['session_id'];
$mdp = $_SESSION ['session_mdp'];
}
if (! isConnected ( $sid, $mdp ))
return - 1;
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
if ($result = $req->fetch ()) {
$adminLevel = $result ['administration'];
} else {
$adminLevel = - 1;
}
$req->closeCursor ();
return $adminLevel;
}
function getPseudo($sid = NULL, $mdp = NULL) {
if (! isset ( $sid ) or ! isset ( $mdp )) {
$sid = $_SESSION ['session_id'];
$mdp = $_SESSION ['session_mdp'];
}
if (! isConnected ( $sid, $mdp ))
return "neant";
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
$pseudo = $req->fetch () ['pseudo'];
$req->closeCursor ();
return $pseudo;
}
function getPseudoOf($sid) {
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE ID=?' );
$req->execute ( array (
$sid
) );
$pseudo = $req->fetch () ['pseudo'];
$req->closeCursor ();
return $pseudo;
}
function tryToConnect($pseudo = NULL, $mdp = NULL) {
if (! isset ( $pseudo ) or ! isset ( $mdp )) {
$pseudo = $_POST ['pseudo'];
$mdp = $_POST ['mdp'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT * FROM users WHERE pseudo=?' );
$req->execute ( array (
$pseudo
) );
$reponce = $req->fetch ();
if ($reponce != NULL) {
if (password_verify ( $mdp, $reponce ['mdp'] )) {
$req->closeCursor ();
return $reponce ['ID'];
} else {
$req->closeCursor ();
return 'errormdp';
}
} else {
$req->closeCursor ();
return 'errorpseudo';
}
}
function getProjectVersionData($project = NULL, $version = NULL) {
if (! isset ( $project ) or ! isset ( $version )) {
$project = $_GET ['id'];
$version = $_GET ['v'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT p.ID AS pID ,' . ' ' . 'v.versionAbs AS versionAbs , ' . ' ' . 'p.name AS name ,' . ' ' . 'v.version AS version ,' . ' ' . 'v.language AS language ,' . ' ' . 'p.permissions AS permissions ,' . ' ' . 'p.ownersID AS owners' . ' ' . 'FROM projets AS p' . ' ' . 'INNER JOIN versions AS v' . ' ' . 'ON v.project_id = p.ID' . ' ' . 'WHERE v.project_id = ? AND v.versionAbs = ?' );
$req->execute ( array (
$project,
$version
) );
if (($data = $req->fetch ())) {
$req->closeCursor ();
return $data;
} else {
$req->closeCursor ();
return NULL;
}
}
function getProjectData($project = NULL) {
if (! isset ( $project )) {
$project = $_GET ['id'];
}
$req = $GLOBALS ['bdd']->prepare ( 'SELECT p.ID AS ID ,' . ' ' . 'p.name AS name ,' . ' ' . 'p.permissions AS permissions ,' . ' ' . 'p.ownersID AS owners' . ' ' . 'FROM projets AS p' . ' ' . 'WHERE p.ID = ?' );
$req->execute ( array (
$project
) );
if (($data = $req->fetch ())) {
$req->closeCursor ();
return $data;
} else {
$req->closeCursor ();
return NULL;
}
}
function getPermissions($data) {
$permissions = array (
FALSE,
FALSE,
FALSE,
FALSE
);
$permissions [0] = preg_match ( '#^1#', $data ['permissions'] );
$permissions [1] = preg_match ( '#^(0|1)1#', $data ['permissions'] );
$permissions [2] = preg_match ( '#^(0|1){2}1#', $data ['permissions'] );
$permissions [3] = preg_match ( '#^(0|1){3}1#', $data ['permissions'] );
return $permissions;
}
function getProjectsWithFirstPermission() {
$requete = 'SELECT p.ID AS projectID , v.versionAbs AS versionAbs , p.name AS projectName , v.version AS versionName ' . 'FROM projets AS p ' . 'INNER JOIN versions AS v ' . 'ON v.project_id = p.ID ' . 'WHERE p.permissions LIKE "1%" ';
$req = $GLOBALS ['bdd']->query ( $requete );
$projects = array ();
while ( $rep = $req->fetch () ) {
if (! isset ( $projects [$rep ['projectID']] )) {
$projects [$rep ['projectID']] = $rep;
} else if ($projects [$rep ['projectID']] ['versionAbs'] < $rep ['versionAbs']) {
$projects [$rep ['projectID']] = $rep;
}
}
$req->closeCursor ();
return $projects;
}
function getVersions($pid = NULL) {
if (! isset ( $pid )) {
$pid = $_GET ['id'];
}
$requete = 'SELECT * FROM versions WHERE project_id = ?';
$req = $GLOBALS ['bdd']->prepare ( $requete );
$req->execute ( array (
$pid
) );
// ADDPOINT langage
$versions = array (
array (),
array ()
);
while ( $rep = $req->fetch () ) {
$versions [$rep ['language']] [] = array (
'versionAbs' => $rep ['versionAbs'],
'versionName' => $rep ['version']
);
}
$req->closeCursor ();
return $versions;
}
function getOwnersisProjects($sid = NULL) {
if (! isset ( $sid )) {
$sid = $_SESSION ['session_id'];
}
$requete = 'SELECT p.ownersID AS ownersID , p.ID AS projectID , v.versionAbs AS versionAbs , p.name AS projectName , v.version AS versionName ' . 'FROM projets AS p ' . 'INNER JOIN versions AS v ' . 'ON v.project_id = p.ID ' . 'WHERE p.ownersID REGEXP \'[^0-9]?' . $sid . '[^0-9]?\' ';
$req = $GLOBALS ['bdd']->query ( $requete );
$projects = array ();
while ( $rep = $req->fetch () ) {
if (! isset ( $projects [$rep ['projectID']] )) {
$projects [$rep ['projectID']] = $rep;
} else if ($projects [$rep ['projectID']] ['versionAbs'] < $rep ['versionAbs']) {
$projects [$rep ['projectID']] = $rep;
}
}
return $projects;
}
function registerPerson($pseudo, $mdp) {
$req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM users WHERE pseudo=?" );
$req->execute ( array (
$_POST ['pseudo']
) );
if ($req->fetch ()) {
return 'usedPseudo';
} else {
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO users(pseudo,mdp,date_creation) VALUES (?,?,NOW())' );
$req->execute ( array (
$_POST ['pseudo'],
password_hash ( $_POST ['mdp'], PASSWORD_DEFAULT )
) );
return 'ok';
}
}
function getMessages($discut = NULL) {
if (! isset ( $discut )) {
$discut = $_GET ['d'];
}
$req = $GLOBALS ['bdd']->prepare ( "SELECT * FROM messages WHERE discussion_id=? ORDER BY sendTime DESC" );
$req->execute ( array (
$discut
) );
$rep = array ();
while ( $rep [] = $req->fetch () )
;
if (count ( $rep ) <= 0)
$rep = NULL;
$req->closeCursor ();
return array_slice ( $rep, 0, - 1, TRUE );
}
function getDiscuts() {
$req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions ORDER BY date_creation DESC" );
$rep = array ();
while ( $rep [] = $req->fetch () )
;
if (count ( $rep ) <= 1)
$rep = NULL;
$req->closeCursor ();
return array_slice ( $rep, 0, - 1, TRUE );
}
function getDiscutInfos($did = NULL) {
if(!isset($did)){
$did = $_GET['d'];
}
$req = $GLOBALS ['bdd']->query ( "SELECT * FROM discussions WHERE ID=?" );
return $req->fetch();
}
function sendMessage($discut = NULL, $text = NULL, $sender = NULL) {
if (! isset ( $discut ) || ! isset ( $text ) || ! isset ( $sender )) {
$discut = $_GET ['d'];
$text = $_POST ['msg'];
$sender = $_SESSION ['session_id'];
}
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO messages(discussion_id,texte,senderID,sendTime) VALUES (?,?,?,NOW())' );
$req->execute ( array (
$discut,
htmlspecialchars ( $text ),
$sender
) );
return 'ok';
}
function createDiscut($name = NULL, $owner = NULL) {
if (! isset ( $name ) || ! isset ( $owner )) {
$name = $_POST ['name'];
$owner = $_SESSION ['session_id'];
}
$req = $GLOBALS ['bdd']->prepare ( 'INSERT INTO discussions(name,creator_id,date_creation) VALUES (?,?,NOW())' );
$req->execute ( array (
$name,
$owner
) );
return 'ok';
}

View File

@ -1,47 +0,0 @@
<?php
session_start();
echo ('extensions:"'.ini_get('extension_dir').'"');
include_once "../includes/bdd.php";
include_once "../includes/inter.php";
include_once "megaapi.php";
$permissions = array (
FALSE,
FALSE,
FALSE,
FALSE
);
$connected = isConnected ();
$owner = FALSE;
$adminLevel = - 1;
$data = NULL;
if (isset ( $_GET ['id'] ) && isset ( $_GET ['v'] )) {
$data = getProjectVersionData( $_GET ['id'], $_GET ['v'] );
if ($data != NULL) {
$permissions = getPermissions( $data );
} else {
header('Location:../40A.php');
goto end;
}
} else {
header('Location:../40A.php');
goto end;
}
if (! $connected) {
header( 'Location:../401.php' );
goto end;
}
$owner = preg_match ( '#[^0-9]?' . $_SESSION ['session_id'] . '[^0-9]?#', $data ['owners'] );
$adminLevel = getAdminLevel ();
if (! $owner && $adminLevel < 12) {
header( 'Location:../403.php' );
goto end;
}
$megaapi = new MegaApiPHP("mA9D1IQQ", "PHP bernard.com");
$megaapi->login("bernard.lafayette63@gmail.com", "*******************");
$node = $megaapi->getNodeByPath('imageFinal.jpg', $megaapi->getRootNode());
$megaapi->startDownload($node, './');
end:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,688 +0,0 @@
#!/usr/bin/env php
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
set_time_limit(0);
set_include_path(get_include_path() . PATH_SEPARATOR . "../../bindings/php");
include 'megaapi.php';
require_once('vendor/autoload.php');
use Symfony\Component\Console\Shell;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
$megaapi = NULL;
$cwd = NULL;
class AppListener implements MegaListenerInterface
{
public function onRequestStart($megaApi, $request)
{
}
public function onRequestFinish($megaApi, $request, $error)
{
global $cwd;
if($error->getErrorCode() != MegaError::API_OK)
{
print("INFO: Request finished with error ( " . $request . " ) Result: " . $error . "\n");
print("MEGA > ");
return;
}
$requestType = $request->getType();
if($requestType == MegaRequest::TYPE_LOGIN)
{
print("Fetchning nodes. Please wait...\n");
print("MEGA > ");
$megaApi->fetchNodes();
}
else if($requestType == MegaRequest::TYPE_FETCH_NODES)
{
print("Account correctly loaded\n");
print("MEGA > ");
$cwd = $megaApi->getRootNode();
}
else if($requestType == MegaRequest::TYPE_EXPORT)
{
print("INFO: Exported link: " . $request->getLink() . "\n");
print("MEGA > ");
}
else if($requestType == MegaRequest::TYPE_ACCOUNT_DETAILS)
{
$accountDetails = $request->getMegaAccountDetails();
print("INFO: Account details received\n");
print("Account e-mail: " . $megaApi->getMyEmail() . "\n");
print("Storage: " . $accountDetails->getStorageUsed() . " of " . $accountDetails->getStorageMax() .
" (" . (100 * $accountDetails->getStorageUsed() / $accountDetails->getStorageMax()) . "%)\n");
print("Pro level: " . $accountDetails->getProLevel() . "\n");
print("MEGA > ");
}
}
public function onRequestTemporaryError($megaApi, $request, $error)
{
print("INFO: Request temporary error ( " . $request . " ) Error: " + $error . "\n");
}
public function onTransferStart($megaApi, $transfer)
{
print("INFO: Transfer start ( " . $transfer . " " . $transfer->getFileName() . " )\n");
}
public function onTransferFinish($megaApi, $transfer, $error)
{
print("INFO: Transfer finished ( " . $transfer . " " . $transfer->getFileName() . " ) Result: " . $error . "\n");
print("MEGA > ");
}
public function onTransferUpdate($megaApi, $transfer)
{
print("INFO: Transfer update ( " . $transfer . " " . $transfer->getFileName() . " ) Progress: " . $transfer->getTransferredBytes()/1024 ." KB of " . $transfer->getTotalBytes()/1024 . " KB, " . $transfer->getSpeed()/1024 . " KB/s\n");
}
public function onTransferTemporaryError($megaApi, $request, $error)
{
print("INFO: Transfer temporary error ( " . $transfer . " " . $transfer->getFileName() . " ) Error: " . $error . "\n");
}
public function onUsersUpdate($megaApi, $users)
{
}
public function onNodesUpdate($megaApi, $nodes)
{
global $cwd;
if($nodes != NULL)
{
print("INFO: Nodes updated ( " . count($nodes) . " )\n");
print("MEGA > ");
}
else
$cwd = $megaApi->getRootNode();
}
public function onReloadNeeded($megaApi)
{
}
}
class LoginCommand extends Command
{
protected function configure()
{
$this->setName('login');
$this->setDescription('Log in to a MEGA account');
$this->addArgument('email', InputArgument::REQUIRED, 'Email of the account');
$this->addArgument('password', InputArgument::REQUIRED, 'Password of the account');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
$email = $input->getArgument('email');
$password = $input->getArgument('password');
$megaapi->login($email, $password);
}
}
class LogoutCommand extends Command
{
protected function configure()
{
$this->setName('logout');
$this->setDescription('Log out a MEGA account');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
$megaapi->logout();
$cwd = null;
}
}
class LsCommand extends Command
{
protected function configure()
{
$this->setName('ls');
$this->setDescription('List a MEGA folder');
$this->addArgument('path', InputArgument::OPTIONAL, 'folder path');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$path = $input->getArgument('path');
if ($path)
{
$folder = $megaapi->getNodeByPath($path, $cwd);
}
else
{
$folder = $cwd;
}
$output->writeln(" .");
if($megaapi->getParentNode($folder) != NULL)
{
$output->writeln(" ..");
}
$children = $megaapi->getChildren($folder);
foreach($children as $node)
{
$output->write(" " . $node->getName());
if($node->getType() == MegaNode::TYPE_FILE)
{
$output->writeln(" (" . $node->getSize() . " bytes)");
}
else
{
$output->writeln(" (folder)");
}
}
}
}
class MkdirCommand extends Command
{
protected function configure()
{
$this->setName('mkdir');
$this->setDescription('Create a folder');
$this->addArgument('name', InputArgument::REQUIRED, 'folder name');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$name = $input->getArgument('name');
$megaapi->createFolder($name, $cwd);
}
}
class CdCommand extends Command
{
protected function configure()
{
$this->setName('cd');
$this->setDescription('Change the current directory');
$this->addArgument('path', InputArgument::REQUIRED, 'new current directory');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$path = $input->getArgument('path');
$new = $megaapi->getNodeByPath($path, $cwd);
if($new == null)
{
$output->writeln("Invalid path");
return;
}
$cwd = $new;
}
}
class MvCommand extends Command
{
protected function configure()
{
$this->setName('mv');
$this->setDescription('Move a file/folder');
$this->addArgument('source', InputArgument::REQUIRED, 'Source file/folder');
$this->addArgument('destination', InputArgument::REQUIRED, 'Destination file/folder');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$source = $input->getArgument('source');
$name = $input->getArgument('destination');
$srcNode = $megaapi->getNodeByPath($source, $cwd);
if($srcNode == null)
{
$output->writeln($source . ": No such file or directory");
return;
}
$dstNode = $megaapi->getNodeByPath($name, $cwd);
if(($dstNode != null) && $dstNode->isFile())
{
$output->writeln($name . ": Not a directory");
return;
}
if($dstNode != null)
{
$megaapi->moveNode($srcNode, $dstNode);
return;
}
if(strpos($name,"/") !== false || strpos($name,"\\") !== false)
{
$str1 = strrchr($name, "/");
$str2 = strrchr($name, "\\");
$index = null;
if($str2 == FALSE || strlen($str1) < strlen($str2))
{
echo "A\n";
$index = strlen($name) - strlen($str1);
}
else
{
echo "B\n";
$index = strlen($name) - strlen($str2);
}
$path = substr($name, 0, $index);
$base = $megaapi->getNodeByPath($path, $cwd);
$name = substr($name, $index+1);
echo "INDEX: " . $index . "\n";
echo "str1: " . $str1 . "\n";
echo "str2: " . $str2 . "\n";
echo "PATH: " . $path . "\n";
echo "NAME: " . $name . "\n";
if($base == null)
{
$output->writeln($path . ": Not such directory");
return;
}
if($base->isFile())
{
$output->writeln($path . ": Not a directory");
return;
}
$megaapi->moveNode($srcNode, $base);
if(strlen($name) != 0)
{
$megaapi->renameNode($srcNode, $name);
}
return;
}
if($dstNode == null)
{
$megaapi->renameNode($srcNode, $name);
}
}
}
class PwdCommand extends Command
{
protected function configure()
{
$this->setName('pwd');
$this->setDescription('Get the current working directory');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$output->writeln($megaapi->getNodePath($cwd));
}
}
class RmCommand extends Command
{
protected function configure()
{
$this->setName('rm');
$this->setDescription('Remove a file/folder');
$this->addArgument('path', InputArgument::REQUIRED, 'Path to file/folder to delete');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$path = $input->getArgument('path');
$node = $megaapi->getNodeByPath($path, $cwd);
if($node == null)
{
$output->writeln("Invalid path");
return;
}
$megaapi->remove($node);
}
}
class GetCommand extends Command
{
protected function configure()
{
$this->setName('get');
$this->setDescription('Download a file from MEGA');
$this->addArgument('path', InputArgument::REQUIRED, 'Path to the file');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$path = $input->getArgument('path');
$node = $megaapi->getNodeByPath($path, $cwd);
if($node == null)
{
$output->writeln("Invalid path");
return;
}
if(!$node->isFile())
{
$output->writeln("Not a file");
return;
}
$megaapi->startDownload($node, "./");
}
}
class PutCommand extends Command
{
protected function configure()
{
$this->setName('put');
$this->setDescription('Upload a file to MEGA');
$this->addArgument('path', InputArgument::REQUIRED, 'Path to the local file');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$path = $input->getArgument('path');
$megaapi->startUpload($path, $cwd);
}
}
class ExportCommand extends Command
{
protected function configure()
{
$this->setName('export');
$this->setDescription('Generate a public link');
$this->addArgument('path', InputArgument::REQUIRED, 'Path to the file/folder in MEGA');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$path = $input->getArgument('path');
$node = $megaapi->getNodeByPath($path, $cwd);
if($node == null)
{
$output->writeln("Invalid path");
return;
}
$megaapi->exportNode($node);
}
}
class ImportCommand extends Command
{
protected function configure()
{
$this->setName('import');
$this->setDescription('Import a MEGA public file link');
$this->addArgument('link', InputArgument::REQUIRED, 'Public MEGA file link');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$link = $input->getArgument('link');
$megaapi->importFileLink($link, $cwd);
}
}
class PasswdCommand extends Command
{
protected function configure()
{
$this->setName('passwd');
$this->setDescription('Change the access password');
$this->addArgument('current_password', InputArgument::REQUIRED, 'Current password');
$this->addArgument('new_password', InputArgument::REQUIRED, 'New password');
$this->addArgument('repeat_new_password', InputArgument::REQUIRED, 'New password');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$current_password = $input->getArgument('current_password');
$new_password = $input->getArgument('new_password');
$repeat_new_password = $input->getArgument('repeat_new_password');
if($new_password != $repeat_new_password)
{
$output->writeln("Error: Password mismatch");
return;
}
$megaapi->changePassword($current_password, $new_password);
}
}
class WhoamiCommand extends Command
{
protected function configure()
{
$this->setName('whoami');
$this->setDescription('Show info about the current user');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$output->writeln($megaapi->getMyEmail());
$megaapi->getAccountDetails();
}
}
class MountCommand extends Command
{
protected function configure()
{
$this->setName('mount');
$this->setDescription('Show incoming shares');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
global $megaapi;
global $cwd;
if($cwd == null)
{
$output->writeln("Not logged in");
return;
}
$output->writeln("INFO: INSHARES:");
$users = $megaapi->getContacts();
foreach($users as $user)
{
$megaapi->getInShares();
$inshares = $megaapi->getInShares($user);
foreach($inshares as $share)
{
$output->writeln("INFO: INSHARE on " . $user->getEmail() . " " . $share->getName() . " Access level: " . $megaapi->getAccess($share));
}
}
}
}
class ExitCommand extends Command
{
protected function configure()
{
$this->setName('exit');
$this->setDescription('Exit the app');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
exit(0);
}
}
class QuitCommand extends ExitCommand
{
protected function configure()
{
$this->setName('quit');
$this->setDescription('Exit the app');
}
}
MegaApi::setLogLevel(MegaApi::LOG_LEVEL_ERROR);
$applistener = new AppListener();
$megaapi = new MegaApiPHP("API_KEY", "PHP megacli");
$megaapi->addListener($applistener);
$application = new Application('MEGA', 'PHP');
$application->add(new LoginCommand());
$application->add(new LogoutCommand());
$application->add(new LsCommand());
$application->add(new MkdirCommand());
$application->add(new CdCommand());
$application->add(new PwdCommand());
$application->add(new RmCommand());
$application->add(new GetCommand());
$application->add(new PutCommand());
$application->add(new ExitCommand());
$application->add(new QuitCommand());
$application->add(new ExportCommand());
$application->add(new ImportCommand());
$application->add(new WhoamiCommand());
$application->add(new PasswdCommand());
$application->add(new MountCommand());
$application->add(new MvCommand());
$shell = new Shell($application);
$shell->run();
?>

View File

@ -1,11 +0,0 @@
#include <iostream>
using namespace std;
int main(){
long long int a=1;
cout << "0.";
while(1){
cout << a;
a++;
}
return 0;
}