Skip to content

Commit

Permalink
Merge branch 'release/v28.1.1.OS'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddave001 committed Nov 7, 2020
2 parents 3ceb427 + e9baf45 commit fb3b5b5
Show file tree
Hide file tree
Showing 20 changed files with 819 additions and 31,233 deletions.
16 changes: 11 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Vagrant.configure("2") do |config|
config.vm.box_version = "1.0.0"
config.vm.network "private_network", ip: "192.168.10.12"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.synced_folder "./deployment/vagrant/sites-available", "/etc/nginx/sites-enabled", type: "nfs"
config.vm.synced_folder "./deployment/vagrant/ssl", "/etc/nginx/ssl", type: "nfs"

config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
Expand All @@ -13,9 +11,17 @@ Vagrant.configure("2") do |config|
end

config.vm.provision "shell", inline: <<-SHELL
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
systemctl restart sshd.service
sudo service nginx restart
sudo rm /etc/nginx/ssl/icehrm.*
sudo ln -s /vagrant/deployment/vagrant/ssl/icehrm.crt /etc/nginx/ssl/icehrm.crt
sudo ln -s /vagrant/deployment/vagrant/ssl/icehrm.key /etc/nginx/ssl/icehrm.key
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /vagrant/deployment/vagrant/sites-available/default /etc/nginx/sites-enabled/default
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo service nginx restart
sudo chmod 755 -R /var/log
SHELL

config.vm.hostname = "icehrm.os"
Expand Down
6 changes: 5 additions & 1 deletion app/rest.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php
include ('config.php');
include (APP_BASE_PATH.'rest.php');
if (isset($_REQUEST['method']) && isset($_REQUEST['url'])) {
include (APP_BASE_PATH.'api.php');
} else {
include (APP_BASE_PATH.'rest.php');
}
41 changes: 41 additions & 0 deletions core/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
define('CLIENT_PATH',dirname(__FILE__));
include ("config.base.php");
include ("include.common.php");
include("server.includes.inc.php");

if(\Classes\SettingsManager::getInstance()->getSetting('Api: REST Api Enabled') == '1') {

\Utils\LogManager::getInstance()->info("Request: " . $_REQUEST);

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}

define('REST_API_PATH', '/');

$echoRoute = \Classes\Macaw::get(REST_API_PATH . 'echo', function () {
echo "Echo " . rand();
});

\Utils\LogManager::getInstance()->debug('Api registered URI: '.$echoRoute);

$moduleManagers = \Classes\BaseService::getInstance()->getModuleManagers();

foreach ($moduleManagers as $moduleManagerObj) {

$moduleManagerObj->setupRestEndPoints();
}
$method = $_SERVER['REQUEST_METHOD'];
if (strtoupper($method) === 'GET') {
\Classes\IceRoute::dispatch($_GET['url'], $method);
} else {
$method = strtoupper($_REQUEST['method']);
\Classes\IceRoute::dispatch($_REQUEST['url'], $method);
}


}else{
echo "REST Api is not enabled. Please set 'Api: REST Api Enabled' setting to true";
}
33 changes: 28 additions & 5 deletions core/src/Classes/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ public function checkAddSmallProfileImageS3($profileImage)
$s3FileSys = new S3FileSystem($uploadFilesToS3Key, $uploadFilesToS3Secret);
$result = $s3FileSys->putObject($s3Bucket, $uploadname, $localFile, 'authenticated-read');

$file->size = filesize($localFile);

unlink("/tmp/".$file->filename);
unlink("/tmp/".$file->filename."_orig");

LogManager::getInstance()->info("Upload Result:".print_r($result, true));

$file->employee = $profileImage->employee;
$file->file_group = 'profile_image_small';
$file->size = filesize(CLIENT_BASE_PATH.'data/'.$file->filename);
$file->size_text = $this->getReadableSize($file->size);

