They do not have any legal right to fire rockets from built up areas. Nor does Israel have any legal rights to use massive force against the same built up areas even if in response to rocket fire. In particular they do not have the right to use white phosphorous in such areas nor do they have the right to hit hospitals or ambulance depots or water sanitation plants or cement factories or to the use of defensive human shields. Indeed all the aforementioned are War Crimes along with Hamas rocket firing. To answer your last question. The No. 1 principle in international laws of war is the principle of distinction. Failing to distinguish between combatants and civilians is another war crime.
Man shot dead in northern Israel town of Bi'ina, police say the murder was gang related (Haaretz)
from the article: A license to kill