| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 | <?php//Déclaration d'un item de menu dans le menu principalfunction hackpoint_menu(&$menuItems){	global $_,$myUser;	if(!$myUser->can('hackpoint','read')) return;	$menuItems[] = array(		'sort'=>3,		'url'=>'index.php',		'label'=>'Sketch',		'icon'=> 'fas fa-wrench',		'color'=> '#3498db'	);	}//Cette fonction va generer une page quand on clique sur hackpoint dans menufunction hackpoint_page(){	global $_,$myUser;	if(isset($_['module']) && $_['module'] !='hackpoint') return;	$page = !isset($_['page']) ? 'list.sketch' : $_['page'];	$file = __DIR__.SLASH.'page.'.$page.'.php';	if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");		require_once($file);}//Fonction executée lors de l'activation du pluginfunction hackpoint_install($id){	if($id != 'fr.idleman.hackpoint') return;	Entity::install(__DIR__);	global $conf;	require_once(__DIR__.SLASH.'ResourceType.class.php');		$conf->put('hackpoint_resource_arduino',true);	$conf->put('hackpoint_resource_file',true);	$conf->put('hackpoint_resource_image',true);	$conf->put('hackpoint_resource_js',true);	$conf->put('hackpoint_resource_php',true);	$conf->put('hackpoint_resource_readme',true);	$conf->put('hackpoint_resource_python',true);	//foreach(ResourceType::types(null,true) as $uid=>$type){	//	$conf->put('hackpoint_resource_'.$uid,true);	//}}//Fonction executée lors de la désactivation du pluginfunction hackpoint_uninstall($id){	if($id != 'fr.idleman.hackpoint') return;	Entity::uninstall(__DIR__);}//Déclaration des sections de droits du pluginfunction hackpoint_section(&$sections){	$sections['hackpoint'] = "Gestion des droits sur le plugin hackpoint";}//cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue htmlfunction hackpoint_action(){	require_once(__DIR__.SLASH.'action.php');}//Déclaration du menu de réglagesfunction hackpoint_menu_setting(&$settingMenu){	global $_, $myUser;		if(!$myUser->can('hackpoint','configure')) return;				$settingMenu[]= array(			'sort' =>1,			'url' => 'setting.php?section=global.hackpoint',			'icon' => 'fas fa-angle-right',			'label' => ' Hackpoint'		);	}//Déclaration des pages de réglagesfunction hackpoint_content_setting(){	global $_;	if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))		require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');} function hackpoint_manage_types(&$types){ 	$types = array_merge($types,glob(__DIR__.SLASH.'types'.SLASH.'*.class.php')); }function hackpoint_dav($requested){	global $conf,$myUser;	$requested = trim($requested, '/');		if(substr($requested, 0,13)!='dav/hackpoint') return;	if(empty($requested)) throw new Exception("Unspecified DAV path");	require_once(__ROOT__.'common.php');	require_once(__DIR__.SLASH.'VirtualWebDav.class.php');	$projectPath = preg_replace('|https?\:\/\/'.$_SERVER['HTTP_HOST'].'|i', '', ROOT_URL);	$server = new VirtualWebDav();	// $server->logs = VirtualWebDav::logPath().SLASH.'dav-logs.txt';	$server->lockfile = VirtualWebDav::logPath().SLASH.'dav-lock.json';	$server->root = str_replace('//','/',$projectPath.'/dav/hackpoint/');	$server->folder = '';	//Windows cherche desktop.ini a chaque ouverture de dossier pour le custom	$server->ignoreFiles[] = 'desktop.ini';	//Tortoise et autre client git d'explorer cherchent les .git a chaques ouverture	$server->ignoreFiles[] = '.git';	$server->do['login'] = function($login,$password){		global $myUser;		if($myUser->login !=''){			return $myUser;		}				$myUser = User::check($login,$password);		if(!$myUser)			throw new Exception("Problème lors de la connexion, veuillez contacter l'administrateur",401);				if(file_exists('enabled.maintenance') && $myUser->superadmin != 1)			throw new Exception('Seul un compte Super Admin peut se connecter en mode maintenance',401);				if(!$myUser->connected())			throw new Exception('Identifiant ou mot de passe incorrect',401);		if(is_numeric($myUser->preference('default_firm')) && $myUser->haveFirm($myUser->preference('default_firm'))){			$_SESSION['firm'] = serialize(Firm::getById($myUser->preference('default_firm')));			if(!$_SESSION['firm'])				throw new Exception("Problème lors de la connexion, veuillez contacter l'administrateur",401);					}else if(count($myUser->firms)!=0){			$_SESSION['firm'] = serialize(reset($myUser->firms));			if(!$_SESSION['firm'])				throw new Exception(" Problème lors de la connexion, veuillez contacter l'administrateur",401);		}else{			throw new Exception('Ce compte n\'est actif sur aucune firm',401);		}							$myFirm = isset($_SESSION['firm']) ? unserialize($_SESSION['firm']) : new Firm();		if(!$myFirm)			throw new Exception("Problème lors de la connexion, veuillez contacter l'administrateur",401);		$_SESSION['currentUser'] = serialize($myUser);		if(!$_SESSION['currentUser'])			throw new Exception("Problème lors de la connexion, veuillez contacter l'administrateur",401);	};	$server->do['delete'] = function($isoPath){		global $myUser,$conf;		$utf8Path = utf8_encode($isoPath);		throw new Exception("Méthode non implémentée",501);	};	$server->do['download'] = function($isoPath){		global $myUser,$_,$conf;		$utf8Path = utf8_encode($isoPath);		//pour verfiier si le fichier existe, on récupere son chemin système avec le bon encodage		$osPath = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? $isoPath: $utf8Path; 		require_once(__DIR__.SLASH.'Resource.class.php');		require_once(__DIR__.SLASH.'ResourceType.class.php');		preg_match_all('/#([0-9]*)/i', $utf8Path,$matches,PREG_SET_ORDER);		$id = end($matches);		$id = $id[1];		$resource = Resource::getById($id);		$stream = 'not implemented';		if(!$resource)  throw new Exception("Fichier inexistant",404);		$type = ResourceType::types($resource->type);		$stream = $type['class']::toFile($resource);		$stream = $stream['content'];			return $stream;	};	$server->do['edit'] = function($isoPath,$body,$type){		global $myUser,$conf;		User::check_access('hackpoint','edit');		$utf8Path = utf8_encode($isoPath);		require_once(__DIR__.SLASH.'Resource.class.php');		require_once(__DIR__.SLASH.'ResourceType.class.php');		preg_match_all('/#([0-9]*)/i', $utf8Path,$matches,PREG_SET_ORDER);		$id = end($matches);		$id = $id[1];		$resource = Resource::getById($id);		if(!$resource)  throw new Exception("Fichier inexistant",404);		if($type!='file')throw new Exception("Non implémenté",501);		/*$maxSize = $conf->get('document_allowed_size');*/		$extension = getExt($utf8Path);		/*$extensions = explode(',',str_replace(' ', '', $conf->get('document_allowed_extensions')));		if(strlen($body) > $maxSize) throw new Exception("Taille du fichier  trop grande, taille maximum :".readable_size($maxSize).' ('.$maxSize.' octets)',406);		if(!in_array($extension , $extensions)) throw new Exception("Extension '".$extension."' du fichier ".$path." non permise, autorisé :".implode(', ',$extensions),415);			if($conf->get('document_enable_logs') || $conf->get('document_enable_logs_verbose')) Log::put('Enregistrement fichier '.$utf8Path,'hackpoint');	*/		$resource->content = $body;		$resource->save();			};	$server->do['move'] = function($isoPath,$isoTo){		global $myUser,$conf;		$utf8Path = utf8_encode($isoPath);		$utf8To = utf8_encode($isoTo);		User::check_access('hackpoint','edit');		throw new Exception("Méthode non implémentée",501);	};	$server->do['copy'] = function($isoPath,$isoTo){		global $myUser,$conf;		$utf8Path = utf8_encode($isoPath);		$utf8To = utf8_encode($isoTo);		User::check_access('hackpoint','edit');		throw new Exception("Méthode non implémentée",501);			};	$server->do['list'] = function($isoPath,$depth =0){		global $myUser,$conf;		$utf8Path = utf8_encode($isoPath);		require_once(__DIR__.SLASH.'Sketch.class.php');		require_once(__DIR__.SLASH.'Resource.class.php');		User::check_access('hackpoint','read');		$files  = array();		$file = array();		$file['label'] = '';		$file['type'] = 'directory';		$file['path'] = '';		$files[] = $file;				if($depth>0){			if(!empty($utf8Path)){				preg_match_all('/#([0-9]*)/i', $utf8Path,$matches,PREG_SET_ORDER);								$sketch = Sketch::getById($matches[0][1]);				if(count($matches)>1){					$resources = array(Resource::getById($matches[1][1]));				}else{					$resources = Resource::loadAll(array('sketch'=>$sketch->id));				}				foreach($resources as $resource){					$type = $resource->type();					$file = array();					if(in_array($type['uid'], array('arduino'))  && count($matches)==1 ){						$file['label'] = $resource->label.' #'.$resource->id;						$file['type'] = 'directory';					}else{						$file['label'] = $resource->label.' #'.$resource->id.'.'.$type['toExtension'];						$file['type'] = 'file';					}					$file['create_time']  = $resource->created;					$file['update_time']  =  $resource->updated;					$file['length'] =  strlen($resource->content);					$files[] = $file;				}			}else{				foreach(Sketch::loadAll() as $sketch){					$file = array();					$file['label'] = $sketch->label.' #'.$sketch->id;					$file['type'] = 'directory';					$file['create_time']  = $sketch->created;					$file['update_time']  =  $sketch->updated;					$file['length'] =  1;					$files[] = $file;				}			}		}				return $files;	};	$server->start();}//Déclation des assetsPlugin::addCss("/css/main.css?v=1"); Plugin::addCss("/css/codemirror.css?v=1"); Plugin::addCss("/css/codemirror-monokai.css?v=1"); Plugin::addCss("/css/component.css?v=1",true); Plugin::addCss("/css/animate.min.css"); Plugin::addJs("/js/marked.min.js?v=1"); Plugin::addJs("/js/main.js?v=1"); Plugin::addJs("/js/codemirror.js?v=1"); Plugin::addJs("/js/component.js?v=2",true); foreach(glob(__DIR__.SLASH.'js'.SLASH.'codemirror-mode'.SLASH.'*.js') as $file){	Plugin::addJs("/js/codemirror-mode/".basename($file)); }$modes = array();Plugin::callHook('hackpoint_codemirror_modes',array(&$modes));foreach($modes as $file){	Plugin::addJs($file); }//Mapping hook / fonctionsPlugin::addHook("install", "hackpoint_install");Plugin::addHook("uninstall", "hackpoint_uninstall"); Plugin::addHook("section", "hackpoint_section");Plugin::addHook("menu_main", "hackpoint_menu"); Plugin::addHook("page", "hackpoint_page");  Plugin::addHook("action", "hackpoint_action");  Plugin::addHook("menu_setting", "hackpoint_menu_setting");    Plugin::addHook("content_setting", "hackpoint_content_setting");   Plugin::addHook("hackpoint_resource_type", "hackpoint_manage_types");   Plugin::addHook("rewrite", "hackpoint_dav");require_once('ResourceType.class.php');$configuration = array("Types de ressources");foreach(ResourceType::types() as $uid=>$type){	$configuration['hackpoint_resource_'.$uid] = array("label"=>" ".$type['label'],"type"=>"checkbox");}//Déclaration des settings de base//Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.Configuration::setting('hackpoint',$configuration);?>
 |