121 lines
5.3 KiB
PHP
121 lines
5.3 KiB
PHP
<?php
|
|
include("IniFile.class.php");
|
|
class WorkstationServices{
|
|
|
|
function loadInst()
|
|
{
|
|
static $inst = null;
|
|
|
|
if ($inst === null) {
|
|
$inst = new self;
|
|
}
|
|
return $inst;
|
|
}
|
|
|
|
function API_Register()
|
|
{
|
|
apiql::register("!DESKTOP/!REMOVE/!SHORTCUT[json]", "WorkstationServices::RemoveDesktopFile");
|
|
apiql::register("!DESKTOP/!CREATE/!SHORTCUT[json]", "WorkstationServices::CreateDesktopFile");
|
|
apiql::register("!DESKTOP/!SET/!ICON[json]","WorkstationServices::SetLauncherIcon");
|
|
apiql::register("!STORAGE/!GET/!FREE/!SPACE[json]", "WorkstationServices::GetFreeSpace");
|
|
apiql::register("!STORAGE/!GET/!TOTAL/!SPACE[json]", "WorkstationServices::GetStorageCapacity");
|
|
apiql::register("!UPLOAD/!LOCAL/!RESOURCE[json]","WorkstationServices::UploadResource");
|
|
}
|
|
|
|
function SetLauncherIcon($sql)
|
|
{
|
|
$DesktopArray = $sql['ICON'];
|
|
|
|
if(!file_exists("/home/phablet"))
|
|
{
|
|
$ErrorArray = array("response_type"=>"error", "error_msg"=>"This device is not an Ubuntu Touch workstation.", "error_code"=>505);
|
|
return json_encode($ErrorArray);
|
|
}
|
|
|
|
if(!file_exists("/home/phablet/.local/share/applications/".$DesktopArray['name'].".desktop")) {
|
|
$ErrorArray = array("response_type"=>"error","error_msg"=>"Desktop File does not Exist.", "error_code"=>404);
|
|
return json_encode($ErrorArray);
|
|
}
|
|
$desktop = IniFile::LoadFromFile("/home/phablet/.local/share/applications/".$DesktopArray['name'].".desktop");
|
|
$desktop->SetKey("Desktop Entry","Icon",$DesktopArray['icon']);
|
|
$desktop->Save();
|
|
}
|
|
|
|
function UploadResource($sql)
|
|
{
|
|
$FileArray = $sql['RESOURCE'];
|
|
$fileMD5 = $FileArray['MD5'];
|
|
$fileContents = base64_decode($FileArray['contents']);
|
|
$destination = $FileArray['dest'];
|
|
file_put_contents($destination, $fileContents);
|
|
$MD5 = md5_file($destination);
|
|
if($MD5 != $fileMD5)
|
|
{
|
|
$ErrorArray = array("response_type"=>"error",
|
|
"error_msg"=>"MD5 Checksums do not match. File corrupt.",
|
|
"error_code"=>500);
|
|
return json_encode($ErrorArray);
|
|
} else {
|
|
$ResponseArray = array("response_type"=>"success",
|
|
"response_msg"=>"File uploaded successfully to ".$destination,
|
|
"response_code"=>200);
|
|
return json_encode($ResponseArray);
|
|
}
|
|
}
|
|
|
|
function module_loaded()
|
|
{
|
|
self::API_Register();
|
|
return true;
|
|
}
|
|
|
|
function GetFreeSpace($sql)
|
|
{
|
|
$resultArray = array("response_type"=>"success",
|
|
"response_msg"=>disk_free_space($sql['SPACE']['volume']),
|
|
"response_code"=>200);
|
|
return json_encode($resultArray);
|
|
}
|
|
|
|
function GetStorageCapacity($sql)
|
|
{
|
|
$resultArray = array("response_type"=>"success",
|
|
"response_msg"=>disk_total_space($sql['SPACE']['volume']),
|
|
"response_code"=>200);
|
|
return json_encode($resultArray);
|
|
}
|
|
|
|
function CreateDesktopFile($sql)
|
|
{
|
|
# Check for the existance of the requested .desktop file.
|
|
|
|
$DesktopArray = $sql['SHORTCUT'];
|
|
if(!file_exists("/usr/share/applications/".$DesktopArray['name'].".desktop")) {
|
|
$ErrorArray = array("response_type"=>"error","error_msg"=>"Desktop File does not Exist.", "error_code"=>404);
|
|
return json_encode($ErrorArray);
|
|
}
|
|
if(!file_exists("/home/phablet"))
|
|
{
|
|
$ErrorArray = array("response_type"=>"error", "error_msg"=>"This device is not an Ubuntu Touch workstation.", "error_code"=>505);
|
|
return json_encode($ErrorArray);
|
|
}
|
|
copy("/usr/share/applications/".$DesktopArray['name'].".desktop", "/home/phablet/.local/share/applications/".$DesktopArray['name'].".desktop");
|
|
$desktop = IniFile::LoadFromFile("/home/phablet/.local/share/applications/".$DesktopArray['name'].".desktop");
|
|
$ExecLine = $desktop->GetKey("Desktop Entry","Exec");
|
|
$ExecLine = "/home/phablet/bin/wm-wrapper " . $ExecLine;
|
|
$desktop->SetKey("Desktop Entry", "Exec", $ExecLine);
|
|
$desktop->SetKey("Desktop Entry", "X-Ubuntu-Touch", "true");
|
|
$desktop->SetKey("Desktop Entry", "X-Ubuntu-XMir-Enable", "true");
|
|
$desktop->Save();
|
|
$ResultArray = array("response_type"=>"success", "response_msg"=>"Desktop file created successfully.", "response_code"=>200);
|
|
}
|
|
|
|
function RemoveDesktopFile($sql)
|
|
{
|
|
$DesktopArray = $sql['SHORTCUT'];
|
|
unlink("/home/phablet/.local/share/applications/".$DesktopArray['name'].".desktop");
|
|
}
|
|
|
|
|
|
}
|
|
?>
|