Section 12. The supreme judicial or superior court may restrain the construction, alteration, repair, maintenance or use of a building or structure in violation of any ordinance or by-law of a city or town or of the state building code and order its removal or abatement as a nuisance; and may restrain the further construction, alteration or repair, maintenance, use or occupancy of a building or structure reported to be dangerous, under a survey authorized by section eight, until the determination of the matter, as provided in section ten.