if (!empty($result)) {
Expand Down Expand Up @@ -293,8 +294,7 @@ public function deleteProfileImage($profileId)
if ($file->employee == $profileId) {
$ok = $file->Delete();
if ($ok) {
LogManager::getInstance()->info("Delete File:".CLIENT_BASE_PATH.$file->filename);
unlink(CLIENT_BASE_PATH.'data/'.$file->filename);
$this->deleteFileFromDisk($file);
} else {
return false;
}
Expand All @@ -306,8 +306,7 @@ public function deleteProfileImage($profileId)
if ($file->employee == $profileId) {
$ok = $file->Delete();
if ($ok) {
LogManager::getInstance()->info("Delete File:".CLIENT_BASE_PATH.$file->filename);
unlink(CLIENT_BASE_PATH.'data/'.$file->filename);
$this->deleteFileFromDisk($file);
} else {
return false;
}
Expand All @@ -317,6 +316,30 @@ public function deleteProfileImage($profileId)
return true;
}

public function deleteFileFromDisk($file)
{
$uploadFilesToS3 = SettingsManager::getInstance()->getSetting("Files: Upload Files to S3");

if ($uploadFilesToS3 == "1") {
$uploadFilesToS3Key = SettingsManager::getInstance()->getSetting(
"Files: Amazon S3 Key for File Upload"
);
$uploadFilesToS3Secret = SettingsManager::getInstance()->getSetting(
"Files: Amazone S3 Secret for File Upload"
);
$s3Bucket = SettingsManager::getInstance()->getSetting("Files: S3 Bucket");

$uploadname = CLIENT_NAME."/".$file->filename;
LogManager::getInstance()->info("Delete from S3:".$uploadname);

$s3FileSys = new S3FileSystem($uploadFilesToS3Key, $uploadFilesToS3Secret);
$s3FileSys->deleteObject($s3Bucket, $uploadname);
} else {
LogManager::getInstance()->info("Delete:".CLIENT_BASE_PATH.'data/'.$file->filename);
unlink(CLIENT_BASE_PATH.'data/'.$file->filename);
}
}

public function deleteFileByField($value, $field)
{
LogManager::getInstance()->info("Delete file by field: $field / value: $value");
Expand Down
177 changes: 177 additions & 0 deletions core/src/Classes/IceRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

namespace Classes;

/**
* @method static IceRoute get(string $route, Callable $callback)
* @method static IceRoute post(string $route, Callable $callback)
* @method static IceRoute put(string $route, Callable $callback)
* @method static IceRoute delete(string $route, Callable $callback)
* @method static IceRoute options(string $route, Callable $callback)
* @method static IceRoute head(string $route, Callable $callback)
*/
class IceRoute
{

public static $halts = false;

public static $routes = array();

public static $methods = array();

public static $callbacks = array();

public static $patterns = array(
':any' => '[^/]+',
':num' => '[0-9]+',
':all' => '.*'
);

public static $error_callback;

/**
* Defines a route w/ callback and method
*/
public static function __callstatic($method, $params)
{

$uri = $params[0][0];
$callback = $params[0][1];

array_push(self::$routes, $uri);
array_push(self::$methods, strtoupper($method));
array_push(self::$callbacks, $callback);

return $uri;
}

/**
* Defines callback if route is not found
*/
public static function error($callback)
{
self::$error_callback = $callback;
}

public static function haltOnMatch($flag = true)
{
self::$halts = $flag;
}

/**
* Runs the callback for the given request
*/
public static function dispatch($uri, $method)
{

$searches = array_keys(static::$patterns);
$replaces = array_values(static::$patterns);

$found_route = false;

self::$routes = str_replace('//', '/', self::$routes);

// check if route is defined without regex
if (in_array($uri, self::$routes)) {
$route_pos = array_keys(self::$routes, $uri);
foreach ($route_pos as $route) {
//using an ANY option to match both GET and POST requests
if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY') {
$found_route = true;

//if route is not an object
if (!is_object(self::$callbacks[$route])) {
//grab all parts based on a / separator
$parts = explode('/', self::$callbacks[$route]);

//collect the last index of the array
$last = end($parts);

//grab the controller name and method call
$segments = explode('@', $last);

//instanitate controller
$controller = new $segments[0]();

//call method
$controller->$segments[1]();

if (self::$halts) {
return;
}
} else {
//call closure
call_user_func(self::$callbacks[$route]);

if (self::$halts) {
return;
}
}
}
}
} else {
// check if defined with regex
$pos = 0;
foreach (self::$routes as $route) {
if (strpos($route, ':') !== false) {
$route = str_replace($searches, $replaces, $route);
}

if (preg_match('#^' . $route . '$#', $uri, $matched)) {
if (self::$methods[$pos] == $method) {
$found_route = true;

array_shift($matched); //remove $matched[0] as [1] is the first parameter.


if (!is_object(self::$callbacks[$pos])) {
//grab all parts based on a / separator
$parts = explode('/', self::$callbacks[$pos]);

//collect the last index of the array
$last = end($parts);

//grab the controller name and method call
$segments = explode('@', $last);

//instanitate controller
$controller = new $segments[0]();

//fix multi parameters
if (!method_exists($controller, $segments[1])) {
echo "controller and action not found";
} else {
call_user_func_array(array($controller, $segments[1]), $matched);
}

//call method and pass any extra parameters to the method
// $controller->$segments[1](implode(",", $matched));

if (self::$halts) {
return;
}
} else {
call_user_func_array(self::$callbacks[$pos], $matched);

if (self::$halts) {
return;
}
}
}
}
$pos++;
}
}

// run the error callback if the route was not found
if ($found_route == false) {
if (!self::$error_callback) {
self::$error_callback = function () {
header($_SERVER['SERVER_PROTOCOL']." 404 Not Found");
echo '404';
};
}
call_user_func(self::$error_callback);
}
}
}
2 changes: 2 additions & 0 deletions core/src/Classes/Macaw.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static function __callstatic($method, $params)
array_push(self::$methods, strtoupper($method));
array_push(self::$callbacks, $callback);

call_user_func('\Classes\IceRoute::'.$method, $params);

return $uri;
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/Classes/RestEndPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ private function getBearerToken()
if (preg_match('/Bearer\s(\S+)/', $headers, $matches)) {
$token = $matches[1];
}
} else {
$token = $_GET['token'];
}

if (strlen($token) > 32) {
Expand Down
6 changes: 5 additions & 1 deletion core/src/Employees/User/Api/EmployeesActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public function changePassword($req)
return new IceResponse(IceResponse::ERROR, "Error occurred while changing password");
}

if (!PasswordManager::verifyPassword($req->current, $user->password)) {
return new IceResponse(IceResponse::ERROR, "Current password is incorrect");
}

$passwordStrengthResponse = PasswordManager::isQualifiedPassword($req->pwd);
if ($passwordStrengthResponse->getStatus() === IceResponse::ERROR) {
return $passwordStrengthResponse;
Expand All @@ -158,6 +162,6 @@ public function changePassword($req)
return new IceResponse(IceResponse::ERROR, $user->ErrorMsg());
}

return new IceResponse(IceResponse::SUCCESS, $user);
return new IceResponse(IceResponse::SUCCESS, []);
}
}
Binary file added favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion web/admin/src/documents/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class EmployeeDocumentAdapter extends AdapterBase {

getFilters() {
return [
['employee', { label: 'Employee', type: 'select2', 'remote-source': ['Employee', 'id', 'first_name+last_name'] }],
['employee', { label: 'Employee', type: 'select2', 'remote-source': ['Employee', 'id', 'first_name+last_name', 'getActiveSubordinateEmployees'] }],

];
}
Expand Down
2 changes: 1 addition & 1 deletion web/api/AdapterBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AdapterBase extends ModuleBase {
}

setupApiClient(token) {
this.apiClient = new IceApiClient(this.apiUrl, token);
this.apiClient = new IceApiClient(this.apiUrl, token, window.CLIENT_BASE_URL, true);
}

setApiUrl(apiUrl) {
Expand Down
Loading

0 comments on commit fb3b5b5

Please sign in to comment.