route.class.php (fogproject-1.5.5) | : | route.class.php (fogproject-1.5.6) | ||
---|---|---|---|---|
skipping to change at line 267 | skipping to change at line 267 | |||
"${expanded}/search/[*:item]", | "${expanded}/search/[*:item]", | |||
array(__CLASS__, 'search'), | array(__CLASS__, 'search'), | |||
'search' | 'search' | |||
) | ) | |||
->get( | ->get( | |||
"${expanded}/[list|all]?", | "${expanded}/[list|all]?", | |||
array(__CLASS__, 'listem'), | array(__CLASS__, 'listem'), | |||
'list' | 'list' | |||
) | ) | |||
->get( | ->get( | |||
"${expanded}/[i:id]", | "${expanded}/[details]/?[*:item]?", | |||
array(__CLASS__, 'listdetails'), | ||||
'listdetails' | ||||
) | ||||
->get( | ||||
"${expanded}/[i:id]/?[*:item]?", | ||||
array(__CLASS__, 'indiv'), | array(__CLASS__, 'indiv'), | |||
'indiv' | 'indiv' | |||
)->get( | ) | |||
->get( | ||||
"${expanded}/names/[*:whereItems]?", | "${expanded}/names/[*:whereItems]?", | |||
[__CLASS__, 'names'], | array(__CLASS__, 'names'), | |||
'names' | 'names' | |||
)->get( | ) | |||
->get( | ||||
"${expanded}/ids/[*:whereItems]?/[*:getField]?", | "${expanded}/ids/[*:whereItems]?/[*:getField]?", | |||
[__CLASS__, 'ids'], | array(__CLASS__, 'ids'), | |||
'ids' | 'ids' | |||
)->put( | ) | |||
->put( | ||||
"${expanded}/[i:id]/[update|edit]?", | "${expanded}/[i:id]/[update|edit]?", | |||
array(__CLASS__, 'edit'), | array(__CLASS__, 'edit'), | |||
'update' | 'update' | |||
) | ) | |||
->post( | ->post( | |||
"${expandedt}/[i:id]/[task]", | "${expandedt}/[i:id]/[task]", | |||
array(__CLASS__, 'task'), | array(__CLASS__, 'task'), | |||
'task' | 'task' | |||
) | ) | |||
->post( | ->post( | |||
skipping to change at line 425 | skipping to change at line 433 | |||
* @param string $sortby How to sort the data. | * @param string $sortby How to sort the data. | |||
* @param bool $bypass Allow showing hidden data. | * @param bool $bypass Allow showing hidden data. | |||
* @param array $find Additional filter items. | * @param array $find Additional filter items. | |||
* | * | |||
* @return void | * @return void | |||
*/ | */ | |||
public static function listem( | public static function listem( | |||
$class, | $class, | |||
$sortby = 'name', | $sortby = 'name', | |||
$bypass = false, | $bypass = false, | |||
$find = array() | $find = array(), | |||
$item = '' | ||||
) { | ) { | |||
$classname = strtolower($class); | $classname = strtolower($class); | |||
$classman = self::getClass($class)->getManager(); | $classman = self::getClass($class)->getManager(); | |||
self::$data = array(); | self::$data = array(); | |||
self::$data['count'] = 0; | self::$data['count'] = 0; | |||
self::$data[$classname.'s'] = array(); | self::$data[$classname.'s'] = array(); | |||
$find = self::fastmerge( | $find = self::fastmerge( | |||
$find, | $find, | |||
self::getsearchbody($classname) | self::getsearchbody($classname) | |||
); | ); | |||
switch ($classname) { | switch ($classname) { | |||
case 'plugin': | case 'plugin': | |||
self::$data['count_active'] = 0; | self::$data['count_active'] = 0; | |||
self::$data['count_installed'] = 0; | self::$data['count_installed'] = 0; | |||
self::$data['count_not_active'] = 0; | self::$data['count_not_active'] = 0; | |||
foreach (self::getClass('Plugin')->getPlugins() as $class) { | foreach (self::getClass('Plugin')->getPlugins() as $class) { | |||
self::$data[$classname.'s'][] = self::getter( | self::$data[$classname.'s'][] = self::getter( | |||
$classname, | $classname, | |||
$class | $class, | |||
$item | ||||
); | ); | |||
if ($class->isActive() && !$class->isInstalled()) { | if ($class->isActive() && !$class->isInstalled()) { | |||
self::$data['count_active']++; | self::$data['count_active']++; | |||
} | } | |||
if ($class->isActive() && $class->isInstalled()) { | if ($class->isActive() && $class->isInstalled()) { | |||
self::$data['count_installed']++; | self::$data['count_installed']++; | |||
} | } | |||
if (!$class->isActive() && !$class->isInstalled()) { | if (!$class->isActive() && !$class->isInstalled()) { | |||
self::$data['count_not_active']++; | self::$data['count_not_active']++; | |||
} | } | |||
skipping to change at line 470 | skipping to change at line 480 | |||
foreach ((array)$classman->find($find, 'AND', $sortby) as &$class) { | foreach ((array)$classman->find($find, 'AND', $sortby) as &$class) { | |||
$test = stripos( | $test = stripos( | |||
$class->get('name'), | $class->get('name'), | |||
'_api_' | '_api_' | |||
); | ); | |||
if (!$bypass && false != $test) { | if (!$bypass && false != $test) { | |||
continue; | continue; | |||
} | } | |||
self::$data[$classname.'s'][] = self::getter( | self::$data[$classname.'s'][] = self::getter( | |||
$classname, | $classname, | |||
$class | $class, | |||
$item | ||||
); | ); | |||
self::$data['count']++; | self::$data['count']++; | |||
unset($class); | unset($class); | |||
} | } | |||
break; | break; | |||
} | } | |||
self::$HookManager | self::$HookManager | |||
->processEvent( | ->processEvent( | |||
'API_MASSDATA_MAPPING', | 'API_MASSDATA_MAPPING', | |||
array( | array( | |||
'data' => &self::$data, | 'data' => &self::$data, | |||
'classname' => &$classname, | 'classname' => &$classname, | |||
'classman' => &$classman | 'classman' => &$classman | |||
) | ) | |||
); | ); | |||
} | } | |||
/** | /** | |||
* Presents the equivalent of a detailed page list. | ||||
* | ||||
* @param string $class The class to work with. | ||||
* @param string $sortby How to sort the data. | ||||
* @param bool $bypass Allow showing hidden data. | ||||
* @param array $find Additional filter items. | ||||
* | ||||
* @return void | ||||
*/ | ||||
public static function listdetails( | ||||
$class, | ||||
$item, | ||||
$sortby = 'name', | ||||
$bypass = false, | ||||
$find = array() | ||||
) { | ||||
$item = empty($item) ? 'all' : $item; | ||||
self::listem($class, $sortby, $bypass, $find, $item); | ||||
} | ||||
/** | ||||
* Presents the equivalent of a page's search. | * Presents the equivalent of a page's search. | |||
* | * | |||
* @param string $class The class to work with. | * @param string $class The class to work with. | |||
* @param string $item The "search". | * @param string $item The "search". | |||
* | * | |||
* @return void | * @return void | |||
*/ | */ | |||
public static function search($class, $item) | public static function search($class, $item) | |||
{ | { | |||
$classname = strtolower($class); | $classname = strtolower($class); | |||
skipping to change at line 531 | skipping to change at line 562 | |||
); | ); | |||
} | } | |||
/** | /** | |||
* Displays the individual item. | * Displays the individual item. | |||
* | * | |||
* @param string $class The class to work with. | * @param string $class The class to work with. | |||
* @param int $id The id of the item. | * @param int $id The id of the item. | |||
* | * | |||
* @return void | * @return void | |||
*/ | */ | |||
public static function indiv($class, $id) | public static function indiv($class, $id, $item = '') | |||
{ | { | |||
$classname = strtolower($class); | $classname = strtolower($class); | |||
$class = new $class($id); | $class = new $class($id); | |||
if (!$class->isValid()) { | if (!$class->isValid()) { | |||
self::sendResponse( | self::sendResponse( | |||
HTTPResponseCodes::HTTP_NOT_FOUND | HTTPResponseCodes::HTTP_NOT_FOUND | |||
); | ); | |||
} | } | |||
self::$data = array(); | self::$data = array(); | |||
self::$data = self::getter( | self::$data = self::getter( | |||
$classname, | $classname, | |||
$class | $class, | |||
$item | ||||
); | ); | |||
self::$HookManager | self::$HookManager | |||
->processEvent( | ->processEvent( | |||
'API_INDIVDATA_MAPPING', | 'API_INDIVDATA_MAPPING', | |||
array( | array( | |||
'data' => &self::$data, | 'data' => &self::$data, | |||
'classname' => &$classname, | 'classname' => &$classname, | |||
'class' => &$class | 'class' => &$class | |||
) | ) | |||
); | ); | |||
skipping to change at line 606 | skipping to change at line 638 | |||
$val = $vars->$key; | $val = $vars->$key; | |||
} | } | |||
if ($key == 'id') { | if ($key == 'id') { | |||
continue; | continue; | |||
} | } | |||
$class->set($key, $val); | $class->set($key, $val); | |||
unset($key); | unset($key); | |||
} | } | |||
switch ($classname) { | switch ($classname) { | |||
case 'host': | case 'host': | |||
if (count($vars->macs)) { | if (isset($vars->macs)) { | |||
$macsToAdd = array_diff( | ||||
(array)$vars->macs, | ||||
$class->get('macs') | ||||
); | ||||
$primac = array_shift($macsToAdd); | ||||
$macsToRem = array_diff( | ||||
$class->get('macs'), | ||||
$vars->macs | ||||
); | ||||
$class | $class | |||
->removeAddMAC($vars->macs) | ->removeAddMAC($macsToRem) | |||
->addPriMAC(array_shift($vars->macs)) | ->addPriMAC($primac) | |||
->addAddMAC($vars->macs); | ->addAddMAC($macsToAdd); | |||
} | } | |||
if (count($vars->snapins)) { | if (isset($vars->snapins)) { | |||
$snapinsToAdd = array_diff( | ||||
(array)$vars->snapins, | ||||
$class->get('snapins') | ||||
); | ||||
$snapinsToRem = array_diff( | ||||
$class->get('snapins'), | ||||
(array)$vars->snapins | ||||
); | ||||
$class | $class | |||
->removeSnapin($class->get('snapins')) | ->removeSnapin($snapinsToRem) | |||
->addSnapin($vars->snapins); | ->addSnapin($snapinsToAdd); | |||
} | } | |||
if (count($vars->printers)) { | if (isset($vars->printers)) { | |||
$printersToAdd = array_diff( | ||||
(array)$vars->printers, | ||||
$class->get('printers') | ||||
); | ||||
$printersToRem = array_diff( | ||||
$class->get('printers'), | ||||
(array)$vars->printers | ||||
); | ||||
$class | $class | |||
->removePrinter($class->get('printers')) | ->removePrinter($printersToRem) | |||
->addPrinter($vars->printers); | ->addPrinter($printersToAdd); | |||
} | } | |||
if (count($vars->modules)) { | if (isset($vars->modules)) { | |||
$modulesToAdd = array_diff( | ||||
(array)$vars->modules, | ||||
$class->get('modules') | ||||
); | ||||
$modulesToRem = array_diff( | ||||
$class->get('modules'), | ||||
(array)$vars->modules | ||||
); | ||||
$class | $class | |||
->removeModule($class->get('modules')) | ->removeModule($modulesToAdd) | |||
->addModule($vars->modules); | ->addModule($modulesToRem); | |||
} | } | |||
if (count($vars->groups)) { | if (isset($vars->groups)) { | |||
$groupsToAdd = array_diff( | ||||
(array)$vars->groups, | ||||
$class->get('groups') | ||||
); | ||||
$groupsToRem = array_diff( | ||||
$class->get('groups'), | ||||
(array)$vars->groups | ||||
); | ||||
$class | $class | |||
->removeGroup($class->get('groups')) | ->removeGroup($groupsToRem) | |||
->addGroup($vars->groups); | ->addGroup($groupsToAdd); | |||
} | } | |||
break; | break; | |||
case 'group': | case 'group': | |||
if (count($vars->snapins)) { | if (isset($vars->snapins)) { | |||
Route::ids('snapin'); | ||||
$snapins = json_decode( | ||||
Route::getData(), | ||||
true | ||||
); | ||||
$snapinsToRem = array_diff( | ||||
$snapins, | ||||
(array)$vars->snapins | ||||
); | ||||
$class | $class | |||
->removeSnapin( | ->removeSnapin($snapinsToRem) | |||
self::getSubObjectIDs('Snapin') | ||||
) | ||||
->addSnapin($vars->snapins); | ->addSnapin($vars->snapins); | |||
} | } | |||
if (count($vars->printers)) { | if (isset($vars->printers)) { | |||
Route::ids('printer'); | ||||
$printers = json_decode( | ||||
Route::getData(), | ||||
true | ||||
); | ||||
$printersToRem = array_diff( | ||||
$printers, | ||||
(array)$vars->printers | ||||
); | ||||
$class | $class | |||
->removePrinter( | ->removePrinter($printersToRem) | |||
self::getSubObjectIDs('Printer') | ||||
) | ||||
->addPrinter($vars->printers); | ->addPrinter($vars->printers); | |||
} | } | |||
if (count($vars->modules)) { | if (isset($vars->modules)) { | |||
Route::ids('module'); | ||||
$modules = json_decode( | ||||
Route::getData(), | ||||
true | ||||
); | ||||
$modulesToRem = array_diff( | ||||
$modules, | ||||
(array)$vars->modules | ||||
); | ||||
$class | $class | |||
->removeModule( | ->removeModule($modulesToRem) | |||
self::getSubObjectIDs('Module') | ->addPrinter($vars->modules); | |||
) | ||||
->addModule($vars->modules); | ||||
} | } | |||
if (count($vars->hosts)) { | if (isset($vars->hosts)) { | |||
$hostsToAdd = array_diff( | ||||
(array)$vars->hosts, | ||||
$class->get('hosts') | ||||
); | ||||
$hostsToRem = array_diff( | ||||
$class->get('hosts'), | ||||
(array)$vars->hosts | ||||
); | ||||
$class | $class | |||
->removeHost( | ->removeHost($hostsToRem) | |||
$class->get('hosts') | ->addHost($hostsToAdd); | |||
) | ||||
->addHost($vars->hosts); | ||||
} | } | |||
if ($vars->imageID) { | if ($vars->imageID) { | |||
$class | $class | |||
->addImage($vars->imageID); | ->addImage($vars->imageID); | |||
} | } | |||
break; | break; | |||
case 'image': | case 'image': | |||
case 'snapin': | case 'snapin': | |||
if (count($vars->hosts)) { | if (isset($vars->hosts)) { | |||
$hostsToAdd = array_diff( | ||||
(array)$vars->hosts, | ||||
$class->get('hosts') | ||||
); | ||||
$hostsToRem = array_diff( | ||||
$class->get('hosts'), | ||||
(array)$vars->hosts | ||||
); | ||||
$class | $class | |||
->removeHost( | ->removeHost($hostsToRem) | |||
$class->get('hosts') | ->addHost($hostsToAdd); | |||
) | ||||
->addHost($vars->hosts); | ||||
} | } | |||
if (count($vars->storagegroups)) { | if (isset($vars->storagegroups)) { | |||
$storageGroupsToAdd = array_diff( | ||||
(array)$vars->storagegroups, | ||||
$class->get('storagegroups') | ||||
); | ||||
$storageGroupsToRem = array_diff( | ||||
$class->get('storagegroups'), | ||||
(array)$vars->storagegroups | ||||
); | ||||
$class | $class | |||
->removeGroup( | ->removeGroup($storageGroupsToRem) | |||
$class->get('storagegroups') | ->addgroup($storageGroupsToAdd); | |||
) | ||||
->addGroup($vars->storagegroups); | ||||
} | } | |||
break; | break; | |||
case 'printer': | case 'printer': | |||
if (count($vars->hosts)) { | if (isset($vars->hosts)) { | |||
$hostsToAdd = array_diff( | ||||
(array)$vars->hosts, | ||||
$class->get('hosts') | ||||
); | ||||
$hostsToRem = array_diff( | ||||
$class->get('hosts'), | ||||
(array)$vars->hosts | ||||
); | ||||
$class | $class | |||
->removeHost( | ->removeHost($hostsToRem) | |||
$class->get('hosts') | ->addHost($hostsToAdd); | |||
) | ||||
->addHost($vars->hosts); | ||||
} | } | |||
break; | break; | |||
} | } | |||
// Store the data and recreate. | // Store the data and recreate. | |||
// If failed present so. | // If failed present so. | |||
if ($class->save()) { | if ($class->save()) { | |||
$class = new $class($id); | $class = new $class($id); | |||
} else { | } else { | |||
self::sendResponse( | self::sendResponse( | |||
HTTPResponseCodes::HTTP_INTERNAL_SERVER_ERROR | HTTPResponseCodes::HTTP_INTERNAL_SERVER_ERROR | |||
skipping to change at line 813 | skipping to change at line 931 | |||
unset($key); | unset($key); | |||
} | } | |||
switch ($classname) { | switch ($classname) { | |||
case 'host': | case 'host': | |||
if (count($vars->macs)) { | if (count($vars->macs)) { | |||
$class | $class | |||
->removeAddMAC($vars->macs) | ->removeAddMAC($vars->macs) | |||
->addPriMAC(array_shift($vars->macs)) | ->addPriMAC(array_shift($vars->macs)) | |||
->addAddMAC($vars->macs); | ->addAddMAC($vars->macs); | |||
} | } | |||
if (count($vars->snapins)) { | if (isset($vars->snapins)) { | |||
$class | $class | |||
->addSnapin($vars->snapins); | ->addSnapin($vars->snapins); | |||
} | } | |||
if (count($vars->printers)) { | if (isset($vars->printers)) { | |||
$class | $class | |||
->addPrinter($vars->printers); | ->addPrinter($vars->printers); | |||
} | } | |||
if (count($vars->modules)) { | if (isset($vars->modules)) { | |||
$class | $class | |||
->addModule($vars->modules); | ->addModule($vars->modules); | |||
} | } | |||
if (count($vars->groups)) { | if (isset($vars->groups)) { | |||
$class | $class | |||
->addGroup($vars->groups); | ->addGroup($vars->groups); | |||
} | } | |||
break; | break; | |||
case 'group': | case 'group': | |||
if (count($vars->snapins)) { | if (isset($vars->snapins)) { | |||
$class | $class | |||
->addSnapin($vars->snapins); | ->addSnapin($vars->snapins); | |||
} | } | |||
if (count($vars->printers)) { | if (isset($vars->printers)) { | |||
$class | $class | |||
->addPrinter($vars->printers); | ->addPrinter($vars->printers); | |||
} | } | |||
if (count($vars->modules)) { | if (isset($vars->modules)) { | |||
$class | $class | |||
->addModule($vars->modules); | ->addModule($vars->modules); | |||
} | } | |||
if (count($vars->hosts)) { | if (isset($vars->hosts)) { | |||
$class | $class | |||
->addHost($vars->hosts); | ->addHost($vars->hosts); | |||
if (isset($vars->imageID)) { | if (isset($vars->imageID)) { | |||
$class | $class | |||
->addImage($vars->imageID); | ->addImage($vars->imageID); | |||
} | } | |||
} | } | |||
break; | break; | |||
case 'image': | case 'image': | |||
case 'snapin': | case 'snapin': | |||
if (count($vars->hosts)) { | if (isset($vars->hosts)) { | |||
$class | $class | |||
->addHost($vars->hosts); | ->addHost($vars->hosts); | |||
} | } | |||
if (count($vars->storagegroups)) { | if (isset($vars->storagegroups)) { | |||
$class | $class | |||
->addGroup($vars->storagegroups); | ->addGroup($vars->storagegroups); | |||
} | } | |||
break; | break; | |||
case 'printer': | case 'printer': | |||
if (count($vars->hosts)) { | if (isset($vars->hosts)) { | |||
$class | $class | |||
->addHost($vars->hosts); | ->addHost($vars->hosts); | |||
} | } | |||
break; | break; | |||
} | } | |||
foreach ($classVars['databaseFieldsRequired'] as &$key) { | foreach ($classVars['databaseFieldsRequired'] as &$key) { | |||
$key = $class->key($key); | $key = $class->key($key); | |||
$val = $class->get($key); | $val = $class->get($key); | |||
if (!is_numeric($val) && !$val) { | if (!is_numeric($val) && !$val) { | |||
self::setErrorMessage( | self::setErrorMessage( | |||
skipping to change at line 1098 | skipping to change at line 1216 | |||
} | } | |||
/** | /** | |||
* This is a commonizing element so list/search/getinfo | * This is a commonizing element so list/search/getinfo | |||
* will operate in the same fasion. | * will operate in the same fasion. | |||
* | * | |||
* @param string $classname The name of the class. | * @param string $classname The name of the class. | |||
* @param object $class The class to work with. | * @param object $class The class to work with. | |||
* | * | |||
* @return object|array | * @return object|array | |||
*/ | */ | |||
public static function getter($classname, $class) | public static function getter($classname, $class, $item = '') | |||
{ | { | |||
if (!$class instanceof $classname) { | if (!$class instanceof $classname) { | |||
return; | return; | |||
} | } | |||
switch ($classname) { | switch ($classname) { | |||
case 'host': | case 'host': | |||
$pass = $class->get('ADPass'); | $pass = $class->get('ADPass'); | |||
$passtest = self::aesdecrypt($pass); | $passtest = self::aesdecrypt($pass); | |||
if ($test_base64 = base64_decode($passtest)) { | if ($test_base64 = base64_decode($passtest)) { | |||
if (mb_detect_encoding($test_base64, 'utf-8', true)) { | if (mb_detect_encoding($test_base64, 'utf-8', true)) { | |||
skipping to change at line 1183 | skipping to change at line 1301 | |||
break; | break; | |||
case 'snapin': | case 'snapin': | |||
$data = FOGCore::fastmerge( | $data = FOGCore::fastmerge( | |||
$class->get(), | $class->get(), | |||
array( | array( | |||
'storagegroupname' => $class->getStorageGroup()->get('name') | 'storagegroupname' => $class->getStorageGroup()->get('name') | |||
) | ) | |||
); | ); | |||
break; | break; | |||
case 'storagenode': | case 'storagenode': | |||
$data = FOGCore::fastmerge( | $extra = array(); | |||
$class->get(), | if ($item == 'all') { | |||
array( | $extra = array( | |||
'logfiles' => ( | 'logfiles' => ( | |||
$class->get('online') ? | $class->get('online') ? | |||
$class->get('logfiles') : | $class->get('logfiles') : | |||
[] | [] | |||
), | ), | |||
'snapinfiles' => ( | 'snapinfiles' => ( | |||
$class->get('online') ? | $class->get('online') ? | |||
$class->get('snapinfiles') : | $class->get('snapinfiles') : | |||
[] | [] | |||
), | ), | |||
'images' => ( | 'images' => ( | |||
$class->get('online') ? | $class->get('online') ? | |||
$class->get('images') : | $class->get('images') : | |||
[] | [] | |||
), | ) | |||
); | ||||
} elseif (!empty($item)) { | ||||
$extra = array( | ||||
"$item" => ( | ||||
$class->get('online') ? | ||||
$class->get($item) : | ||||
[] | ||||
) | ||||
); | ||||
} | ||||
$data = FOGCore::fastmerge( | ||||
$class->get(), | ||||
$extra, | ||||
array( | ||||
'storagegroup' => self::getter( | 'storagegroup' => self::getter( | |||
'storagegroup', | 'storagegroup', | |||
$class->get('storagegroup') | $class->get('storagegroup') | |||
), | ), | |||
'clientload' => $class->getClientLoad(), | 'clientload' => $class->getClientLoad(), | |||
'online' => $class->get('online') | 'online' => $class->get('online') | |||
) | ) | |||
); | ); | |||
break; | break; | |||
case 'storagegroup': | case 'storagegroup': | |||
End of changes. 49 change blocks. | ||||
79 lines changed or deleted | 211 lines changed or added |