/kloxo/httpdocs/htmllib/lib/commandlinelib.php

https://bitbucket.org/Nemcio/kloxo-mr · PHP · 226 lines · 170 code · 44 blank · 12 comment · 37 complexity · c6a39b25a55769714192eabc2027cfa3 MD5 · raw file

  1. <?php
  2. function __cmd_desc_add($p, $parent = null)
  3. {
  4. global $gbl, $sgbl, $login, $ghtml;
  5. if (!$parent) {
  6. if (isset($p['parent-class']) && isset($p['parent-name'])) {
  7. $parent = new $p['parent-class'](null, 'localhost', $p['parent-name']);
  8. dprint("$parent->nname\n");
  9. $parent->get();
  10. if ($parent->dbaction === 'add') {
  11. throw new lxException("parent_doesnt_exist", "nname", $p['parent-name']);
  12. }
  13. if (!$parent->checkIfSomeParent($login->getClName())) {
  14. throw new lxException("you_are_not_the_owner_of_parent", "", $p['parent-name']);
  15. }
  16. } else {
  17. $parent = $login;
  18. }
  19. }
  20. copy_nname_to_name($p);
  21. $class = $p['class'];
  22. $var = get_variable($p);
  23. if (isset($p['count'])) {
  24. $oldname = $p['name'];
  25. for($i = 0; $i < $p['count']; $i++) {
  26. if ($class === 'domain') {
  27. $p['name'] = "$oldname$i.com";
  28. } else {
  29. $p['name'] = "$oldname$i";
  30. }
  31. $param = exec_class_method($class, "addCommand", $parent, $class, $p);
  32. unset($var['template-name']);
  33. $param = lx_array_merge(array($param, $var));
  34. do_desc_add($parent, $class, $param);
  35. }
  36. $parent->was();
  37. exit;
  38. }
  39. $param = exec_class_method($class, "addCommand", $parent, $class, $p);
  40. unset($var['template-name']);
  41. $param = lx_array_merge(array($param, $var));
  42. do_desc_add($parent, $class, $param);
  43. $parent->was();
  44. }
  45. function __cmd_desc_delete($p)
  46. {
  47. global $gbl, $sgbl, $login, $ghtml;
  48. /*
  49. if (isset($p['parent-class']) && isset($p['parent-name'])) {
  50. $parent = new $p['parent-class'](null, 'localhost', $p['parent-name']);
  51. $parent->get();
  52. if ($parent->dbaction === 'add') {
  53. throw new lxException("parent_doesnt_exist", "nname", $class);
  54. }
  55. } else {
  56. $parent = $login;
  57. }
  58. */
  59. $class = $p['class'];
  60. $name = $p['name'];
  61. $object = new $class(null, 'localhost', $name);
  62. $object->get();
  63. if ($object->dbaction === 'add') {
  64. throw new lxException('object_doesnt_exist', '', $name);
  65. }
  66. if (!$object->checkIfSomeParent($login->getClName())) {
  67. throw new lxException("the_object_doesnt_exist_under_you", "", $object->nname);
  68. }
  69. do_desc_delete_single($object);
  70. $object->was();
  71. }
  72. function __cmd_desc_simplelist($p)
  73. {
  74. global $gbl, $sgbl, $login, $ghtml;
  75. ob_start();
  76. $resource = $p['resource'];
  77. $parent = null;
  78. if (!$parent) {
  79. if (isset($p['parent-class']) && isset($p['parent-name'])) {
  80. $parent = new $p['parent-class'](null, 'localhost', $p['parent-name']);
  81. dprint($parent->nname);
  82. $parent->get();
  83. if ($parent->dbaction === 'add') {
  84. throw new lxException("parent_doesnt_exist", "nname", $p['parent-name']);
  85. }
  86. if (!$parent->checkIfSomeParent($login->getClName())) {
  87. throw new lxException("you_are_not_the_owner_of_parent", "", $p['parent-name']);
  88. }
  89. } else {
  90. $parent = $login;
  91. }
  92. }
  93. $list = $parent->getCommandResource($resource);
  94. if (!$list) {
  95. // Fix for WHMCS needing pserver in client.
  96. if (!$parent->isAdmin() && $sgbl->isKloxo() && $resource === 'pserver') {
  97. $list['localhost'] = 'localhost';
  98. return $list;
  99. }
  100. $list = $parent->getList($resource);
  101. if (isset($p['v-filter'])) {
  102. list($var, $val) = explode(":", $p['v-filter']);
  103. foreach($list as $k => $l) {
  104. if ($l->$var !== $val) {
  105. unset($list[$k]);
  106. }
  107. }
  108. }
  109. if (!$list) {
  110. json_print("error", $p, "__error_no_resource_for_$resource");
  111. exit;
  112. }
  113. $list = get_namelist_from_objectlist($list, "nname", "nname");
  114. }
  115. ob_end_clean();
  116. return $list;
  117. }
  118. function copy_nname_to_name(&$p)
  119. {
  120. if (isset($p['nname']) && !isset($p['name'])) {
  121. $p['name'] = $p['nname'];
  122. }
  123. }
  124. function __cmd_desc_update($p)
  125. {
  126. global $gbl, $sgbl, $login, $ghtml;
  127. copy_nname_to_name($p);
  128. $object = new $p['class'](null, 'localhost', $p['name']);
  129. $object->get();
  130. if ($object->dbaction === 'add') {
  131. throw new lxException("object_doesnt_exist", "name", $p['name']);
  132. }
  133. if (!$object->checkIfSomeParent($login->getClName())) {
  134. throw new lxException("the_object_doesnt_exist_under_you", "", $object->nname);
  135. }
  136. $tparam = get_variable($p);
  137. $subaction = $p['subaction'];
  138. $tparam = $object->commandUpdate($subaction, $tparam);
  139. $param = array();
  140. foreach($tparam as $k => $v) {
  141. $k = str_replace("-", "_s_", $k);
  142. $param[$k] = $v;
  143. }
  144. dprintr($param);
  145. do_desc_update($object, $subaction, $param);
  146. $object->was();
  147. }
  148. function __cmd_desc_getproperty($param)
  149. {
  150. global $gbl, $sgbl, $login, $ghtml;
  151. if (isset($param['name']) && isset($param['class'])) {
  152. $name = $param['name'];
  153. $class = $param['class'];
  154. $object = new $class(null, 'localhost', $name);
  155. $object->get();
  156. if ($object->dbaction === 'add') {
  157. throw new lxException('object_doesnt_exist', 'name', $name);
  158. }
  159. } else {
  160. $object = $login;
  161. }
  162. $object->getHardProperty();
  163. $vlist = get_variable($param);
  164. foreach($vlist as $k => $v) {
  165. $nv = $k;
  166. if (csa($nv, "-")) {
  167. $cc = explode("-", $nv);
  168. $result["v-$k"] = $object->{$cc[0]}->$cc[1];
  169. continue;
  170. }
  171. if ($nv === 'priv' || $nv === 'used') {
  172. foreach($object->$nv as $kk => $nnv) {
  173. if ($object->isQuotaVariable($kk)) {
  174. $result["v-$nv-$kk"] = $nnv;
  175. }
  176. }
  177. continue;
  178. }
  179. $result["v-$nv"] = $object->$nv;
  180. }
  181. return $result;
  182. }