One of the best recent pieces about our Middle Eastern quagmire is Peter Van Buren's What has Worked Against ISIS? Nothing, in RealClear Politics. He details the successive failures - a decade of boots on the ground in Iraq and Afghanistan, trillions of dollars wasted trying to train indigenous armies, ineffective but very expensive airstrikes, handpicked US-backed presidents in Iraq and Afghanistan who have turned out to be disasters, etc, etc, etc. Nothing we have tried has worked, and yet presidential candidates - Republican and Democratic alike - keep proposing more of the same.
His conclusion, I suspect, is correct. There is nothing we can do to help the situation, and our continuing involvement is just exacerbating the problems and wasting US lives and money. This is a complex cultural war in the Middle East that simply has to play out. In the end the national borders will probably be different (since, after all, the current borders were drawn arbitrarily by Western powers with no regard at all to local tribal or ethnic affiliations), most of the nations will probably have illiberal governments, and they will continue to sell oil on the world market, irrespective of who runs the countries, because they will need the revenue.
Will they be a threat to us when everything settles out? Not much. A few jihadists radicalized over the web may still occasionally kill a few Americans, but thus far statistically an American is more likely to killed by a nutty Christian anti-abortionist or a disgruntled postal service employee than by a Muslim jihadist. And a thousand times more likely to be killed by a drunk driver.
This piece is worth reading to keep some perspective on the problem, since presidential candidates in both parties seem to be thoroughly unrealistic on this issue.