<?php
# vim: syntax=php tabstop=4 softtabstop=0 noexpandtab laststatus=1 ruler
/**
* html/includes/api_folders.php
*
* Folders related functions for REST APIs.
*
* @author Andrea Dainese <andrea.dainese@gmail.com>
* @copyright 2014-2016 Andrea Dainese
* @license BSD-3-Clause https://github.com/dainok/unetlab/blob/master/LICENSE
* @link http://www.unetlab.com/
* @version 20160719
*/
/*
* Function to add a folder to a path.
*
* @param string $name Folder name
* @param string $path Path
* @return Array Return code (JSend data)
*/
function apiAddFolder($name, $path) {
$rc = checkFolder(BASE_LAB.$path);
if ($rc === 2) {
// Folder is not valid
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60009];
return $output;
} else if ($rc === 1) {
// Folder does not exist
$output['code'] = 404;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60008];
return $output;
}
if ($path == '/') {
// Avoid double '/'
$path = '';
}
// Check if exists
if (is_dir(BASE_LAB.$path.'/'.$name)) {
// Folder already exists
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60013];
} else {
try {
mkdir(BASE_LAB.$path.'/'.$name);
$output['code'] = 200;
$output['status'] = 'success';
$output['message'] = $GLOBALS['messages'][60014];
} catch (Exception $e) {
error_log(date('M d H:i:s ').'ERROR: '.$GLOBALS['messages'][60015]);
error_log(date('M d H:i:s ').(string) $e);
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60015];
}
}
return $output;
}
/**
* Function to delete a folder.
*
* @param string $path Path
* @return Array Return code (JSend data)
*/
function apiDeleteFolder($path) {
$rc = checkFolder(BASE_LAB.$path);
if ($rc === 2) {
// Folder is not valid
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60009];
return $output;
} else if ($rc === 1) {
// Folder does not exist
$output['code'] = 404;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60008];
return $output;
}
if ($path == '/') {
// Cannot delete '/'
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60010];
return $output;
}
// Deleting all tmp files for lab inside the folder
$cmd = 'find '.BASE_LAB.$path.' -name "*.unl" -exec sudo /opt/unetlab/wrappers/unl_wrapper -a delete -F "{}" -T 0 \;'; // Tenant not required for delete operation
exec($cmd, $o, $rc);
// Deleting the folder
$cmd = 'rm -rf "'.BASE_LAB.$path.'" 2>&1';
exec($cmd, $o, $rc);
if ($rc == 0) {
$output['code'] = 200;
$output['status'] = 'success';
$output['message'] = 'Folder deleted';
$output['message'] = $GLOBALS['messages'][60012];
} else {
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = 'Cannot delete folder';
$output['message'] = $GLOBALS['messages'][60011];
}
return $output;
}
/**
* Function to edit a folder.
*
* @param string $s Full path of the source folder
* @param string $d Full path of the destination folder
* @return Array Return code (JSend data)
*/
function apiEditFolder($s, $d) {
$rc = checkFolder(BASE_LAB.$s);
if ($rc === 2) {
// Folder is not valid
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60009];
return $output;
} else if ($rc === 1) {
// Folder does not exist
$output['code'] = 404;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60008];
return $output;
}
$rc = checkFolder(BASE_LAB.$d);
if ($rc === 2) {
// Folder is not valid
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60047];
return $output;
} else if ($rc === 0) {
// Folder already exists
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60046];
return $output;
}
// Moving the folder
$cmd = 'mv "'.BASE_LAB.$s.'" "'.BASE_LAB.$d.'" 2>&1';
exec($cmd, $o, $rc);
if ($rc == 0) {
$output['code'] = 200;
$output['status'] = 'success';
$output['message'] = $GLOBALS['messages'][60049];
} else {
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = 'Cannot move folder';
$output['message'] = $GLOBALS['messages'][60048];
}
return $output;
}
/**
* Function to get all folders from a path.
*
* @param string $path Path
* @return Array List of folders (JSend data)
*/
function apiGetFolders($path) {
$rc = checkFolder(BASE_LAB.$path);
if ($rc === 2) {
// Folder is not valid
$output['code'] = 400;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60009];
return $output;
} else if ($rc === 1) {
// Folder does not exist
$output['code'] = 404;
$output['status'] = 'fail';
$output['message'] = $GLOBALS['messages'][60008];
return $output;
}
// Listing content
$folders = Array();
$labs = Array();
if ($path != '/') {
// Adding '..' folder
$folders[] = Array(
'name' => '..',
'path' => dirname($path)
);
}
// Scanning directory
foreach (scandir(BASE_LAB.$path) as $element) {
if (!in_array($element, array('.', '..'))) {
if (is_dir(BASE_LAB.$path.'/'.$element)) {
if ($path == '/') {
$folders[] = Array(
'name' => $element,
'path' => '/'.$element
);
} else {
$folders[] = Array(
'name' => $element,
'path' => $path.'/'.$element
);
}
continue;
}
if (is_file(BASE_LAB.$path.'/'.$element) && preg_match('/^.+\.unl$/', $element)) {
if ($path == '/') {
$labs[] = Array(
'file' => $element,
'path' => '/'.$element,
'umtime' => filemtime(BASE_LAB.$path.'/'.$element),
'mtime' => date ("Y-m-d H:i", filemtime(BASE_LAB.$path.'/'.$element))
);
} else {
$labs[] = Array(
'file' => $element,
'path' => $path.'/'.$element,
'umtime' => filemtime(BASE_LAB.$path.'/'.$element),
'mtime' => date ("Y-m-d H:i", filemtime(BASE_LAB.$path.'/'.$element))
);
}
continue;
}
}
}
// Sorting
usort($folders, function($a, $b){
return strnatcasecmp($a['name'], $b['name']);
});
usort($labs, function($a, $b){
return strnatcasecmp($a['file'], $b['file']);
});
// Printing info
$output['code'] = 200;
$output['status'] = 'success';
$output['message'] = $GLOBALS['messages'][60007];
$output['data'] = Array(
'folders' => $folders,
'labs' => $labs
);
return $output;
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
5.0.1-19-Community_zh_CN.zip (20个子文件)
5.0.1-19-Community_zh_CN
html
includes
api_folders.php 7KB
themes
default
js
messages_en.js 6KB
functions.js 244KB
actions.js 181KB
ejs
form_text.ejs 2KB
form_node_configs.ejs 2KB
adminLTE
unl_data
pages
constant
header.html 4KB
labView.html 5KB
footer.html 308B
syslog.html 3KB
main.html 17KB
sysstat.html 5KB
login.html 2KB
modals
edituser.html 4KB
adduser.html 3KB
editfile.html 4KB
addfile.html 6KB
editNode.html 10KB
moveto.html 3KB
usermgmt.html 5KB
共 20 条
- 1
资源评论
- 是因为太久2023-07-28汉化后的界面清晰易懂,给人一种亲切感,使用起来非常顺手。
- 思想假2023-07-28这个汉化语言升级包真的很方便,让我在使用EVE-NG时更容易理解和操作。
- 阿葱的葱白2023-07-28汉化后的界面更符合我们中国用户的使用习惯,让人感到非常亲切和舒适。
- Period熹微2023-07-28对于不擅长英文操作的用户来说,这个汉化包真的是一个福音,使用起来非常方便。
- 爱吃番茄great2023-07-28很感谢开发者的努力,这个汉化包是我在EVE-NG上首选的语言升级工具。
avenjan
- 粉丝: 124
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功