Esempio n. 1
0
function InteractiveShell($sExpression, $sQueryId, $sFormat, $sFileName, $sMode)
{
    if ($sMode == 'dialog') {
        $oP = new ajax_page('');
        $oP->add('<div id="interactive_export_dlg">');
        $sExportBtnLabel = json_encode(Dict::S('UI:Button:Export'));
        $sJSTitle = json_encode(htmlentities(utils::ReadParam('dialog_title', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8'));
        $oP->add_ready_script(<<<EOF
\t\t\$('#interactive_export_dlg').dialog({
\t\t\tautoOpen: true,
\t\t\tmodal: true,
\t\t\twidth: '80%',
\t\t\ttitle: {$sJSTitle},
\t\t\tclose: function() { \$('#export-form').attr('data-state', 'cancelled'); \$(this).remove(); },
\t\t\tbuttons: [
\t\t\t\t{text: {$sExportBtnLabel}, id: 'export-dlg-submit', click: function() {} }
\t\t\t]
\t\t});
\t\t\t
\t\tsetTimeout(function() { \$('#interactive_export_dlg').dialog('option', { position: { my: "center", at: "center", of: window }}); \$('#export-btn').hide(); ExportInitButton('#export-dlg-submit'); }, 100);
EOF
);
    } else {
        $oP = new iTopWebPage('iTop Export');
    }
    if ($sExpression === null) {
        // No expression supplied, let's check if phrasebook entry is given
        if ($sQueryId !== null) {
            $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId));
            $oQueries = new DBObjectSet($oSearch);
            if ($oQueries->Count() > 0) {
                $oQuery = $oQueries->Fetch();
                $sExpression = $oQuery->Get('oql');
                $sFields = trim($oQuery->Get('fields'));
            } else {
                ReportErrorAndExit("Invalid query phrasebook identifier: '{$sQueryId}'");
            }
        } else {
            if (utils::IsModeCLI()) {
                Usage();
                ReportErrorAndExit("No expression or query phrasebook identifier supplied.");
            } else {
                // form to enter an OQL query or pick a query phrasebook identifier
                DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat);
                $oP->output();
                exit;
            }
        }
    }
    if ($sFormat !== null) {
        $oExporter = BulkExport::FindExporter($sFormat);
        if ($oExporter === null) {
            $aSupportedFormats = BulkExport::FindSupportedFormats();
            ReportErrorAndExit("Invalid output format: '{$sFormat}'. The supported formats are: " . implode(', ', array_keys($aSupportedFormats)));
        } else {
            DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat);
        }
    } else {
        DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat);
    }
    if ($sMode == 'dialog') {
        $oP->add('</div>');
    }
    $oP->output();
}
Esempio n. 2
0
                    $oAttachment->Set('expire', time() + 3600);
                    // one hour...
                    $oAttachment->Set('temp_id', $sTempId);
                    $oAttachment->Set('item_class', $sObjClass);
                    $oAttachment->SetDefaultOrgId();
                    $oAttachment->Set('contents', $oDoc);
                    $iAttId = $oAttachment->DBInsert();
                    $aResult['msg'] = $oDoc->GetFileName();
                    $aResult['icon'] = utils::GetAbsoluteUrlAppRoot() . AttachmentPlugIn::GetFileIcon($oDoc->GetFileName());
                    $aResult['att_id'] = $iAttId;
                    $aResult['preview'] = $oDoc->IsPreviewAvailable() ? 'true' : 'false';
                } catch (FileUploadException $e) {
                    $aResult['error'] = $e->GetMessage();
                }
            }
            $oPage->add(json_encode($aResult));
            break;
        case 'remove':
            $iAttachmentId = utils::ReadParam('att_id', '');
            $oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE id = :id");
            $oSet = new DBObjectSet($oSearch, array(), array('id' => $iAttachmentId));
            while ($oAttachment = $oSet->Fetch()) {
                $oAttachment->DBDelete();
            }
            break;
        default:
            $oPage->p("Missing argument 'operation'");
    }
    $oPage->output();
} catch (Exception $e) {
    // note: transform to cope with XSS attacks
Esempio n. 3
0
                            $aHeaders = array(0 => explode(',', $sResult));
                            // comma is the default separator
                            $writer->writeSheet($aHeaders, $sClassDisplayName, array());
                            $oPage->add($writer->writeToString());
                            break;
                        case 'csv':
                        default:
                            $oPage = new CSVPage("");
                            $oPage->add_header("Content-type: text/csv; charset=utf-8");
                            $oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\"");
                            $oPage->no_cache();
                            $oPage->add($sResult);
                    }
                } else {
                    $oPage = new ajax_page("");
                    $oPage->no_cache();
                    $oPage->add('<p style="text-align:center">');
                    $oPage->add('<div style="display:inline-block;margin:0.5em;"><a style="text-decoration:none" href="' . utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&class_name=' . $sClassName . '"><img border="0" src="../images/csv.png"><br/>' . $sClassDisplayName . '.csv</a></div>');
                    $oPage->add('<div style="display:inline-block;margin:0.5em;"><a style="text-decoration:none" href="' . utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&format=xlsx&class_name=' . $sClassName . '"><img border="0" src="../images/xlsx.png"><br/>' . $sClassDisplayName . '.xlsx</a></div>');
                    $oPage->add('</p>');
                    $oPage->add('<p><textarea rows="5" cols="100">' . $sResult . '</textarea></p>');
                }
            } else {
                $oPage = new ajax_page("Class {$sClassName} is not a valid class !");
            }
            break;
    }
    $oPage->output();
} catch (Exception $e) {
    IssueLog::Error($e->getMessage());
}
Esempio n. 4
0
    $sRelation = 'impacts';
}
try {
    if ($id != 0) {
        switch ($sFormat) {
            case 'html':
                $oPage->SetContentType('text/html');
                $oObj = MetaModel::GetObject($sClass, $id, true);
                $aResults = array();
                $iMaxRecursionDepth = MetaModel::GetConfig()->Get('relations_max_depth', 20);
                $oObj->GetRelatedObjects($sRelation, $iMaxRecursionDepth, $aResults);
                $iBlock = 1;
                // Zero is not a valid blockid
                foreach ($aResults as $sClass => $aObjects) {
                    $oSet = CMDBObjectSet::FromArray($sClass, $aObjects);
                    $oPage->add("<h1>" . MetaModel::GetRelationDescription($sRelation) . ' ' . $oObj->GetName() . "</h1>\n");
                    $oPage->add("<div class=\"page_header\">\n");
                    $oPage->add("<h2>" . MetaModel::GetClassIcon($sClass) . "&nbsp;<span class=\"hilite\">" . Dict::Format('UI:Search:Count_ObjectsOf_Class_Found', count($aObjects), Metamodel::GetName($sClass)) . "</h2>\n");
                    $oPage->add("</div>\n");
                    $oBlock = DisplayBlock::FromObjectSet($oSet, 'list');
                    $oBlock->Display($oPage, $iBlock++);
                    $oPage->P('&nbsp;');
                    // Some space ?
                }
                break;
            case 'xml':
            default:
                $oPage->SetContentType('text/xml');
                $oObj = MetaModel::GetObject($sClass, $id, true);
                // Build the root XML part
                $oXmlDoc = new DOMDocument('1.0', 'UTF-8');
Esempio n. 5
0
    $oResult = new RestResult();
    if ($e->GetCode() == 0) {
        $oResult->code = RestResult::INTERNAL_ERROR;
    } else {
        $oResult->code = $e->GetCode();
    }
    $oResult->message = "Error: " . $e->GetMessage();
}
// Output the results
//
$sResponse = json_encode($oResult);
$oP->add_header('Access-Control-Allow-Origin: *');
$sCallback = utils::ReadParam('callback', null);
if ($sCallback == null) {
    $oP->SetContentType('application/json');
    $oP->add($sResponse);
} else {
    $oP->SetContentType('application/javascript');
    $oP->add($sCallback . '(' . $sResponse . ')');
}
$oP->Output();
// Log usage
//
if (MetaModel::GetConfig()->Get('log_rest_service')) {
    $oLog = new EventRestService();
    $oLog->SetTrim('userinfo', UserRights::GetUser());
    $oLog->Set('version', $sVersion);
    $oLog->Set('operation', $sOperation);
    $oLog->SetTrim('json_input', $sJsonString);
    $oLog->Set('provider', $sProvider);
    $sMessage = $oResult->message;
Esempio n. 6
0
     } else {
         $oPage->p(Dict::S('bkp-restore-running'));
     }
     $oPage->output();
     break;
 case 'restore_exec':
     require_once APPROOT . "setup/runtimeenv.class.inc.php";
     require_once APPROOT . '/application/utils.inc.php';
     require_once APPROOT . '/setup/backup.class.inc.php';
     require_once dirname(__FILE__) . '/dbrestore.class.inc.php';
     IssueLog::Enable(APPROOT . 'log/error.log');
     $oPage = new ajax_page("");
     $oPage->no_cache();
     $oPage->SetContentType('text/html');
     if (utils::GetConfig()->Get('demo_mode')) {
         $oPage->add("<div data-error-stimulus=\"Error\">Sorry, iTop is in <b>demonstration mode</b>: the feature is disabled.</div>");
     } else {
         $sEnvironment = utils::ReadParam('environment', 'production', false, 'raw_data');
         $oRestoreMutex = new iTopMutex('restore.' . $sEnvironment);
         IssueLog::Info("Backup Restore - Acquiring the LOCK 'restore.{$sEnvironment}'");
         $oRestoreMutex->Lock();
         IssueLog::Info('Backup Restore - LOCK acquired, executing...');
         try {
             set_time_limit(0);
             // Get the file and destroy the token (single usage)
             $sToken = utils::ReadParam('token', '', false, 'raw_data');
             $sTokenFile = APPROOT . '/data/restore.' . $sToken . '.tok';
             if (!is_file($sTokenFile)) {
                 throw new Exception("Error: missing token file: '{$sTokenFile}'");
             }
             $sFile = file_get_contents($sTokenFile);
Esempio n. 7
0
                 cmdbAbstractObject::DisplaySetAsXML($oP, $oSet, array('localize_values' => $bLocalize));
                 break;
             case 'xlsx':
                 $oP = new ajax_page('');
                 $oExporter = new ExcelExporter();
                 $oExporter->SetObjectList($oFilter);
                 // Run the export by chunk of 1000 objects to limit memory usage
                 $oExporter->SetChunkSize(1000);
                 do {
                     $aStatus = $oExporter->Run();
                     // process one chunk
                 } while ($aStatus['code'] != 'done' && $aStatus['code'] != 'error');
                 if ($aStatus['code'] == 'done') {
                     $oP->SetContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                     $oP->SetContentDisposition('attachment', $oFilter->GetClass() . '.xlsx');
                     $oP->add(file_get_contents($oExporter->GetExcelFilePath()));
                     $oExporter->Cleanup();
                 } else {
                     $oP->add('Error, xlsx export failed: ' . $aStatus['message']);
                 }
                 break;
             default:
                 $oP = new WebPage("iTop - Export");
                 $oP->add("Unsupported format '{$sFormat}'. Possible values are: html, csv, spreadsheet or xml.");
         }
     }
 } catch (Exception $e) {
     $oP = new WebPage("iTop - Export");
     $oP->p("Error the query can not be executed.");
     if ($e instanceof CoreException) {
         $oP->p($e->GetHtmlDesc());
Esempio n. 8
0
 /**
  * Helper to download the file directly from the browser	
  */
 public function DownloadBackup($sFile)
 {
     $oP = new ajax_page('backup');
     $oP->SetContentType("multipart/x-zip");
     $oP->SetContentDisposition('inline', basename($sFile));
     $oP->add(file_get_contents($sFile));
     $oP->output();
 }
Esempio n. 9
0
            $oResult->AddOperation($sVerb, $aOpData['description'], get_class($aOpData['service_provider']));
        }
    } else {
        if (!array_key_exists($sOperation, $aOpToRestService)) {
            throw new Exception("Unknown verb '{$sOperation}' in version '{$sVersion}'", RestResult::UNKNOWN_OPERATION);
        }
        $oRS = $aOpToRestService[$sOperation]['service_provider'];
        CMDBObject::SetTrackOrigin('webservice-rest');
        $oResult = $oRS->ExecOperation($sVersion, $sOperation, $aJsonData);
    }
} catch (Exception $e) {
    $oResult = new RestResult();
    if ($e->GetCode() == 0) {
        $oResult->code = RestResult::INTERNAL_ERROR;
    } else {
        $oResult->code = $e->GetCode();
    }
    $oResult->message = "Error: " . $e->GetMessage();
}
// Output the results
//
$oP->add_header('Access-Control-Allow-Origin: *');
$sCallback = utils::ReadParam('callback', null);
if ($sCallback == null) {
    $oP->SetContentType('application/json');
    $oP->add(json_encode($oResult));
} else {
    $oP->SetContentType('application/javascript');
    $oP->add($sCallback . '(' . json_encode($oResult) . ')');
}
$oP->Output();
Esempio n. 10
0
         }
     }
     if ($operation == 'relation_attachment') {
         $sObjClass = utils::ReadParam('obj_class', '', false, 'class');
         $iObjKey = (int) utils::ReadParam('obj_key', 0, false, 'integer');
         // Save the generated PDF as an attachment
         $sPDF = $oPage->get_pdf();
         $oPage = new ajax_page('');
         $oAttachment = new Attachment();
         $oAttachment->Set('item_class', $sObjClass);
         $oAttachment->Set('item_id', $iObjKey);
         $oDoc = new ormDocument($sPDF, 'application/pdf', $sTitle . '.pdf');
         $oAttachment->Set('contents', $oDoc);
         $iAttachmentId = $oAttachment->DBInsert();
         $aRet = array('status' => 'ok', 'att_id' => $iAttachmentId);
         $oPage->add(json_encode($aRet));
     }
     break;
 case 'relation_json':
     require_once APPROOT . 'core/simplegraph.class.inc.php';
     require_once APPROOT . 'core/relationgraph.class.inc.php';
     require_once APPROOT . 'core/displayablegraph.class.inc.php';
     $sRelation = utils::ReadParam('relation', 'impacts');
     $sDirection = utils::ReadParam('direction', 'down');
     $iGroupingThreshold = utils::ReadParam('g', 5);
     $sPositions = utils::ReadParam('positions', null, false, 'raw_data');
     $aExcludedClasses = utils::ReadParam('excluded_classes', array(), false, 'raw_data');
     $aContexts = utils::ReadParam('contexts', array(), false, 'raw_data');
     $sContextKey = utils::ReadParam('context_key', array(), false, 'raw_data');
     $aPositions = null;
     if ($sPositions != null) {
Esempio n. 11
0
         }
     }
     if ($operation == 'relation_attachment') {
         $sObjClass = utils::ReadParam('obj_class', '', false, 'class');
         $iObjKey = (int) utils::ReadParam('obj_key', 0, false, 'integer');
         // Save the generated PDF as an attachment
         $sPDF = $oPage->get_pdf();
         $oPage = new ajax_page('');
         $oAttachment = new Attachment();
         $oAttachment->Set('item_class', $sObjClass);
         $oAttachment->Set('item_id', $iObjKey);
         $oDoc = new ormDocument($sPDF, 'application/pdf', $sTitle . '.pdf');
         $oAttachment->Set('contents', $oDoc);
         $iAttachmentId = $oAttachment->DBInsert();
         $aRet = array('status' => 'ok', 'att_id' => $iAttachmentId);
         $oPage->add(json_encode($aRet));
     }
     break;
 case 'relation_json':
     require_once APPROOT . 'core/simplegraph.class.inc.php';
     require_once APPROOT . 'core/relationgraph.class.inc.php';
     require_once APPROOT . 'core/displayablegraph.class.inc.php';
     $sRelation = utils::ReadParam('relation', 'impacts');
     $sDirection = utils::ReadParam('direction', 'down');
     $iGroupingThreshold = utils::ReadParam('g', 5);
     $sPositions = utils::ReadParam('positions', null, false, 'raw_data');
     $aExcludedClasses = utils::ReadParam('excluded_classes', array(), false, 'raw_data');
     $aContexts = utils::ReadParam('contexts', array(), false, 'raw_data');
     $sContextKey = utils::ReadParam('context_key', array(), false, 'raw_data');
     $aPositions = null;
     if ($sPositions != null) {