ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
svg-scanner.php File Reference

Go to the source code of this file.

Functions

 sysexit ( $results, $status)
 

Variables

global $argv
 
 $results
 
 $files_to_scan = $argv
 
if(empty( $files_to_scan)) $sanitizer = new enshrined\svgSanitize\Sanitizer()
 

Function Documentation

◆ sysexit()

sysexit (   $results,
  $status 
)

Definition at line 24 of file svg-scanner.php.

References $results, and exit.

27  {
28  echo json_encode(
29  $results,
30  JSON_PRETTY_PRINT
31  );
32 
33  exit( $status );
34 }
35 
36 
37 /*
38  * Main part begins
39  */
40 
41 global $argv;
42 
43 /*
44  * Set up results array, to
45  * be printed on exit.
46  */
47 $results = array(
48  'totals' => array(
49  'errors' => 0,
50  ),
51 
52  'files' => array(
53  ),
54 );
55 
56 
57 /*
58  * Catch files to scan from $argv.
59  */
60 
62 unset( $files_to_scan[0] );
63 
64 $files_to_scan = array_values(
66 );
67 
68 /*
69  * Catch no file specified.
70  */
71 
72 if ( empty( $files_to_scan ) ) {
73  $results['totals']['errors']++;
74  $results['messages'] = array(
75  array( 'No files to scan specified' ),
76  );
77 
78  sysexit(
79  $results,
80  1
81  );
82 }
83 
84 /*
85  * Initialize the SVG scanner.
86  *
87  * Make sure to allow custom attributes,
88  * and to remove remote references.
89  */
91 
92 $sanitizer->removeRemoteReferences( true );
93 
94 /*
95  * Scan each file specified to be scanned.
96  */
97 
98 foreach( $files_to_scan as $file_name ) {
99  /*
100  * Read SVG file.
101  */
102  $svg_file = @file_get_contents( $file_name );
103 
104  /*
105  * If not found, report that and continue.
106  */
107  if ( false === $svg_file ) {
108  $results['totals']['errors']++;
109 
110  $results['files'][ $file_name ][] = array(
111  'errors' => 1,
112  'messages' => array(
113  array(
114  'message' => 'File specified could not be read (' . $file_name . ')',
115  'line' => null,
116  ),
117  ),
118  );
119 
120  continue;
121  }
122 
123  /*
124  * Sanitize file and get issues found.
125  */
126  $sanitize_status = $sanitizer->sanitize( $svg_file );
127 
128  $xml_issues = $sanitizer->getXmlIssues();
129 
130  /*
131  * If we find no issues, simply note that.
132  */
133  if ( empty( $xml_issues ) && ( false !== $sanitize_status ) ) {
134  $results['files'][ $file_name ] = array(
135  'errors' => 0,
136  'messages' => array()
137  );
138  }
139 
140  /*
141  * Could not sanitize the file.
142  */
143  else if (
144  ( '' === $sanitize_status ) ||
145  ( false === $sanitize_status )
146  ) {
147  $results['totals']['errors']++;
148 
149  $results['files'][ $file_name ] = array(
150  'errors' => 1,
151  'messages' => array(
152  array(
153  'message' => 'Unable to sanitize file \'' . $file_name . '\'' ,
154  'line' => null,
155  )
156  ),
157  );
158  }
159 
160  /*
161  * If we find issues, note it and update statistics.
162  */
163 
164  else {
165  $results['totals']['errors'] += count( $xml_issues );
166 
167  $results['files'][ $file_name ] = array(
168  'errors' => count( $xml_issues ),
169  'messages' => $xml_issues,
170  );
171  }
172 
173  unset( $svg_file );
174  unset( $xml_issues );
175  unset( $sanitize_status );
176 }
global $argv
Definition: svg-scanner.php:41
$files_to_scan
Definition: svg-scanner.php:61
if(empty( $files_to_scan)) $sanitizer
Definition: svg-scanner.php:90
sysexit( $results, $status)
Definition: svg-scanner.php:24
exit
Definition: backend.php:16
$results
Definition: svg-scanner.php:47

Variable Documentation

◆ $argv

global $argv

Definition at line 41 of file svg-scanner.php.

Referenced by Enviro\initialize(), and showHelp().

◆ $files_to_scan

$files_to_scan = $argv

Definition at line 61 of file svg-scanner.php.

◆ $results

$results
Initial value:
= array(
'totals' => array(
'errors' => 0,
),
'files' => array(
),
)

Definition at line 47 of file svg-scanner.php.

