示例#1
0
                    $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
    echo htmlentities($e->GetMessage(), ENT_QUOTES, 'utf-8');
    IssueLog::Error($e->getMessage());
}
示例#2
0
             $sMySQLBinDir = utils::ReadParam('mysql_bindir', '', false, 'raw_data');
             $sDBHost = utils::ReadParam('db_host', '', false, 'raw_data');
             $sDBUser = utils::ReadParam('db_user', '', false, 'raw_data');
             $sDBPwd = utils::ReadParam('db_pwd', '', false, 'raw_data');
             $sDBName = utils::ReadParam('db_name', '', false, 'raw_data');
             $sDBSubName = utils::ReadParam('db_subname', '', false, 'raw_data');
             $oDBRS = new DBRestore($sDBHost, $sDBUser, $sDBPwd, $sDBName, $sDBSubName);
             $oDBRS->SetMySQLBinDir($sMySQLBinDir);
             $sBackupDir = APPROOT . 'data/backups/';
             $sBackupFile = $sBackupDir . $sFile;
             $sRes = $oDBRS->RestoreFromZip($sBackupFile, $sEnvironment);
             IssueLog::Info('Backup Restore - Done, releasing the LOCK');
             $oRestoreMutex->Unlock();
         } catch (Exception $e) {
             $oRestoreMutex->Unlock();
             $oPage->p('Error: ' . $e->getMessage());
         }
     }
     $oPage->output();
     break;
 case 'download':
     require_once APPROOT . '/application/startup.inc.php';
     require_once APPROOT . '/application/loginwebpage.class.inc.php';
     LoginWebPage::DoLogin(true);
     // Check user rights and prompt if needed (must be admin)
     if (utils::GetConfig()->Get('demo_mode')) {
         throw new Exception('iTop is in demonstration mode: the feature is disabled');
     }
     $sFile = utils::ReadParam('file', '', false, 'raw_data');
     $oBackup = new DBBackupScheduled();
     $sBackupDir = APPROOT . 'data/backups/';
示例#3
0
 $sTextQualifier = utils::ReadParam('qualifier', '"', false, 'raw_data');
 $iLinesToSkip = utils::ReadParam('do_skip_lines', 0);
 $bFirstLineAsHeader = utils::ReadParam('header_line', false);
 $sData = stripslashes(utils::ReadParam('csvdata', '', false, 'raw_data'));
 $sClassName = utils::ReadParam('class_name', '');
 $bAdvanced = utils::ReadParam('advanced', false);
 $sEncoding = utils::ReadParam('encoding', 'UTF-8');
 $sInitFieldMapping = utils::ReadParam('init_field_mapping', '', false, 'raw_data');
 $sInitSearchField = utils::ReadParam('init_search_field', '', false, 'raw_data');
 $aInitFieldMapping = empty($sInitFieldMapping) ? array() : json_decode($sInitFieldMapping, true);
 $aInitSearchField = empty($sInitSearchField) ? array() : json_decode($sInitSearchField, true);
 $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier);
 $aData = $oCSVParser->ToArray($iLinesToSkip);
 $iTarget = count($aData);
 if ($iTarget == 0) {
     $oPage->p(Dict::S('UI:CSVImport:NoData'));
 } else {
     $oPage->add("<table>");
     $aFirstLine = $aData[0];
     // Use the first row to determine the number of columns
     $iStartLine = 0;
     $iNbColumns = count($aFirstLine);
     if ($bFirstLineAsHeader) {
         $iStartLine = 1;
         foreach ($aFirstLine as $sField) {
             $aHeader[] = $sField;
         }
     } else {
         // Build some conventional name for the fields: field1...fieldn
         $index = 1;
         foreach ($aFirstLine as $sField) {
示例#4
0
            ini_set('display_errors', true);
            ini_set('display_startup_errors', true);
            require_once APPROOT . '/setup/wizardcontroller.class.inc.php';
            require_once APPROOT . '/setup/wizardsteps.class.inc.php';
            $sClass = utils::ReadParam('step_class', '');
            $sState = utils::ReadParam('step_state', '');
            $sActionCode = utils::ReadParam('code', '');
            $aParams = utils::ReadParam('params', array(), false, 'raw_data');
            $oPage = new ajax_page('');
            $oDummyController = new WizardController('');
            if (is_subclass_of($sClass, 'WizardStep')) {
                $oStep = new $sClass($oDummyController, $sState);
                $sConfigFile = utils::GetConfigFilePath();
                if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig()) {
                    $oPage->error("<b>Error:</b> the configuration file '" . $sConfigFile . "' already exists and cannot be overwritten.");
                    $oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade " . ITOP_APPLICATION . ", make sure that the file '<b>" . realpath($sConfigFile) . "</b>' can be modified by the web server.");
                    $oPage->output();
                } else {
                    $oStep->AsyncAction($oPage, $sActionCode, $aParams);
                }
            }
            $oPage->output();
            break;
        default:
            throw new Exception("Error unsupported operation '{$sOperation}'");
    }
} catch (Exception $e) {
    header("HTTP/1.0 500 Internal server error.");
    echo "<p>An error happened while processing the installation:</p>\n";
    echo '<p>' . $e . "</p>\n";
    SetupPage::log_error("An error happened while processing the installation: " . $e);