From f9a84635813f15d60b5389981ba1bb9d174e0ad5 Mon Sep 17 00:00:00 2001 From: olevole Date: Sun, 15 Jan 2017 13:55:48 +0300 Subject: [PATCH] make network, authkey menu; begining to work in bhyve, sources and bases --- php/clonos.php | 870 +++++- php/config.php | 92 +- php/menu.php | 16 +- public/css/styles-old.css | 680 +++++ public/css/styles.css | 816 +++++- public/dialogs/authkey.php | 25 + public/dialogs/bhyve-new.php | 57 + public/dialogs/bhyve-obtain.php | 57 + public/dialogs/jail-settings-config-menu.php | 9 + public/dialogs/jail-settings.php | 71 + public/dialogs/media.php | 26 + public/dialogs/tasklog.php | 9 + public/dialogs/vnc-bhyve.php | 8 + public/dialogs/vnc.php | 8 + public/dialogs/vpnet.php | 26 + public/font-old/animation.css | 85 + public/font-old/clonos-codes.css | 59 + public/font-old/clonos-embedded.css | 112 + public/font-old/clonos-ie7-codes.css | 59 + public/font-old/clonos-ie7.css | 70 + public/font-old/clonos.css | 115 + public/font-old/clonos.eot | Bin 0 -> 23476 bytes public/font-old/clonos.svg | 126 + public/font-old/clonos.ttf | Bin 0 -> 23316 bytes public/font-old/clonos.woff | Bin 0 -> 14404 bytes public/font-old/clonos.woff2 | Bin 0 -> 12328 bytes public/font/clonos-codes.css | 101 + public/font/clonos-embedded.css | 113 +- public/font/clonos-ie7-codes.css | 101 + public/font/clonos-ie7.css | 101 + public/font/clonos.css | 115 +- public/font/clonos.eot | Bin 23240 -> 66000 bytes public/font/clonos.svg | 204 +- public/font/clonos.ttf | Bin 23080 -> 65840 bytes public/font/clonos.woff | Bin 14268 -> 38964 bytes public/font/clonos.woff2 | Bin 12256 -> 32984 bytes public/index-old.php | 93 + public/index.php | 70 +- public/js/clonos.js | 1328 +++++++++ public/js/lang-delete/en.js | 3 + public/js/lang-delete/ru.js | 26 + public/js/noty/jquery.noty.js | 623 +++++ public/js/noty/layouts/bottom.js | 30 + public/js/noty/layouts/bottomCenter.js | 38 + public/js/noty/layouts/bottomLeft.js | 39 + public/js/noty/layouts/bottomRight.js | 39 + public/js/noty/layouts/center.js | 53 + public/js/noty/layouts/centerLeft.js | 58 + public/js/noty/layouts/centerRight.js | 58 + public/js/noty/layouts/inline.js | 27 + public/js/noty/layouts/top.js | 30 + public/js/noty/layouts/topCenter.js | 37 + public/js/noty/layouts/topLeft.js | 39 + public/js/noty/layouts/topRight.js | 39 + .../js/noty/packaged/jquery.noty.packaged.js | 1768 ++++++++++++ .../noty/packaged/jquery.noty.packaged.min.js | 1 + public/js/noty/promise.js | 432 +++ public/js/noty/themes/bootstrap.js | 58 + public/js/noty/themes/default.js | 182 ++ public/js/noty/themes/metroui.js | 143 + public/js/noty/themes/relax.js | 149 + public/js/noty/themes/semanticUI.js | 103 + public/js/scripts.js | 413 --- public/json.php | 6 +- public/lang/en.js | 7 +- public/lang/ru.js | 43 +- public/lang/ru.php | 83 +- public/novnc/.gitignore | 6 + public/novnc/.gitmodules | 0 public/novnc/.travis.yml | 22 + public/novnc/CONTRIBUTING.md | 54 + public/novnc/LICENSE.txt | 85 + public/novnc/README.md | 132 + public/novnc/docs/LICENSE.Apache-2.0 | 202 ++ public/novnc/docs/LICENSE.BSD-2-Clause | 22 + public/novnc/docs/LICENSE.BSD-3-Clause | 24 + public/novnc/docs/LICENSE.GPL-3 | 621 +++++ public/novnc/docs/LICENSE.LGPL-3 | 165 ++ public/novnc/docs/LICENSE.MPL-2.0 | 373 +++ public/novnc/docs/LICENSE.OFL-1.1 | 91 + public/novnc/docs/LICENSE.pako | 21 + public/novnc/docs/LICENSE.zlib | 27 + public/novnc/docs/VERSION | 1 + public/novnc/docs/flash_policy.txt | 4 + public/novnc/docs/links | 76 + public/novnc/docs/notes | 5 + public/novnc/docs/release.txt | 34 + public/novnc/docs/rfb_notes | 147 + public/novnc/docs/rfbproto-3.3.pdf | Bin 0 -> 110778 bytes public/novnc/docs/rfbproto-3.7.pdf | Bin 0 -> 165552 bytes public/novnc/docs/rfbproto-3.8.pdf | Bin 0 -> 143840 bytes public/novnc/favicon.ico | 1 + public/novnc/images/alt.png | Bin 0 -> 339 bytes public/novnc/images/clipboard.png | Bin 0 -> 501 bytes public/novnc/images/connect.png | Bin 0 -> 404 bytes public/novnc/images/ctrl.png | Bin 0 -> 354 bytes public/novnc/images/ctrlaltdel.png | Bin 0 -> 317 bytes public/novnc/images/disconnect.png | Bin 0 -> 1378 bytes public/novnc/images/drag.png | Bin 0 -> 963 bytes public/novnc/images/esc.png | Bin 0 -> 385 bytes public/novnc/images/favicon.ico | Bin 0 -> 1150 bytes public/novnc/images/favicon.png | Bin 0 -> 453 bytes public/novnc/images/fullscreen.png | Bin 0 -> 851 bytes public/novnc/images/keyboard.png | Bin 0 -> 1283 bytes public/novnc/images/mouse_left.png | Bin 0 -> 511 bytes public/novnc/images/mouse_middle.png | Bin 0 -> 517 bytes public/novnc/images/mouse_none.png | Bin 0 -> 497 bytes public/novnc/images/mouse_right.png | Bin 0 -> 513 bytes public/novnc/images/power.png | Bin 0 -> 390 bytes public/novnc/images/screen_320x460.png | Bin 0 -> 12778 bytes public/novnc/images/screen_57x57.png | Bin 0 -> 1807 bytes public/novnc/images/screen_700x700.png | Bin 0 -> 17930 bytes public/novnc/images/settings.png | Bin 0 -> 2495 bytes public/novnc/images/tab.png | Bin 0 -> 387 bytes public/novnc/images/toggleextrakeys.png | Bin 0 -> 735 bytes public/novnc/include/Orbitron700.ttf | Bin 0 -> 38580 bytes public/novnc/include/Orbitron700.woff | Bin 0 -> 17472 bytes public/novnc/include/base.css | 527 ++++ public/novnc/include/base64.js | 113 + public/novnc/include/black.css | 71 + public/novnc/include/blue.css | 64 + public/novnc/include/chrome-app/tcp-client.js | 321 +++ public/novnc/include/des.js | 276 ++ public/novnc/include/display.js | 908 +++++++ public/novnc/include/inflator.js | 2418 +++++++++++++++++ public/novnc/include/input.js | 397 +++ public/novnc/include/keyboard.js | 674 +++++ public/novnc/include/keysym.js | 378 +++ public/novnc/include/keysymdef.js | 15 + public/novnc/include/logo.js | 1 + public/novnc/include/playback.js | 120 + public/novnc/include/rfb.js | 2327 ++++++++++++++++ public/novnc/include/ui.js | 1293 +++++++++ public/novnc/include/util.js | 622 +++++ public/novnc/include/websock.js | 440 +++ public/novnc/include/webutil.js | 292 ++ public/novnc/include/xtscancodes.js | 146 + public/novnc/karma.conf.js | 198 ++ public/novnc/package.json | 50 + public/novnc/tests/arrays.html | 39 + public/novnc/tests/arrays.js | 375 +++ public/novnc/tests/assertions.js | 102 + public/novnc/tests/base64.html | 91 + public/novnc/tests/base64.js | 12 + public/novnc/tests/browser.js | 134 + public/novnc/tests/canvas.html | 148 + public/novnc/tests/cursor.html | 135 + public/novnc/tests/face.png | Bin 0 -> 2303 bytes public/novnc/tests/face.png.js | 1 + public/novnc/tests/fake.websocket.js | 91 + public/novnc/tests/input.html | 133 + public/novnc/tests/keyboard-tests.html | 29 + public/novnc/tests/run_from_console.casper.js | 114 + public/novnc/tests/run_from_console.js | 361 +++ public/novnc/tests/run_from_console.zombie.js | 82 + public/novnc/tests/stats.js | 53 + public/novnc/tests/test.base64.js | 33 + public/novnc/tests/test.display.js | 461 ++++ public/novnc/tests/test.helper.js | 262 ++ public/novnc/tests/test.keyboard.js | 842 ++++++ public/novnc/tests/test.rfb.js | 2032 ++++++++++++++ public/novnc/tests/test.util.js | 105 + public/novnc/tests/test.websock.js | 457 ++++ public/novnc/tests/viewport.css | 43 + public/novnc/tests/viewport.html | 203 ++ public/novnc/tests/vnc_perf.html | 214 ++ public/novnc/tests/vnc_playback.html | 138 + public/novnc/utils/README.md | 14 + public/novnc/utils/b64-to-binary.pl | 17 + public/novnc/utils/img2js.py | 40 + public/novnc/utils/inflator.partial.js | 40 + public/novnc/utils/json2graph.py | 206 ++ public/novnc/utils/launch.sh | 154 ++ public/novnc/utils/parse.js | 97 + public/novnc/utils/u2x11 | 28 + public/novnc/vnc.html | 225 ++ public/novnc/vnc_auto.html | 248 ++ public/pages/authkey/a.json.php | 39 + public/pages/authkey/authkeyslist.table | 9 + public/pages/authkey/ru.index.php | 19 + public/pages/bases/a.json.php | 65 + public/pages/bases/baseslist.table | 15 + public/pages/bases/ru.index.php | 28 + public/pages/bhyvevms/a.json.php | 82 + public/pages/bhyvevms/bhyveslist.table | 15 + public/pages/bhyvevms/en.index.php | 19 + public/pages/bhyvevms/ru.index.php | 28 + public/pages/jailscontainers/a.json.php | 79 +- public/pages/jailscontainers/en.index.php | 22 + public/pages/jailscontainers/jailslist.table | 13 + public/pages/jailscontainers/ru.index.php | 22 +- public/pages/media/a.json.php | 39 + public/pages/media/mediaslist.table | 9 + public/pages/media/ru.index.php | 21 + public/pages/nodes/a.json.php | 2 +- public/pages/overview/a.json.php | 6 +- public/pages/sources/a.json.php | 70 + public/pages/sources/ru.index.php | 24 + public/pages/sources/srcslist.table | 13 + public/pages/tasklog/a.json.php | 67 + public/pages/tasklog/ru.index.php | 24 + public/pages/tasklog/tasklog.table | 12 + public/pages/vpnet/a.json.php | 39 + public/pages/vpnet/ru.index.php | 19 + public/pages/vpnet/vpnetslist.table | 9 + public/templates/jail.tpl | 63 + public/templates/vm.tpl | 83 + public/test.php | 24 + public/vnc.php | 11 + 209 files changed, 32000 insertions(+), 662 deletions(-) create mode 100644 public/css/styles-old.css create mode 100644 public/dialogs/authkey.php create mode 100644 public/dialogs/bhyve-new.php create mode 100644 public/dialogs/bhyve-obtain.php create mode 100644 public/dialogs/jail-settings-config-menu.php create mode 100644 public/dialogs/jail-settings.php create mode 100644 public/dialogs/media.php create mode 100644 public/dialogs/tasklog.php create mode 100644 public/dialogs/vnc-bhyve.php create mode 100644 public/dialogs/vnc.php create mode 100644 public/dialogs/vpnet.php create mode 100644 public/font-old/animation.css create mode 100644 public/font-old/clonos-codes.css create mode 100644 public/font-old/clonos-embedded.css create mode 100644 public/font-old/clonos-ie7-codes.css create mode 100644 public/font-old/clonos-ie7.css create mode 100644 public/font-old/clonos.css create mode 100644 public/font-old/clonos.eot create mode 100644 public/font-old/clonos.svg create mode 100644 public/font-old/clonos.ttf create mode 100644 public/font-old/clonos.woff create mode 100644 public/font-old/clonos.woff2 create mode 100644 public/index-old.php create mode 100644 public/js/clonos.js create mode 100644 public/js/lang-delete/en.js create mode 100644 public/js/lang-delete/ru.js create mode 100644 public/js/noty/jquery.noty.js create mode 100644 public/js/noty/layouts/bottom.js create mode 100644 public/js/noty/layouts/bottomCenter.js create mode 100644 public/js/noty/layouts/bottomLeft.js create mode 100644 public/js/noty/layouts/bottomRight.js create mode 100644 public/js/noty/layouts/center.js create mode 100644 public/js/noty/layouts/centerLeft.js create mode 100644 public/js/noty/layouts/centerRight.js create mode 100644 public/js/noty/layouts/inline.js create mode 100644 public/js/noty/layouts/top.js create mode 100644 public/js/noty/layouts/topCenter.js create mode 100644 public/js/noty/layouts/topLeft.js create mode 100644 public/js/noty/layouts/topRight.js create mode 100644 public/js/noty/packaged/jquery.noty.packaged.js create mode 100644 public/js/noty/packaged/jquery.noty.packaged.min.js create mode 100644 public/js/noty/promise.js create mode 100644 public/js/noty/themes/bootstrap.js create mode 100644 public/js/noty/themes/default.js create mode 100644 public/js/noty/themes/metroui.js create mode 100644 public/js/noty/themes/relax.js create mode 100644 public/js/noty/themes/semanticUI.js delete mode 100644 public/js/scripts.js create mode 100644 public/novnc/.gitignore create mode 100644 public/novnc/.gitmodules create mode 100644 public/novnc/.travis.yml create mode 100644 public/novnc/CONTRIBUTING.md create mode 100644 public/novnc/LICENSE.txt create mode 100644 public/novnc/README.md create mode 100644 public/novnc/docs/LICENSE.Apache-2.0 create mode 100644 public/novnc/docs/LICENSE.BSD-2-Clause create mode 100644 public/novnc/docs/LICENSE.BSD-3-Clause create mode 100644 public/novnc/docs/LICENSE.GPL-3 create mode 100644 public/novnc/docs/LICENSE.LGPL-3 create mode 100644 public/novnc/docs/LICENSE.MPL-2.0 create mode 100644 public/novnc/docs/LICENSE.OFL-1.1 create mode 100644 public/novnc/docs/LICENSE.pako create mode 100644 public/novnc/docs/LICENSE.zlib create mode 100644 public/novnc/docs/VERSION create mode 100644 public/novnc/docs/flash_policy.txt create mode 100644 public/novnc/docs/links create mode 100644 public/novnc/docs/notes create mode 100644 public/novnc/docs/release.txt create mode 100644 public/novnc/docs/rfb_notes create mode 100644 public/novnc/docs/rfbproto-3.3.pdf create mode 100644 public/novnc/docs/rfbproto-3.7.pdf create mode 100644 public/novnc/docs/rfbproto-3.8.pdf create mode 120000 public/novnc/favicon.ico create mode 100644 public/novnc/images/alt.png create mode 100644 public/novnc/images/clipboard.png create mode 100644 public/novnc/images/connect.png create mode 100644 public/novnc/images/ctrl.png create mode 100644 public/novnc/images/ctrlaltdel.png create mode 100644 public/novnc/images/disconnect.png create mode 100644 public/novnc/images/drag.png create mode 100644 public/novnc/images/esc.png create mode 100644 public/novnc/images/favicon.ico create mode 100644 public/novnc/images/favicon.png create mode 100644 public/novnc/images/fullscreen.png create mode 100644 public/novnc/images/keyboard.png create mode 100644 public/novnc/images/mouse_left.png create mode 100644 public/novnc/images/mouse_middle.png create mode 100644 public/novnc/images/mouse_none.png create mode 100644 public/novnc/images/mouse_right.png create mode 100644 public/novnc/images/power.png create mode 100644 public/novnc/images/screen_320x460.png create mode 100644 public/novnc/images/screen_57x57.png create mode 100644 public/novnc/images/screen_700x700.png create mode 100644 public/novnc/images/settings.png create mode 100644 public/novnc/images/tab.png create mode 100644 public/novnc/images/toggleextrakeys.png create mode 100644 public/novnc/include/Orbitron700.ttf create mode 100644 public/novnc/include/Orbitron700.woff create mode 100644 public/novnc/include/base.css create mode 100644 public/novnc/include/base64.js create mode 100644 public/novnc/include/black.css create mode 100644 public/novnc/include/blue.css create mode 100644 public/novnc/include/chrome-app/tcp-client.js create mode 100644 public/novnc/include/des.js create mode 100644 public/novnc/include/display.js create mode 100644 public/novnc/include/inflator.js create mode 100644 public/novnc/include/input.js create mode 100644 public/novnc/include/keyboard.js create mode 100644 public/novnc/include/keysym.js create mode 100644 public/novnc/include/keysymdef.js create mode 100644 public/novnc/include/logo.js create mode 100644 public/novnc/include/playback.js create mode 100644 public/novnc/include/rfb.js create mode 100644 public/novnc/include/ui.js create mode 100644 public/novnc/include/util.js create mode 100644 public/novnc/include/websock.js create mode 100644 public/novnc/include/webutil.js create mode 100644 public/novnc/include/xtscancodes.js create mode 100644 public/novnc/karma.conf.js create mode 100644 public/novnc/package.json create mode 100644 public/novnc/tests/arrays.html create mode 100644 public/novnc/tests/arrays.js create mode 100644 public/novnc/tests/assertions.js create mode 100644 public/novnc/tests/base64.html create mode 100644 public/novnc/tests/base64.js create mode 100644 public/novnc/tests/browser.js create mode 100644 public/novnc/tests/canvas.html create mode 100644 public/novnc/tests/cursor.html create mode 100644 public/novnc/tests/face.png create mode 100644 public/novnc/tests/face.png.js create mode 100644 public/novnc/tests/fake.websocket.js create mode 100644 public/novnc/tests/input.html create mode 100644 public/novnc/tests/keyboard-tests.html create mode 100644 public/novnc/tests/run_from_console.casper.js create mode 100755 public/novnc/tests/run_from_console.js create mode 100644 public/novnc/tests/run_from_console.zombie.js create mode 100644 public/novnc/tests/stats.js create mode 100644 public/novnc/tests/test.base64.js create mode 100644 public/novnc/tests/test.display.js create mode 100644 public/novnc/tests/test.helper.js create mode 100644 public/novnc/tests/test.keyboard.js create mode 100644 public/novnc/tests/test.rfb.js create mode 100644 public/novnc/tests/test.util.js create mode 100644 public/novnc/tests/test.websock.js create mode 100644 public/novnc/tests/viewport.css create mode 100644 public/novnc/tests/viewport.html create mode 100644 public/novnc/tests/vnc_perf.html create mode 100644 public/novnc/tests/vnc_playback.html create mode 100644 public/novnc/utils/README.md create mode 100755 public/novnc/utils/b64-to-binary.pl create mode 100755 public/novnc/utils/img2js.py create mode 100644 public/novnc/utils/inflator.partial.js create mode 100755 public/novnc/utils/json2graph.py create mode 100755 public/novnc/utils/launch.sh create mode 100644 public/novnc/utils/parse.js create mode 100755 public/novnc/utils/u2x11 create mode 100644 public/novnc/vnc.html create mode 100644 public/novnc/vnc_auto.html create mode 100644 public/pages/authkey/a.json.php create mode 100644 public/pages/authkey/authkeyslist.table create mode 100644 public/pages/authkey/ru.index.php create mode 100644 public/pages/bases/a.json.php create mode 100644 public/pages/bases/baseslist.table create mode 100644 public/pages/bases/ru.index.php create mode 100644 public/pages/bhyvevms/a.json.php create mode 100644 public/pages/bhyvevms/bhyveslist.table create mode 100644 public/pages/bhyvevms/en.index.php create mode 100644 public/pages/bhyvevms/ru.index.php create mode 100644 public/pages/jailscontainers/en.index.php create mode 100644 public/pages/jailscontainers/jailslist.table create mode 100644 public/pages/media/a.json.php create mode 100644 public/pages/media/mediaslist.table create mode 100644 public/pages/media/ru.index.php create mode 100644 public/pages/sources/a.json.php create mode 100644 public/pages/sources/ru.index.php create mode 100644 public/pages/sources/srcslist.table create mode 100644 public/pages/tasklog/a.json.php create mode 100644 public/pages/tasklog/ru.index.php create mode 100644 public/pages/tasklog/tasklog.table create mode 100644 public/pages/vpnet/a.json.php create mode 100644 public/pages/vpnet/ru.index.php create mode 100644 public/pages/vpnet/vpnetslist.table create mode 100644 public/templates/jail.tpl create mode 100644 public/templates/vm.tpl create mode 100644 public/test.php create mode 100644 public/vnc.php diff --git a/php/clonos.php b/php/clonos.php index b93d1d6d..e7aceeaa 100644 --- a/php/clonos.php +++ b/php/clonos.php @@ -6,8 +6,18 @@ class ClonOS public $workdir=''; public $realpath_php=''; public $realpath_public=''; + public $realpath_page=''; + public $json_name=''; + public $language='en'; + public $language_file_loaded=false; + public $translate_arr=array(); + public $table_templates=array(); + private $_post=false; private $_db=null; + private $_client_ip=''; + private $_dialogs=array(); + private $_cmd_array=array('jcreate','jstart','jstop','jrestart','jedit','jremove','jexport','jimport','jclone','madd','sstart','sstop','projremove','bcreate','bstart','bstop','brestart','bremove','vm_obtain','removesrc'); /* public $projectId=0; @@ -31,9 +41,11 @@ class ClonOS 1 => array('pipe','w'), 2 => array('pipe','r') ); -//echo self::CBSD_CMD.$cmd;exit; + $process = proc_open(self::CBSD_CMD.trim($cmd),$descriptorspec,$pipes,null,null); - + + $full_cmd=self::CBSD_CMD.trim($cmd); + $error=false; $error_message=''; $message=''; @@ -45,44 +57,122 @@ class ClonOS fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); - + $task_id=-1; $return_value = proc_close($process); if($return_value!=0) { $error=true; $error_message=$buf; - //$log_file='/tmp'; - //if(file_exists()) }else{ $message=trim($buf); } - //echo self::CBSD_CMD.$cmd; - return array('cmd'=>$cmd,'retval'=>$return_value, 'message'=>$message, 'error'=>$error,'error_message'=>$error_message); + + return array('cmd'=>$cmd,'full_cmd'=>$full_cmd,'retval'=>$return_value, 'message'=>$message, 'error'=>$error,'error_message'=>$error_message); } } function __construct($_REALPATH) # /usr/home/web/cp/clonos { + $this->_post=($_SERVER['REQUEST_METHOD']=='POST'); + $this->_vars=$_POST; + if(isset($_COOKIE['lang'])) $this->language=$_COOKIE['lang']; + $this->workdir=getenv('WORKDIR'); # // /usr/jails $this->realpath_php=$_REALPATH.'/php/'; # /usr/home/web/cp/clonos/php/ - $this->realpath_php=$_REALPATH.'/public/'; + $this->realpath_public=$_REALPATH.'/public/'; # /usr/home/web/cp/clonos/public/ + $translate_filename=$this->realpath_public.'/lang/'.$this->language.'.php'; + $translate_filename_alt=$this->realpath_public.'/lang/en.php'; + if(file_exists($translate_filename)) $t_filename=$translate_filename; else $t_filename=$translate_filename; + include($t_filename); + $this->translate_arr=$lang; + unset($lang); + unset($t_filename); + + $this->_client_ip=$_SERVER['REMOTE_ADDR']; + + if(isset($this->_vars['path'])) + { + $this->realpath_page=$this->realpath_public.'pages/'.trim($this->_vars['path'],'/').'/'; + $this->json_name=$this->realpath_page.'a.json.php'; + } +// $this->json_name=$this->realpath_php.'pages' +// $clonos->json_name=$file_path.'a.json.php'; + include('config.php'); include('db.php'); include('menu.php'); + $this->_db_tasks=new Db('base','cbsdtaskd'); + $this->_db_local=new Db('base','local'); + $this->config=new Config(); - $this->menu=new Menu($this->config->menu); - - + $this->menu=new Menu($this->config->menu,$this); + if(isset($this->_vars['mode'])) $this->mode=$this->_vars['mode']; + if(isset($this->_vars['form_data'])) $this->form=$this->_vars['form_data']; + if($this->_post && isset($this->mode)) + { + unset($_POST); + switch($this->mode) + { + case 'getTasksStatus': + echo json_encode($this->_getTasksStatus($this->form['jsonObj'])); + return;break; + case 'getJsonPage': + if(file_exists($this->json_name)) include($this->json_name); else echo '{}'; + return;break; + case 'freejname': + echo json_encode($this->getFreeJname()); + break; + + case 'jailAdd': + echo json_encode($this->jailAdd()); + return;break; + case 'bhyveAdd': + echo json_encode($this->bhyveAdd()); + return;break; + case 'bhyveObtain': + echo json_encode($this->bhyveObtain()); + return;break; + + case 'authkeyAdd': + echo json_encode($this->authkeyAdd()); + return;break; + case 'authkeyRemove': + echo json_encode($this->authkeyRemove()); + return;break; + + case 'vpnetAdd': + echo json_encode($this->vpnetAdd()); + return;break; + case 'vpnetRemove': + echo json_encode($this->vpnetRemove()); + return;break; + + case 'mediaAdd': + //echo json_encode($this->mediaAdd()); + return;break; + case 'mediaRemove': + echo json_encode($this->mediaRemove()); + return;break; + + case 'srcRemove': + echo json_encode($this->srcRemove()); + return;break; + + case 'logLoad': + echo json_encode($this->logLoad()); + return;break; + } + } @@ -253,6 +343,33 @@ class ClonOS } } } + function getLang() + { + return $this->language; + } + function translate($phrase) + { + if(isset($this->translate_arr[$phrase])) + return $this->translate_arr[$phrase]; + else + return $phrase; + } + + function getTableChunk($table_name='',$tag) + { + if(empty($table_name)) return false; + if(isset($this->table_templates[$table_name][$tag])) return $this->table_templates[$table_name][$tag]; + + $file_name=$this->realpath_page.$table_name.'.table'; + if(!file_exists($file_name)) return false; + $file=file_get_contents($file_name); + $pat='#[\s]*?<'.$tag.'[^>]*>(.*)<\/'.$tag.'>#iUs'; + if(preg_match($pat,$file,$res)) + { + $this->table_templates[$table_name][$tag]=$res; + return $res; + } + } function check_locktime($nodeip) { @@ -266,13 +383,32 @@ class ClonOS $difftime=(( $cur_time - $st_time ) / 60 ); if ( $difftime > 1 ) { - return round($difftime);; + return round($difftime); } else { return 0; //lock exist but too fresh } } + + function check_vmonline($vm) + { + $vmmdir="/dev/vmm"; + + if(!file_exists($vmmdir)) return 0; + + if($handle=opendir($vmmdir)) + { + while(false!==($entry=readdir($handle))) + { + if($entry[0]==".") continue; + if($vm==$entry) return 1; + } + closedir($handle); + } + + return 0; + } - function get_node_info($nodename,$value) +/* function get_node_info($nodename,$value) { $db = new SQLite3($this->realpath."/var/db/nodes.sqlite"); $db->busyTimeout(5000); if (!$db) return; @@ -285,6 +421,54 @@ class ClonOS if(!isset($res["$value"])) return; return $res["$value"]; } + } */ + + function getRunningTasks($ids=array()) + { + $check_arr=array( + 'jcreate'=>'Creating', + 'jstart'=>'Starting', + 'jstop'=>'Stopping', + 'jrestart'=>'Restarting', + 'jremove'=>'Removing', + 'jexport'=>'Exporting', + 'jclone'=>'Cloning', + 'bcreate'=>'Creating', + 'bstart'=>'Starting', + 'bstop'=>'Stopping', + 'brestart'=>'Restarting', + 'bremove'=>'Removing', + 'vm_obtain'=>'Creating', + 'removesrc'=>'Removing', + ); + + $res=array(); + if(!empty($ids)) + { + $tid=join("','",$ids); + $query="select id,cmd,status,jname from taskd where status<2 and jname in ('{$tid}')"; + //echo $query; + $tasks=$this->_db_tasks->select($query); + if(!empty($tasks)) foreach($tasks as $task) + { + $rid=preg_replace('/^#/','',$task['jname']); + foreach($check_arr as $key=>$val) + { + if(strpos($task['cmd'],$key)!==false) + { + $cmd=$key; + $txt_status=$val; + break; + } + } + $res[$rid]['status']=$task['status']; + $res[$rid]['task_cmd']=$cmd; + $res[$rid]['txt_status']=$txt_status; + $res[$rid]['task_id']=$task['id']; + } + return $res; + } + return null; } /* @@ -315,22 +499,36 @@ class ClonOS if(isset($obj['proj_ops'])) return $this->GetProjectTasksStatus($obj); if(isset($obj['mod_ops'])) return $this->GetModulesTasksStatus($obj); - $ops_array=array('jcreate','jstart','jstop','jedit','jremove','jexport','jimport','jclone','madd','sstart','sstop','projremove'); //,'mremove' + $ops_array=$this->_cmd_array; + /* array('jcreate','jstart','jstop','jrestart','jedit','jremove','jexport','jimport','jclone','madd','sstart','sstop','projremove', + 'bcreate','bstart','bstop','brestart','bremove', + 'vm_obtain'); //,'mremove' + */ $stat_array=array( - 'jcreate'=>array(get_translate('Creating'),get_translate('Not running')), - 'jstart'=>array(get_translate('Starting'),get_translate('Launched')), - 'jstop'=>array(get_translate('Stopping'),get_translate('Stopped')), - 'jedit'=>array(get_translate('Saving'),get_translate('Saved')), - 'jremove'=>array(get_translate('Removing'),get_translate('Removed')), - 'jexport'=>array(get_translate('Exporting'),get_translate('Exported')), - 'jimport'=>array(get_translate('Importing'),get_translate('Imported')), - 'jclone'=>array(get_translate('Cloning'),get_translate('Cloned')), - 'madd'=>array(get_translate('Installing'),get_translate('Installed')), + 'jcreate'=>array($this->translate('Creating'),$this->translate('Created')), + 'jstart'=>array($this->translate('Starting'),$this->translate('Launched')), + 'jstop'=>array($this->translate('Stopping'),$this->translate('Stopped')), + 'jrestart'=>array($this->translate('Restarting'),$this->translate('Restarted')), + 'jedit'=>array($this->translate('Saving'),$this->translate('Saved')), + 'jremove'=>array($this->translate('Removing'),$this->translate('Removed')), + 'jexport'=>array($this->translate('Exporting'),$this->translate('Exported')), + 'jimport'=>array($this->translate('Importing'),$this->translate('Imported')), + 'jclone'=>array($this->translate('Cloning'),$this->translate('Cloned')), + 'madd'=>array($this->translate('Installing'),$this->translate('Installed')), //'mremove'=>array('Removing','Removed'), - 'sstart'=>array(get_translate('Starting'),get_translate('Started')), - 'sstop'=>array(get_translate('Stopping'),get_translate('Stopped')), + 'sstart'=>array($this->translate('Starting'),$this->translate('Started')), + 'sstop'=>array($this->translate('Stopping'),$this->translate('Stopped')), + 'vm_obtain'=>array($this->translate('Creating'),$this->translate('Created')), //'projremove'=>array('Removing','Removed'), ); + $stat_array['bcreate']=&$stat_array['jcreate']; + $stat_array['bstart']=&$stat_array['jstart']; + $stat_array['bstop']=&$stat_array['jstop']; + $stat_array['brestart']=&$stat_array['jrestart']; + $stat_array['bremove']=&$stat_array['jremove']; + $stat_array['removesrc']=&$stat_array['jremove']; + + if(!empty($obj)) foreach($obj as $key=>$task) { $op=$task['operation']; @@ -342,18 +540,26 @@ class ClonOS { switch($op) { - case 'jstart': $res=$this->jailStart('jail'.$key,$key);break; - case 'jstop': $res=$this->jailStop('jail'.$key,$key);break; - case 'jedit': $res=$this->jailEdit('jail'.$key);break; - case 'jremove': $res=$this->jailRemove('jail'.$key,$key);break; - case 'jexport': $res=$this->jailExport('jail'.$key,$task['jname'],$key);break; - case 'jimport': $res=$this->jailImport('jail'.$key,$task['jname'],$key);break; - case 'jclone': $res=$this->jailClone('jail'.$key,$key,$obj[$key]);break; - case 'madd': $res=$this->moduleAdd('jail'.$key,$task['jname'],$key);break; - //case 'mremove': $res=$this->moduleRemove('jail'.$key,$task['jname'],$key);break; - case 'sstart': $res=$this->serviceStart($task);break; - case 'sstop': $res=$this->serviceStop($task);break; - //case 'projremove': $res=$this->projectRemove($key,$task);break; + case 'jstart': $res=$this->jailStart($key);break; + case 'jstop': $res=$this->jailStop($key);break; + case 'jrestart':$res=$this->jailRestart($key);break; + //case 'jedit': $res=$this->jailEdit('jail'.$key);break; + case 'jremove': $res=$this->jailRemove($key);break; + + case 'bstart': $res=$this->bhyveStart($key);break; + case 'bstop': $res=$this->bhyveStop($key);break; + case 'brestart':$res=$this->bhyveRestart($key);break; + case 'bremove': $res=$this->bhyveRemove($key);break; + case 'removesrc': $res=$this->srcRemove($key);break; + + //case 'jexport': $res=$this->jailExport('jail'.$key,$task['jname'],$key);break; + //case 'jimport': $res=$this->jailImport('jail'.$key,$task['jname'],$key);break; + //case 'jclone': $res=$this->jailClone('jail'.$key,$key,$obj[$key]);break; + //case 'madd': $res=$this->moduleAdd('jail'.$key,$task['jname'],$key);break; + ////case 'mremove': $res=$this->moduleRemove('jail'.$key,$task['jname'],$key);break; + //case 'sstart': $res=$this->serviceStart($task);break; + //case 'sstop': $res=$this->serviceStop($task);break; + ////case 'projremove': $res=$this->projectRemove($key,$task);break; } } @@ -398,20 +604,8 @@ class ClonOS if($stat['errcode']>0) { $obj[$key]['errmsg']=file_get_contents($stat['logfile']); - $obj[$key]['txt_status']=get_translate('Error'); + $obj[$key]['txt_status']=$this->translate('Error'); } - # Удаляем джейл - if($stat['status']==2 && $task['operation']=='jremove') - { - $this->jailRemoveFromDb($stat['errcode'],$task); - } - # Удаляем модуль - /* - if($stat['status']==2 && $task['operation']=='mremove') - { - $this->moduleRemoveFromDb($stat['errcode'],$task); - } - */ # Возвращаем IP клонированному джейлу, если он был присвоен по DHCP if($stat['status']==2 && $task['operation']=='jclone') { @@ -422,15 +616,478 @@ class ClonOS } } - if(isset($res['cloned']) && $res['cloned']) - { - $obj[-1]['jails']=$this->getJailsList(); - } - return $obj; } + function jailAdd() + { + $form=$this->_vars['form_data']; + $err=array(); + $arr=array( + 'workdir'=>$this->workdir, + 'mount_devfs'=>1, + 'arch'=>'native', + 'mkhostfile'=>1, + 'devfs_ruleset'=>4, + 'ver'=>'native', + 'mount_src'=>0, + 'mount_obj'=>0, + 'mount_kernel'=>0, + 'applytpl'=>1, + 'floatresolv'=>1, + 'allow_mount'=>1, + 'allow_devfs'=>1, + 'allow_nullfs'=>1, + 'mkhostsfile'=>1, + 'pkg_bootstrap'=>0, + 'mdsize'=>0, + 'runasap'=>0, + 'with_img_helpers'=>'', + ); + + $arr_copy=array('jname','host_hostname','ip4_addr','user_pw_root','interface'); + foreach($arr_copy as $a) if(isset($form[$a])) $arr[$a]=$form[$a]; + + $arr_copy=array('baserw','mount_ports','astart','vnet'); + foreach($arr_copy as $a) if(isset($form[$a]) && $form[$a]=='on') $arr[$a]=1; else $arr[$a]=0; + + $sysrc=array(); + if(isset($form['serv-ftpd'])) $sysrc[]=$form['serv-ftpd']; + if(isset($form['serv-sshd'])) $sysrc[]=$form['serv-sshd']; + $arr['sysrc_enable']=join($sysrc,' '); + + /* create jail */ + $file_name='/tmp/'.$arr['jname'].'.conf'; + + $file=file_get_contents($this->realpath_public.'templates/jail.tpl'); + if(!empty($file)) + { + foreach($arr as $var=>$val) + { + $file=str_replace('#'.$var.'#',$val,$file); + } + } + file_put_contents($file_name,$file); + + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jcreate inter=0 jconf='.$file_name); + $err='Jail is not create!'; + $taskId=-1; + if($res['retval']==0) + { + $err='Jail was created!'; + $taskId=$res['message']; + } + // local - поменять на реальный сервер, на котором создаётся клетка! + $jid=$arr['jname']; + + $html=''; + $hres=$this->getTableChunk('jailslist','tbody'); + if($hres!==false) + { + $html_tpl=$hres[1]; + $vars=array( + 'nth-num'=>'nth0', // исправить на актуальные данные! + 'node'=>'local', // исправить на актуальные данные! + 'ip4_addr'=>str_replace(',',',',$form['ip4_addr']), + 'jname'=>$arr['jname'], + 'jstatus'=>$this->translate('Creating'), + 'icon'=>'spin6 animate-spin', + 'desktop'=>'s-on', + 'maintenance'=>' maintenance', + 'protected'=>'icon-cancel', + 'protitle'=>$this->translate('Delete'), + 'vnc_title'=>$this->translate('Open VNC'), + 'reboot_title'=>$this->translate('Restart jail'), + ); + + foreach($vars as $var=>$val) + $html_tpl=str_replace('#'.$var.'#',$val,$html_tpl); + + $html=$html_tpl; + } + + /* + $html= +<<local{$jid}{$arr['ip4_addr']}{$this->translate('Creating')} +EOT; + */ + + return array('errorMessage'=>$err,'jail_id'=>$jid,'taskId'=>$taskId,'html'=>$html,'mode'=>$this->mode); + } + /* + function jailCreate($name,$hostname,$ip,$jprofile) + { + $tpl=$this->getJailTemplate(); //$name,$hostname,1,$ip,$jprofile); + $file_name='/tmp/'.$name.'.conf'; + file_put_contents($file_name,$tpl); + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jcreate inter=0 jconf='.$file_name); + return $res; + } + function getJailTemplate() //$jailname,$hostname,$astart="1",$ipv4='DHCP',$jprofile) + { + $form=$this->_vars['form_data']; + $replaces=array( + 'workdir'=>$this->workdir, + 'jname'=>$form['jailname'], + 'host_hostname'=>$form['hostname'], + 'ip4_addr'=>$form['ipv4'], + 'mount_devfs'=>$form[''], + 'allow_mount'=>$form[''], + 'allow_devfs'=>$form[''], + 'allow_nullfs'=>$form[''], + 'mkhostsfile'=>$form[''], + 'devfs_ruleset'=>$form[''], + 'ver'=>$form[''], + 'baserw'=>$form[''], + 'mount_src'=>$form[''], + 'mount_obj'=>$form[''], + 'mount_kernel'=>$form[''], + 'mount_ports'=>$form[''], + 'astart'=>$form['astart'], + 'vnet'=>$form[''], + 'applytpl'=>$form[''], + 'mdsize'=>$form[''], + 'floatresolv'=>$form[''], + 'pkg_bootstrap'=>$form[''], + 'user_pw_root'=>$form[''], + 'interface'=>$form[''], + 'sysrc_enable'=>$form[''], + 'with_img_helpers'=>$form[''], + 'runasap'=>$form[''], + ); + $file=file_get_contents($this->realpath_public.'templates/jail.tpl'); + if(!empty($file)) + { + foreach($replaces as $var=>$val) + { + $file=str_replace('#'.$var.'#',$val,$file); + } + } + return $file; + } + */ + + function jailStart($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jstart inter=0 jname='.$name); // autoflush=2 + return $res; + } + function jailStop($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jstop inter=0 jname='.$name); // autoflush=2 + return $res; + } + function jailRestart($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jrestart inter=0 jname='.$name); // autoflush=2 + return $res; + } + function jailRemove($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jremove inter=0 jname='.$name); // autoflush=2 + return $res; + } + + function bhyveAdd() + { + $form=$this->_vars['form_data']; + + $os_types=$this->config->os_types; + $sel_os=$form['vm_os_profile']; + list($os_num,$item_num)=explode('.',$sel_os); + if(!isset($os_types[$os_num])) return array('error'=>true,'errorMessage'=>'Error in list of OS types!'); + $os_name=$os_types[$os_num]['os']; + $os_items=$os_types[$os_num]['items'][$item_num]; + + $err=array(); + $arr=array( + 'workdir'=>$this->workdir, + 'jname'=>$form['vm_name'], + 'host_hostname'=>'', + 'ip4_addr'=>'', + 'arch'=>'native', + 'ver'=>'native', + 'astart'=>0, + 'interface'=>$form['interface'], + 'vm_size'=>$form['vm_size'], + 'vm_cpus'=>$form['vm_cpus'], + 'vm_ram'=>$form['vm_ram'], + 'vm_os_type'=>$os_items['type'], + 'vm_efi'=>'uefi', + 'vm_os_profile'=>$os_items['profile'], + 'vm_guestfs'=>'', + ); + + /* create vm */ + $file_name='/tmp/'.$arr['jname'].'.conf'; + + $file=file_get_contents($this->realpath_public.'templates/vm.tpl'); + if(!empty($file)) + { + foreach($arr as $var=>$val) + { + $file=str_replace('#'.$var.'#',$val,$file); + } + } + file_put_contents($file_name,$file); + + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bcreate inter=0 jconf='.$file_name); + + $err='Virtual Machine is not create!'; + $taskId=-1; + if($res['retval']==0) + { + $err='Virtual Machine was created!'; + $taskId=$res['message']; + } + // local - поменять на реальный сервер, на котором создаётся клетка! + $jid=$arr['jname']; + + $vm_ram=str_replace('g',' GB',$form['vm_ram']); + + $html=''; + $hres=$this->getTableChunk('bhyveslist','tbody'); + if($hres!==false) + { + $html_tpl=$hres[1]; + $vars=array( + 'nth-num'=>'nth0', // исправить на актуальные данные! + 'node'=>'local', // исправить на актуальные данные! + 'jname'=>$arr['jname'], + 'vm_status'=>$this->translate('Creating'), + 'vm_cpus'=>$form['vm_cpus'], + 'vm_ram'=>$vm_ram, + 'vm_os_type'=>$os_items['type'], //$os_name, + 'icon'=>'spin6 animate-spin', + 'desktop'=>' s-off', + 'maintenance'=>' maintenance', + 'protected'=>'icon-cancel', + 'protitle'=>$this->translate('Delete'), + 'vnc_title'=>$this->translate('Open VNC'), + 'reboot_title'=>$this->translate('Restart VM'), + ); + + foreach($vars as $var=>$val) + $html_tpl=str_replace('#'.$var.'#',$val,$html_tpl); + + $html=$html_tpl; + } + + return array('errorMessage'=>$err,'jail_id'=>$jid,'taskId'=>$taskId,'html'=>$html,'mode'=>$this->mode); + } + function bhyveObtain() + { + $form=$this->_vars['form_data']; + + $os_types=$this->config->os_types; + $sel_os=$form['vm_os_profile']; + list($os_num,$item_num)=explode('.',$sel_os); + if(!isset($os_types[$os_num])) return array('error'=>true,'errorMessage'=>'Error in list of OS types!'); + //$os_name=$os_types[$os_num]['os']; + $os_items=$os_types[$os_num]['items'][$item_num]; + $os_type=$os_items['type']; + + $key_name='/usr/home/olevole/.ssh/authorized_keys'; + $key_id=$form['vm_authkey']; + $db=new Db('base','authkey'); + $nres=$db->selectAssoc('select name from authkey where idx='.$key_id); + if($nres['name']!==false) + { + $key_name=$nres['name']; + } + $cmd="task owner=cbsdweb mode=new /usr/local/bin/cbsd vm_obtain jname={$form['vm_name']} vm_size={$form['vm_size']} vm_cpus={$form['vm_cpus']} vm_ram={$form['vm_ram']} vm_os_type={$os_type} mask={$form['mask']} ip4_addr={$form['ip4_addr']} gw={$form['gateway']} authkey={$key_name} pw={$form['vm_password']}"; + + $res=$this->cbsd_cmd($cmd); + $err='Virtual Machine is not create!'; + $taskId=-1; + if($res['retval']==0) + { + $err='Virtual Machine was created!'; + $taskId=$res['message']; + } + + $vm_ram=str_replace('g',' GB',$form['vm_ram']); + + $html=''; + $hres=$this->getTableChunk('bhyveslist','tbody'); + if($hres!==false) + { + $html_tpl=$hres[1]; + $vars=array( + 'nth-num'=>'nth0', // исправить на актуальные данные! + 'node'=>'local', // исправить на актуальные данные! + 'jname'=>$form['vm_name'], + 'vm_status'=>$this->translate('Creating'), + 'vm_cpus'=>$form['vm_cpus'], + 'vm_ram'=>$vm_ram, + 'vm_os_type'=>$os_type, + 'icon'=>'spin6 animate-spin', + 'desktop'=>' s-off', + 'maintenance'=>' maintenance', + 'protected'=>'icon-cancel', + 'protitle'=>$this->translate('Delete'), + 'vnc_title'=>$this->translate('Open VNC'), + 'reboot_title'=>$this->translate('Restart VM'), + ); + + foreach($vars as $var=>$val) + $html_tpl=str_replace('#'.$var.'#',$val,$html_tpl); + + $html=$html_tpl; + } + + return array('errorMessage'=>$err,'jail_id'=>$form['vm_name'],'taskId'=>$taskId,'html'=>$html,'mode'=>$this->mode); + } + function bhyveStart($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bstart inter=0 jname='.$name); // autoflush=2 + return $res; + } + function bhyveStop($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bstop inter=0 jname='.$name); // autoflush=2 + return $res; + } + function bhyveRestart($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd brestart inter=0 jname='.$name); // autoflush=2 + return $res; + } + function bhyveRemove($name) + { + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bremove inter=0 jname='.$name); // autoflush=2 + return $res; + } + + function authkeyAdd() + { + $form=$this->_vars['form_data']; + + $query="insert into authkey (name,authkey) values ('{$form['keyname']}','{$form['keysrc']}')"; + + $db=new Db('base','authkey'); + //$res=array('error'=>false,'lastId'=>2); + $res=$db->insert($query); + if($res['error']) + { + return array('error'=>$res); + } + + $html=''; + $hres=$this->getTableChunk('authkeyslist','tbody'); + if($hres!==false) + { + $html_tpl=$hres[1]; + $vars=array( + 'keyid'=>$res['lastID'], + 'keyname'=>$form['keyname'], + 'keysrc'=>$form['keysrc'], + 'deltitle'=>$this->translate('Delete'), + ); + + foreach($vars as $var=>$val) + $html_tpl=str_replace('#'.$var.'#',$val,$html_tpl); + + $html=$html_tpl; + } + + return array('keyname'=>$form['keyname'],'html'=>$html); + } + function authkeyRemove() + { + $form=$this->_vars['form_data']; + + $db=new Db('base','authkey'); + $res=$db->update('delete from authkey where idx='.$form['auth_id']); + if($res===false) return array('error'=>true,'res'=>print_r($res,true)); + + return array('error'=>false,'auth_id'=>$form['auth_id']); + } + + function vpnetAdd() + { + $form=$this->_vars['form_data']; + + $query="insert into vpnet (name,vpnet) values ('{$form['netname']}','{$form['network']}')"; + + $db=new Db('base','vpnet'); + + $res=$db->insert($query); + if($res['error']) + { + return array('error'=>$res); + } + + $html=''; + $hres=$this->getTableChunk('vpnetslist','tbody'); + if($hres!==false) + { + $html_tpl=$hres[1]; + $vars=array( + 'netid'=>$res['lastID'], + 'netname'=>$form['netname'], + 'network'=>$form['network'], + 'deltitle'=>$this->translate('Delete'), + ); + + foreach($vars as $var=>$val) + $html_tpl=str_replace('#'.$var.'#',$val,$html_tpl); + + $html=$html_tpl; + } + + return array('netname'=>$form['netname'],'html'=>$html); + } + function vpnetRemove() + { + $form=$this->_vars['form_data']; + + $db=new Db('base','vpnet'); + $res=$db->update('delete from vpnet where idx='.$form['vpnet_id']); + if($res===false) return array('error'=>true,'res'=>print_r($res,true)); + + return array('error'=>false,'vpnet_id'=>$form['vpnet_id']); + } + + + function mediaRemove() + { + $form=$this->_vars['form_data']; + /* + $db=new Db('base','storage_media'); + $res=$db->update('delete from media where idx='.$form['media_id']); + if($res===false) return array('error'=>true,'res'=>print_r($res,true)); + */ + return array('error'=>false,'media_id'=>$form['media_id']); + } + + function srcRemove($ver) + { + $ver=str_replace('src','',$ver); + if(empty($ver)) return array('error'=>true,'errorMessage'=>'Version of sources is emtpy!'); + $res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd removesrc inter=0 ver='.$ver.' jname=#src'.$ver); + return $res; + } + + + function logLoad() + { + $form=$this->_vars['form_data']; + $log_id=$form['log_id']; + if(!is_numeric($log_id)) return array('error'=>'Log ID must be a number'); + + $log_file='/tmp/taskd.'.$log_id.'.log'; + if(file_exists($log_file)) + { + $html=file_get_contents($log_file); + $html=str_replace("\n",'
',$html); + return array('html'=>'
Log ID: '.$log_id.'

'.$html); + } + + return array('error'=>'Log file is not exists!'); + } @@ -440,6 +1097,25 @@ class ClonOS + function useDialogs($arr=array()) + { + //print_r($arr); + $this->_dialogs=$arr; + } + function placeDialogs() + { + if(empty($this->_dialogs)) return; + echo PHP_EOL; + foreach($this->_dialogs as $dialog_name) + { + $file_name=$this->realpath_public.'dialogs/'.$dialog_name.'.php'; + if(file_exists($file_name)) + { + include($file_name); + echo PHP_EOL,PHP_EOL; + } + } + } @@ -449,15 +1125,30 @@ class ClonOS + function runVNC($jname) + { + $res=$this->cbsd_cmd("vm_vncwss jname={$jname} permit={$this->_client_ip}"); + $res=$this->_db_local->selectAssoc('select nodeip from local'); + $nodeip=$res['nodeip']; + if(strlen($nodeip)<10) $nodeip='127.0.0.1'; + header('Location: http://'.$nodeip.':6080/vnc_auto.html?host='.$nodeip.'&port=6080'); + exit; + } - - - - - - - - + function getFreeJname() + { + $arr=array(); + $res=$this->cbsd_cmd("freejname"); + if($res['error']) + { + $arr['error']=true; + $arr['error_message']=$err['error_message']; + }else{ + $arr['error']=false; + $arr['freejname']=$res['message']; + } + return $arr; + } @@ -469,7 +1160,7 @@ class ClonOS return round($Hz/$h,2).' '.$l; } - function fileSizeConvert($bytes, $bytes_in_mb=1024) + function fileSizeConvert($bytes,$bytes_in_mb=1024,$round=false) { $bytes = floatval($bytes); $arBytes = array( @@ -501,49 +1192,24 @@ class ClonOS if($bytes >= $arItem["VALUE"]) { $result = $bytes / $arItem["VALUE"]; + if($round) $result=round($result); $result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"]; break; } } return $result; } -} - -function translate($phrase) -{ - $lang=getLang(); - $file=getLangFilePath($lang); - if(!file_exists($file)) $file=getLangFilePath('en'); - if(!file_exists($file)) return; - require($file); - if(isset($lang[$phrase])) - echo $lang[$phrase]; - else - echo $phrase; -} -function get_translate($phrase) -{ - $lang=getLang(); - $file=getLangFilePath($lang); - if(!file_exists($file)) $file=getLangFilePath('en'); - require($file); - - if(isset($lang[$phrase])) - return $lang[$phrase]; - else - return $phrase; -} - -function getLang() -{ - if(isset($_COOKIE['lang'])) - $lang=$_COOKIE['lang']; - if(empty($lang)) $lang='en'; - return $lang; -} -function getLangFilePath($lang) -{ - global $_REALPATH; - return $_REALPATH.'/public/lang/'.$lang.'.php'; + function colorizeCmd($cmd_string) + { + $arr=$this->_cmd_array; + foreach($arr as $item) + { + $cmd_string=str_replace($item,''.$item.'',$cmd_string); + } + + $cmd_string=preg_replace('#(\/.+/cbsd)#','$1',$cmd_string); + + return ''.$cmd_string.''; + } } \ No newline at end of file diff --git a/php/config.php b/php/config.php index 5124a0eb..dcf66e9e 100644 --- a/php/config.php +++ b/php/config.php @@ -5,7 +5,6 @@ class Config public $languages=array( 'en'=>'English', 'ru'=>'Russian', - 'de'=>'Deutch', ); /* Меню проекта */ @@ -14,76 +13,165 @@ class Config 'overview'=>array( 'name'=>'Overview', 'title'=>'Summary Overview', // заголовки лучше делать более полными, чем просто повторение пункта меню + 'icon'=>'icon-chart-bar', ), 'jailscontainers'=>array( 'name'=>'Jails containers', 'title'=>'Jails containers control panel', + 'icon'=>'icon-server', ), 'instance_jail'=>array( 'name'=>'Template for jail', 'title'=>'Helpers and wizard for containers', + 'icon'=>'icon-cubes', ), 'bhyvevms'=>array( 'name'=>'Bhyve VMs', 'title'=>'Virtual machine control panel', + 'icon'=>'icon-th-list', ), 'nodes'=>array( 'name'=>'Nodes', 'title'=>'Nodes control panel', + 'icon'=>'icon-buffer', ), 'vpnet'=>array( 'name'=>'Virtual Private Network', 'title'=>'Manage for virtual private networks', + 'icon'=>'icon-plug', ), 'authkey'=>array( - 'name'=>'Authkey', + 'name'=>'Authkeys', 'title'=>'Manage for SSH auth key', + 'icon'=>'icon-key', ), 'media'=>array( 'name'=>'Storage Media', 'title'=>'Virtual Media Manager', + 'icon'=>'icon-inbox', ), 'repo'=>array( 'name'=>'Repository', 'title'=>'Remote repository', + 'icon'=>'icon-globe', ), 'bases'=>array( 'name'=>'FreeBSD Bases', 'title'=>'FreeBSD bases manager', + 'icon'=>'icon-database', ), 'sources'=>array( 'name'=>'FreeBSD Sources', 'title'=>'FreeBSD sources manager', + 'icon'=>'icon-edit', ), 'jail_marketplace'=>array( 'name'=>'Jail Marketplace', 'title'=>'Public remote containers marketplace', + 'icon'=>'icon-flag', ), 'bhyve_marketplace'=>array( 'name'=>'Bhyve Marketplace', 'title'=>'Public remote virtual machine marketplace', + 'icon'=>'icon-flag-checkered', ), 'tasklog'=>array( 'name'=>'TaskLog', 'title'=>'System task log', + 'icon'=>'icon-list-alt', ), 'sqlite'=>array( 'name'=>'SQLite admin', 'title'=>'SQLite admin interface', + 'icon'=>'icon-wpforms', ), ); + + public $os_types=array( + array( + 'os'=>'FreeBSD', + 'items'=>array( + array('name'=>'FreeBSD 11.0-RELEASE','type'=>'freebsd', + 'profile'=>'FreeBSD-x64-11.0','obtain'=>true), + array('name'=>'FreeBSD pfSense 2.4.0-DEVELOP','type'=>'freebsd', + 'profile'=>'pfSense-2-LATEST-amd64','obtain'=>false), + array('name'=>'FreeBSD OPNsense-16.7','type'=>'freebsd', + 'profile'=>'OPNsense-16-RELEASE-amd64','obtain'=>false), + ), + ), + array( + 'os'=>'Linux', + 'items'=>array( + array('name'=>'Linux Arch 2016','type'=>'linux', + 'profile'=>'ArchLinux-x86-2016','obtain'=>false), + array('name'=>'Linux CentOS 7','type'=>'linux', + 'profile'=>'CentOS-7-x86_64','obtain'=>false), + array('name'=>'Linux Debian 7','type'=>'linux', + 'profile'=>'Debian-x86-7','obtain'=>false), + array('name'=>'Linux Debian 8','type'=>'linux', + 'profile'=>'Debian-x86-8','obtain'=>false), + array('name'=>'Linux Open Suse 42','type'=>'linux', + 'profile'=>'opensuse-x86-42','obtain'=>false), + array('name'=>'Linux Ubuntu 16.04','type'=>'linux', + 'profile'=>'ubuntuserver-x86-16.04','obtain'=>true), + ), + ), + array( + 'os'=>'Windows', + 'items'=>array( + array('name'=>'Windows 10','type'=>'windows', + 'profile'=>'10_86x_64x','obtain'=>false), + ), + ) + ); + function os_types_create($obtain='new') + { + $obtain=($obtain=='obtain'); + + $html=''; + foreach($this->os_types as $num1=>$os) + { + $obtain_count=0; + $html_tmp=' '.PHP_EOL; + $items=$os['items']; + foreach($items as $num2=>$item) + { + if(!$obtain || $item['obtain']) + $html_tmp.=' '.PHP_EOL; + if($item['obtain']) $obtain_count++; + } + $html_tmp.=' '.PHP_EOL; + + if(!$obtain || $obtain_count>0) $html.=$html_tmp; + } + return $html; + } + + + function authkeys_list() + { + $db=new Db('base','authkey'); + $res=$db->select('SELECT idx,name FROM authkey;'); + + $html=''; + if(!empty($res))foreach($res as $item) + { + $html.=' '.PHP_EOL; + } + return $html; + } } \ No newline at end of file diff --git a/php/menu.php b/php/menu.php index 118e1809..610b8320 100644 --- a/php/menu.php +++ b/php/menu.php @@ -33,7 +33,7 @@ class Menu public $path=''; public $first_key=array(); - function __construct($menu_config=array()) + function __construct($menu_config=array(),$parent) { if(!empty($menu_config)) { @@ -47,8 +47,8 @@ class Menu $this->path=$qstr; //$_MENU_PATH if(!empty($menu_config))foreach($menu_config as $key=>$val) { - $mname=get_translate($val['name']); - $mtitle=get_translate($val['title']); + $mname=$parent->translate($val['name']); + $mtitle=$parent->translate($val['title']); $link=$key; $sel=''; @@ -57,14 +57,18 @@ class Menu $this->title=$mtitle; //$_TITLE $this->name=$mname; //$_MENU_NAME } - $this->html.='
  • '.$mname.''; + + $icon='empty'; + if(isset($val['icon']) && !empty($val['icon'])) $icon=$val['icon']; + $span=''; + $this->html.='
  • '.$span.''.$mname.''; if(!empty($val['submenu'])) { $this->html.= PHP_EOL.'