function openqrm_dhcpd_appliance($cmd, $appliance_fields)
{
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_EXEC_PORT;
    $openqrm_server = new openqrm_server();
    $OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
    $event = new event();
    $appliance_id = $appliance_fields["appliance_id"];
    $appliance_name = $appliance_fields["appliance_name"];
    $resource = new resource();
    $resource->get_instance_by_id($appliance_fields["appliance_resources"]);
    $resource_mac = $resource->mac;
    $resource_ip = $resource->ip;
    $appliance = new appliance();
    $appliance->get_instance_by_id($appliance_id);
    if ($resource->id == "-1" || $resource->id == "") {
        return;
    }
    $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Handling {$cmd} event {$appliance_id}/{$appliance_name}/{$resource_ip}/{$resource_mac}", "", "", 0, 0, $resource->id);
    switch ($cmd) {
        case "start":
            $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Adding hostname " . $appliance->name . " from resource " . $resource->id . ".", "", "", 0, 0, $resource->id);
            $dhcpd_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-appliance add_hostname -m " . $resource_mac . " -n " . $appliance->name . " -d " . $resource->id . " --openqrm-cmd-mode background";
            $openqrm_server->send_command($dhcpd_command);
            break;
        case "stop":
            $event->log("openqrm_dhcpd_appliance", $_SERVER['REQUEST_TIME'], 5, "openqrm-dhcpd-appliance-hook.php", "Removing hostname " . $appliance->name . " from resource " . $resource->id . ".", "", "", 0, 0, $resource->id);
            $dhcpd_command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/dhcpd/bin/openqrm-dhcpd-appliance remove_hostname -m " . $resource_mac . " -n " . $appliance->name . " -d " . $resource->id . " --openqrm-cmd-mode background";
            $openqrm_server->send_command($dhcpd_command);
            break;
    }
}
 function remotelogin_action() {
     cookie::del('passinfo');
     $this->view->loginfalse=cookie::get('loginfalse'.md5($_SERVER['REQUEST_URI']));
     if (front::$args) {
         $user=new user();
         $args = xxtea_decrypt(base64_decode(front::$args), config::get('cookie_password'));
         $user=$user->getrow(unserialize($args));
         if (is_array($user)) {
             if ($user['groupid'] == '888')
                 front::$isadmin=true;
             cookie::set('login_username',$user['username']);
             cookie::set('login_password',front::cookie_encode($user['password']));
             session::set('username',$user['username']);
             require_once ROOT.'/celive/include/config.inc.php';
             require_once ROOT.'/celive/include/celive.class.php';
             $login=new celive();
             $login->auth();
             $GLOBALS['auth']->remotelogin($user['username'],$user['password']);
             $GLOBALS['auth']->check_login1();
             front::$user=$user;
         }elseif (!is_array(front::$user) ||!isset(front::$isadmin)) {
             cookie::set('loginfalse'.md5($_SERVER['REQUEST_URI']),(int) cookie::get('loginfalse'.md5($_SERVER['REQUEST_URI'])) +1,time() +3600);
             event::log('loginfalse','失败 user='******'username']);
             front::flash('密码错误或不存在该管理员!');
             front::refresh(url('admin/login',true));
         }
     }
     $this->render();
 }
 function batch_action(){
     if(front::post('batch') == 'delete'){
         $sql = "DELETE FROM `".config::get('database', 'prefix')."event`";
         $this->_table->query($sql);
         event::log('日志清除','成功');
         front::refresh(url::modify('act/manage',true));
     }
 }
 function delete_action() {
     $path=ROOT.'/lang/'.config::get('lang_type').'/system.php';
     $lang=include $path;
     event::log('删除语言包','成功');
     exit;
     front::refresh(url('language/edit',true));
 }
Exemple #5
0
 function stop()
 {
     $response = '';
     $vms = $this->response->html->request()->get($this->identifier_name);
     if ($vms !== '') {
         $appliance_id = $this->response->html->request()->get('appliance_id');
         $appliance = new appliance();
         $resource = new resource();
         $errors = array();
         $message = array();
         foreach ($vms as $key => $vm) {
             $appliance->get_instance_by_id($appliance_id);
             $resource->get_instance_by_id($appliance->resources);
             $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.vm_list';
             $command = $this->openqrm->get('basedir') . '/plugins/kvm/bin/openqrm-kvm-vm stop -n ' . $vm;
             $command .= ' -u ' . $this->openqrm->admin()->name . ' -p ' . $this->openqrm->admin()->password;
             $command .= ' --openqrm-ui-user ' . $this->user->name;
             $command .= ' --openqrm-cmd-mode background';
             $resource->send_command($resource->ip, $command);
             $message[] = sprintf($this->lang['msg_stoped'], $vm);
             $file = $this->openqrm->get('basedir') . '/plugins/kvm/web/kvm-stat/' . $resource->id . '.vm_list';
             if ($this->file->exists($file)) {
                 $lines = explode("\n", $this->file->get_contents($file));
                 foreach ($lines as $line) {
                     if ($line !== '') {
                         $line = explode('@', $line);
                         if ($line[1] === $vm) {
                             $tmp = explode(':', $line[5]);
                             $server = $tmp[0];
                             $port = $tmp[1];
                             $mac = $line[2];
                             $resource->get_instance_by_mac($mac);
                             $rid = $resource->id;
                         }
                     }
                     $event = new event();
                     $plugin = new plugin();
                     $enabled = $plugin->enabled();
                     foreach ($enabled as $index => $name) {
                         $running = $this->openqrm->get('webdir') . '/plugins/' . $name . '/.running';
                         $hook = $this->openqrm->get('webdir') . '/plugins/' . $name . '/openqrm-' . $name . '-remote-console-hook.php';
                         if (file_exists($hook)) {
                             if (file_exists($running)) {
                                 $event->log("console", $_SERVER['REQUEST_TIME'], 5, "kvm-vm.console.class.php", 'Found plugin ' . $name . ' providing a remote console.', "", "", 0, 0, $resource->id);
                                 require_once $hook;
                                 $console_function = 'openqrm_' . $name . '_disable_remote_console';
                                 $console_function = str_replace("-", "_", $console_function);
                                 $console_function($server, $port, $rid, $mac, $vm);
                             }
                         }
                     }
                 }
             }
         }
         if (count($errors) === 0) {
             $response = join('<br>', $message);
         } else {
             $msg = array_merge($errors, $message);
             $response = join('<br>', $msg);
         }
     } else {
         $response = '';
     }
     return $response;
 }