Referenced by SAML2\ArtifactResolve\__construct(), ilObjLearningModuleAccess\_getCommands(), phpseclib\Net\SFTP\Stream\_stream_stat(), phpseclib\Net\SFTP\Stream\_url_stat(), sspmod_statistics_Aggregator\aggregate(), ilTestPlayerAbstractGUI\archiveParticipantSubmission(), ilTestSubmissionReviewGUI\buildUserReviewOutput(), assFormulaQuestionResult\calculateFormula(), ilContainerAccess\canBeDelivered(), ilObjBlogAccess\canBeDelivered(), ilObjectAccess\canBeDelivered(), ilObjExerciseAccess\canBeDelivered(), ilObjPollAccess\canBeDelivered(), ilPortfolioAccessHandler\canBeDelivered(), ilParticipantsTestResultsGUI\createUserResults(), ilObjectTileImage\delete(), ilSurveySkill\determineSkillLevelsForAppraisee(), ilSurveyEvaluationGUI\evaluation(), sspmod_core_Storage_SQLPermanentStorage\exists(), ilSCORM2004Asset\exportPDF(), ilObjSCORM2004LearningModule\exportPDF(), ilNotificationDatabaseHandler\fillPlaceholders(), ilSurveyResultsUserTableGUI\fillRow(), assFormulaQuestionResult\findValidRandomVariables(), sspmod_core_Storage_SQLPermanentStorage\get(), ilObjTest\getAggregatedResultsData(), ilObjTest\getAllTestResults(), Sabre\CalDAV\Backend\AbstractBackend\getCalendarObjectByUID(), ilBasicSkill\getCommonSkillIdForImportId(), ilObjTest\getCustomStyles(), ilObjTest\getDetailedTestResults(), sspmod_core_Storage_SQLPermanentStorage\getKeys(), ilChatroom\getLastMessages(), ilBasicSkill\getLevelIdForImportId(), sspmod_core_Storage_SQLPermanentStorage\getList(), PhpOffice\PhpSpreadsheet\Collection\Memory\getMultiple(), assFormulaQuestionResult\getReachedPoints(), ilDatabaseAtomRunTest\getResultFromDB(), assFormulaQuestionResult\getResultInfo(), SurveyMatrixQuestionEvaluation\getResults(), SurveyQuestionEvaluation\getResults(), ilObjTest\getTestResult(), ilDclTokenizer\getTokens(), ilTestService\getVirtualSequenceUserResults(), Sabre\CalDAV\Schedule\Plugin\handleFreeBusyRequest(), ilObjTestGUI\importVerifiedFileObject(), ilTestImporter\importXmlRepresentation(), ilObjPollGUI\initEditCustomForm(), ilObjSurveyGUI\initPropertiesForm(), sspmod_core_Storage_SQLPermanentStorage\insert(), assFormulaQuestionResult\isCorrect(), assFormulaQuestionGUI\isSaveCommand(), ilLOTestQuestionAdapter\lookupRelevantObjectiveIdsForTest(), ilLTIDataConnector\lookupResourcesForAllUsersSinceDate(), Sabre\DAVACL\Plugin\principalSearch(), ilAdvancedMDValues\queryForRecords(), arConnectorCache\read(), SAML2\SOAP\receive(), sspmod_core_Storage_SQLPermanentStorage\remove(), GuzzleHttp\Psr7\UriResolver\removeDotSegments(), ilTestArchiveService\renderOverviewContent(), SimpleSAML_Auth_LDAP\searchformultiple(), ilDclRecordEditGUI\searchObjects(), ilObjectCopyGUI\searchSource(), phpseclib\File\X509\setDN(), assFormulaQuestionTest\simpleRatedCalculationsData(), statistics_hook_cron(), sspmod_statistics_Aggregator\store(), assFormulaQuestionResult\substituteFormula(), assFormulaQuestionResult\suggestRange(), sysexit(), ilUserCertificateRepositoryTest\testFetchActiveCertificatesByType(), ilUserCertificateRepositoryTest\testFetchAllActiveCertificateForUser(), ilUserCertificateRepositoryTest\testFetchObjectWithCertificateForUser(), ilUserCertificateRepositoryTest\testFetchUserIdsWithCertificateForObject(), Sabre\CalDAV\Backend\AbstractPDOTest\testSchedulingMethods(), sspmod_core_Storage_SQLPermanentStorage\update(), Sabre\CardDAV\Plugin\validateFilters(), and SAML2\Utils\xpQuery().

◆ $sanitizer