Skip to content

Commit

Permalink
19-09-2019 update
Browse files Browse the repository at this point in the history
+ fixDesktop filename script for window
+ Added more icon and images
+ Change to USB mount script
+ Change in shutdown GUI
+ more
  • Loading branch information
tobychui committed Sep 19, 2019
1 parent 446e92e commit 2f39722
Show file tree
Hide file tree
Showing 23 changed files with 1,488 additions and 27 deletions.
60 changes: 60 additions & 0 deletions src/Desktop/fixWinDesktop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*
Desktop filename decode error auto fixing script
*/
function gen_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),

// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),

// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,

// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,

// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}

include_once("../auth.php");
include_once("../SystemAOB/functions/personalization/configIO.php");
$username = $_SESSION['login'];
$desktopFolder = "files/" . $username . "/";
if (file_exists($desktopFolder)){
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
//Window Host
//There might be problems when translating UTF-8 encoded filename into local encoding filenames. This might lead to load fail of the desktop icons.
$desktopFiles = glob($desktopFolder . "*");
$configs = getConfig("encoding",true);
$counter = 0;
foreach ($desktopFiles as $file){
//Find the file that do not fits the current local encoding environment set by the system setting
$conFilename = mb_convert_encoding($file, "UTF-8",$configs["forceEncodingType"][3]);
if ($conFilename != $file){
echo $conFilename;
if (!file_exists($desktopFolder. "recovery/")){
mkdir($desktopFolder . "recovery/");
}
rename($file, $desktopFolder . "recovery/" . gen_uuid() . ".zip");
$counter++;
}
}
if ($counter > 0){
echo "DONE";
}else{
echo "ERROR. Unable to fix the issue.";
}

}else{
//Linux
}
}
?>
44 changes: 42 additions & 2 deletions src/Desktop/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ function updateDesktopFiles(){
$.get( "desktopFileLoader.php?username=" + username, function(data) {
if (Array.isArray(data) == false && data.substring(0, 5) == "ERROR"){
showNotification("<i class='help icon'></i> Desktop file Synchronization");
}else if (data == ""){
//PHP returns nothing, mostly due to Windows Filename encoding error.
}else{
returnedFileList = returnedFileList.concat(data[0]);
}

if (arraysEqual(desktopFiles,returnedFileList)){
//All the files are the same as before, keep the current desktop file list
}else{
Expand All @@ -384,6 +385,45 @@ function initUserDesktop(callback = null,callbackvar = "",callbackSeq = 0){
desktopFileLocations = [];
desktopEmptyPositions = [];
//showNotification("<i class='loading spinner icon'></i> Desktop environment initializing...");
$.ajax({
url: "desktopFileLoader.php?username=" + username,
success: function(data){
if (Array.isArray(data) == false && data.substring(0, 5) == "ERROR"){
showNotification(data);
}else{
desktopFiles = desktopFiles.concat(data[0]); //All the raw filenames
desktopFileNames = desktopFileNames.concat(data[1]); //All decoded filenames
desktopFileLocations = desktopFileLocations.concat(data[2]); //All desktop file locations
calculateEmptyDesktopSlots();
if (callbackSeq == 0){
updateDesktopGraphic();
}
}
if (callback != null){
if (callbackvar == ""){
callback();
}else{
callback(callbackvar);
}
}
if (callbackSeq == 1){
updateDesktopGraphic();
}
},
timeout: 10000,
error: function(jqXHR, textStatus, errorThrown) {
parent.msgbox("Your desktop is unable to load due to host system encoding issue. We are trying to fix the issue.","<i class='caution sign icon'></i> Critial Error!",undefined,false);
$.get("fixWinDesktop.php",function(data){
if (data.includes("ERROR") == false){
parent.msgbox("Your desktop is fixed and the corrupted file is moved to recover/ folder on your desktop. Click the link below to refresh.","<i class='checkmark sign icon'></i> Recovery Completed","{reload}",false);
}else{
alert("Unable to recover. See console.log for more information.");
}
});
}
}
);
/*
$.get( "desktopFileLoader.php?username=" + username, function(data) {
if (Array.isArray(data) == false && data.substring(0, 5) == "ERROR"){
showNotification(data);
Expand All @@ -407,7 +447,7 @@ function initUserDesktop(callback = null,callbackvar = "",callbackSeq = 0){
updateDesktopGraphic();
}
});

*/
$.get( "loadAllModule.php", function( data ) {
openWithModuleList = data;

Expand Down
3 changes: 2 additions & 1 deletion src/System Settings/menus/file.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
file outline,File & Storage
fsearch,File Search,SystemAOB/functions/system_statistic/searchFile.php
fshortcut,Explorer Shortcuts,SystemAOB/functions/file_system/fileShortcutUI.php
diskmg,Disk Manager,SystemAOB/system/diskmg/index.php
usbdev,USB Mounting,SystemAOB/functions/usbMount.php
fshortcut,Explorer Shortcuts,SystemAOB/functions/file_system/fileShortcutUI.php
smbconf,Samba Config,SystemAOB/functions/samba_config/index.php
Empty file.
7 changes: 4 additions & 3 deletions src/SystemAOB/functions/file_system/filesUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
if (isset($_FILES['files']) && !empty($_FILES['files'])) {
if (isset($_GET['path']) && $_GET['path'] != ""){
$path = $_GET['path'];
if (strpos($path,"/SystemAOB") === false && $path != "/media"){
if ((strpos($path,"/SystemAOB") === false || file_exists("developer.mode")) && $path != "/media"){
$path = $path . "/";
if (strpos($path,"AOB/") !== false){
$path = str_replace("AOB/","../../../",$path);
if (strpos($path,"AOB/") === 0){
$path = "../../../" . substr($path,4);
}
$no_files = count($_FILES["files"]['name']);
for ($i = 0; $i < $no_files; $i++) {
Expand Down Expand Up @@ -49,6 +49,7 @@
die("ERROR. /media is mounting directory.");
}else{
die("ERROR. SystemAOB is not a valid upload path for files.");

}

}
Expand Down
2 changes: 1 addition & 1 deletion src/SystemAOB/functions/info/version.inf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AOB-DEVB_v6-9-2019
AOB-DEVB_v19-9-2019
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"syspaths":["System Paths","Allowed system paths and mount points. Seperate each path with ;","html","\/media;\/var\/www"]}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
<head>
<title>Shutdown Sequence</title>
</head>
<body style="background-color:black;color:white;">
The shutdown sequence has been running in the background.<br>
Please wait until your ArOZ Portable System completed the shutdown sequence before you switching off the main power supply.<br>
<br>
You can observe the finishing of shutdown sequence of the board if you are using:<br>
Raspberry Pi (2 / 3 / 3B+) --> Green LED is no longer flashing <br>
Raspberry Pi Zero / Zero W --> Red Power LED is turned off<br>
Banana Pi M2-Zero --> Red Power LED is turned on<br>
<br>
If you are using other development board for the ArOZ Online Portable build,<br>
Please refer to the documentation of your board for shutdown complete indication.<br><br>
Progress: <br>
<body style="background-color:black;color:white;" align="center">
<br><br><br><br><br><br>
<div style="width:100%;color:#eb8934;" id="shutingDown" align="center">
<div style="width:100%;font-size:200%;" >䷄ Your host device is shutting down.</div>
<div>Do not unplug your host until the process finish.</div>
</div>
<div style="width:100%;color:#eb8934;display:none;" id="shutdownFinish" align="center">
<div style="width:100%;font-size:200%;" >✔ It is now safe to turn off your host device.</div><br>
<div>If you are running the system on SBCs, you will need to unplug the board and power it up again for restart.<br>
Or otherwise, assume your system is running on modern PC hardware, the system will poweroff itself.</div>
</div>
<script>
setTimeout(function(){
document.getElementById("shutingDown").style.display = 'none';
document.getElementById('shutdownFinish').style.display = 'block';

},10000);
</script>
</body>
</html>

<?php
echo "Initiated Shutdown Sequence <br>";
system('sudo shutdown -t 0');
system('sudo poweroff');
echo "DONE";
?>
2 changes: 1 addition & 1 deletion src/SystemAOB/functions/system_statistic/WIN32_USBlist.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Generic USB Hub,Standard Enhanced PCI to USB Host Controller,Realtek RTL8192CU Wireless LAN 802.11n USB 2.0 Network Adapter,Generic USB Hub,Standard Enhanced PCI to USB Host Controller,Intel(R) USB 3.0 可延伸主機控制器,USB Composite Device,USB Root Hub,USB Root Hub,Intel(R) USB 3.0 根集線器,
Realtek RTL8192CU Wireless LAN 802.11n USB 2.0 Network Adapter,Standard Enhanced PCI to USB Host Controller,Generic USB Hub,Standard Enhanced PCI to USB Host Controller,USB Composite Device,Intel(R) USB 3.0 可延伸主機控制器,USB Root Hub,USB Root Hub,Intel(R) USB 3.0 根集線器,Generic USB Hub,
13 changes: 11 additions & 2 deletions src/SystemAOB/functions/system_statistic/getDriveStat.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
$n = "[Drive not ready]";
}
//echo "Drive " . $dO->DriveLetter . ": - " . $type[$dO->DriveType] . " - " . $n . " - " . $s . "<br>";
array_push($result,[$dO->DriveLetter . ":",$n,$s]);
if (isset($_GET["nomerge"])){
array_push($result,[$dO->DriveLetter . ":",$n,file_size($dO->FreeSpace),file_size($dO->TotalSize)]);
}else{
array_push($result,[$dO->DriveLetter . ":",$n,$s]);
}

}
header('Content-Type: application/json');
echo json_encode($result);
Expand All @@ -34,7 +39,11 @@
$dataline = preg_replace("!\s+!",",",$line);
$dataline = explode(",",$dataline);
if ($dataline[0] != "tmpfs" && $dataline[0] != "Filesystem"){
array_push($result,[$dataline[5],$dataline[0],$dataline[3] . "/" . $dataline[1]]);
if (isset($_GET["nomerge"])){
array_push($result,[$dataline[5],$dataline[0],$dataline[3] , $dataline[1]]);
}else{
array_push($result,[$dataline[5],$dataline[0],$dataline[3] . "/" . $dataline[1]]);
}
}
}
header('Content-Type: application/json');
Expand Down
10 changes: 8 additions & 2 deletions src/SystemAOB/functions/system_statistic/searchFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="sixteen wide field">
<label>Keyword</label>
<input type="text" placeholder="Keyword" id="keywordInput">
&nbsp;
 
<button onclick="updatelist()" id="btn" class="ts button">Search</button>
</div>
</div>
Expand Down Expand Up @@ -89,6 +89,8 @@
var targetFilepath = "";
var targetFilename = "";
function updatelist(){
$("body").parent().append($("#operationSelect")); //Move the selection box away first
$("#operationSelect").hide(); //Hide the selection box
$('#mainmenu').html('<div class="item"><div class="ts active centered inline loader"></div></div>');
$.get("searchFile.php?keyword=" + $('#keywordInput').val(), function(data, status){
$('#mainmenu').html("");
Expand Down Expand Up @@ -322,10 +324,14 @@ function hexFilenameDecoder($file){
$files = getDirContents('../../../');
$result = [];
foreach ($files as $file){
if (strpos(basename($file),$keyword)){
if (strpos(basename($file),$keyword) !== false){
$relativePath = getRelativePath(realpath("../../../"),$file);
$decodedName = hexFilenameDecoder(basename($file));
array_push($result,[$relativePath,$decodedName]);
}else if (strpos(basename($file),bin2hex($keyword)) !== false){
$relativePath = getRelativePath(realpath("../../../"),$file);
$decodedName = hexFilenameDecoder(basename($file));
array_push($result,[$relativePath,$decodedName]);
}
}
header('Content-Type: application/json');
Expand Down
Binary file added src/SystemAOB/system/diskmg/DiskmgWin.exe
Binary file not shown.
13 changes: 13 additions & 0 deletions src/SystemAOB/system/diskmg/definition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
$supportedFormats = ["ntfs","vfat"];
$allowedDirectories = ["/media", "/var/www"];
if (file_exists("../../functions/personalization/sysconf/fsaccess.config")){
$allowedDirectories = [];
$settings = json_decode(file_get_contents("../../functions/personalization/sysconf/fsaccess.config"),true);
$paths = $settings["syspaths"][3];
$paths = explode(";",$paths);
foreach ($paths as $path){
array_push($allowedDirectories,$path);
}
}
?>
18 changes: 18 additions & 0 deletions src/SystemAOB/system/diskmg/diskmg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
$partition = json_decode(shell_exec("lsblk -b --json"));
$format = json_decode(shell_exec("lsblk -f -b --json"));
$freeSpace =shell_exec("df");
while(strpos($freeSpace," ") !== false){
$freeSpace = str_replace(" "," ",$freeSpace);
}
$freeSpace = explode("\n",$freeSpace);
$freeSpaceParsed = [];
foreach ($freeSpace as $part){
$part = explode(" ",$part);
array_push($freeSpaceParsed,$part);
}
//Throw away the table header
array_shift($freeSpaceParsed);
header('Content-Type: application/json');
echo json_encode([$partition,$format,$freeSpaceParsed]);
?>
23 changes: 23 additions & 0 deletions src/SystemAOB/system/diskmg/diskmgWin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
//This php requires DiskmgWin.exe to work.
//The three numbers following the disk info is Available space to current user, Total available space, Disk total space in bytes.
include_once("../../../auth.php");
if (isset($_GET['partition'])){
$output = shell_exec("DiskmgWin.exe -d");
}else{
$output = shell_exec("DiskmgWin.exe");
}
$tmp = explode(";",trim($output));
$emptyCheck = array_pop($tmp);
if (trim($emptyCheck) !== ""){
//Check if the last item is empty. If it is not, push it back into the queue.
array_push($tmp,$emptyCheck);
}
$diskInfo = [];
foreach ($tmp as $disk){
array_push($diskInfo,explode(",",$disk));
}

header('Content-Type: application/json');
echo json_encode($diskInfo);
?>
54 changes: 54 additions & 0 deletions src/SystemAOB/system/diskmg/formatTool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
include_once("../auth.php");
include_once("definition.php");

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
die("ERROR. Window is currently not supported.");
}else{
//Linux environment
if (isset($_GET['dev']) && isset($_GET['format'])){
$dev = $_GET['dev'];
$format = $_GET['format'];
//Check if dev id correct
preg_match('/sd[a-z][1-9]/', $dev, $result);
if (count($result) == 0){
die("ERROR. Invalid device ID. " . $dev . " given.");
}

//Check if dev exists
if (!file_exists("/dev/" . $dev)){
die("ERROR. Device not exists.");
}

//Check if format is supported
if (!in_array($format,$supportedFormats)){
die("ERROR. Not supported format.");
}

//Check if the dev is mounted. Unmount it if nessary.
$out = shell_exec("lsblk -f -b --json | grep " . $dev);
if (strlen(trim($out)) == 0){
//Something strange happended
die("ERROR. Unknown error has occured. lsblk return no result.");
}
$out = json_decode(trim($out),true);
if ($out["mountpoint"] !== null){
//Unmount the dev if it is mounted
shell_exec("sudo umount " . $out["mountpoint"]);
}

//Unmount once more on dev ID just for safty
shell_exec("sudo umount /dev/" . $dev);

//Drive ready to be formatted.
if ($format == "ntfs"){
shell_exec("sudo mkfs.ntfs -f /dev/" . $dev);
}else if ($format == "vfat"){
shell_exec("sudo mkfs.vfat /dev/" . $dev);
}
echo "DONE";
}else{
die("ERROR. Called with invalid paramters.");
}
}
?>
Loading

0 comments on commit 2f39722

Please sign in to comment.