Exemple #6
0
 function get_instance($id, $name)
 {
     global $USER_INFO_TABLE;
     $event = new event();
     $db = openqrm_get_db_connection();
     if ($id != "") {
         $user_array = $db->GetAll("select * from " . $this->_user_table . " where user_id={$id}");
     } else {
         if ($name != "") {
             $user_array = $db->GetAll("select * from " . $USER_INFO_TABLE . " where user_name='{$name}'");
         } else {
             $event->log("get_instance", $_SERVER['REQUEST_TIME'], 2, "user.class.php", "Could not create instance of user without data", "", "", 0, 0, 0);
             return;
         }
     }
     foreach ($user_array as $index => $user) {
         $this->id = $user["user_id"];
         $this->name = $user["user_name"];
         $this->password = $user["user_password"];
         $this->gender = $user["user_gender"];
         $this->first_name = $user["user_first_name"];
         $this->last_name = $user["user_last_name"];
         $this->department = $user["user_department"];
         $this->office = $user["user_office"];
         $this->role = $user["user_role"];
         $this->lang = $user["user_lang"];
         $this->last_update_time = $user["user_last_update_time"];
         $this->description = $user["user_description"];
         $this->capabilities = $user["user_capabilities"];
         $this->wizard_name = $user["user_wizard_name"];
         $this->wizard_step = $user["user_wizard_step"];
         $this->wizard_id = $user["user_wizard_id"];
         $this->state = $user["user_state"];
     }
     return $this;
 }
require_once $RootDir . '/class/htmlobjects/htmlobject.class.php';
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
$event = new event();
$openqrm_server = new openqrm_server();
$OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
global $OPENQRM_SERVER_IP_ADDRESS;
global $event;
$cloud_product_hook = $RootDir . '/plugins/hybrid-cloud/openqrm-hybrid-cloud-cloud-product-hook.php';
$cloud_selector_class = $RootDir . '/plugins/cloud/class/cloudselector.class.php';
$cloud_usergroup_class = $RootDir . '/plugins/cloud/class/cloudusergroup.class.php';
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "hybrid-cloud-action", "Un-Authorized access to hybrid-cloud-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
// get command
$hybrid_cloud_command = $request->get('hybrid_cloud_command');
// main
$event->log("{$hybrid_cloud_command}", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-action", "Processing hybrid-cloud command {$hybrid_cloud_command}", "", "", 0, 0, 0);
switch ($hybrid_cloud_command) {
    case 'init':
        // this command creates the following table
        // -> hybrid_cloud_accounts
        // hybrid_cloud_id BIGINT
        // hybrid_cloud_account_name VARCHAR(50)
        // hybrid_cloud_account_type VARCHAR(50)
        // hybrid_cloud_access_key VARCHAR(255)
        // hybrid_cloud_secret_key VARCHAR(255)
Exemple #8
0
$template_command = $request->get('template_command');
$template_domain = $request->get('template_domain');
// special template classes
require_once "{$RootDir}/plugins/template/class/templateconfig.class.php";
global $TEMPLATE_USER_TABLE;
global $TEMPLATE_REQUEST_TABLE;
global $OPENQRM_SERVER_BASE_DIR;
$refresh_delay = 5;
$event = new event();
$openqrm_server = new openqrm_server();
$OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
global $OPENQRM_SERVER_IP_ADDRESS;
global $event;
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "template-action", "Un-Authorized access to template-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
// gather request parameter in array
foreach ($_REQUEST as $key => $value) {
    if (strncmp($key, "cr_", 3) == 0) {
        $request_fields[$key] = $value;
    }
}
// main
$event->log("{$template_command}", $_SERVER['REQUEST_TIME'], 5, "template-action", "Processing template command {$template_command}", "", "", 0, 0, 0);
switch ($template_command) {
    case 'init':
        // this command creates the following table
        //
        // -> templateconfig
 function import()
 {
     $response = '';
     $errors = array();
     $message = array();
     $event = new event();
     $instance_command = $this->response->html->request()->get('instance_command');
     if ($instance_command !== '') {
         switch ($instance_command) {
             case 'add':
                 // instance_command=add
                 // &instance_name='.$name.'
                 // &instance_mac='.$mac.'
                 // &instance_public_ip='.$public_ip.'
                 // &instance_type='.$type.'
                 // &instance_keypair='.$keypair.'
                 // &instance_region='.$region.'
                 // &instance_ami='.$ami;
                 $now = $_SERVER['REQUEST_TIME'];
                 $openqrm = new openqrm_server();
                 $instance_name = $this->response->html->request()->get('instance_name');
                 $instance_mac = $this->response->html->request()->get('instance_mac');
                 $instance_public_ip = $this->response->html->request()->get('instance_public_ip');
                 $instance_type = $this->response->html->request()->get('instance_type');
                 $instance_keypair = $this->response->html->request()->get('instance_keypair');
                 $instance_region = $this->response->html->request()->get('instance_region');
                 $instance_ami = $this->response->html->request()->get('instance_ami');
                 // create resource, image and appliance
                 $event->log("import", $_SERVER['REQUEST_TIME'], 5, "hybrid-cloud-vm-import", "Importing " . $instance_name . " - " . $instance_mac . " - " . $instance_public_ip . " - " . $instance_type . " - " . $instance_keypair . " - " . $instance_region . " - " . $instance_ami . ".", "", "", 0, 0, 0);
                 $import_resource = new resource();
                 $deployment = new deployment();
                 $deployment->get_instance_by_name('ami-deployment');
                 $virtualization = new virtualization();
                 $virtualization->get_instance_by_type("hybrid-cloud-vm-local");
                 // create resource
                 $resid = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                 // send command to the openQRM-server
                 $openqrm->send_command('openqrm_server_add_resource ' . $resid . ' ' . $instance_mac . ' ' . $instance_public_ip);
                 // add to openQRM database
                 $resource_fields["resource_id"] = $resid;
                 $resource_fields["resource_ip"] = $instance_public_ip;
                 $resource_fields["resource_mac"] = $instance_mac;
                 $resource_fields["resource_kernel"] = 'local';
                 $resource_fields["resource_kernelid"] = 0;
                 $resource_fields["resource_localboot"] = 0;
                 $resource_fields["resource_hostname"] = $this->hc->account_type . $resid;
                 $resource_fields["resource_vtype"] = $virtualization->id;
                 $resource_fields["resource_vhostid"] = 0;
                 $import_resource->add($resource_fields);
                 $import_resource->get_instance_by_mac($instance_mac);
                 // update stats
                 #if ($state == 'running') {
                 $rfields["resource_state"] = 'idle';
                 #$rfields["resource_lastgood"]=$now;
                 #} else {
                 #	$rfields["resource_state"]='off';
                 #}
                 #$import_resource->update_info($import_resource->id, $rfields);
                 // set account id in resource capabilities
                 $import_resource->set_resource_capabilities("HCACL", $this->id);
                 // auto create image object
                 $storage = new storage();
                 $storage->get_instance_by_name('ami-image-storage');
                 $image = new image();
                 $image->get_instance_by_name($instance_ami);
                 if (isset($image->id) && $image->id > 0) {
                     $image_exists = true;
                 } else {
                     $image_fields = array();
                     $vm_image_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $image_fields["image_id"] = $vm_image_id;
                     $image_fields['image_name'] = $instance_ami;
                     $image_fields['image_type'] = 'ami-deployment';
                     $image_fields['image_rootfstype'] = 'local';
                     $image_fields['image_isactive'] = 0;
                     $image_fields['image_storageid'] = $storage->id;
                     $image_fields['image_comment'] = "Image Object for AMI {$instance_ami}";
                     $image_fields['image_rootdevice'] = $instance_ami;
                     $image->add($image_fields);
                     # update image object
                     $image->get_instance_by_id($vm_image_id);
                     // update resource with image infos
                     $rfields["resource_id"] = $resid;
                     $rfields["resource_image"] = $image->name;
                     $rfields["resource_imageid"] = $image->id;
                     $import_resource->update_info($import_resource->id, $rfields);
                     $import_resource->get_instance_by_mac($instance_mac);
                 }
                 // create the appliance
                 $appliance = new appliance();
                 $appliance->get_instance_by_name($instance_name);
                 if (isset($appliance->id) && $appliance->id > 0) {
                     $appliance_exists = true;
                 } else {
                     $new_appliance_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                     $afields['appliance_id'] = $new_appliance_id;
                     $afields['appliance_name'] = $this->hc->account_type . $resid;
                     $afields['appliance_resources'] = $resid;
                     $afields['appliance_kernelid'] = '1';
                     $afields['appliance_imageid'] = $image->id;
                     $afields["appliance_virtual"] = 0;
                     $afields["appliance_virtualization"] = $virtualization->id;
                     $afields['appliance_wizard'] = '';
                     $afields['appliance_comment'] = 'Cloud VM Appliance for Resource ' . $resid;
                     $appliance->add($afields);
                     // update state/start+stoptime
                     $aufields['appliance_stoptime'] = $now;
                     $aufields['appliance_starttime'] = '';
                     $aufields['appliance_state'] = 'stopped';
                     $appliance->update($new_appliance_id, $aufields);
                 }
                 $hc_authentication = '';
                 if ($this->hc->account_type == 'aws' || $this->hc->account_type == 'euca') {
                     $hc_authentication .= ' -O ' . $this->hc->access_key;
                     $hc_authentication .= ' -W ' . $this->hc->secret_key;
                     $hc_authentication .= ' -ir ' . $this->response->html->request()->get('region');
                     $hc_authentication .= ' -iz ' . $instance_region;
                 }
                 if ($this->hc->account_type == 'lc-openstack') {
                     $hc_authentication .= ' -u ' . $this->hc->username;
                     $hc_authentication .= ' -p ' . $this->hc->password;
                     $hc_authentication .= ' -q ' . $this->hc->host;
                     $hc_authentication .= ' -x ' . $this->hc->port;
                     $hc_authentication .= ' -g ' . $this->hc->tenant;
                     $hc_authentication .= ' -e ' . $this->hc->endpoint;
                 }
                 $command = $this->openqrm->get('basedir') . '/plugins/hybrid-cloud/bin/openqrm-hybrid-cloud-vm create';
                 $command .= ' -i ' . $this->hc->id;
                 $command .= ' -n ' . $this->hc->account_name;
                 $command .= ' -t ' . $this->hc->account_type;
                 $command .= $hc_authentication;
                 $command .= ' -in ' . $this->hc->account_type . $resid;
                 $command .= ' -im ' . $instance_mac;
                 $command .= ' -a ' . $instance_ami;
                 $command .= ' -it ' . $instance_type;
                 $command .= ' -ik ' . $instance_keypair;
                 if ($this->hc->account_type == 'aws') {
                     $command .= ' -subnet ' . $this->response->html->request()->get('instance_subnet');
                 } else {
                     # TODO
                     $command .= ' -ig ' . $form->get_request('group');
                 }
                 $command .= ' --openqrm-ui-user ' . $this->user->name;
                 $command .= ' --openqrm-cmd-mode background';
                 $openqrm->send_command($command, NULL, true);
                 $message[] = sprintf($this->lang['msg_imported'], $instance_name);
                 break;
         }
         if (count($errors) === 0) {
             $response = join('<br>', $message);
         } else {
             $msg = array_merge($errors, $message);
             $response = join('<br>', $msg);
         }
     } else {
         $response = '';
     }
     return $response;
 }
 function add()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $kernel_id = $form->get_request('kernel');
         $fields['appliance_kernelid'] = $kernel_id;
         $fields['appliance_wizard'] = null;
         $this->appliance->update($this->appliance->id, $fields);
         // reset wizard
         $rs = $this->user->set_wizard($this->user->name, 0, 0, 0);
         // now we have to run the appliance add hook
         $this->appliance->run_add_hook($this->appliance->id);
         $response->msg = sprintf($this->lang['msg'], $kernel_id, $this->appliance->name);
         $event = new event();
         $event_description_step3 = sprintf($this->lang['appliance_create_in_progress_event'], $this->appliance->name, 3, $this->user->name);
         $event_description_step4 = sprintf($this->lang['appliance_created'], $this->appliance->name, $this->user->name);
         $event->log("appliance", $_SERVER['REQUEST_TIME'], 10, "add", $event_description_step3, "", "", 0, 0, 0);
         $event->log("appliance", $_SERVER['REQUEST_TIME'], 5, "add", $event_description_step4, "", "", 0, 0, 0);
     }
     $response->name = $this->appliance->name;
     return $response;
 }
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
$ansible_command = $request->get('ansible_command');
$ansible_server_id = $request->get('ansible_id');
$ansible_server_name = $request->get('ansible_name');
$ansible_server_mac = $request->get('ansible_mac');
$ansible_server_ip = $request->get('ansible_ip');
global $OPENQRM_SERVER_BASE_DIR;
$event = new event();
$openqrm_server = new openqrm_server();
$OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
global $OPENQRM_SERVER_IP_ADDRESS;
global $event;
// main
$event->log($ansible_command, $_SERVER['REQUEST_TIME'], 5, "ansible-apply", "Processing ansible command " . $ansible_command, "", "", 0, 0, 0);
switch ($ansible_command) {
    case 'apply':
        $appliance = new appliance();
        $appliance->get_instance_by_id($ansible_server_id);
        if ($ansible_server_name == $appliance->name) {
            $resource = new resource();
            $resource->get_instance_by_id($appliance->resources);
            if ($ansible_server_mac == $resource->mac && $ansible_server_ip == $resource->ip) {
                $command = $OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/ansible/bin/openqrm-ansible-manager apply " . $appliance->id . " " . $appliance->name . " " . $resource->ip . "  --openqrm-cmd-mode background";
                $openqrm_server = new openqrm_server();
                $openqrm_server->send_command($command, NULL, true);
            } else {
                $event->log($ansible_command, $_SERVER['REQUEST_TIME'], 3, "ansible-apply", "Request for Ansible apply for server id " . $ansible_server_id . " with wrong resource " . $resource->id, "", "", 0, 0, 0);
            }
        } else {
Exemple #12
0
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
global $IMAGE_INFO_TABLE;
global $DEPLOYMENT_INFO_TABLE;
global $OPENQRM_SERVER_BASE_DIR;
$lvm_storage_command = $request->get('lvm_storage_command');
$lvm_image_name = $request->get('lvm_image_name');
// place for the storage stat files
$StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/lvm-storage/storage';
// global event for logging
$event = new event();
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "lvm-action", "Un-Authorized access to lvm-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$event->log("{$lvm_storage_command}", $_SERVER['REQUEST_TIME'], 5, "lvm-storage-action", "Processing lvm-storage command {$lvm_storage_command}", "", "", 0, 0, 0);
switch ($lvm_storage_command) {
    case 'get_storage':
        if (!file_exists($StorageDir)) {
            mkdir($StorageDir);
        }
        $filename = $StorageDir . "/" . $_POST['filename'];
        $filedata = base64_decode($_POST['filedata']);
        echo "<h1>{$filename}</h1>";
        $fout = fopen($filename, "wb");
        fwrite($fout, $filedata);
        fclose($fout);
        break;
Exemple #13
0
$request = $html->request();
$request->filter = $requestfilter;
global $CLOUD_USER_TABLE;
global $CLOUD_REQUEST_TABLE;
global $CLOUD_USER_GROUPS_TABLE;
global $OPENQRM_SERVER_BASE_DIR;
$refresh_delay = 5;
$event = new event();
$openqrm_server = new openqrm_server();
$OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
global $OPENQRM_SERVER_IP_ADDRESS;
global $event;
$cloud_command = $request->get('cloud_command');
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "cloud-action", "Un-Authorized access to cloud-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
// gather user parameter in array
foreach ($_REQUEST as $key => $value) {
    if (strncmp($key, "cu_", 3) == 0) {
        $user_fields[$key] = $value;
    }
}
// gather user group parameter in array
foreach ($_REQUEST as $key => $value) {
    if (strncmp($key, "cg_", 3) == 0) {
        $user_group_fields[$key] = $value;
    }
}
// gather request parameter in array
Exemple #14
0
 function action()
 {
     global $OPENQRM_SERVER_BASE_DIR;
     $RootDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/';
     $token = $this->response->html->request()->get('token');
     $event_id = $this->response->html->request()->get('event_id');
     $msg = '';
     if ($token !== '' && $event_id !== '') {
         $event = new event();
         $event->get_instance_by_id($event_id);
         $event->log("event-action", $_SERVER['REQUEST_TIME'], 5, "event-overview.php", "Re-Running command {$token}", "", "", 0, 0, 0);
         $command = "mv -f " . $OPENQRM_SERVER_BASE_DIR . "/openqrm/web/base/server/event/errors/" . $token . ".cmd " . $OPENQRM_SERVER_BASE_DIR . "/openqrm/var/spool/openqrm-queue." . $token . " && rm -f " . $OPENQRM_SERVER_BASE_DIR . "/openqrm/web/base/server/event/errors/" . $token . ".out";
         shell_exec($command);
         $fields = array();
         $fields["event_priority"] = 4;
         $event->update($event_id, $fields);
         $msg .= "Re-running token " . $token . " / Event ID " . $event_id . "<br>";
     }
     $this->response->redirect($this->response->get_url($this->actions_name, 'select', $this->message_param, $msg));
 }
Exemple #15
0
require_once "{$RootDir}/class/image.class.php";
require_once "{$RootDir}/class/kernel.class.php";
require_once "{$RootDir}/class/event.class.php";
require_once "{$RootDir}/class/openqrm_server.class.php";
require_once "{$RootDir}/class/virtualization.class.php";
// filter inputs
require_once $RootDir . '/class/htmlobjects/htmlobject.class.php';
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
global $RESOURCE_INFO_TABLE;
$event = new event();
// user/role authentication
if (!strstr($OPENQRM_USER->role, "administrator")) {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "resource-action", "Un-Authorized access to resource-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$resource_command = $request->get('resource_command');
$resource_id = $request->get('resource_id');
$resource_hostname = $request->get('resource_hostname');
$resource_mac = strtolower($request->get('resource_mac'));
$resource_ip = $request->get('resource_ip');
$resource_state = $request->get('resource_state');
$resource_event = $request->get('resource_event');
foreach ($_REQUEST as $key => $value) {
    if (strncmp($key, "resource_", 9) == 0) {
        $resource_fields[$key] = $request->get($key);
    }
}
unset($resource_fields["resource_command"]);
 function init() {
 }
 
 function getcnzz_action(){
 function setting_action() {
 	if($this->table == 'archive'){
 		chkpw('archive_setting');
 	}
 	if($this->table == 'friendlink'){
 		chkpw('seo_friendlink_setting');
 	}
     $this->_view_table=false;
     $set=settings::getInstance();
     $sets=$set->getrow(array('tag'=>'table-'.$this->table));
     $data=unserialize($sets['value']);
     if (front::post('submit')) {
         $var=front::$post;
         unset($var['submit']);
         $set->rec_replace(array('value'=>mysql_escape_string(serialize($var)),'tag'=>'table-'.$this->table,'array'=>mysql_escape_string(var_export($var,true))));
         event::log("修改{$this->tname}配置",'成功');
         front::flash("配置成功!");
     }
     $this->view->settings=$data;
 }
 function add()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $name = $form->get_request('name');
         $comment = $form->get_request('comment');
         $check = new appliance();
         $check->get_instance_by_name($name);
         if ($check->id > 0) {
             $error = sprintf($this->lang['error_exists'], $name);
         }
         if (isset($error)) {
             $response->error = $error;
         } else {
             $appliance = new appliance();
             $fields['appliance_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
             $fields['appliance_name'] = $name;
             $fields['appliance_resources'] = '-1';
             $fields['appliance_kernelid'] = '1';
             $fields['appliance_imageid'] = '1';
             $fields["appliance_virtual"] = 0;
             $fields["appliance_virtualization"] = '1';
             $fields['appliance_wizard'] = 'wizard=step2,user='******'appliance_comment'] = $comment;
             $appliance->add_no_hook($fields);
             // wizard
             $rs = $this->user->set_wizard($this->user->name, 'appliance', 2, $fields['appliance_id']);
             // long term event
             $event = new event();
             $event_description = sprintf($this->lang['appliance_create_in_progress_event'], $name, 1, $this->user->name);
             $event->log("appliance", $_SERVER['REQUEST_TIME'], 9, "add", $event_description, "", "", 0, 0, 0);
             // set wizard id
             $response->appliance_wizard_id = $fields['appliance_id'];
             $response->msg = sprintf($this->lang['msg'], $name);
         }
     }
     return $response;
 }
Exemple #19
0
switch ($resource_command) {
    // get_parameter requires :
    // resource_mac
    default:
    case 'get_parameter':
        // if resource-id = -1 we add a new resource first
        if ($resource_id == "-1") {
            // check if resource already exists
            $resource = new resource();
            if (!$resource->exists($resource_mac)) {
                // add resource
                $new_resource_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                $resource->id = $new_resource_id;
                // 	check if resource_id is free
                if (!$resource->is_id_free($resource->id)) {
                    $event->log("get_parameter", $_SERVER['REQUEST_TIME'], 3, "resource-monitor", "Given resource id {$resource->id} is already in use!", "", "", 0, 1, $resource->id);
                    echo "Given resource id {$resource->id} is already in use!";
                    exit;
                }
                $event->log("get_parameter", $_SERVER['REQUEST_TIME'], 5, "resource-monitor", "Adding new resource {$new_resource_id} ({$resource_mac})", "", "", 0, 1, $resource->id);
                # send add resource to openQRM-server
                $openqrm_server->send_command("openqrm_server_add_resource {$new_resource_id} {$resource_mac} {$resource_ip}");
                # add resource to db
                $resource_fields["resource_id"] = $new_resource_id;
                $resource_fields["resource_localboot"] = 0;
                $resource_fields["resource_vtype"] = 1;
                $resource_fields["resource_vhostid"] = $new_resource_id;
                $resource_fields["resource_subnet"] = $resource_subnet;
                $resource->add($resource_fields);
            }
        }
Exemple #20
0
require_once "{$RootDir}/class/deployment.class.php";
require_once "{$RootDir}/class/openqrm_server.class.php";
// filter inputs
require_once $RootDir . '/class/htmlobjects/htmlobject.class.php';
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
$event = new event();
$openqrm_server = new openqrm_server();
$OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
global $OPENQRM_SERVER_IP_ADDRESS;
global $event;
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "nagios3-action", "Un-Authorized access to nagios3-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
// get command
$nagios3_command = $request->get('nagios3_command');
// main
$event->log("{$nagios3_command}", $_SERVER['REQUEST_TIME'], 5, "nagios3-action", "Processing nagios3 command {$nagios3_command}", "", "", 0, 0, 0);
switch ($nagios3_command) {
    case 'init':
        // this command creates the following tables
        // -> nagios3_services
        // nagios3_service_id BIGINT
        // nagios3_service_name VARCHAR(50)
        // nagios3_service_port VARCHAR(50)
        // nagios3_service_type VARCHAR(50)
        // nagios3_service_description VARCHAR(255)
Exemple #21
0
 function lock()
 {
     require_once $this->controller->rootdir . '/class/lock.class.php';
     require_once $this->controller->rootdir . '/class/event.class.php';
     $event = new event();
     $lock_cmd = $this->response->html->request()->get('lock');
     $resource_id = $this->response->html->request()->get('resource_id');
     $section = $this->response->html->request()->get('section');
     if (!strlen($lock_cmd) || !strlen($resource_id) || !strlen($section)) {
         $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Got empty paramater for lock, section or resource_id!", "", "", 0, 0, 0);
         return;
     }
     $lock = new lock();
     switch ($lock_cmd) {
         case 'aquire':
             $description = $this->response->html->request()->get('description');
             $token = $this->response->html->request()->get('token');
             $lock_fields['lock_resource_id'] = $resource_id;
             $lock_fields['lock_section'] = $section;
             $lock_fields['lock_description'] = $description;
             $lock_fields['lock_token'] = $token;
             $lock_id = $lock->add($lock_fields);
             if (strlen($lock_id)) {
                 echo $lock_id;
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 5, "openqrm.api.class.php", "Section " . $section . " is now locked by " . $resource_id . "!", "", "", 0, 0, 0);
             } else {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Section " . $section . " is still locked!", "", "", 0, 0, 0);
             }
             break;
         case 'release':
             $lock->get_instance_by_section($section);
             if (!strlen($lock->id)) {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Resource " . $resource_id . " trying to remove lock but no lock active for section " . $section, "", "", 0, 0, 0);
                 return;
             }
             if ($resource_id == $lock->resource_id) {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 5, "openqrm.api.class.php", "Resource " . $resource_id . " released lock for section " . $section, "", "", 0, 0, 0);
                 echo $lock->id;
                 $lock->remove_by_section($section);
             } else {
                 $event->log("lock", $_SERVER['REQUEST_TIME'], 2, "openqrm.api.class.php", "Resource " . $resource_id . " trying to remove lock from " . $lock->resource_id . " for section " . $section, "", "", 0, 0, 0);
             }
             break;
     }
 }
Exemple #22
0
require_once $RootDir . '/include/requestfilter.inc.php';
// filter inputs
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
$ansible_command = $request->get('ansible_command');
$cloud_product_hook = $RootDir . '/plugins/ansible/openqrm-ansible-cloud-product-hook.php';
$cloud_selector_class = $RootDir . '/plugins/cloud/class/cloudselector.class.php';
global $IMAGE_INFO_TABLE;
global $DEPLOYMENT_INFO_TABLE;
global $OPENQRM_SERVER_BASE_DIR;
// global event for logging
$event = new event();
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "ansible-action", "Un-Authorized access to ansible-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$event->log("{$ansible_command}", $_SERVER['REQUEST_TIME'], 5, "ansible-action", "Processing ansible command {$ansible_command}", "", "", 0, 0, 0);
switch ($ansible_command) {
    case 'init':
        if (file_exists($cloud_selector_class)) {
            if (file_exists($cloud_product_hook)) {
                require_once $cloud_product_hook;
                openqrm_ansible_cloud_product("add", NULL);
            }
        }
        break;
    case 'uninstall':
        if (file_exists($cloud_selector_class)) {
            if (file_exists($cloud_product_hook)) {
 function add()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         $image = $form->get_request('image');
         $fields['appliance_imageid'] = $image;
         $fields['appliance_wizard'] = 'wizard=step4,user='******'msg'], $image, $this->appliance->name);
         // wizard
         $rs = $this->user->set_wizard($this->user->name, 'appliance', 3, $this->appliance->id);
         // update long term event, remove old event and add new one
         $event = new event();
         $event_description_step2 = sprintf($this->lang['appliance_create_in_progress_event'], $this->appliance->name, 2, $this->user->name);
         $event_description_step3 = sprintf($this->lang['appliance_create_in_progress_event'], $this->appliance->name, 3, $this->user->name);
         $event->log("appliance", $_SERVER['REQUEST_TIME'], 10, "add", $event_description_step2, "", "", 0, 0, 0);
         $event->log("appliance", $_SERVER['REQUEST_TIME'], 9, "add", $event_description_step3, "", "", 0, 0, 0);
         if ($form->get_request('image_edit') === 'on') {
             $response->image_edit = "step4";
         }
     }
     $response->name = $this->appliance->name;
     return $response;
 }
Exemple #24
0
require_once "{$RootDir}/include/openqrm-database-functions.php";
require_once "{$RootDir}/include/user.inc.php";
require_once "{$RootDir}/class/kernel.class.php";
require_once "{$RootDir}/class/event.class.php";
require_once "{$RootDir}/class/openqrm_server.class.php";
// filter inputs
require_once $RootDir . '/class/htmlobjects/htmlobject.class.php';
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
global $KERNEL_INFO_TABLE;
$event = new event();
// user/role authentication
if (!strstr($OPENQRM_USER->role, "administrator")) {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "kernel-action", "Un-Authorized access to kernel-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$kernel_command = $request->get('kernel_command');
$kernel_name = $request->get('kernel_name');
$kernel_id = $request->get('kernel_id');
$kernel_name = $request->get('kernel_name');
$kernel_version = $request->get('kernel_version');
$kernel_fields = array();
foreach ($_REQUEST as $key => $value) {
    if (strncmp($key, "kernel_", 7) == 0) {
        $kernel_fields[$key] = $value;
    }
}
unset($kernel_fields["kernel_command"]);
$openqrm_server = new openqrm_server();
 function CloudRequestRemove($method_parameters)
 {
     $event = new event();
     $parameter_array = explode(',', $method_parameters);
     $mode = $parameter_array[0];
     $username = $parameter_array[1];
     $password = $parameter_array[2];
     $cr_id = $parameter_array[3];
     // check all user input
     for ($i = 0; $i <= 3; $i++) {
         if (!$this->check_param($parameter_array[$i])) {
             $event->log("cloudsoap->CloudRequestRemove", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Not allowing user-intput with special-characters : {$parameter_array[$i]}", "", "", 0, 0, 0);
             return;
         }
     }
     // check parameter count
     $parameter_count = count($parameter_array);
     if ($parameter_count != 4) {
         $event->log("cloudsoap->CloudRequestRemove", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Wrong parameter count {$parameter_count} ! Exiting.", "", "", 0, 0, 0);
         return;
     }
     // check authentication
     if (!$this->check_user($mode, $username, $password)) {
         $event->log("cloudsoap->CloudRequestSetState", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0);
         return;
     }
     // check for admin
     if (strcmp($mode, "admin")) {
         $event->log("cloudsoap->CloudRequestSetState", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud method only available in admin mode", "", "", 0, 0, 0);
         return;
     }
     $cr_request = new cloudrequest();
     $cr_request->remove($cr_id);
     $event->log("cloudsoap->CloudRequestRemove", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Removing Cloud request {$cr_id}", "", "", 0, 0, 0);
     return 0;
 }
 function login_false() {
     cookie::set('loginfalse',(int) cookie::get('loginfalse')+1,time()+3600);
     event::log('loginfalse','失败 user='******'username'));
     front::flash(lang('登陆失败!')."<a href=''>".lang('backuppage')."</a>");
 }
Exemple #27
0
require_once "{$RootDir}/class/image.class.php";
require_once "{$RootDir}/class/deployment.class.php";
require_once "{$RootDir}/class/openqrm_server.class.php";
require_once "{$RootDir}/class/event.class.php";
// filter inputs
require_once $RootDir . '/class/htmlobjects/htmlobject.class.php';
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
global $IMAGE_INFO_TABLE;
global $DEPLOYMENT_INFO_TABLE;
$event = new event();
// user/role authentication
if (!strstr($OPENQRM_USER->role, "administrator")) {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "image-action", "Un-Authorized access to image-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$image_command = $request->get('image_command');
$image_id = $request->get('image_id');
$image_name = $request->get('image_name');
$image_type = $request->get('image_type');
$image_fields = array();
foreach ($_REQUEST as $key => $value) {
    if (strncmp($key, "image_", 6) == 0) {
        $image_fields[$key] = $value;
    }
}
unset($image_fields["image_command"]);
$deployment_id = $request->get('deployment_id');
$deployment_name = $request->get('deployment_name');
Exemple #28
0
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
global $IMAGE_INFO_TABLE;
global $DEPLOYMENT_INFO_TABLE;
global $OPENQRM_SERVER_BASE_DIR;
$nfs_storage_command = $request->get('nfs_storage_command');
$nfs_image_name = $request->get('nfs_image_name');
// place for the storage stat files
$StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/nfs-storage/storage';
// global event for logging
$event = new event();
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "nfs-action", "Un-Authorized access to nfs-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$event->log("{$nfs_storage_command}", $_SERVER['REQUEST_TIME'], 5, "nfs-storage-action", "Processing nfs-storage command {$nfs_storage_command}", "", "", 0, 0, 0);
switch ($nfs_storage_command) {
    case 'get_storage':
        if (!file_exists($StorageDir)) {
            mkdir($StorageDir);
        }
        $filename = $StorageDir . "/" . $_POST['filename'];
        $filedata = base64_decode($_POST['filedata']);
        echo "<h1>{$filename}</h1>";
        $fout = fopen($filename, "wb");
        fwrite($fout, $filedata);
        fclose($fout);
        break;
Exemple #29
0
require_once "{$RootDir}/class/openqrm_server.class.php";
// filter inputs
require_once $RootDir . '/class/htmlobjects/htmlobject.class.php';
require_once $RootDir . '/include/requestfilter.inc.php';
$html = new htmlobject($RootDir . '/class/htmlobjects/');
$request = $html->request();
$request->filter = $requestfilter;
global $IMAGE_INFO_TABLE;
global $DEPLOYMENT_INFO_TABLE;
global $OPENQRM_SERVER_BASE_DIR;
// get params
$lcmc_command = $request->get('lcmc_command');
$lcmc_resource_id = $request->get('resource_id');
$lcmc_resource_ip = $request->get('resource_ip');
// get event + openQRM server
$event = new event();
$openqrm_server = new openqrm_server();
$OPENQRM_SERVER_IP_ADDRESS = $openqrm_server->get_ip_address();
global $OPENQRM_SERVER_IP_ADDRESS;
global $event;
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "lcmc-action", "Un-Authorized access to lcmc-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
$event->log("{$lcmc_command}", $_SERVER['REQUEST_TIME'], 5, "lcmc-action", "Processing lcmc command {$lcmc_command}", "", "", 0, 0, 0);
switch ($lcmc_command) {
    default:
        $event->log("{$lcmc_command}", $_SERVER['REQUEST_TIME'], 3, "lcmc-action", "No such lcmc command ({$lcmc_command})", "", "", 0, 0, 0);
        break;
}
Exemple #30
0
$StorageDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/kvm/storage';
// place for the kvm_server stat files
$KvmDir = $_SERVER["DOCUMENT_ROOT"] . '/openqrm/base/plugins/kvm/kvm-stat';
// get params
$lvm_command = $request->get('lvm_command');
$kvm_server_command = $request->get('kvm_server_command');
$kvm_server_id = $request->get('kvm_server_id');
if (!strlen($lvm_command)) {
    $lvm_command = $kvm_server_command;
}
$kvm_image_name = $request->get('kvm_image_name');
// global event for logging
$event = new event();
// user/role authentication
if ($OPENQRM_USER->role != "administrator") {
    $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "lvm-action", "Un-Authorized access to lvm-actions from {$OPENQRM_USER->name}", "", "", 0, 0, 0);
    exit;
}
// $event->log("$lvm_command", $_SERVER['REQUEST_TIME'], 5, "kvm-action", "Processing kvm command $lvm_command", "", "", 0, 0, 0);
switch ($lvm_command) {
    // storage commands
    case 'get':
        if (!file_exists($StorageDir)) {
            mkdir($StorageDir);
        }
        $filename = $StorageDir . "/" . $_POST['filename'];
        $filedata = base64_decode($_POST['filedata']);
        echo "<h1>{$filename}</h1>";
        $fout = fopen($filename, "wb");
        fwrite($fout, $filedata);
        fclose($fout);